def setUp(self): # Create a simple fake DEM conn = connections[DEFAULT_DB_ALIAS] cur = conn.cursor() cur.execute('CREATE TABLE mnt (rid serial primary key, rast raster)') cur.execute( 'INSERT INTO mnt (rast) VALUES (ST_MakeEmptyRaster(3, 3, 0, 3, 1, -1, 0, 0, %s))', [settings.SRID]) cur.execute('UPDATE mnt SET rast = ST_AddBand(rast, \'16BSI\')') for x in range(1, 4): for y in range(1, 4): cur.execute( 'UPDATE mnt SET rast = ST_SetValue(rast, %s, %s, %s::float)', [x, y, x + y]) conn.commit_unless_managed() self.path = Path( geom=LineString((1.5, 1.5, 0), (2.5, 1.5, 0), (1.5, 2.5, 0))) self.path.save()
def test_link_closest_visible_path(self): """ Topology must be linked to the closest visible path only """ path_visible = Path(name="visible", geom='LINESTRING(0 0, 1 0, 2 0)', visible=True) path_visible.save() path_unvisible = Path(name="unvisible", geom='LINESTRING(0 3, 1 3, 2 3)', visible=False) path_unvisible.save() # default manager see 1 path self.assertEqual(Path.objects.count(), 1) # custom manager see 2 paths self.assertEqual(Path.include_invisible.count(), 2) # create topo on visible path topology = Topology._topologypoint(0, 0, None) topology.save() # because FK and M2M are used with default manager only, others tests are in SQL conn = connections[DEFAULT_DB_ALIAS] cur = conn.cursor() cur.execute(""" SELECT t.id as id_path, et.topo_object_id as id_topology, t.visible as visible FROM core_pathaggregation et JOIN core_path t ON et.path_id=t.id WHERE et.topo_object_id={topo_id} """.format(topo_id=topology.pk)) datas = dictfetchall(cur) # topo must be linked to visible path self.assertIn(topology.pk, [ele['id_topology'] for ele in datas], "{}".format(datas)) self.assertIn(path_visible.pk, [ele['id_path'] for ele in datas], "{}".format(datas)) self.assertNotIn(path_unvisible.pk, [ele['id_path'] for ele in datas], "{}".format(datas)) # new topo on invible path topology = Topology._topologypoint(0, 3, None) topology.save() cur.execute(""" SELECT t.id as id_path, et.topo_object_id as id_topology, t.visible as visible FROM core_pathaggregation et JOIN core_path t ON et.path_id=t.id WHERE et.topo_object_id={topo_id} """.format(topo_id=topology.pk)) datas = dictfetchall(cur) self.assertIn(topology.pk, [ele['id_topology'] for ele in datas], "{}".format(datas)) self.assertIn(path_visible.pk, [ele['id_path'] for ele in datas], "{}".format(datas)) self.assertNotIn(path_unvisible.pk, [ele['id_path'] for ele in datas], "{}".format(datas)) cur.close()
def test_snap_not_saved(self): p = Path() with self.assertRaisesRegex(ValueError, "Cannot compute snap on unsaved path"): p.snap(Point(0, 0))
def test_interpolate_not_saved(self): p = Path() with self.assertRaisesRegex( ValueError, "Cannot compute interpolation on unsaved path"): p.interpolate(Point(0, 0))