12 |
import os |
import os |
13 |
import warnings |
import warnings |
14 |
|
|
15 |
|
from wxproj import point_in_polygon_shape, shape_centroid |
16 |
|
|
17 |
from Thuban import _ |
from Thuban import _ |
18 |
|
|
19 |
from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \ |
from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \ |
24 |
from color import Transparent, Black |
from color import Transparent, Black |
25 |
from base import TitledObject, Modifiable |
from base import TitledObject, Modifiable |
26 |
from data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT |
from data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT |
27 |
|
from label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
28 |
|
ALIGN_LEFT, ALIGN_RIGHT |
29 |
|
|
30 |
import resource |
import resource |
31 |
|
|
347 |
|
|
348 |
return (left, bottom, right, top) |
return (left, bottom, right, top) |
349 |
|
|
350 |
|
def GetLabelPosFromShape(self, cmap, shape_index): |
351 |
|
''' |
352 |
|
Return the label position parameters (x, y, halign, valign) from the |
353 |
|
shape object |
354 |
|
''' |
355 |
|
proj = cmap.projection |
356 |
|
if proj is not None: |
357 |
|
map_proj = proj |
358 |
|
else: |
359 |
|
map_proj = None |
360 |
|
proj = self.projection |
361 |
|
if proj is not None: |
362 |
|
layer_proj = proj |
363 |
|
else: |
364 |
|
layer_proj = None |
365 |
|
|
366 |
|
shapetype = self.ShapeType() |
367 |
|
if shapetype == SHAPETYPE_POLYGON: |
368 |
|
shapefile = self.ShapeStore().Shapefile().cobject() |
369 |
|
x, y = shape_centroid(shapefile, shape_index, |
370 |
|
map_proj, layer_proj, 1, 1, 0, 0) |
371 |
|
if map_proj is not None: |
372 |
|
x, y = map_proj.Inverse(x, y) |
373 |
|
else: |
374 |
|
shape = self.Shape(shape_index) |
375 |
|
if shapetype == SHAPETYPE_POINT: |
376 |
|
x, y = shape.Points()[0][0] |
377 |
|
else: |
378 |
|
# assume SHAPETYPE_ARC |
379 |
|
points = shape.Points()[0] |
380 |
|
x, y = points[len(points) / 2] |
381 |
|
if layer_proj is not None: |
382 |
|
x, y = layer_proj.Inverse(x, y) |
383 |
|
if shapetype == SHAPETYPE_POINT: |
384 |
|
halign = ALIGN_LEFT |
385 |
|
valign = ALIGN_CENTER |
386 |
|
elif shapetype == SHAPETYPE_POLYGON: |
387 |
|
halign = ALIGN_CENTER |
388 |
|
valign = ALIGN_CENTER |
389 |
|
elif shapetype == SHAPETYPE_ARC: |
390 |
|
halign = ALIGN_LEFT |
391 |
|
valign = ALIGN_CENTER |
392 |
|
|
393 |
|
return (x, y, halign, valign) |
394 |
|
|
395 |
|
|
396 |
|
|
397 |
if resource.has_gdal_support(): |
if resource.has_gdal_support(): |
398 |
import gdal |
import gdal |