def test_topology_geom_with_intermediate_markers(self): # Intermediate (forced passage) markers for topologies # Use a bifurcation, make sure computed geometry is correct # +--p2---+ # +---+-------+---+ # p1 p3 p4 p1 = PathFactory.create(geom=LineString((0, 0), (2, 0))) p2 = PathFactory.create( geom=LineString((2, 0), (2, 1), (4, 1), (4, 0))) p3 = PathFactory.create(geom=LineString((2, 0), (4, 0))) p4 = PathFactory.create(geom=LineString((4, 0), (6, 0))) """ From p1 to p4, with point in the middle of p3 """ t = TopologyFactory.create(paths=[p1, p3, (p3, 0.5, 0.5), p4]) self.assertEqual( t.geom, LineString((0, 0), (2, 0), (4, 0), (6, 0), srid=settings.SRID)) """ From p1 to p4, through p2 """ t = TopologyFactory.create(paths=[p1, p2, (p2, 0.5, 0.5), p4]) self.assertEqual( t.geom, LineString((0, 0), (2, 0), (2, 1), (4, 1), (4, 0), (6, 0), srid=settings.SRID)) """ From p1 to p4, though p2, but **with start/end at 0.0** """ t2 = TopologyFactory.create(paths=[p1, p2, (p2, 0, 0), p4]) self.assertEqual(t2.geom, t.geom)
def create_pair_of_distinct_by_topo_project(self): p1, seek_path = self.create_pair_of_distinct_path() topo_1 = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=topo_1, path=p1, start_position=0, end_position=1) seek_topo = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=seek_topo, path=seek_path, start_position=0, end_position=1) it_p1 = InterventionFactory.create(topology=topo_1) seek_it = InterventionFactory.create(topology=seek_topo) seek_proj = ProjectFactory.create() seek_proj.interventions.add(seek_it) proj_1 = ProjectFactory.create() proj_1.interventions.add(it_p1) return seek_proj, seek_path
def test_project_bbox_filter(self): self.login() p1 = ProjectFactory.create() ProjectFactory.create() ProjectFactory.create() if settings.TREKKING_TOPOLOGY_ENABLED: t = TopologyFactory.create() else: t = TopologyFactory.create(geom='SRID=2154;POINT (700000 6600000)') InterventionFactory.create(project=p1, topology=t) def jsonlist(bbox): url = self.model.get_jsonlist_url() + bbox response = self.client.get(url) self.assertEqual(response.status_code, 200) jsondict = response.json() return jsondict['aaData'] # Check that projects without interventions are always present self.assertEqual(len(Project.objects.all()), 3) self.assertEqual(len(jsonlist('')), 3) self.assertEqual( len( jsonlist( '?bbox=POLYGON((1%202%200%2C1%202%200%2C1%202%200%2C1%202%200%2C1%202%200))' )), 2) # Give a bbox that match intervention, and check that all 3 projects are back bbox = '?bbox=POLYGON((2.9%2046.4%2C%203.1%2046.4%2C%203.1%2046.6%2C%202.9%2046.6%2C%202.9%2046.4))' self.assertEqual(len(jsonlist(bbox)), 3)
def test_topology_geom(self): p1 = PathFactory.create(geom=LineString((0, 0), (2, 2))) p2 = PathFactory.create(geom=LineString((2, 2), (2, 0))) p3 = PathFactory.create(geom=LineString((2, 0), (4, 0))) # Type Point t = TopologyFactory.create(paths=[(p1, 0.5, 0.5)]) self.assertEqual(t.geom, Point((1, 1), srid=settings.SRID)) # 50% of path p1, 100% of path p2 t = TopologyFactory.create(paths=[(p1, 0.5, 1), p2]) self.assertEqual( t.geom, LineString((1, 1), (2, 2), (2, 0), srid=settings.SRID)) # 100% of path p2 and p3, with offset of 1 t = TopologyFactory.create(offset=1, paths=[p2, p3]) self.assertEqual( t.geom, LineString((3, 2), (3, 1), (4, 1), srid=settings.SRID)) # Change offset, geometry is computed again t.offset = 0.5 t.save() self.assertEqual( t.geom, LineString((2.5, 2), (2.5, 0.5), (4, 0.5), srid=settings.SRID))
def test_simple_loop(self): """ ========== || || A +==------==+ B """ p1 = PathFactory.create(geom=LineString((10, 0), (0, 0))) p2 = PathFactory.create( geom=LineString((0, 0), (0, 5), (10, 5), (10, 0))) # Full loop topo = TopologyFactory.create(no_path=True) topo.add_path(p1, order=0) topo.add_path(p2, order=1) topo.save() self.assertEqual( topo.geom, LineString((10, 0), (0, 0), (0, 5), (10, 5), (10, 0), srid=settings.SRID)) # Subpart, like in diagram topo = TopologyFactory.create(no_path=True) topo.add_path(p1, start=0.8, end=1, order=0) topo.add_path(p2, order=1) topo.add_path(p1, start=0, end=0.2, order=2) topo.save() self.assertEqual( topo.geom, LineString((2, 0), (0, 0), (0, 5), (10, 5), (10, 0), (8, 0), srid=settings.SRID))
def test_latestupdate_delete(self): for i in range(10): TopologyFactory.create() t1 = dbnow() self.assertTrue(t1 > Topology.objects.latest("date_update").date_update) (Topology.objects.all()[0]).delete(force=True) self.assertFalse(t1 > Topology.objects.latest("date_update").date_update)
def test_topology_geom(self): p1 = PathFactory.create(geom=LineString((0, 0, 0), (2, 2, 2))) p2 = PathFactory.create(geom=LineString((2, 2, 2), (2, 0, 0))) p3 = PathFactory.create(geom=LineString((2, 0, 0), (4, 0, 0))) # Type Point t = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t, path=p1, start_position=0.5, end_position=0.5) t = Topology.objects.get(pk=t.pk) self.assertEqual(t.geom, Point((1, 1, 1))) # 50% of path p1, 100% of path p2 t = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t, path=p1, start_position=0.5) PathAggregationFactory.create(topo_object=t, path=p2) t = Topology.objects.get(pk=t.pk) self.assertEqual(t.geom, LineString((1, 1, 1), (2, 2, 2), (2, 0, 0))) # 100% of path p2 and p3, with offset of 1 t = TopologyFactory.create(no_path=True, offset=1) PathAggregationFactory.create(topo_object=t, path=p2) PathAggregationFactory.create(topo_object=t, path=p3) t.save() self.assertEqual(t.geom, LineString((3, 2, 2), (3, 1, 0), (4, 1, 0))) # Change offset, geometry is computed again t.offset = 0.5 t.save() self.assertEqual(t.geom, LineString((2.5, 2, 2), (2.5, 0.5, 0), (4, 0.5, 0)))
def test_mutate(self): topology1 = TopologyFactory.create(paths=[]) self.assertEqual(len(topology1.paths.all()), 0) topology2 = TopologyFactory.create(offset=14.5) self.assertEqual(len(topology2.paths.all()), 1) # Normal usecase topology1.mutate(topology2) self.assertEqual(topology1.offset, 14.5) self.assertEqual(len(topology1.paths.all()), 1)
def setUpTestData(cls): p1 = PathFactory() cls.seek_path = PathFactory(geom=getRandomLineStringInBounds()) topo_1 = TopologyFactory.create(paths=[p1]) seek_topo = TopologyFactory.create(paths=[cls.seek_path]) InterventionFactory.create(target=topo_1) cls.seek_inter = InterventionFactory.create(target=seek_topo)
def test_topology_geom_with_intermediate_markers(self): # Intermediate (forced passage) markers for topologies # Use a bifurcation, make sure computed geometry is correct # +--p2---+ # +---+-------+---+ # p1 p3 p4 p1 = PathFactory.create(geom=LineString((0, 0), (2, 0))) p2 = PathFactory.create( geom=LineString((2, 0), (2, 1), (4, 1), (4, 0))) p3 = PathFactory.create(geom=LineString((2, 0), (4, 0))) p4 = PathFactory.create(geom=LineString((4, 0), (6, 0))) """ From p1 to p4, with point in the middle of p3 """ t = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t, path=p1) PathAggregationFactory.create(topo_object=t, path=p3) PathAggregationFactory.create(topo_object=t, path=p3, start_position=0.5, end_position=0.5) PathAggregationFactory.create(topo_object=t, path=p4) t.save() self.assertEqual( t.geom, LineString((0, 0), (2, 0), (4, 0), (6, 0), srid=settings.SRID)) """ From p1 to p4, through p2 """ t = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t, path=p1) PathAggregationFactory.create(topo_object=t, path=p2) # There will a forced passage in database... PathAggregationFactory.create(topo_object=t, path=p2, start_position=0.5, end_position=0.5) PathAggregationFactory.create(topo_object=t, path=p4) t.save() self.assertEqual( t.geom, LineString((0, 0), (2, 0), (2, 1), (4, 1), (4, 0), (6, 0), srid=settings.SRID)) """ From p1 to p4, though p2, but **with start/end at 0.0** """ t2 = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t2, path=p1) PathAggregationFactory.create(topo_object=t2, path=p2) PathAggregationFactory.create(topo_object=t2, path=p2, start_position=0.0, end_position=0.0) PathAggregationFactory.create(topo_object=t2, path=p4) t2.save() self.assertEqual(t2.geom, t.geom)
def test_recompute_pk_reverse_AB_CD(self): """ A---------------B + C-------------------D B----------------AD----------------C | | |--| | => | | | |--| E1 (0.2) | E3 (0.2, 0.3) | | E1 (0.4) | E3 (0.8, 0.9) E2 (0.6) E4 (0.8) E2 (0.2) E4 (0.6) In case of AB == CD, matching A and D """ path_AB = PathFactory.create(name="PATH_AB", geom=LineString((10, 1), (0, 1))) path_CD = PathFactory.create(name="PATH_CD", geom=LineString((20, 1), (10, 1))) e1 = TopologyFactory.create(geom=Point(2, 2)) a1 = PathAggregationFactory.create(path=path_AB, topo_object=e1) e2 = TopologyFactory.create(geom=Point(6, 1)) a2 = PathAggregationFactory.create(path=path_AB, topo_object=e2) e3 = TopologyFactory.create(geom=LineString((2, 1), (3, 1),)) a3 = PathAggregationFactory.create(path=path_CD, topo_object=e3) e4 = TopologyFactory.create(geom=Point(8, 2)) a4 = PathAggregationFactory.create(path=path_CD, topo_object=e4) path_AB_original_length = path_AB.length path_CD_original_length = path_CD.length path_AB.merge_path(path_CD) self.assertEqual(path_AB.geom, LineString((0, 1), (10, 1), (20, 1))) # reload updated objects a1_updated = PathAggregation.objects.get(pk=a1.pk) a2_updated = PathAggregation.objects.get(pk=a2.pk) a3_updated = PathAggregation.objects.get(pk=a3.pk) a4_updated = PathAggregation.objects.get(pk=a4.pk) # test pk recompute on path_1 : new pk = old pk * old_path_1_length / new_path_1_length self.assertEqual(a1_updated.start_position, (1 - a1.start_position) * (path_AB_original_length / path_AB.length)) self.assertEqual(a1_updated.end_position, (1 - a1.end_position) * (path_AB_original_length / path_AB.length)) self.assertEqual(a2_updated.start_position, (1 - a2.start_position) * (path_AB_original_length / path_AB.length)) self.assertEqual(a2_updated.end_position, (1 - a1.end_position) * (path_AB_original_length / path_AB.length)) # test pk recompute on path_2 : new pk = old pk * old_path_2_length / new_path_1_length + old_path_1_length / new_path_1_length self.assertEqual(a3_updated.start_position, (1 - a3.start_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) self.assertEqual(a3_updated.end_position, (1 - a3.end_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) self.assertEqual(a4_updated.start_position, (1 - a4.start_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) self.assertEqual(a4_updated.end_position, (1 - a4.end_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) # test offset changes e1_updated = Topology.objects.get(pk=e1.pk) self.assertEqual(e1_updated.offset, -e1.offset) e4_updated = Topology.objects.get(pk=e4.pk) self.assertEqual(e4_updated.offset, -e4.offset)
def test_detail_target_objects(self): self.login() if settings.TREKKING_TOPOLOGY_ENABLED: path = PathFactory.create(geom=LineString((200, 200), (300, 300))) signa = SignageFactory.create(paths=[(path, .5, .5)]) signa.save() infrastructure = InfrastructureFactory.create(paths=[(path, .5, .5)]) infrastructure.save() poi = POIFactory.create(paths=[(path, .5, .5)]) trek = TrekFactory.create(paths=[(path, .5, .5)]) service = ServiceFactory.create(paths=[(path, .5, .5)]) topo = TopologyFactory.create(paths=[(path, .5, .5)]) topo.save() path_other = PathFactory.create( geom=LineString((10000, 0), (10010, 0))) signa_other = SignageFactory.create(paths=[(path_other, .5, .5)]) signa_other.save() else: signa = SignageFactory.create(geom='SRID=2154;POINT (250 250)') infrastructure = InfrastructureFactory.create( geom='SRID=2154;POINT (250 250)') poi = POIFactory.create(geom='SRID=2154;POINT (250 250)') trek = TrekFactory.create(geom='SRID=2154;POINT (250 250)') service = ServiceFactory.create(geom='SRID=2154;POINT (250 250)') topo = TopologyFactory.create(geom='SRID=2154;POINT (250 250)') signa_other = SignageFactory.create( geom='SRID=2154;POINT (10005 0)') intervention_signa = InterventionFactory.create(target=signa) intervention_infra = InterventionFactory.create(target=infrastructure) intervention_poi = InterventionFactory.create(target=poi) intervention_trek = InterventionFactory.create(target=trek) intervention_service = InterventionFactory.create(target=service) intervention_topo = InterventionFactory.create(target=topo) blade = BladeFactory(signage=signa, number="1") intervention_blade = InterventionFactory.create(target=blade) intervention_other = InterventionFactory.create(target=signa_other) response = self.client.get(signa.get_detail_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, intervention_signa.target_display) self.assertContains(response, intervention_infra.target_display) self.assertContains(response, intervention_poi.target_display) self.assertContains(response, intervention_trek.target_display) self.assertContains(response, intervention_service.target_display) self.assertContains(response, intervention_blade.target_display) self.assertContains(response, intervention_topo.target_display) self.assertNotContains(response, intervention_other.target_display)
def test_recompute_pk_reverse_AB_CD(self): """ A---------------B + C-------------------D B----------------AD----------------C | | |--| | => | | | |--| E1 (0.2) | E3 (0.2, 0.3) | | E1 (0.4) | E3 (0.8, 0.9) E2 (0.6) E4 (0.8) E2 (0.2) E4 (0.6) In case of AB == CD, matching A and D """ path_AB = PathFactory.create(name="PATH_AB", geom=LineString((10, 1), (0, 1))) path_CD = PathFactory.create(name="PATH_CD", geom=LineString((20, 1), (10, 1))) e1 = TopologyFactory.create(geom=Point(2, 2)) a1 = PathAggregationFactory.create(path=path_AB, topo_object=e1) e2 = TopologyFactory.create(geom=Point(6, 1)) a2 = PathAggregationFactory.create(path=path_AB, topo_object=e2) e3 = TopologyFactory.create(geom=LineString((2, 1), (3, 1),)) a3 = PathAggregationFactory.create(path=path_CD, topo_object=e3) e4 = TopologyFactory.create(geom=Point(8, 2)) a4 = PathAggregationFactory.create(path=path_CD, topo_object=e4) path_AB_original_length = path_AB.length path_CD_original_length = path_CD.length path_AB.merge_path(path_CD) self.assertEqual(path_AB.geom, LineString((0, 1), (10, 1), (20, 1), srid=settings.SRID)) # reload updated objects a1_updated = PathAggregation.objects.get(pk=a1.pk) a2_updated = PathAggregation.objects.get(pk=a2.pk) a3_updated = PathAggregation.objects.get(pk=a3.pk) a4_updated = PathAggregation.objects.get(pk=a4.pk) # test pk recompute on path_1 : new pk = old pk * old_path_1_length / new_path_1_length self.assertEqual(a1_updated.start_position, (1 - a1.start_position) * (path_AB_original_length / path_AB.length)) self.assertEqual(a1_updated.end_position, (1 - a1.end_position) * (path_AB_original_length / path_AB.length)) self.assertEqual(a2_updated.start_position, (1 - a2.start_position) * (path_AB_original_length / path_AB.length)) self.assertEqual(a2_updated.end_position, (1 - a1.end_position) * (path_AB_original_length / path_AB.length)) # test pk recompute on path_2 : new pk = old pk * old_path_2_length / new_path_1_length + old_path_1_length / new_path_1_length self.assertEqual(a3_updated.start_position, (1 - a3.start_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) self.assertEqual(a3_updated.end_position, (1 - a3.end_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) self.assertEqual(a4_updated.start_position, (1 - a4.start_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) self.assertEqual(a4_updated.end_position, (1 - a4.end_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length) # test offset changes e1_updated = Topology.objects.get(pk=e1.pk) self.assertEqual(e1_updated.offset, -e1.offset) e4_updated = Topology.objects.get(pk=e4.pk) self.assertEqual(e4_updated.offset, -e4.offset)
def test_elevation_topology_outside_dem(self): if settings.TREKKING_TOPOLOGY_ENABLED: outside_path = Path.objects.create( geom=LineString((200, 200), (300, 300))) topo = TopologyFactory.create(paths=[(outside_path, 0.5, 0.5)]) else: topo = TopologyFactory.create(geom="SRID=2154;POINT(250 250)") self.assertEqual(topo.geom_3d.coords[2], 0) self.assertEqual(topo.ascent, 0) self.assertEqual(topo.descent, 0) self.assertEqual(topo.min_elevation, 0) self.assertEqual(topo.max_elevation, 0)
def create_pair_of_distinct_by_topo_intervention(self): p1, seek_path = self.create_pair_of_distinct_path() topo_1 = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=topo_1, path=p1, start_position=0, end_position=1) seek_topo = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=seek_topo, path=seek_path, start_position=0, end_position=1) it_p1 = InterventionFactory.create(topology=topo_1) seek_it = InterventionFactory.create(topology=seek_topo) return seek_it, seek_path
def create_pair_of_distinct_by_topo_intervention(self): p1, seek_path = self.create_pair_of_distinct_path() topo_1 = TopologyFactory.create(no_path=True) topo_1.add_path(path=p1, start=0, end=1) seek_topo = TopologyFactory.create(no_path=True) seek_topo.add_path(path=seek_path, start=0, end=1) InterventionFactory.create(topology=topo_1) seek_it = InterventionFactory.create(topology=seek_topo) return seek_it, seek_path
def setUpTestData(cls): p1 = PathFactory() cls.seek_path = PathFactory(geom=getRandomLineStringInBounds()) topo_1 = TopologyFactory.create(paths=[p1]) seek_topo = TopologyFactory.create(paths=[cls.seek_path]) it_p1 = InterventionFactory.create(target=topo_1) seek_it = InterventionFactory.create(target=seek_topo) cls.seek_proj = ProjectFactory.create() cls.seek_proj.interventions.add(seek_it) proj_1 = ProjectFactory.create() proj_1.interventions.add(it_p1)
def test_split_twice(self): """ C D + + | | A +--==+===+==--+ B | | +---+ """ ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0))) # Create a topology topology = TopologyFactory.create(no_path=True) topology.add_path(ab, start=0.1, end=0.9) topogeom = topology.geom self.assertEqual(len(topology.paths.all()), 1) cd = PathFactory.create(name="CD", geom=LineString((1, 2, 0), (1, -2, 0), (3, -2, 0), (3, 2, 0))) self.assertEqual(len(topology.paths.all()), 3) self.assertEqual(len(ab.aggregations.all()), 1) aggr_ab = ab.aggregations.all()[0] self.assertEqual((0.4, 1.0), (aggr_ab.start_position, aggr_ab.end_position)) ab2 = Path.objects.filter(name="AB").exclude(pk=ab.pk)[0] ab3 = Path.objects.filter(name="AB").exclude(pk__in=[ab.pk, ab2.pk])[0] aggr_ab2 = ab2.aggregations.all()[0] aggr_ab3 = ab3.aggregations.all()[0] self.assertEqual((0.0, 1.0), (aggr_ab2.start_position, aggr_ab2.end_position)) self.assertEqual((0.0, 0.6), (aggr_ab3.start_position, aggr_ab3.end_position)) topology.reload() self.assertNotEqual(topology.geom, topogeom) self.assertEqual(topology.geom.coords[0], topogeom.coords[0]) self.assertEqual(topology.geom.coords[-1], topogeom.coords[-1])
def test_path_aggregation(self): """ A---------------B + C-------------------D A-----------------BC----------------D |---------------------| |------------------| E1 E1 2 path aggregations """ path_AB = PathFactory.create(name="PATH_AB", geom=LineString((0, 1), (10, 1))) path_CD = PathFactory.create(name="PATH_CD", geom=LineString((10, 1), (20, 1))) e1 = TopologyFactory.create(paths=[(path_AB, 0.5, 1), (path_CD, 0, 0.5)]) path_AB.merge_path(path_CD) self.assertEqual( path_AB.geom, LineString((0, 1), (10, 1), (20, 1), srid=settings.SRID)) self.assertEqual( PathAggregation.objects.filter(topo_object=e1).count(), 2) self.assertEqual(PathAggregation.objects.count(), 2) first = PathAggregation.objects.first() last = PathAggregation.objects.last() self.assertEqual((first.start_position, first.end_position), (0.25, 0.5)) self.assertEqual((last.start_position, last.end_position), (0.5, 0.75)) self.assertEqual(Topology.objects.count(), 1)
def test_split_tee_2(self): """ C A +---+---=====--+ B | A' B' + AB exists with topology A'B'. D Add CD """ ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0))) # Create a topology topology = TopologyFactory.create(no_path=True) topology.add_path(ab, start=0.5, end=0.75) topogeom = topology.geom # Topology covers 1 path self.assertEqual(len(ab.aggregations.all()), 1) self.assertEqual(len(topology.paths.all()), 1) self.assertEqual(topology.paths.all()[0], ab) cd = PathFactory.create(geom=LineString((1, 0, 0), (1, 2, 0))) # CB was just created cb = Path.objects.filter(name="AB").exclude(pk=ab.pk)[0] # AB has no topology anymore self.assertEqual(len(ab.aggregations.all()), 0) # Topology now still covers 1 path, but the new one self.assertEqual(len(topology.paths.all()), 1) self.assertEqual(len(cb.aggregations.all()), 1) self.assertEqual(topology.paths.all()[0].pk, cb.pk) topology.reload() self.assertEqual(topology.geom, topogeom)
def test_split_tee_3(self): """ C A +--=====--+---+ B A' B' | + AB exists with topology A'B'. D Add CD """ ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0))) # Create a topology topology = TopologyFactory.create(no_path=True) topology.add_path(ab, start=0.3, end=0.6) topogeom = topology.geom # Topology covers 1 path self.assertEqual(len(ab.aggregations.all()), 1) self.assertEqual(len(topology.paths.all()), 1) self.assertEqual(topology.paths.all()[0], ab) cd = PathFactory.create(geom=LineString((3, 0, 0), (3, 2, 0))) cb = Path.objects.filter(name="AB").exclude(pk=ab.pk)[0] # CB does not have any self.assertEqual(len(cb.aggregations.all()), 0) # AB has still its topology self.assertEqual(len(ab.aggregations.all()), 1) # But start/end have changed aggr_ab = ab.aggregations.all()[0] self.assertEqual((0.4, 0.8), (aggr_ab.start_position, aggr_ab.end_position)) topology.reload() self.assertEqual(topology.geom, topogeom)
def test_split_tee_1(self): """ C A +---===+===---+ B A' | B' + AB exists with topology A'B'. D Add CD. """ ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0))) # Create a topology topology = TopologyFactory.create(no_path=True) topology.add_path(ab, start=0.25, end=0.75) topogeom = topology.geom # Topology covers 1 path self.assertEqual(len(topology.paths.all()), 1) cd = PathFactory.create(geom=LineString((2, 0, 0), (2, 2, 0))) cb = Path.objects.filter(name="AB").exclude(pk=ab.pk)[0] # Topology now covers 2 paths self.assertEqual(len(topology.paths.all()), 2) # AB and AB2 has one topology each self.assertEqual(len(ab.aggregations.all()), 1) self.assertEqual(len(cb.aggregations.all()), 1) # Topology position became proportional aggr_ab = ab.aggregations.all()[0] aggr_cb = cb.aggregations.all()[0] self.assertEqual((0.5, 1.0), (aggr_ab.start_position, aggr_ab.end_position)) self.assertEqual((0.0, 0.5), (aggr_cb.start_position, aggr_cb.end_position)) topology.reload() self.assertNotEqual(topology.geom, topogeom) self.assertEqual(topology.geom.coords[0], topogeom.coords[0]) self.assertEqual(topology.geom.coords[-1], topogeom.coords[-1])
def test_delete_show_topologies(self): self.login() path = PathFactory(name="PATH_AB", geom=LineString((0, 0), (4, 0))) poi = POIFactory.create(name='POI', no_path=True) poi.add_path(path, start=0.5, end=0.5) trail = TrailFactory.create(name='Trail', no_path=True) trail.add_path(path, start=0.1, end=0.2) trek = TrekFactory.create(name='Trek', no_path=True) trek.add_path(path, start=0.2, end=0.3) service = ServiceFactory.create(no_path=True, type__name='ServiceType') service.add_path(path, start=0.2, end=0.3) signage = SignageFactory.create(name='Signage', no_path=True) signage.add_path(path, start=0.2, end=0.2) infrastructure = InfrastructureFactory.create(name='Infrastructure', no_path=True) infrastructure.add_path(path, start=0.2, end=0.2) intervention1 = InterventionFactory.create(topology=signage, name='Intervention1') t = TopologyFactory.create(no_path=True) t.add_path(path, start=0.2, end=0.5) intervention2 = InterventionFactory.create(topology=t, name='Intervention2') response = self.client.get(path.get_delete_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Different topologies are linked with this path') self.assertContains(response, '<a href="/poi/%d/">POI</a>' % poi.pk) self.assertContains(response, '<a href="/trail/%d/">Trail</a>' % trail.pk) self.assertContains(response, '<a href="/trek/%d/">Trek</a>' % trek.pk) self.assertContains(response, '<a href="/service/%d/">ServiceType</a>' % service.pk) self.assertContains(response, '<a href="/signage/%d/">Signage</a>' % signage.pk) self.assertContains(response, '<a href="/infrastructure/%d/">Infrastructure</a>' % infrastructure.pk) self.assertContains(response, '<a href="/intervention/%d/">Intervention1</a>' % intervention1.pk) self.assertContains(response, '<a href="/intervention/%d/">Intervention2</a>' % intervention2.pk)
def test_elevation_topology_point(self): topo = TopologyFactory.create(geom="SRID=2154;POINT(33 57)") self.assertEqual(topo.geom_3d.coords[2], 15) self.assertEqual(topo.ascent, 0) self.assertEqual(topo.descent, 0) self.assertEqual(topo.min_elevation, 15) self.assertEqual(topo.max_elevation, 15)
def test_split_on_update_7(self): """ C A +-----------+ B A +-----X---+ B : C X-------+ D : + D """ ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0))) cd = PathFactory.create(name="CD", geom=LineString((0, 1, 0), (4, 1, 0))) topology = TopologyFactory.create(no_path=True) topology.add_path(cd, start=0.0, end=0.0) self.assertEqual(len(topology.paths.all()), 1) cd.geom = LineString((2, 0, 0), (2, -2, 0)) cd.save() cb = Path.objects.filter(name="AB").exclude(pk=ab.pk)[0] self.assertEqual(len(ab.aggregations.all()), 1) self.assertEqual(len(cb.aggregations.all()), 1) self.assertEqual(len(cd.aggregations.all()), 1) self.assertEqual(len(topology.paths.all()), 3) aggr_ab = ab.aggregations.all()[0] aggr_cb = cb.aggregations.all()[0] aggr_cd = cd.aggregations.all()[0] self.assertEqual((1.0, 1.0), (aggr_ab.start_position, aggr_ab.end_position)) self.assertEqual((0.0, 0.0), (aggr_cb.start_position, aggr_cb.end_position)) self.assertEqual((0.0, 0.0), (aggr_cd.start_position, aggr_cd.end_position))
def test_split_tee_1(self): """ C A +-----X----+ B | + AB exists with topology at C. D Add CD. """ ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0))) topology = TopologyFactory.create(no_path=True) topology.add_path(ab, start=0.5, end=0.5) self.assertEqual(len(topology.paths.all()), 1) cd = PathFactory.create(geom=LineString((2, 0, 0), (2, 2, 0))) cb = Path.objects.filter(name="AB").exclude(pk=ab.pk)[0] self.assertEqual(len(topology.paths.all()), 3) self.assertEqual(len(ab.aggregations.all()), 1) aggr_ab = ab.aggregations.all()[0] self.assertEqual(len(cb.aggregations.all()), 1) aggr_cb = cb.aggregations.all()[0] self.assertEqual(len(cd.aggregations.all()), 1) aggr_cd = cd.aggregations.all()[0] self.assertEqual((1.0, 1.0), (aggr_ab.start_position, aggr_ab.end_position)) self.assertEqual((0.0, 0.0), (aggr_cb.start_position, aggr_cb.end_position)) self.assertEqual((0.0, 0.0), (aggr_cd.start_position, aggr_cd.end_position))
def test_elevation_topology_point_offset(self): topo = TopologyFactory.create(paths=[(self.path, 0.5, 0.5)], offset=1) self.assertEqual(topo.geom_3d.coords[2], 15) self.assertEqual(topo.ascent, 0) self.assertEqual(topo.descent, 0) self.assertEqual(topo.min_elevation, 15) self.assertEqual(topo.max_elevation, 15)
def test_junction_point(self): p1 = PathFactory.create(geom=LineString((0, 0, 0), (2, 2, 2))) p2 = PathFactory.create(geom=LineString((0, 0, 0), (2, 0, 0))) p3 = PathFactory.create(geom=LineString((0, 2, 2), (0, 0, 0))) # Create a junction point topology t = TopologyFactory.create(no_path=True) self.assertEqual(len(t.paths.all()), 0) pa = PathAggregationFactory.create(topo_object=t, path=p1, start_position=0.0, end_position=0.0) self.assertItemsEqual(t.paths.all(), [p1, p2, p3]) # Update to a non junction point topology pa.end_position = 0.4 pa.save() self.assertItemsEqual(t.paths.all(), [p1]) # Update to a junction point topology pa.end_position = 0.0 pa.save() self.assertItemsEqual(t.paths.all(), [p1, p2, p3])
def test_split_on_update(self): """ + E : || A +-----------+ B A +----++---+ B || C +-====-+ D C +--===+ D """ ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0))) cd = PathFactory.create(name="CD", geom=LineString((0, -1, 0), (4, -1, 0))) # Create a topology topology = TopologyFactory.create(no_path=True) topology.add_path(cd, start=0.3, end=0.9) self.assertEqual(len(topology.paths.all()), 1) cd.geom = LineString((0, -1, 0), (2, -1, 0), (2, 2, 0)) cd.save() cd2 = Path.objects.filter(name="CD").exclude(pk=cd.pk)[0] self.assertEqual(len(topology.paths.all()), 2) self.assertEqual(len(cd.aggregations.all()), 1) self.assertEqual(len(cd2.aggregations.all()), 1) aggr_cd = cd.aggregations.all()[0] aggr_cd2 = cd2.aggregations.all()[0] self.assertEqual((0.5, 1.0), (aggr_cd.start_position, aggr_cd.end_position)) self.assertEqual((0.0, 0.75), (aggr_cd2.start_position, aggr_cd2.end_position))
def test_project_bbox_filter(self): self.login() p1 = ProjectFactory.create() ProjectFactory.create() ProjectFactory.create() t = TopologyFactory.create() InterventionFactory.create(project=p1, topology=t) def jsonlist(bbox): url = self.model.get_jsonlist_url() + bbox response = self.client.get(url) self.assertEqual(response.status_code, 200) jsondict = json.loads(response.content) return jsondict['aaData'] # Check that projects without interventions are always present self.assertEqual(len(Project.objects.all()), 3) self.assertEqual(len(jsonlist('')), 3) self.assertEqual( len( jsonlist( '?bbox=POLYGON((1%202%200%2C1%202%200%2C1%202%200%2C1%202%200%2C1%202%200))' )), 2) # Give a bbox that match intervention, and check that all 3 projects are back bbox = '?bbox=POLYGON((2.9%2046.4%2C%203.1%2046.4%2C%203.1%2046.6%2C%202.9%2046.6%2C%202.9%2046.4))' self.assertEqual(len(jsonlist(bbox)), 3)
def test_project_bbox_filter(self): p1 = ProjectFactory.create() ProjectFactory.create() ProjectFactory.create() t = TopologyFactory.create() InterventionFactory.create(project=p1, topology=t) def jsonlist(bbox): url = self.model.get_jsonlist_url() + bbox response = self.client.get(url) self.assertEqual(response.status_code, 200) jsondict = json.loads(response.content) return jsondict['aaData'] # Check that projects without interventions are always present self.assertEqual(len(Project.objects.all()), 3) self.assertEqual(len(jsonlist('')), 3) self.assertEqual( len( jsonlist( '?bbox=POLYGON((1%202%200%2C1%202%200%2C1%202%200%2C1%202%200%2C1%202%200))' )), 2) # Give a bbox that match intervention, and check that all 3 projects are back bbox = '?bbox=POLYGON((-1.3630753338765911%20-5.9838497371070440%2C%20-1.3630694576343052%20-5.9838497371070440%2C%20-1.3630694576343052%20-5.9838431650051289%2C%20-1.3630753338765911%20-5.9838431650051289%2C%20-1.3630753338765911%20-5.9838497371070440))' self.assertEqual(len(jsonlist(bbox)), 3)
def test_helpers_nds(self): i1 = InterventionFactory.create() i2 = InterventionFactory.create() i3 = InterventionFactory.create() sign = SignageFactory.create(geom="SRID=4326;POINT(0 5)") i1.set_topology(sign) infra = InfrastructureFactory.create(geom="SRID=4326;POINT(1 5)") i2.set_topology(infra) t = TopologyFactory.create(geom="SRID=4326;POINT(2 5)") i3.topology = t proj = ProjectFactory.create() self.assertCountEqual(proj.paths.all(), []) self.assertEqual(proj.signages, []) self.assertEqual(proj.infrastructures, []) i1.save() proj.interventions.add(i1) self.assertEqual(proj.signages, [sign]) self.assertEqual(proj.infrastructures, []) i2.save() proj.interventions.add(i2) self.assertEqual(proj.signages, [sign]) self.assertEqual(proj.infrastructures, [infra]) i3.save() proj.interventions.add(i3) self.assertEqual(proj.signages, [sign]) self.assertEqual(proj.infrastructures, [infra])
def test_project_bbox_filter(self): self.login() p1 = ProjectFactory.create() ProjectFactory.create() ProjectFactory.create() t = TopologyFactory.create() InterventionFactory.create(project=p1, topology=t) def jsonlist(bbox): url = self.model.get_jsonlist_url() + bbox response = self.client.get(url) self.assertEqual(response.status_code, 200) jsondict = json.loads(response.content) return jsondict['aaData'] # Check that projects without interventions are always present self.assertEqual(len(Project.objects.all()), 3) self.assertEqual(len(jsonlist('')), 3) self.assertEqual(len(jsonlist('?bbox=POLYGON((1%202%200%2C1%202%200%2C1%202%200%2C1%202%200%2C1%202%200))')), 2) # Give a bbox that match intervention, and check that all 3 projects are back bbox = '?bbox=POLYGON((2.9%2046.4%2C%203.1%2046.4%2C%203.1%2046.6%2C%202.9%2046.6%2C%202.9%2046.4))' self.assertEqual(len(jsonlist(bbox)), 3)
def test_mutate(self): topology1 = TopologyFactory.create(no_path=True) self.assertEqual(len(topology1.paths.all()), 0) topology2 = TopologyFactory.create(offset=14.5) self.assertEqual(len(topology2.paths.all()), 1) # Normal usecase topology1.mutate(topology2) self.assertEqual(topology1.offset, 14.5) self.assertEqual(len(topology1.paths.all()), 1) # topology2 does not exist anymore self.assertEqual(len(Topology.objects.filter(pk=topology2.pk)), 0) # Without deletion topology3 = TopologyFactory.create() topology1.mutate(topology3, delete=False) # topology3 still exists self.assertEqual(len(Topology.objects.filter(pk=topology3.pk)), 1)
def test_spoon_loop_2(self): """ =====>==== || || +-------===<===>===+=====<=== """ p1 = PathFactory.create(geom=LineString((0, 0, 0), (10, 0, 0))) p2 = PathFactory.create(geom=LineString((10, 0, 0), (10, 5, 0), (20, 5, 0), (20, 0, 0), (10, 0, 0))) topo = TopologyFactory.create(no_path=True) topo.add_path(p1, start=0.3, end=1) topo.add_path(p2, start=0, end=0.4) topo.add_path(p2, start=0.4, end=0.4) topo.add_path(p2, start=0.4, end=0.8) topo.add_path(p2, start=0.8, end=0.8) topo.add_path(p2, start=0.8, end=1.0) topo.add_path(p1, start=1, end=0.3) topo.save() self.assertEqual(topo.geom, LineString((3, 0, 0), (10, 0, 0), (10, 5, 0), (17, 5, 0), (20, 5, 0), # extra point due middle aggregation (20, 0, 0), (16, 0, 0), (10, 0, 0), (3, 0, 0))) # De/Serializing should work too serialized = """ [{"kind": "TOPOLOGY","positions":{"0":[0.3,1],"1":[0, 0.4]},"paths":[%(pk1)s,%(pk2)s],"offset": 0.0}, {"kind": "TOPOLOGY","positions":{"0":[0.4, 0.8]},"paths":[%(pk2)s],"offset": 0.0}, {"kind": "TOPOLOGY","positions":{"0":[0.8,1],"1":[1,0.3]},"paths":[%(pk2)s,%(pk1)s],"offset": 0.0}]""" % {'pk1': p1.pk, 'pk2': p2.pk} self.assertEqual(json.loads(serialized), json.loads(topo.serialize())) topod = Topology.deserialize(serialized) self.assertEqual(topo.geom, topod.geom) self.assertEqual(len(topod.aggregations.all()), 7)
def test_spoon_loop(self): """ =====<==== || || +-------===<===>===+=====>=== """ p1 = PathFactory.create(geom=LineString((0, 0, 0), (10, 0, 0))) p2 = PathFactory.create(geom=LineString((10, 0, 0), (10, 5, 0), (20, 5, 0), (20, 0, 0), (10, 0, 0))) topo = TopologyFactory.create(no_path=True) topo.add_path(p1, start=0.3, end=1) topo.add_path(p2, start=1, end=0.4) topo.add_path(p2, start=0.4, end=0.4) topo.add_path(p2, start=0.4, end=0.2) topo.add_path(p2, start=0.2, end=0.2) topo.add_path(p2, start=0.2, end=0) topo.add_path(p1, start=1, end=0.3) topo.save() self.assertEqual(topo.geom, LineString((3, 0, 0), (10, 0, 0), (20, 0, 0), (20, 5, 0), (17, 5, 0), (11, 5, 0), # extra point due middle aggregation (10, 5, 0), (10, 0, 0), (3, 0, 0))) # Deserializing should work too topod = Topology.deserialize(""" [{"positions":{"0":[0.3,1],"1":[1, 0.4]},"paths":[%(pk1)s,%(pk2)s]}, {"positions":{"0":[0.4, 0.2]},"paths":[%(pk2)s]}, {"positions":{"0":[0.2,0],"1":[1,0.3]},"paths":[%(pk2)s,%(pk1)s]}]""" % {'pk1': p1.pk, 'pk2': p2.pk}) self.assertEqual(topo.geom, topod.geom) self.assertEqual(len(topod.aggregations.all()), 7)
def test_junction_point(self): p1 = PathFactory.create(geom=LineString((0, 0), (2, 2))) p2 = PathFactory.create(geom=LineString((0, 0), (2, 0))) p3 = PathFactory.create(geom=LineString((0, 2), (0, 0))) # Create a junction point topology t = TopologyFactory.create(paths=[]) self.assertEqual(len(t.paths.all()), 0) pa = PathAggregationFactory.create(topo_object=t, path=p1, start_position=0.0, end_position=0.0) self.assertCountEqual(t.paths.all(), [p1, p2, p3]) # Update to a non junction point topology pa.end_position = 0.4 pa.save() self.assertCountEqual(t.paths.all(), [p1]) # Update to a junction point topology pa.end_position = 0.0 pa.save() self.assertCountEqual(t.paths.all(), [p1, p2, p3])
def setUp(self): self.path1 = PathFactory.create(geom=LineString((0, 0), (0, 10))) self.path2 = PathFactory.create(geom=LineString((0, 20), (0, 10))) self.path3 = PathFactory.create(geom=LineString((0, 20), (0, 30))) self.path4 = PathFactory.create(geom=LineString((0, 30), (0, 40))) self.topo1 = TopologyFactory.create( paths=[(self.path1, 0.5, 1), (self.path2, 1, 0), self.path3, (self.path4, 0, 0.5)]) self.topo2 = TopologyFactory.create(paths=[self.path2]) self.point1 = TopologyFactory.create(paths=[(self.path2, 0.4, 0.4)]) self.point2 = TopologyFactory.create(paths=[(self.path2, 0.8, 0.8)]) self.point3 = TopologyFactory.create(paths=[(self.path2, 0.6, 0.6)])
def test_length(self): e = TopologyFactory.build() self.assertEqual(e.length, 0) e.save() self.assertEqual(e.length, 0) PathAggregationFactory.create(topo_object=e) e.save() self.assertNotEqual(e.length, 0)
def test_length(self): e = TopologyFactory.build(no_path=True) self.assertEqual(e.length, 0) e.save() self.assertEqual(e.length, 0) PathAggregationFactory.create(topo_object=e) e.save() self.assertNotEqual(e.length, 0)
def test_troncon_geom_update(self): # Create a path p = PathFactory.create(geom=LineString((0, 0, 0), (4, 0, 0))) # Create a linear topology t1 = TopologyFactory.create(offset=1, no_path=True) t1.add_path(p, start=0.0, end=0.5) t1_agg = t1.aggregations.get() # Create a point topology t2 = TopologyFactory.create(offset=-1, no_path=True) t2.add_path(p, start=0.5, end=0.5) t2_agg = t2.aggregations.get() # Ensure linear topology is correct before path modification self.assertEqual(t1.offset, 1) self.assertEqual(t1.geom.coords, ((0, 1, 0), (2, 1, 0))) self.assertEqual(t1_agg.start_position, 0.0) self.assertEqual(t1_agg.end_position, 0.5) # Ensure point topology is correct before path modification self.assertEqual(t2.offset, -1) self.assertEqual(t2.geom.coords, (2, -1, 0)) self.assertEqual(t2_agg.start_position, 0.5) self.assertEqual(t2_agg.end_position, 0.5) # Modify path geometry and refresh computed data p.geom = LineString((0, 2, 0), (8, 2, 0)) p.save() t1.reload() t1_agg = t1.aggregations.get() t2.reload() t2_agg = t2.aggregations.get() # Ensure linear topology is correct after path modification self.assertEqual(t1.offset, 1) self.assertEqual(t1.geom.coords, ((0, 3, 0), (4, 3, 0))) self.assertEqual(t1_agg.start_position, 0.0) self.assertEqual(t1_agg.end_position, 0.5) # Ensure point topology is correct before path modification self.assertEqual(t2.offset, -3) self.assertEqual(t2.geom.coords, (2, -1, 0)) self.assertEqual(t2_agg.start_position, 0.25) self.assertEqual(t2_agg.end_position, 0.25)
def test_troncon_geom_update(self): # Create a path p = PathFactory.create(geom=LineString((0, 0), (4, 0))) # Create a linear topology t1 = TopologyFactory.create(offset=1, no_path=True) t1.add_path(p, start=0.0, end=0.5) t1_agg = t1.aggregations.get() # Create a point topology t2 = TopologyFactory.create(offset=-1, no_path=True) t2.add_path(p, start=0.5, end=0.5) t2_agg = t2.aggregations.get() # Ensure linear topology is correct before path modification self.assertEqual(t1.offset, 1) self.assertEqual(t1.geom.coords, ((0, 1), (2, 1))) self.assertEqual(t1_agg.start_position, 0.0) self.assertEqual(t1_agg.end_position, 0.5) # Ensure point topology is correct before path modification self.assertEqual(t2.offset, -1) self.assertEqual(t2.geom.coords, (2, -1)) self.assertEqual(t2_agg.start_position, 0.5) self.assertEqual(t2_agg.end_position, 0.5) # Modify path geometry and refresh computed data p.geom = LineString((0, 2), (8, 2)) p.save() t1.reload() t1_agg = t1.aggregations.get() t2.reload() t2_agg = t2.aggregations.get() # Ensure linear topology is correct after path modification self.assertEqual(t1.offset, 1) self.assertEqual(t1.geom.coords, ((0, 3), (4, 3))) self.assertEqual(t1_agg.start_position, 0.0) self.assertEqual(t1_agg.end_position, 0.5) # Ensure point topology is correct before path modification self.assertEqual(t2.offset, -3) self.assertEqual(t2.geom.coords, (2, -1)) self.assertEqual(t2_agg.start_position, 0.25) self.assertEqual(t2_agg.end_position, 0.25)
def test_topology_geom_with_intermediate_markers(self): # Intermediate (forced passage) markers for topologies # Use a bifurcation, make sure computed geometry is correct # +--p2---+ # +---+-------+---+ # p1 p3 p4 p1 = PathFactory.create(geom=LineString((0, 0, 0), (2, 0, 0))) p2 = PathFactory.create(geom=LineString((2, 0, 0), (2, 1, 0), (4, 1, 0), (4, 0, 0))) p3 = PathFactory.create(geom=LineString((2, 0, 0), (4, 0, 0))) p4 = PathFactory.create(geom=LineString((4, 0, 0), (6, 0, 0))) """ From p1 to p4, with point in the middle of p3 """ t = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t, path=p1) PathAggregationFactory.create(topo_object=t, path=p3) PathAggregationFactory.create(topo_object=t, path=p3, start_position=0.5, end_position=0.5) PathAggregationFactory.create(topo_object=t, path=p4) t.save() self.assertEqual(t.geom, LineString((0, 0, 0), (2, 0, 0), (4, 0, 0), (6, 0, 0))) """ From p1 to p4, through p2 """ t = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t, path=p1) PathAggregationFactory.create(topo_object=t, path=p2) # There will a forced passage in database... PathAggregationFactory.create(topo_object=t, path=p2, start_position=0.5, end_position=0.5) PathAggregationFactory.create(topo_object=t, path=p4) t.save() self.assertEqual(t.geom, LineString((0, 0, 0), (2, 0, 0), (2, 1, 0), (4, 1, 0), (4, 0, 0), (6, 0, 0))) """ From p1 to p4, though p2, but **with start/end at 0.0** """ t2 = TopologyFactory.create(no_path=True) PathAggregationFactory.create(topo_object=t2, path=p1) PathAggregationFactory.create(topo_object=t2, path=p2) PathAggregationFactory.create(topo_object=t2, path=p2, start_position=0.0, end_position=0.0) PathAggregationFactory.create(topo_object=t2, path=p4) t2.save() self.assertEqual(t2.geom, t.geom)
def test_elevation_topology_point_offset(self): topo = TopologyFactory.create(no_path=True, offset=1) topo.add_path(self.path, start=0.5, end=0.5) topo.save() self.assertEqual(topo.geom_3d.coords[2], 15) self.assertEqual(topo.ascent, 0) self.assertEqual(topo.descent, 0) self.assertEqual(topo.min_elevation, 15) self.assertEqual(topo.max_elevation, 15)
def test_elevation_topology_point(self): topo = TopologyFactory.create(no_path=True) topo.add_path(self.path, start=0.5, end=0.5) topo.save() self.assertEqual(topo.ascent, 0) self.assertEqual(topo.descent, 0) self.assertEqual(topo.min_elevation, 5) self.assertEqual(topo.max_elevation, 5)
def test_serialize_two_consecutive_forced(self): path1 = PathFactory.create() path2 = PathFactory.create() path3 = PathFactory.create() topology = TopologyFactory.create( paths=[path1, (path2, 0.2, 0.2), (path2, 0.4, 0.4), path3]) fieldvalue = topology.serialize() field = json.loads(fieldvalue) self.assertEqual(len(field), 2)
def create_pair_of_distinct_by_topo_project(self): p1, seek_path = self.create_pair_of_distinct_path() topo_1 = TopologyFactory.create(no_path=True) topo_1.add_path(path=p1, start=0, end=1) seek_topo = TopologyFactory.create(no_path=True) seek_topo.add_path(path=seek_path, start=0, end=1) it_p1 = InterventionFactory.create(topology=topo_1) seek_it = InterventionFactory.create(topology=seek_topo) seek_proj = ProjectFactory.create() seek_proj.interventions.add(seek_it) proj_1 = ProjectFactory.create() proj_1.interventions.add(it_p1) return seek_proj, seek_path
def test_elevation_topology_line(self): topo = TopologyFactory.create(no_path=True) topo.add_path(self.path, start=0.2, end=0.8) topo.save() self.assertEqual(topo.ascent, 5) self.assertEqual(topo.descent, -2) self.assertEqual(topo.min_elevation, 5) self.assertEqual(topo.max_elevation, 10) self.assertEqual(len(topo.geom_3d.coords), 4)
def test_serialize_point(self): path = PathFactory.create() topology = TopologyFactory.create(offset=1, no_path=True) topology.add_path(path, start=0.5, end=0.5) fieldvalue = topology.serialize() # fieldvalue is like '{"lat": -5.983842291017086, "lng": -1.3630770374505987, "kind": "TOPOLOGY"}' field = json.loads(fieldvalue) self.assertTrue(almostequal(field['lat'], -5.983)) self.assertTrue(almostequal(field['lng'], -1.363)) self.assertEqual(field['kind'], "TOPOLOGY")
def test_deleted_when_all_path_are_deleted(self): topology = TopologyFactory.create() self.assertFalse(topology.deleted) paths = path = topology.paths.all() for path in paths: path.delete() topology.reload() self.assertTrue(topology.deleted)
def test_dates(self): t1 = dbnow() e = TopologyFactory.build(no_path=True) e.save() t2 = dbnow() self.assertTrue(t1 < e.date_insert < t2) e.delete() t3 = dbnow() self.assertTrue(t2 < e.date_update < t3)
def test_elevation_topology_outside_dem(self): outside_path = Path.objects.create(geom=LineString((200, 200), (300, 300))) topo = TopologyFactory.create(no_path=True) topo.add_path(outside_path, start=0.5, end=0.5) topo.save() self.assertEqual(topo.geom_3d.coords[2], 0) self.assertEqual(topo.ascent, 0) self.assertEqual(topo.descent, 0) self.assertEqual(topo.min_elevation, 0) self.assertEqual(topo.max_elevation, 0)
def test_serialize_line(self): path = PathFactory.create() test_objdict = dict(kind=Topology.KIND, offset=1.0, positions={}, paths=[path.pk]) # +|========>+ topo = TopologyFactory.create(offset=1.0, no_path=True) topo.add_path(path) test_objdict['pk'] = topo.pk test_objdict['positions']['0'] = [0.0, 1.0] objdict = json.loads(topo.serialize()) self.assertDictEqual(objdict[0], test_objdict) # +<========|+ topo = TopologyFactory.create(offset=1.0, no_path=True) topo.add_path(path, start=1.0, end=0.0) test_objdict['pk'] = topo.pk test_objdict['positions']['0'] = [1.0, 0.0] objdict = json.loads(topo.serialize()) self.assertDictEqual(objdict[0], test_objdict) # +|========>+<========|+ path2 = PathFactory.create() topo = TopologyFactory.create(offset=1.0, no_path=True) topo.add_path(path, start=0.0, end=1.0) topo.add_path(path2, start=1.0, end=0.0) test_objdict['pk'] = topo.pk test_objdict['paths'] = [path.pk, path2.pk] test_objdict['positions'] = {'0': [0.0, 1.0], '1': [1.0, 0.0]} objdict = json.loads(topo.serialize()) self.assertDictEqual(objdict[0], test_objdict) # +<========|+|========>+ topo = TopologyFactory.create(offset=1.0, no_path=True) topo.add_path(path, start=1.0, end=0.0) topo.add_path(path2, start=0.0, end=1.0) test_objdict['pk'] = topo.pk test_objdict['paths'] = [path.pk, path2.pk] test_objdict['positions'] = {'0': [1.0, 0.0], '1': [0.0, 1.0]} objdict = json.loads(topo.serialize()) self.assertDictEqual(objdict[0], test_objdict)