+ self.scene_cache = {}
+
+ def parse_geometry(self, geom, scene):
+ if geom.find(':') >= 0:
+ out = self.get_scene_geometry(scene, geom)
+ elif geom.find(',') < 0:
+ out = "'POINT(%s)'::geometry" % geom
+ elif geom.find('(') < 0:
+ out = "'LINESTRING(%s)'::geometry" % geom
+ else:
+ out = "'POLYGON(%s)'::geometry" % geom
+
+ return "ST_SetSRID(%s, 4326)" % out
+
+ def get_scene_geometry(self, default_scene, name):
+ geoms = []
+ for obj in name.split('+'):
+ oname = obj.strip()
+ if oname.startswith(':'):
+ assert_is_not_none(default_scene, "You need to set a scene")
+ defscene = self.load_scene(default_scene)
+ wkt = defscene[oname[1:]]
+ else:
+ scene, obj = oname.split(':', 2)
+ scene_geoms = self.load_scene(scene)
+ wkt = scene_geoms[obj]
+
+ geoms.append("'%s'::geometry" % wkt)
+
+ if len(geoms) == 1:
+ return geoms[0]
+ else:
+ return 'ST_LineMerge(ST_Collect(ARRAY[%s]))' % ','.join(geoms)