12 |
wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \ |
wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \ |
13 |
wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL |
wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL |
14 |
|
|
15 |
from wxproj import draw_polygon_shape |
from wxproj import draw_polygon_shape, draw_polygon_init |
16 |
|
|
17 |
from Thuban import _ |
from Thuban import _ |
18 |
from Thuban.UI.common import * |
from Thuban.UI.common import * |
25 |
from Thuban.Model.classification import Classification |
from Thuban.Model.classification import Classification |
26 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
27 |
|
|
28 |
|
import time |
29 |
|
|
30 |
|
|
31 |
class MapRenderer: |
class MapRenderer: |
32 |
|
|
51 |
""" |
""" |
52 |
# resolution in pixel/inch |
# resolution in pixel/inch |
53 |
|
|
54 |
assert(scale > 0) |
assert scale > 0 |
55 |
|
|
56 |
self.dc = dc |
self.dc = dc |
57 |
self.scale = scale |
self.scale = scale |
87 |
lc = layer.GetClassification() |
lc = layer.GetClassification() |
88 |
field = lc.GetField() |
field = lc.GetField() |
89 |
|
|
90 |
defaultProps = lc.GetDefaultGroup().GetProperties() |
#print "drawing layer: ", layer.Title(), |
91 |
|
#start = time.clock() |
92 |
|
#count = 0 |
93 |
|
|
94 |
|
if shapetype != SHAPETYPE_POINT: |
95 |
|
offx, offy = self.offset |
96 |
|
draw_polygon_init(layer.shapefile.cobject(), |
97 |
|
self.dc, |
98 |
|
self.map.projection, layer.projection, |
99 |
|
self.scale, -self.scale, offx, offy) |
100 |
|
|
101 |
for i in self.layer_ids(layer): |
for i in self.layer_ids(layer): |
102 |
value = None |
value = None |
114 |
# be null, at which point this call will |
# be null, at which point this call will |
115 |
# at least retreive the NullData |
# at least retreive the NullData |
116 |
# |
# |
117 |
prop = lc.GetProperties(value) |
|
118 |
|
group = lc.FindGroup(value) |
119 |
|
|
120 |
|
#prop = lc.GetProperties(value) |
121 |
else: |
else: |
122 |
prop = defaultProps |
group = lc.GetDefaultGroup() |
123 |
|
|
124 |
|
|
125 |
|
if not group.IsVisible(): |
126 |
|
continue |
127 |
|
|
128 |
|
prop = group.GetProperties() |
129 |
|
|
130 |
# don't recreate new objects if they are the same as before |
# don't recreate new objects if they are the same as before |
131 |
if prop != old_prop: |
if prop != old_prop: |
132 |
old_prop = prop |
old_prop = prop |
133 |
|
|
134 |
if shapetype == SHAPETYPE_ARC: |
if shapetype == SHAPETYPE_ARC: |
135 |
fill = Color.None |
fill = Color.Transparent |
136 |
else: |
else: |
137 |
fill = prop.GetFill() |
fill = prop.GetFill() |
138 |
|
|
139 |
|
|
140 |
if fill is Color.None: |
if fill is Color.Transparent: |
141 |
brush = wxTRANSPARENT_BRUSH |
brush = wxTRANSPARENT_BRUSH |
142 |
else: |
else: |
143 |
color = Color2wxColour(fill) |
color = Color2wxColour(fill) |
145 |
|
|
146 |
stroke = prop.GetLineColor() |
stroke = prop.GetLineColor() |
147 |
stroke_width = prop.GetLineWidth() |
stroke_width = prop.GetLineWidth() |
148 |
if stroke is Color.None: |
if stroke is Color.Transparent: |
149 |
pen = wxTRANSPARENT_PEN |
pen = wxTRANSPARENT_PEN |
150 |
else: |
else: |
151 |
color = Color2wxColour(stroke) |
color = Color2wxColour(stroke) |
152 |
pen = wxPen(color, stroke_width, wxSOLID) |
pen = wxPen(color, stroke_width, wxSOLID) |
153 |
|
|
|
if shapetype == SHAPETYPE_POINT: |
|
154 |
self.dc.SetBrush(brush) |
self.dc.SetBrush(brush) |
155 |
self.dc.SetPen(pen) |
self.dc.SetPen(pen) |
156 |
|
|
157 |
|
if shapetype == SHAPETYPE_POINT: |
158 |
self.draw_point_shape(layer, i) |
self.draw_point_shape(layer, i) |
159 |
else: |
else: |
160 |
self.draw_polygon_shape(layer, i, pen, brush) |
self.draw_polygon_shape(layer, i, pen, brush) |
161 |
|
|
162 |
|
#count += 1 |
163 |
|
|
164 |
|
#end = time.clock() |
165 |
|
#print (end-start), "seconds -- ", count |
166 |
|
|
167 |
|
|
168 |
def layer_ids(self, layer): |
def layer_ids(self, layer): |
169 |
"""Return the shape ids of the given layer that have to be drawn. |
"""Return the shape ids of the given layer that have to be drawn. |
170 |
|
|
174 |
return range(layer.NumShapes()) |
return range(layer.NumShapes()) |
175 |
|
|
176 |
def draw_polygon_shape(self, layer, index, pen, brush): |
def draw_polygon_shape(self, layer, index, pen, brush): |
177 |
offx, offy = self.offset |
draw_polygon_shape(index, pen, brush) |
|
draw_polygon_shape(layer.shapefile.cobject(), index, |
|
|
self.dc, pen, brush, |
|
|
self.map.projection, layer.projection, |
|
|
self.scale, -self.scale, offx, offy) |
|
178 |
|
|
179 |
def projected_points(self, layer, index): |
def projected_points(self, layer, index): |
180 |
proj = self.map.projection |
proj = self.map.projection |
205 |
self.dc.DrawLines(points) |
self.dc.DrawLines(points) |
206 |
|
|
207 |
def draw_point_shape(self, layer, index): |
def draw_point_shape(self, layer, index): |
208 |
p = self.projected_points(layer, index)[0] |
pp = self.projected_points(layer, index) |
209 |
|
|
210 |
|
if len(pp) == 0: return # ignore Null Shapes which have no points |
211 |
|
|
212 |
|
p = pp[0] |
213 |
radius = self.resolution * 5 |
radius = self.resolution * 5 |
214 |
self.dc.DrawEllipse(p.x - radius, p.y - radius, 2*radius, 2*radius) |
self.dc.DrawEllipse(p.x - radius, p.y - radius, 2*radius, 2*radius) |
215 |
|
|