- def get_scene_geometry(self, default_scene, name):
- """ Load the geometry from a scene.
- """
- geoms = []
- for obj in name.split('+'):
- oname = obj.strip()
- if oname.startswith(':'):
- assert default_scene is not None, "Scenario error: 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("'{}'::geometry".format(wkt))
-
- if len(geoms) == 1:
- return geoms[0]
-
- return 'ST_LineMerge(ST_Collect(ARRAY[{}]))'.format(','.join(geoms))
-
- def load_scene(self, name):
- """ Load a scene from a file.
- """
- if name in self.scene_cache:
- return self.scene_cache[name]
-
- scene = {}
- with open(Path(self.scene_path) / "{}.wkt".format(name), 'r') as fd:
- for line in fd:
- if line.strip():
- obj, wkt = line.split('|', 2)
- scene[obj.strip()] = wkt.strip()
- self.scene_cache[name] = scene
-
- return scene