9 |
|
|
10 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
11 |
|
|
12 |
|
import cStringIO |
13 |
|
|
14 |
from Thuban import _ |
from Thuban import _ |
15 |
|
|
16 |
from wxPython.wx import wxMemoryDC, wxEmptyBitmap, \ |
from wxPython.wx import wxMemoryDC, wxEmptyBitmap, \ |
17 |
wxPoint, wxRect, wxPen, wxBrush, wxFont, \ |
wxPoint, wxRect, wxPen, wxBrush, wxFont, \ |
18 |
wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \ |
wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \ |
19 |
wxBLACK_PEN, wxRED_PEN, wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL |
wxBLACK_PEN, wxRED_PEN, wxBLACK, \ |
20 |
|
wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL, \ |
21 |
|
wxBitmap, wxImageFromBitmap, wxBitmapFromImage, \ |
22 |
|
wxImageFromStream, wxBITMAP_TYPE_BMP |
23 |
|
|
24 |
from wxproj import draw_polygon_shape, draw_polygon_init |
from wxproj import draw_polygon_shape, draw_polygon_init |
25 |
|
from gdalwarp import ProjectRasterFile |
26 |
|
|
27 |
from Thuban.UI.common import Color2wxColour |
from Thuban.UI.common import Color2wxColour |
28 |
from Thuban.UI.classifier import ClassDataPreviewer |
from Thuban.UI.classifier import ClassDataPreviewer |
29 |
from Thuban.UI.scalebar import ScaleBar |
from Thuban.UI.scalebar import ScaleBar |
30 |
|
|
31 |
from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \ |
from Thuban.Model.layer import Layer, RasterLayer, \ |
32 |
SHAPETYPE_POINT |
SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT |
33 |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
34 |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
35 |
|
|
70 |
|
|
71 |
def render_map(self, map): |
def render_map(self, map): |
72 |
self.map = map |
self.map = map |
73 |
|
seenRaster = True |
74 |
|
|
75 |
|
# |
76 |
|
# This is only a good optimization if there is only one |
77 |
|
# raster layer and the image covers the entire window (as |
78 |
|
# it currently does). |
79 |
|
# |
80 |
|
for layer in map.Layers(): |
81 |
|
if isinstance(layer, RasterLayer): |
82 |
|
seenRaster = False |
83 |
|
break |
84 |
|
|
85 |
for layer in map.Layers(): |
for layer in map.Layers(): |
86 |
# if honor_visibility is true, only draw visible layers, |
# if honor_visibility is true, only draw visible layers, |
87 |
# otherwise draw all layers |
# otherwise draw all layers |
88 |
if not self.honor_visibility or layer.Visible(): |
if not self.honor_visibility or layer.Visible(): |
89 |
self.draw_shape_layer(layer) |
if isinstance(layer, Layer) and seenRaster: |
90 |
|
self.draw_shape_layer(layer) |
91 |
|
elif isinstance(layer, RasterLayer): |
92 |
|
self.draw_raster_layer(layer) |
93 |
|
seenRaster = True |
94 |
|
|
95 |
self.draw_label_layer(map.LabelLayer()) |
self.draw_label_layer(map.LabelLayer()) |
96 |
|
|
97 |
def draw_shape_layer(self, layer): |
def draw_shape_layer(self, layer): |
172 |
|
|
173 |
draw_func(i) |
draw_func(i) |
174 |
|
|
175 |
|
def draw_raster_layer(self, layer): |
176 |
|
data = None |
177 |
|
offx, offy = self.offset |
178 |
|
width, height = self.dc.GetSizeTuple() |
179 |
|
|
180 |
|
inProj = "" |
181 |
|
proj = layer.GetProjection() |
182 |
|
if proj is not None: |
183 |
|
for p in proj.GetAllParameters(): |
184 |
|
inProj += "+" + p + " " |
185 |
|
|
186 |
|
outProj = "" |
187 |
|
proj = self.map.GetProjection() |
188 |
|
if proj is not None: |
189 |
|
for p in proj.GetAllParameters(): |
190 |
|
outProj += "+" + p + " " |
191 |
|
|
192 |
|
print "self.scale: ", self.scale, offx, offy, width, height |
193 |
|
xmin = (0 - offx) / self.scale |
194 |
|
ymin = (offy - height) / self.scale |
195 |
|
xmax = (width - offx) / self.scale |
196 |
|
ymax = (offy - 0) / self.scale |
197 |
|
|
198 |
|
try: |
199 |
|
data = ProjectRasterFile( |
200 |
|
layer.GetImageFilename(), |
201 |
|
inProj, |
202 |
|
outProj, |
203 |
|
str(xmin), str(ymin), str(xmax), str(ymax), |
204 |
|
"", str(width), str(height)); |
205 |
|
except (AttributeError, IOError, ValueError): |
206 |
|
pass |
207 |
|
else: |
208 |
|
if data is not None: |
209 |
|
stream = cStringIO.StringIO(data) |
210 |
|
image = wxImageFromStream(stream, wxBITMAP_TYPE_BMP) |
211 |
|
bitmap = wxBitmapFromImage(image) |
212 |
|
self.dc.BeginDrawing() |
213 |
|
self.dc.DrawBitmap(bitmap, 0, 0) |
214 |
|
self.dc.EndDrawing() |
215 |
|
|
216 |
def layer_ids(self, layer): |
def layer_ids(self, layer): |
217 |
"""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. |
218 |
|
|