Changeset 1225
- Timestamp:
- 11/05/07 18:16:43 (1 year ago)
- Files:
-
- PleiadesEntity/trunk/geo.py (modified) (6 diffs)
- PleiadesEntity/trunk/tests/Entities.txt (modified) (2 diffs)
- PleiadesEntity/trunk/tests/GeoRSS_KML.txt (modified) (8 diffs)
- PleiadesEntity/trunk/tests/LoadEntity.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
PleiadesEntity/trunk/geo.py
r1184 r1225 46 46 self.context = context 47 47 48 def getSRS(self):49 return 'EPSG:4326'50 51 def setSRS(self, srs):52 pass53 54 def getGeometryType(self):55 return 'point'56 57 48 @property 58 49 def geom_type(self): 59 50 return 'Point' 60 61 def setGeometryType(self, geomtype):62 pass63 51 64 52 def getSpatialCoordinates(self): … … 102 90 return coords[0] 103 91 104 def setGeometry(self, geomtype, coords):105 value = ''106 for point in coords:107 if len(point) == 3:108 value = ' '.join([value, "%f %f %f" % point])109 elif len(point) == 2:110 value = ' '.join([value, "%f %f 0.0" % point])111 else:112 raise ValueError, \113 "Insufficient number of ordinates: %s" % str(point)114 x0 = self.context.getRefs('hasLocation')[0]115 x0.setSpatialCoordinates(value.lstrip())116 117 92 def isGeoreferenced(self): 118 93 """Return True if the object is "on the map".""" 119 94 return bool(len(self.context.getRefs('hasLocation'))) 120 121 def hasPoint(self):122 return 1123 124 def hasLineString(self):125 return 0126 127 def hasPolygon(self):128 return 0129 130 def getInfo(self, dims=3):131 """Return an informative dict."""132 context = self.context133 info = {'srs': self.getSRS(),134 'geometryType': self.getGeometryType(),135 }136 points = self.getSpatialCoordinates()137 coords = []138 for i in range(len(points)):139 coords.extend([str(v) for v in points[i][0:dims]])140 info['spatialCoordinates'] = ' '.join(coords)141 142 # Content objects143 info.update(144 {'id': context.getId(),145 'title': context.title_or_id(),146 'description': context.Description(),147 'url': context.absolute_url(),}148 )149 return info150 95 151 96 @property … … 153 98 context = self.context 154 99 return { 100 'type': 'Feature', 155 101 'id': context.getId(), 156 102 'properties': { … … 182 128 raise Exception, "Could not adapt %s" % str(context) 183 129 184 def getSRS(self):185 return 'EPSG:4326'186 187 def setSRS(self, srs):188 pass189 190 def getGeometryType(self):191 return 'point'192 193 def setGeometryType(self, geomtype):194 pass195 196 def getSpatialCoordinates(self):197 return self._primary_association.getSpatialCoordinates()198 199 @property200 def spatialCoordinates(self):201 return self._primary_association.spatialCoordinates202 203 def setGeometry(self, geomtype, coords):204 raise NotImplementedError205 206 130 def isGeoreferenced(self): 207 131 """Return True if the object is "on the map".""" 208 132 return self._primary_association.isGeoreferenced() 209 133 210 def hasPoint(self): 211 return self._primary_association.hasPoint() 212 213 def hasLineString(self): 214 return self._primary_association.hasLineString() 134 @property 135 def geom_type(self): 136 return self._primary_association.geom_type 215 137 216 def hasPolygon(self): 217 return self._primary_association.hasPolygon() 218 219 def getInfo(self, dims=3): 220 """Return an informative dict.""" 221 context = self.context 222 info = self._primary_association.getInfo(dims) 223 info.update( 224 {'id': context.getId(), 225 'title': context.title_or_id(), 226 'description': context.Description(), 227 'url': context.absolute_url(),} 228 ) 229 return info 138 @property 139 def coords(self): 140 return self._primary_association.coords 230 141 231 142 @property … … 233 144 context = self.context 234 145 return { 146 'type': 'Feature', 235 147 'id': context.getId(), 236 148 'properties': { … … 282 194 pass 283 195 284 def getItemsInfo(self):285 infos = []286 for item in self.geoItems():287 infos.append(item.getInfo())288 return infos289 290 def getBoundingBox(self):291 raise NotImplementedError292 PleiadesEntity/trunk/tests/Entities.txt
r746 r1225 64 64 >>> g.isGeoreferenced() 65 65 True 66 >>> info = {'srs': 'EPSG:4326', 'geometryType': 'point', 'description': '', 'spatialCoordinates': '34.7697222222 -86.4808333333 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/%s/%s' % (pid, aid), 'title': 'Civitas Non', 'id': aid} 67 >>> g.getInfo() == info 68 True 66 >>> gi = g.__geo_interface__ 67 >>> gi['type'] 68 'Feature' 69 >>> gi['geometry']['type'] 70 'Point' 71 >>> gi['geometry']['coordinates'] 72 (-86.480833333333294, 34.769722222222001, 0.0) 69 73 70 74 Place … … 73 77 >>> g.isGeoreferenced() 74 78 True 75 >>> info = {'srs': 'EPSG:4326', 'geometryType': 'point', 'description': '', 'spatialCoordinates': '34.7697222222 -86.4808333333 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/%s' % pid, 'title': 'Civitas Non', 'id': pid} 76 >>> g.getInfo() == info 77 True 79 >>> gi = g.__geo_interface__ 80 >>> gi['type'] 81 'Feature' 82 >>> gi['geometry']['type'] 83 'Point' 84 >>> gi['geometry']['coordinates'] 85 (-86.480833333333294, 34.769722222222001, 0.0) 86 >>> gi['properties']['title'] 87 'Civitas Non' 78 88 79 89 >>> c = IGeoCollectionSimple(places) 80 >>> c.getItemsInfo() == [{'srs': 'EPSG:4326', 'geometryType': 'point', 'description': '', 'spatialCoordinates': '34.7697222222 -86.4808333333 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/%s' % pid, 'title': 'Civitas Non', 'id': pid}] 81 True 90 >>> x = list(c.geoItems()) 91 >>> len(x) 92 1 82 93 PleiadesEntity/trunk/tests/GeoRSS_KML.txt
r686 r1225 73 73 <?xml version="1.0" encoding="utf-8"?> 74 74 <feed xmlns="http://www.w3.org/2005/Atom" 75 xmlns:georss="http://www.georss.org/georss"> 75 xmlns:georss="http://www.georss.org/georss" 76 xmlns:gml="http://www.opengis.net/gml"> 76 77 <BLANKLINE> 77 78 <BLANKLINE> … … 90 91 <updated/> 91 92 <summary>A testing entity</summary> 92 <georss:point>0.0 0.0</georss:point> 93 <BLANKLINE> 94 <BLANKLINE> 95 <georss:where> 96 <gml:Point> 97 <gml:pos>0.000000 0.000000</gml:pos> 98 </gml:Point> 99 </georss:where> 100 <BLANKLINE> 101 <BLANKLINE> 102 <BLANKLINE> 93 103 </entry> 94 <BLANKLINE>95 104 </feed> 96 105 <BLANKLINE> 97 106 <BLANKLINE> 98 99 107 100 108 >>> browser.open("%s/kml" % url) … … 106 114 <BLANKLINE> 107 115 <BLANKLINE> 108 <Folder> 116 <Document> 117 <Style id="defaultStyle"> 118 <LineStyle> 119 <color>ffff0000</color> 120 <width>2</width> 121 </LineStyle> 122 <PolyStyle> 123 <color>33ff0000</color> 124 </PolyStyle> 125 </Style> 109 126 <name></name> 110 127 <visibility>0</visibility> … … 124 141 </description> 125 142 <BLANKLINE> 143 <styleUrl>#defaultStyle</styleUrl> 126 144 <BLANKLINE> 127 145 <Point> 128 <coordinates>0.0 ,0.0,0.0</coordinates>146 <coordinates>0.000000,0.000000,0.000000</coordinates> 129 147 </Point> 130 148 <BLANKLINE> 149 <BLANKLINE> 150 <BLANKLINE> 131 151 </Placemark> 132 </ Folder>152 </Document> 133 153 </kml> 134 154 <BLANKLINE> … … 142 162 <?xml version="1.0" encoding="utf-8"?> 143 163 <feed xmlns="http://www.w3.org/2005/Atom" 144 xmlns:georss="http://www.georss.org/georss"> 164 xmlns:georss="http://www.georss.org/georss" 165 xmlns:gml="http://www.opengis.net/gml"> 145 166 <BLANKLINE> 146 167 <BLANKLINE> … … 159 180 <updated/> 160 181 <summary>A testing entity</summary> 161 <georss:point>0.0 0.0</georss:point> 182 <BLANKLINE> 183 <BLANKLINE> 184 <georss:where> 185 <gml:Point> 186 <gml:pos>0.000000 0.000000</gml:pos> 187 </gml:Point> 188 </georss:where> 189 <BLANKLINE> 190 <BLANKLINE> 191 <BLANKLINE> 162 192 </entry> 163 <BLANKLINE>164 193 </feed> 165 194 <BLANKLINE> … … 172 201 <BLANKLINE> 173 202 <BLANKLINE> 174 <Folder> 203 <Document> 204 <Style id="defaultStyle"> 205 <LineStyle> 206 <color>ffff0000</color> 207 <width>2</width> 208 </LineStyle> 209 <PolyStyle> 210 <color>33ff0000</color> 211 </PolyStyle> 212 </Style> 175 213 <name>Neverpolis</name> 176 214 <visibility>0</visibility> … … 190 228 </description> 191 229 <BLANKLINE> 230 <styleUrl>#defaultStyle</styleUrl> 192 231 <BLANKLINE> 193 232 <Point> 194 <coordinates>0.0 ,0.0,0.0</coordinates>233 <coordinates>0.000000,0.000000,0.000000</coordinates> 195 234 </Point> 196 235 <BLANKLINE> 236 <BLANKLINE> 237 <BLANKLINE> 197 238 </Placemark> 198 </ Folder>239 </Document> 199 240 </kml> 200 241 <BLANKLINE> PleiadesEntity/trunk/tests/LoadEntity.txt
r1107 r1225 81 81 ['BAtlas 65 A2 Aphrodisias/Ninoe', 'RE Aphrodisias 2', 'NPauly Aphrodisias 1', 'RE Ninoe'] 82 82 >>> [(assoc[s.id].getItem(), assoc[s.id].getRange()) for s in srs] 83 [('http://www.unc.edu/awmc/pleiades/bibliography/batlas.html', ' 65 A2 Aphrodisias/Ninoe'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'Aphrodisias 1'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'Ninoe')]83 [('http://www.unc.edu/awmc/pleiades/bibliography/batlas.html', 'BAtlas 65 A2 Aphrodisias/Ninoe'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'RE Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'NPauly Aphrodisias 1'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'RE Ninoe')] 84 84 85 85 Test names … … 133 133 ['RE Aphrodisias 2', 'NPauly Aphrodisias 1'] 134 134 >>> [(n0[s.id].getItem(), n0[s.id].getRange()) for s in srs] 135 [('http://www.unc.edu/awmc/pleiades/bibliography/re.html', ' Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'Aphrodisias 1')]135 [('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'RE Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'NPauly Aphrodisias 1')] 136 136 137 137 … … 259 259 >>> g.isGeoreferenced() 260 260 True 261 >>> g.getInfo() 262 {'description': 'An ancient settlement, attested during the Classical, Roman and Late Antique periods (modern location: Geyre). It was known in antiquity by the names: Aphrodisias and Ninoe.', 'spatialCoordinates': '37.7145 28.7289 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638753', 'title': 'Aphrodisias/Ninoe', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638753'} 261 >>> g.geom_type 262 'Point' 263 >>> g.coords 264 (28.728899999999999, 37.714500000000001, 0.0) 265 >>> gi = g.__geo_interface__ 266 >>> gi['type'] 267 'Feature' 268 >>> gi['properties']['title'] 269 'Aphrodisias/Ninoe' 270 >>> gi['properties']['description'] 271 'An ancient settlement, attested during the Classical, Roman and Late Antique periods (modern location: Geyre). It was known in antiquity by the names: Aphrodisias and Ninoe.' 263 272 264 273 >>> c = IGeoCollectionSimple(folder.places) 265 >>> c.getItemsInfo()266 [{'description': 'An ancient settlement, attested during the Classical, Roman and Late Antique periods (modern location: Geyre). It was known in antiquity by the names: Aphrodisias and Ninoe.', 'spatialCoordinates': '37.7145 28.7289 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638753', 'title': 'Aphrodisias/Ninoe', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638753'}]274 >>> len(list(c.geoItems())) 275 1 267 276 268 277 Load one nameless entity … … 294 303 >>> g.isGeoreferenced() 295 304 True 296 >>> g.getInfo()297 {'description': 'An ancient fort, attested during the Roman period (modern location: Emeriye). Its ancient name is not known.', 'spatialCoordinates': '37.1751 31.7324 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638830', 'title': '638830', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638830'}298 299 305 300 306 Reload that entity
