-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog.py
More file actions
101 lines (88 loc) · 2.99 KB
/
catalog.py
File metadata and controls
101 lines (88 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from AccessControl import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import setSecurityManager
from AccessControl.User import nobody
from pleiades.geographer.geo import location_precision, NotLocatedError
from pleiades.geographer.interfaces import IExtent, IFootprint, ILocatable
from pleiades.geographer.interfaces import IRepresentativePoint
from plone.indexer.decorator import indexer
from Products.CMFCore.utils import getToolByName
from Products.PleiadesEntity.content.interfaces import ILocation
from Products.PleiadesEntity.content.interfaces import IPlace
from shapely.geometry import shape
import logging
log = logging.getLogger('pleiades.geographer')
# To be registered as an indexable attribute adapter
# For use with pleiades.vaytrouindex
@indexer(ILocation)
def location_geo(obj, **kw):
url_tool = getToolByName(obj, 'portal_url')
portal_path = url_tool.getPortalObject().getPhysicalPath()
ob_path = obj.getPhysicalPath()[len(portal_path):]
try:
ex = IExtent(obj).extent
return dict(
id=obj.getPhysicalPath(),
bbox=shape(ex).bounds,
properties=dict(
path='/'.join(ob_path),
pid=obj.getId(),
title=obj.Title(),
description=obj.Description(),
),
geometry=ex
)
except (AttributeError, NotLocatedError, TypeError, ValueError) as e:
log.warn("Failed to adapt %s in 'location_geo': %s", obj, str(e))
return None
@indexer(ILocatable)
def location_precision_indexer(obj, **kw):
return location_precision(obj)
@indexer(ILocatable)
def zgeo_geometry_value(obj, **kw):
# Execute this as 'Anonymous'
try:
sm = getSecurityManager()
newSecurityManager(None, nobody.__of__(obj.acl_users))
ex = IExtent(obj)
return ex.extent
except:
raise AttributeError
finally:
setSecurityManager(sm)
@indexer(ILocatable)
def reprPt_value(obj, **kw):
# Execute this as 'Anonymous'
try:
sm = getSecurityManager()
newSecurityManager(None, nobody.__of__(obj.acl_users))
pt = IRepresentativePoint(obj)
return pt.coords, pt.precision
except:
raise AttributeError
finally:
setSecurityManager(sm)
@indexer(ILocatable)
def bbox_value(obj, **kw):
# Execute this as 'Anonymous'
try:
sm = getSecurityManager()
newSecurityManager(None, nobody.__of__(obj.acl_users))
ex = IExtent(obj)
return tuple(shape(ex.extent).bounds)
except:
raise AttributeError
finally:
setSecurityManager(sm)
@indexer(IPlace)
def footprint_value(obj, **kw):
# Execute this as 'Anonymous'
try:
sm = getSecurityManager()
newSecurityManager(None, nobody.__of__(obj.acl_users))
fp = IFootprint(obj).footprint()
return fp
except:
raise AttributeError
finally:
setSecurityManager(sm)