10 |
import os |
import os |
11 |
from math import log, ceil |
from math import log, ceil |
12 |
|
|
13 |
|
from Thuban import _ |
14 |
|
|
15 |
import shapelib, shptree |
import shapelib, shptree |
16 |
|
|
17 |
from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \ |
from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \ |
21 |
# Some predefined colors for internal use |
# Some predefined colors for internal use |
22 |
_black = Color(0, 0, 0) |
_black = Color(0, 0, 0) |
23 |
|
|
24 |
|
from classification import Classification |
25 |
|
|
26 |
from table import Table |
from table import Table |
27 |
|
|
143 |
self.shapetable = Table(filename) |
self.shapetable = Table(filename) |
144 |
self.table = self.shapetable |
self.table = self.shapetable |
145 |
|
|
146 |
|
self.classification = Classification(self) |
147 |
|
self.classification.SetDefaultStroke(stroke) |
148 |
|
self.classification.SetDefaultStrokeWidth(stroke_width) |
149 |
|
self.classification.SetDefaultFill(fill) |
150 |
|
|
151 |
|
self.UnsetModified() |
152 |
|
|
153 |
def open_shapefile(self): |
def open_shapefile(self): |
154 |
if self.shapefile is None: |
if self.shapefile is None: |
155 |
self.shapefile = shapelib.ShapeFile(self.filename) |
self.shapefile = shapelib.ShapeFile(self.filename) |
225 |
"""Return the shape with index index""" |
"""Return the shape with index index""" |
226 |
self.open_shapefile() |
self.open_shapefile() |
227 |
shape = self.shapefile.read_object(index) |
shape = self.shapefile.read_object(index) |
228 |
|
|
229 |
if self.shapetype == SHAPETYPE_POINT: |
if self.shapetype == SHAPETYPE_POINT: |
230 |
points = shape.vertices() |
points = shape.vertices() |
231 |
else: |
else: |
234 |
points = [] |
points = [] |
235 |
for x, y in poly: |
for x, y in poly: |
236 |
points.append((x, y)) |
points.append((x, y)) |
237 |
|
|
238 |
return Shape(points) |
return Shape(points) |
239 |
|
|
240 |
def ShapesInRegion(self, box): |
def ShapesInRegion(self, box): |
251 |
self.projection = projection |
self.projection = projection |
252 |
self.changed(LAYER_PROJECTION_CHANGED, self) |
self.changed(LAYER_PROJECTION_CHANGED, self) |
253 |
|
|
|
def SetFill(self, fill): |
|
|
"""Set the layer's fill color. None means the shapes are not filled""" |
|
|
self.fill = fill |
|
|
self.changed(LAYER_LEGEND_CHANGED, self) |
|
|
|
|
|
def SetStroke(self, stroke): |
|
|
"""Set the layer's stroke color. None means the shapes are not |
|
|
stroked.""" |
|
|
self.stroke = stroke |
|
|
self.changed(LAYER_LEGEND_CHANGED, self) |
|
|
|
|
|
def SetStrokeWidth(self, width): |
|
|
"""Set the layer's stroke width.""" |
|
|
self.stroke_width = width |
|
|
self.changed(LAYER_LEGEND_CHANGED, self) |
|
|
|
|
254 |
def TreeInfo(self): |
def TreeInfo(self): |
255 |
items = [] |
items = [] |
256 |
|
|
257 |
if self.Visible(): |
if self.Visible(): |
258 |
items.append("Shown") |
items.append(_("Shown")) |
259 |
else: |
else: |
260 |
items.append("Hidden") |
items.append(_("Hidden")) |
261 |
items.append("Shapes: %d" % self.NumShapes()) |
items.append(_("Shapes: %d") % self.NumShapes()) |
262 |
|
|
263 |
bbox = self.LatLongBoundingBox() |
bbox = self.LatLongBoundingBox() |
264 |
if bbox is not None: |
if bbox is not None: |
265 |
items.append("Extent (lat-lon): (%g, %g, %g, %g)" % bbox) |
items.append(_("Extent (lat-lon): (%g, %g, %g, %g)") % bbox) |
266 |
else: |
else: |
267 |
items.append("Extent (lat-lon):") |
items.append(_("Extent (lat-lon):")) |
268 |
items.append("Shapetype: %s" % shapetype_names[self.ShapeType()]) |
items.append(_("Shapetype: %s") % shapetype_names[self.ShapeType()]) |
269 |
|
|
270 |
def color_string(color): |
def color_string(color): |
271 |
if color is None: |
if color is None: |
272 |
return "None" |
return "None" |
273 |
return "(%.3f, %.3f, %.3f)" % (color.red, color.green, color.blue) |
return "(%.3f, %.3f, %.3f)" % (color.red, color.green, color.blue) |
|
items.append("Fill: " + color_string(self.fill)) |
|
|
items.append("Outline: " + color_string(self.stroke)) |
|
274 |
|
|
275 |
return ("Layer '%s'" % self.Title(), items) |
# layers will always have a classification with at least a NULL data set |
276 |
|
|
277 |
|
#items.append((_("Fill: %s") % color_string(self.fill), self.fill)) |
278 |
|
#items.append((_("Outline: %s") % color_string(self.stroke), self.stroke)) |
279 |
|
|
280 |
|
items.append(self.classification) |
281 |
|
|
282 |
|
return (_("Layer '%s'") % self.Title(), items) |
283 |
|
|