22 |
wxImageFromStream, wxBITMAP_TYPE_BMP |
wxImageFromStream, wxBITMAP_TYPE_BMP |
23 |
|
|
24 |
from wxproj import draw_polygon_shape, draw_polygon_init |
from wxproj import draw_polygon_shape, draw_polygon_init |
|
from gdalwarp import ProjectRasterFile |
|
25 |
|
|
26 |
from Thuban.UI.common import Color2wxColour |
from Thuban.UI.common import Color2wxColour |
27 |
from Thuban.UI.classifier import ClassDataPreviewer |
from Thuban.UI.classifier import ClassDataPreviewer |
33 |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
34 |
|
|
35 |
from Thuban.Model.classification import Classification |
from Thuban.Model.classification import Classification |
36 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Transparent |
37 |
import Thuban.Model.resource |
import Thuban.Model.resource |
38 |
|
|
39 |
|
if Thuban.Model.resource.has_gdal_support(): |
40 |
|
from gdalwarp import ProjectRasterFile |
41 |
|
|
42 |
class MapRenderer: |
class MapRenderer: |
43 |
|
|
44 |
"""Class to render a map onto a wxDC""" |
"""Class to render a map onto a wxDC""" |
85 |
# and only begin drawing layers once we have drawn it. |
# and only begin drawing layers once we have drawn it. |
86 |
# That way we avoid drawing layers that won't be seen. |
# That way we avoid drawing layers that won't be seen. |
87 |
# |
# |
88 |
for layer in map.Layers(): |
if Thuban.Model.resource.has_gdal_support(): |
89 |
if isinstance(layer, RasterLayer) and layer.Visible(): |
for layer in map.Layers(): |
90 |
seenRaster = False |
if isinstance(layer, RasterLayer) and layer.Visible(): |
91 |
break |
seenRaster = False |
92 |
|
break |
93 |
|
|
94 |
for layer in map.Layers(): |
for layer in map.Layers(): |
95 |
# if honor_visibility is true, only draw visible layers, |
# if honor_visibility is true, only draw visible layers, |
132 |
else: |
else: |
133 |
draw_func = lambda i: \ |
draw_func = lambda i: \ |
134 |
self.draw_polygon_shape(polygon_render_param, i, pen, brush) |
self.draw_polygon_shape(polygon_render_param, i, pen, brush) |
135 |
|
|
136 |
|
table = layer.ShapeStore().Table() |
137 |
for i in self.layer_ids(layer): |
for i in self.layer_ids(layer): |
138 |
|
|
139 |
if field is None: |
if field is None: |
140 |
group = defaultGroup |
group = defaultGroup |
141 |
else: |
else: |
142 |
record = layer.table.ReadRowAsDict(i) |
record = table.ReadRowAsDict(i) |
143 |
assert record is not None |
assert record is not None |
144 |
group = lc.FindGroup(record[field]) |
group = lc.FindGroup(record[field]) |
145 |
|
|
158 |
old_prop = prop |
old_prop = prop |
159 |
|
|
160 |
if shapetype == SHAPETYPE_ARC: |
if shapetype == SHAPETYPE_ARC: |
161 |
fill = Color.Transparent |
fill = Transparent |
162 |
else: |
else: |
163 |
fill = prop.GetFill() |
fill = prop.GetFill() |
164 |
|
|
165 |
|
|
166 |
if fill is Color.Transparent: |
if fill is Transparent: |
167 |
brush = wxTRANSPARENT_BRUSH |
brush = wxTRANSPARENT_BRUSH |
168 |
else: |
else: |
169 |
color = Color2wxColour(fill) |
color = Color2wxColour(fill) |
171 |
|
|
172 |
stroke = prop.GetLineColor() |
stroke = prop.GetLineColor() |
173 |
stroke_width = prop.GetLineWidth() |
stroke_width = prop.GetLineWidth() |
174 |
if stroke is Color.Transparent: |
if stroke is Transparent: |
175 |
pen = wxTRANSPARENT_PEN |
pen = wxTRANSPARENT_PEN |
176 |
else: |
else: |
177 |
color = Color2wxColour(stroke) |
color = Color2wxColour(stroke) |
236 |
def polygon_render_param(self, layer): |
def polygon_render_param(self, layer): |
237 |
"""Return the low-lever render parameter for the layer""" |
"""Return the low-lever render parameter for the layer""" |
238 |
offx, offy = self.offset |
offx, offy = self.offset |
239 |
return draw_polygon_init(layer.shapefile, self.dc, |
return draw_polygon_init(layer.ShapeStore().Shapefile(), self.dc, |
240 |
self.map.projection, |
self.map.projection, |
241 |
layer.projection, |
layer.projection, |
242 |
self.scale, -self.scale, |
self.scale, -self.scale, |
515 |
# Render the legend |
# Render the legend |
516 |
dc.SetTextForeground(wxBLACK) |
dc.SetTextForeground(wxBLACK) |
517 |
if map.HasLayers(): |
if map.HasLayers(): |
518 |
for l in map.Layers(): |
layers = map.Layers() |
519 |
|
layers.reverse() |
520 |
|
for l in layers: |
521 |
if l.Visible(): |
if l.Visible(): |
522 |
# Render title |
# Render title |
523 |
dc.DrawText(l.Title(), posx, posy) |
dc.DrawText(l.Title(), posx, posy) |
524 |
posy+=stepy |
posy+=stepy |
525 |
# Render classification |
if l.HasClassification(): |
526 |
clazz = l.GetClassification() |
# Render classification |
527 |
shapeType = l.ShapeType() |
clazz = l.GetClassification() |
528 |
for g in clazz: |
shapeType = l.ShapeType() |
529 |
if g.IsVisible(): |
for g in clazz: |
530 |
previewer.Draw(dc, |
if g.IsVisible(): |
531 |
wxRect(posx+dx, posy, iconwidth, iconheight), |
previewer.Draw(dc, |
532 |
g.GetProperties(), shapeType) |
wxRect(posx+dx, posy, |
533 |
dc.DrawText(g.GetDisplayText(), |
iconwidth, iconheight), |
534 |
posx+2*dx+iconwidth, posy) |
g.GetProperties(), shapeType) |
535 |
posy+=stepy |
dc.DrawText(g.GetDisplayText(), |
536 |
|
posx+2*dx+iconwidth, posy) |
537 |
|
posy+=stepy |
538 |
|
|
539 |
def render_scalebar(self, map): |
def render_scalebar(self, map): |
540 |
"""Render the scalebar.""" |
"""Render the scalebar.""" |