Ejemplo n.º 1
0
 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])
Ejemplo n.º 2
0
    def test_delete_cascade(self):
        p1 = PathFactory.create()
        p2 = PathFactory.create()
        t = TrekFactory.create(no_path=True)
        t.add_path(p1)
        t.add_path(p2)

        # Everything should be all right before delete
        self.assertTrue(t.published)
        self.assertFalse(t.deleted)
        self.assertEqual(t.aggregations.count(), 2)

        # When a path is deleted
        p1.delete()
        t = Trek.objects.get(pk=t.pk)
        self.assertFalse(t.published)
        self.assertFalse(t.deleted)
        self.assertEqual(t.aggregations.count(), 1)

        # Reset published status
        t.published = True
        t.save()

        # When all paths are deleted
        p2.delete()
        t = Trek.objects.get(pk=t.pk)
        self.assertFalse(t.published)
        self.assertTrue(t.deleted)
        self.assertEqual(t.aggregations.count(), 0)
Ejemplo n.º 3
0
 def test_delete_multiple_path(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     poi = POIFactory.create(no_path=True, name="POI_1")
     poi.add_path(path_1, start=0, end=0)
     infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1")
     infrastructure.add_path(path_1, start=0, end=1)
     signage = SignageFactory.create(no_path=True, name="SIGNA_1")
     signage.add_path(path_1, start=0, end=1)
     trail = TrailFactory.create(no_path=True, name="TRAIL_1")
     trail.add_path(path_2, start=0, end=1)
     service = ServiceFactory.create(no_path=True)
     service.add_path(path_2, start=0, end=1)
     InterventionFactory.create(topology=signage, name="INTER_1")
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertIn("POI_1", response.content)
     self.assertIn("INFRA_1", response.content)
     self.assertIn("SIGNA_1", response.content)
     self.assertIn("TRAIL_1", response.content)
     self.assertIn("ServiceType", response.content)
     self.assertIn("INTER_1", response.content)
     response = self.client.post(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(Path.objects.count(), 2)
     self.assertEqual(Path.objects.filter(pk__in=[path_1.pk, path_2.pk]).count(), 0)
Ejemplo n.º 4
0
 def test_latestupdate_delete(self):
     for i in range(10):
         PathFactory.create()
     t1 = dbnow()
     self.assertTrue(t1 > Path.latest_updated())
     (Path.objects.all()[0]).delete()
     self.assertFalse(t1 > Path.latest_updated())
Ejemplo n.º 5
0
    def test_helpers(self):
        trek = TrekFactory.create(no_path=True)
        p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
        p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
        poi = POIFactory.create(no_path=True)
        PathAggregationFactory.create(topo_object=trek, path=p1,
                                      start_position=0.5)
        PathAggregationFactory.create(topo_object=trek, path=p2)
        PathAggregationFactory.create(topo_object=poi, path=p1,
                                      start_position=0.6, end_position=0.6)
        # /!\ District are automatically linked to paths at DB level
        d1 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2)))))

        # Ensure related objects are accessible
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(poi.treks, [trek])
        self.assertItemsEqual(trek.districts, [d1])

        # Ensure there is no duplicates
        PathAggregationFactory.create(topo_object=trek, path=p1,
                                      end_position=0.5)
        self.assertItemsEqual(trek.pois, [poi])
        self.assertItemsEqual(poi.treks, [trek])

        d2 = DistrictFactory.create(geom=MultiPolygon(
            Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3)))))
        self.assertItemsEqual(trek.districts, [d1, d2])
Ejemplo n.º 6
0
    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)))
Ejemplo n.º 7
0
    def test_split_twice(self):
        """

             C   D
             +   +
             |   |
        A +--+---+--+ B
             |   |
             +---+

        """
        ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0)))
        cd = PathFactory.create(name="CD", geom=LineString((1, 2, 0), (1, -2, 0),
                                                           (3, -2, 0), (3, 2, 0)))
        ab.reload()
        self.assertEqual(ab.length, 1)
        self.assertEqual(cd.length, 2)
        ab_clones = Path.objects.filter(name="AB").exclude(pk=ab.pk)
        cd_clones = Path.objects.filter(name="CD").exclude(pk=cd.pk)
        self.assertEqual(len(ab_clones), 2)
        self.assertEqual(len(cd_clones), 2)
        self.assertEqual(ab_clones[0].geom, LineString((1, 0, 0), (3, 0, 0)))
        self.assertEqual(ab_clones[1].geom, LineString((3, 0, 0), (4, 0, 0)))

        self.assertEqual(cd_clones[0].geom, LineString((1, 0, 0), (1, -2, 0),
                                                       (3, -2, 0), (3, 0, 0)))
        self.assertEqual(cd_clones[1].geom, LineString((3, 0, 0), (3, 2, 0)))
Ejemplo n.º 8
0
 def test_merge_works(self):
     self.login()
     p1 = PathFactory.create(name="AB", geom=LineString((0, 0), (1, 0)))
     p2 = PathFactory.create(name="BC", geom=LineString((1, 0), (2, 0)))
     response = self.client.post(reverse('core:merge_path'), {'path[]': [p1.pk, p2.pk]})
     self.assertIn('success', response.json())
     self.logout()
Ejemplo n.º 9
0
 def test_default_stake(self):
     i = InterventionFactory.create()
     i.stake = None
     self.assertTrue(i.stake is None)
     i.save()
     self.assertTrue(i.stake is None)
     
     lowstake = StakeFactory.create()
     highstake = StakeFactory.create()
     if lowstake > highstake:
         tmp = lowstake
         lowstake = highstake
         highstake = tmp
     
     # Add paths to topology
     infra = InfrastructureFactory.create(no_path=True)
     infra.add_path(PathFactory.create(stake=lowstake))
     infra.add_path(PathFactory.create(stake=highstake))
     infra.add_path(PathFactory.create(stake=lowstake))
     i.set_infrastructure(infra)
     # Stake is not None anymore
     i.save()
     self.assertFalse(i.stake is None)
     # Make sure it took higher stake
     self.assertEqual(i.stake, highstake)
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
 def test_snapping_is_idempotent(self):
     PathFactory.create(geom=LineString((0, 0), (9.8, 0), (9.9, 0), (10, 0)))
     path_snapped = PathFactory.create(geom=LineString((10, 0.1), (10, 10)))
     old_geom = path_snapped.geom
     path_snapped.geom = old_geom
     path_snapped.save()
     self.assertEqual(path_snapped.geom.coords, old_geom.coords)
Ejemplo n.º 13
0
    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))
Ejemplo n.º 14
0
    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])
Ejemplo n.º 15
0
    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))
Ejemplo n.º 16
0
    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))
Ejemplo n.º 17
0
 def test_show_delete_multiple_path_in_list(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     poi = POIFactory.create(no_path=True)
     poi.add_path(path_1, start=0, end=0)
     response = self.client.get(reverse('core:path_list'))
     self.assertIn('<a href="#delete" id="btn-delete" role="button">', response.content)
Ejemplo n.º 18
0
    def test_point_geom_3d(self):
        """
           +
          / \
         / X \
        +     +
        """
        p1 = PathFactory.create(geom=LineString((0, 0, 1000), (4, 4, 2000)))
        p2 = PathFactory.create(geom=LineString((4, 4, 2000), (8, 0, 0)))

        poi = Point(3, 1, srid=settings.SRID)
        position, distance = Path.interpolate(p1, poi)
        self.assertTrue(almostequal(0.5, position))
        self.assertTrue(almostequal(-1.414, distance))
        # Verify that deserializing this, we obtain the same original coordinates
        # (use lat/lng as in forms)
        poi.transform(settings.API_SRID)
        poitopo = Topology.deserialize({'lat': poi.y, 'lng': poi.x})
        # Computed topology properties match original interpolation
        self.assertTrue(almostequal(0.5, poitopo.aggregations.all()[0].start_position))
        self.assertTrue(almostequal(-1.414, poitopo.offset))
        # Resulting geometry
        self.assertTrue(almostequal(3, poitopo.geom.x))
        self.assertTrue(almostequal(1, poitopo.geom.y))
        self.assertTrue(almostequal(0, poitopo.geom.z))
Ejemplo n.º 19
0
    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])
Ejemplo n.º 20
0
 def test_return_path_serialized(self):
     """
     Same as test_return_path() but from deserialization.
     """
     p1 = PathFactory.create(geom=LineString((0, 0), (10, 0)))
     p2 = PathFactory.create(geom=LineString((5, 0), (5, 10), (10, 10)))
     p3 = Path.objects.filter(name=p1.name).exclude(pk=p1.pk)[0]  # Was splitted :)
     topo = Topology.deserialize(
         """
        [{"offset":0,
          "positions":{"0":[0.5,1],
                       "1":[0.0, 0.8]},
          "paths":[%(p1)s,%(p2)s]
         },
         {"offset":0,
          "positions":{"0":[0.8,0.0],
                       "1":[0.0, 0.5]},
          "paths":[%(p2)s,%(p3)s]
         }
        ]
     """
         % {"p1": p1.pk, "p2": p2.pk, "p3": p3.pk}
     )
     topo.save()
     self.assertEqual(topo.geom, LineString((2.5, 0), (5, 0), (5, 10), (7, 10), (5, 10), (5, 0), (7.5, 0)))
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
 def test_delete_view_multiple_path(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     poi = POIFactory.create(no_path=True)
     poi.add_path(path_1, start=0, end=0)
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 200)
     self.assertIn('Do you really wish to delete', response.content)
Ejemplo n.º 24
0
    def test_merge_fails_donttouch(self):
        self.login()
        p3 = PathFactory.create(name="AB", geom=LineString((0, 0), (1, 0)))
        p4 = PathFactory.create(name="BC", geom=LineString((500, 0), (1000, 0)))

        response = self.client.post(reverse('core:merge_path'), {'path[]': [p3.pk, p4.pk]})
        self.assertIn('error', response.json())
        self.logout()
Ejemplo n.º 25
0
 def get_good_data(self):
     PathFactory.create()
     return {
         "name": "test",
         "description": "oh",
         "structure": default_structure().pk,
         "type": InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         "topology": '{"lat": 0.42, "lng": 0.666}',
     }
Ejemplo n.º 26
0
 def get_good_data(self):
     PathFactory.create()
     return {
         'name': 'test',
         'description': 'oh',
         'structure': default_structure().pk,
         'type': InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         'topology': '{"lat": 0.42, "lng": 0.666}'
     }
Ejemplo n.º 27
0
 def get_good_data(self):
     PathFactory.create()
     return {
         'name_fr': 'test',
         'name_en': 'test',
         'description_fr': 'ici',
         'description_en': 'here',
         'type': POITypeFactory.create().pk,
         'topology': '{"lat": 5.1, "lng": 6.6}'
     }
Ejemplo n.º 28
0
 def test_split_cross_on_deleted(self):
     """
     Paths should not be splitted if they cross deleted paths.
     (attribute delete=True)
     """
     ab = PathFactory.create(name="AB", geom=LineString((0, 0, 0), (4, 0, 0)))
     self.assertEqual(len(Path.objects.all()), 1)
     ab.delete()
     self.assertEqual(len(Path.objects.all()), 0)
     cd = PathFactory.create(name="CD", geom=LineString((2, -2, 0), (2, 2, 0)))
     self.assertEqual(len(Path.objects.all()), 1)
Ejemplo n.º 29
0
    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)
Ejemplo n.º 30
0
    def test_path_merge_without_snap(self):
        """
          A         B   C         D     A                  D
          |---------| + |---------| --> |------------------|

          Test five cases : 1 - A match with C : unification D-C-A-B
                            2 - A match with D : unification C-D-A-B
                            3 - B match with C : unification A-B-C-D
                            4 - B match with D : unification A-B-D-C
                            5 - no match       : no unification
        """
        path_AB = PathFactory.create(name="PATH_AB", geom=LineString((0, 0), (4, 0)))
        path_CD = PathFactory.create(name="PATH_CD", geom=LineString((4, 0), (8, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(path_AB.geom, LineString((0, 0), (4, 0), (8, 0)))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB = PathFactory.create(name="path_AB", geom=LineString((4, 0), (0, 0)))
        path_CD = PathFactory.create(name="path_CD", geom=LineString((4, 0), (8, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(path_AB.geom, LineString((0, 0), (4, 0), (8, 0)))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB = PathFactory.create(name="path_AB", geom=LineString((4, 0), (0, 0)))
        path_CD = PathFactory.create(name="path_CD", geom=LineString((8, 0), (4, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(path_AB.geom, LineString((0, 0), (4, 0), (8, 0)))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB = PathFactory.create(name="path_AB", geom=LineString((0, 0), (4, 0)))
        path_CD = PathFactory.create(name="path_CD", geom=LineString((8, 0), (4, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(path_AB.geom, LineString((0, 0), (4, 0), (8, 0)))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB = PathFactory.create(name="PATH_AB", geom=LineString((0, 0), (4, 0)))
        path_CD = PathFactory.create(name="PATH_CD", geom=LineString((50, 0), (100, 0)))
        original_AB_length = path_AB.length

        self.assertEqual(path_AB.merge_path(path_CD), False)
        self.assertEqual(path_AB.length, original_AB_length)
Ejemplo n.º 31
0
    def test_shape_mixed(self):
        """
        Test that a project made of intervention of different geom create multiple files.
        Check that those files are each of a different type (Point/LineString) and that
        the project and the intervention are correctly referenced in it.
        """

        # Create topology line
        topo_line = TopologyFactory.create(no_path=True)
        line = PathFactory.create(
            geom=LineString(Point(10, 10), Point(11, 10)))
        PathAggregationFactory.create(topo_object=topo_line, path=line)

        # Create a topology point
        lng, lat = tuple(
            Point(1, 1, srid=settings.SRID).transform(settings.API_SRID,
                                                      clone=True))

        closest_path = PathFactory(
            geom=LineString(Point(0, 0), Point(1, 0), srid=settings.SRID))
        topo_point = TopologyHelper._topologypoint(lng, lat, None).reload()

        self.assertEquals(topo_point.paths.get(), closest_path)

        # Create one intervention by geometry (point/linestring)
        it_point = InterventionFactory.create(topology=topo_point)
        it_line = InterventionFactory.create(topology=topo_line)
        # reload
        it_point = type(it_point).objects.get(pk=it_point.pk)
        it_line = type(it_line).objects.get(pk=it_line.pk)

        proj = ProjectFactory.create()
        proj.interventions.add(it_point)
        proj.interventions.add(it_line)

        # instanciate the class based view 'abnormally' to use create_shape directly
        # to avoid making http request, authent and reading from a zip
        pfl = ZipShapeSerializer()
        devnull = open(os.devnull, "wb")
        pfl.serialize(Project.objects.all(),
                      stream=devnull,
                      delete=False,
                      fields=ProjectFormatList.columns)
        self.assertEquals(len(pfl.layers), 2)

        ds_point = gdal.DataSource(pfl.layers.values()[0])
        layer_point = ds_point[0]
        ds_line = gdal.DataSource(pfl.layers.values()[1])
        layer_line = ds_line[0]

        self.assertEquals(layer_point.geom_type.name, 'MultiPoint')
        self.assertEquals(layer_line.geom_type.name, 'LineString')

        for layer in [layer_point, layer_line]:
            self.assertEquals(layer.srs.name, 'RGF93_Lambert_93')
            self.assertItemsEqual(layer.fields, [
                u'id', u'name', u'period', u'type', u'domain', u'constraint',
                u'global_cos', u'interventi', u'interven_1', u'comments',
                u'contractor', u'project_ow', u'project_ma', u'founders',
                u'related_st', u'insertion_', u'update_dat', u'cities',
                u'districts', u'restricted'
            ])

        self.assertEquals(len(layer_point), 1)
        self.assertEquals(len(layer_line), 1)

        for feature in layer_point:
            self.assertEquals(str(feature['id']), str(proj.pk))
            self.assertEquals(len(feature.geom.geos), 1)
            self.assertAlmostEqual(feature.geom.geos[0].x, it_point.geom.x)
            self.assertAlmostEqual(feature.geom.geos[0].y, it_point.geom.y)

        for feature in layer_line:
            self.assertEquals(str(feature['id']), str(proj.pk))
            self.assertTrue(feature.geom.geos.equals(it_line.geom))

        # Clean-up temporary shapefiles
        for layer_file in pfl.layers.values():
            for subfile in shapefile_files(layer_file):
                os.remove(subfile)
Ejemplo n.º 32
0
 def test_snapping_choose_closest_point(self):
     # Line with several points in less than PATH_SNAPPING_DISTANCE
     PathFactory.create(
         geom=LineString((0, 0), (9.8, 0), (9.9, 0), (10, 0)))
     path_snapped = PathFactory.create(geom=LineString((10, 0.1), (10, 10)))
     self.assertEqual(path_snapped.geom.coords, ((10, 0), (10, 10)))
Ejemplo n.º 33
0
    def test_path_merge_with_snap(self):
        """
          A         B   C         D     A                  D
          |---------| + |---------| --> |------------------|

          Test five cases : 1 - A match with C : unification D-C-A-B
                            2 - A match with D : unification C-D-A-B
                            3 - B match with C : unification A-B-C-D
                            4 - B match with D : unification A-B-D-C
                            5 - no match       : no unification
        """
        path_AB = PathFactory.create(name="PATH_AB",
                                     geom=LineString((0, 0), (15, 0)))
        path_CD = PathFactory.create(name="PATH_CD",
                                     geom=LineString((16, 0), (30, 0)))

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(
            path_AB.geom,
            LineString((0, 0), (15, 0), (16, 0), (30, 0), srid=settings.SRID))

        path_AB.delete()
        path_CD.delete()

        path_AB = PathFactory.create(name="path_AB",
                                     geom=LineString((15, 0), (0, 0)))
        path_CD = PathFactory.create(name="path_CD",
                                     geom=LineString((16, 0), (30, 0)))

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(
            path_AB.geom,
            LineString((0, 0), (15, 0), (16, 0), (30, 0), srid=settings.SRID))

        path_AB.delete()
        path_CD.delete()

        path_AB = PathFactory.create(name="path_AB",
                                     geom=LineString((15, 0), (0, 0)))
        path_CD = PathFactory.create(name="path_CD",
                                     geom=LineString((30, 0), (16, 0)))

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(
            path_AB.geom,
            LineString((0, 0), (15, 0), (16, 0), (30, 0), srid=settings.SRID))

        path_AB.delete()
        path_CD.delete()

        path_AB = PathFactory.create(name="path_AB",
                                     geom=LineString((0, 0), (15, 0)))
        path_CD = PathFactory.create(name="path_CD",
                                     geom=LineString((30, 0), (16, 0)))

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(
            path_AB.geom,
            LineString((0, 0), (15, 0), (16, 0), (30, 0), srid=settings.SRID))

        path_AB.delete()
        path_CD.delete()

        path_AB = PathFactory.create(name="PATH_AB",
                                     geom=LineString((0, 0), (5, 0)))
        path_CD = PathFactory.create(name="PATH_CD",
                                     geom=LineString((50, 0), (100, 0)))

        self.assertEqual(path_AB.merge_path(path_CD), False)
Ejemplo n.º 34
0
    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)
Ejemplo n.º 35
0
 def test_extent(self):
     p1 = PathFactory.create()
     self.assertEqual(p1.extent, (3.0, 46.499999999999936, 3.0013039767202154, 46.50090044234927))
Ejemplo n.º 36
0
 def test_valid_geometry_can_be_saved(self):
     PathFactory.create(geom=LineString((0, 0), (2, 0), (1, 1)))
Ejemplo n.º 37
0
 def test_snapping_3d_extremities(self):
     PathFactory.create(geom=LineString(((0, 0, 0), (10, 0, 1000))))
     path_snapped = PathFactory.create(
         geom=LineString((8, 0, 0), (-50, -50, 0)))
     self.assertEqual(path_snapped.geom.coords, ((8, 0, 0), (-50, -50, 0)))
Ejemplo n.º 38
0
    def test_shape_mixed(self):
        """
        Test that a project made of intervention of different geom create multiple files.
        Check that those files are each of a different type (Point/LineString) and that
        the project and the intervention are correctly referenced in it.
        """

        # Create topology line

        line = PathFactory.create(geom=LineString(Point(10, 10), Point(11, 10)))
        topo_line = TopologyFactory.create(paths=[line])

        # Create a topology point
        lng, lat = tuple(Point(1, 1, srid=settings.SRID).transform(settings.API_SRID, clone=True))

        closest_path = PathFactory(geom=LineString(Point(0, 0), Point(1, 0), srid=settings.SRID))
        topo_point = Topology._topologypoint(lng, lat, None)
        topo_point.save()

        self.assertEqual(topo_point.paths.get(), closest_path)

        # Create one intervention by geometry (point/linestring)
        it_point = InterventionFactory.create(target=topo_point)
        it_line = InterventionFactory.create(target=topo_line)
        # reload
        it_point = type(it_point).objects.get(pk=it_point.pk)
        it_line = type(it_line).objects.get(pk=it_line.pk)

        proj = ProjectFactory.create()
        proj.interventions.add(it_point)
        proj.interventions.add(it_line)

        # instanciate the class based view 'abnormally' to use create_shape directly
        # to avoid making http request, authent and reading from a zip
        pfl = ZipShapeSerializer()
        shapefiles = pfl.path_directory
        devnull = open(os.devnull, "wb")
        pfl.serialize(Project.objects.all(), stream=devnull, delete=False,
                      fields=ProjectFormatList.columns)
        shapefiles = [shapefile for shapefile in os.listdir(shapefiles) if shapefile[-3:] == "shp"]
        datasources = [gdal.DataSource(os.path.join(pfl.path_directory, s)) for s in shapefiles]
        layers = [ds[0] for ds in datasources]

        self.assertEqual(len(datasources), 2)
        geom_type_layer = {layer.name: layer for layer in layers}
        geom_types = geom_type_layer.keys()
        self.assertIn('MultiPoint', geom_types)
        self.assertIn('MultiLineString', geom_types)

        for layer in layers:
            self.assertEqual(layer.srs.name, 'RGF93_Lambert_93')
            self.assertCountEqual(layer.fields, [
                'id', 'name', 'period', 'type', 'domain', 'constraint',
                'global_cos', 'interventi', 'comments',
                'contractor', 'project_ow', 'project_ma', 'founders',
                'related_st', 'insertion_', 'update_dat',
                'cities', 'districts', 'restricted'
            ])

        self.assertEqual(len(layers[0]), 1)
        self.assertEqual(len(layers[1]), 1)

        for feature in geom_type_layer['MultiPoint']:
            self.assertEqual(str(feature['id']), str(proj.pk))
            self.assertEqual(len(feature.geom.geos), 1)
            self.assertAlmostEqual(feature.geom.geos[0].x, it_point.geom.x)
            self.assertAlmostEqual(feature.geom.geos[0].y, it_point.geom.y)

        for feature in geom_type_layer['MultiLineString']:
            self.assertEqual(str(feature['id']), str(proj.pk))
            self.assertTrue(feature.geom.geos.equals(it_line.geom))
Ejemplo n.º 39
0
 def test_no_trail_csv(self):
     p1 = PathFactory.create()
     self.assertEqual(p1.trails_csv_display, 'None')
Ejemplo n.º 40
0
 def test_trail_csv(self):
     p1 = PathFactory.create()
     t1 = TrailFactory.create(paths=[p1])
     self.assertEqual(p1.trails_csv_display, t1.name)
Ejemplo n.º 41
0
 def test_trails_verbose_name(self):
     path = PathFactory.create()
     self.assertEqual(path.trails_verbose_name, 'Trails')
Ejemplo n.º 42
0
 def create_path():
     PathFactory.create(
         geom=LineString((0, 0), (2, 0), (1, 1), (1, -1)))
Ejemplo n.º 43
0
 def test_delete_view_multiple_path(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)]))
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'Do you really wish to delete')
Ejemplo n.º 44
0
    def test_path_merge_without_snap(self):
        """
          A         B   C         D     A                  D
          |---------| + |---------| --> |------------------|

          Test five cases : 1 - A match with C : unification D-C-A-B
                            2 - A match with D : unification C-D-A-B
                            3 - B match with C : unification A-B-C-D
                            4 - B match with D : unification A-B-D-C
                            5 - no match       : no unification
        """
        path_AB = PathFactory.create(name="PATH_AB", geom=LineString((0, 0), (4, 0)))
        path_CD = PathFactory.create(name="PATH_CD", geom=LineString((4, 0), (8, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)

        self.assertEqual(path_AB.geom, LineString((0.0, 0.0), (4.0, 0.0), (8.0, 0.0), srid=settings.SRID))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB.delete()
        path_CD.delete()

        path_AB = PathFactory.create(name="path_AB", geom=LineString((4, 0), (0, 0)))
        path_CD = PathFactory.create(name="path_CD", geom=LineString((4, 0), (8, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(path_AB.geom, LineString((0, 0), (4, 0), (8, 0), srid=settings.SRID))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB.delete()
        path_CD.delete()

        path_AB = PathFactory.create(name="path_AB", geom=LineString((4, 0), (0, 0)))
        path_CD = PathFactory.create(name="path_CD", geom=LineString((8, 0), (4, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(path_AB.geom, LineString((0, 0), (4, 0), (8, 0), srid=settings.SRID))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB.delete()
        path_CD.delete()

        path_AB = PathFactory.create(name="path_AB", geom=LineString((0, 0), (4, 0)))
        path_CD = PathFactory.create(name="path_CD", geom=LineString((8, 0), (4, 0)))
        original_AB_length = path_AB.length
        original_CD_length = path_CD.length

        self.assertEqual(path_AB.merge_path(path_CD), True)
        self.assertEqual(path_AB.geom, LineString((0, 0), (4, 0), (8, 0), srid=settings.SRID))
        self.assertEqual(path_AB.length, original_AB_length + original_CD_length)

        path_AB = PathFactory.create(name="PATH_AB", geom=LineString((0, 0), (4, 0)))
        path_CD = PathFactory.create(name="PATH_CD", geom=LineString((50, 0), (100, 0)))
        original_AB_length = path_AB.length

        self.assertEqual(path_AB.merge_path(path_CD), False)
        self.assertEqual(path_AB.length, original_AB_length)
Ejemplo n.º 45
0
 def test_interpolate_reproj(self):
     p = PathFactory.create()
     self.assertEqual(p.interpolate(Point(3, 46.5, srid=4326)), (0, 0))
Ejemplo n.º 46
0
 def test_modify_self_intersection_raises_integrity_error(self):
     p = PathFactory.create(geom=LineString((0, 0), (2, 0), (1, 1)))
     p.geom = LineString((0, 0), (2, 0), (1, 1), (1, -1))
     self.assertRaises(IntegrityError, p.save)
Ejemplo n.º 47
0
 def test_geom(self):
     t = TrailFactory.create()
     self.assertTrue(t.geom is None)
     p = PathFactory.create()
     t.paths.add(p)
     self.assertFalse(t.geom is None)
Ejemplo n.º 48
0
 def test_snap_reproj(self):
     p = PathFactory.create()
     snap = p.snap(Point(3, 46.5, srid=4326))
     self.assertEqual(snap.x, 700000)
     self.assertEqual(snap.y, 6600000)
Ejemplo n.º 49
0
 def test_snapping_3d(self):
     PathFactory.create(geom=LineString(((0, 0, 0), (5, 0, 1000), (6, 0,
                                                                   0))))
     path_snapped = PathFactory.create(
         geom=LineString((0, 0, 0), (5.2, 0, 0)))
     self.assertEqual(path_snapped.geom.coords, ((0, 0, 0), (5, 0, 1000)))
Ejemplo n.º 50
0
 def get_good_data(self):
     path = PathFactory.create()
     return {
         'physical_type': PhysicalTypeFactory.create().pk,
         'topology': '{"paths": [%s]}' % path.pk,
     }
Ejemplo n.º 51
0
 def test_trail_csv(self):
     p1 = PathFactory.create()
     t1 = TrailFactory.create(no_path=True)
     t1.add_path(p1)
     self.assertEqual(p1.trails_csv_display, t1.name)
Ejemplo n.º 52
0
 def get_good_data(self):
     path = PathFactory.create()
     return {
         'land_type': LandTypeFactory.create().pk,
         'topology': '{"paths": [%s]}' % path.pk,
     }
Ejemplo n.º 53
0
 def setUp(self):
     self.cmd = Command()
     self.filename = os.path.join(os.path.dirname(__file__), 'data',
                                  'poi.shp')
     self.path = PathFactory.create()
Ejemplo n.º 54
0
    def get_good_data(self):
        path = PathFactory.create()
        return {
            'name_fr': 'Hoho',
            'name_it': '',
            'name_en': '',
            'departure_fr': '',
            'departure_it': '',
            'departure_en': '',
            'arrival_fr': '',
            'arrival_en': '',
            'arrival_it': '',
            'published': '',
            'difficulty': '',
            'route': '',
            'description_teaser_fr': '',
            'description_teaser_it': '',
            'description_teaser_en': '',
            'description_fr': '',
            'description_it': '',
            'description_en': '',
            'ambiance_fr': '',
            'ambiance_it': '',
            'ambiance_en': '',
            'access_fr': '',
            'access_it': '',
            'access_en': '',
            'disabled_infrastructure_fr': '',
            'disabled_infrastructure_it': '',
            'disabled_infrastructure_en': '',
            'duration': '0',
            'is_park_centered': '',
            'advised_parking': 'Very close',
            'parking_location': 'POINT (1.0 1.0)',
            'public_transport': 'huhu',
            'advice_fr': '',
            'advice_it': '',
            'advice_en': '',
            'themes': ThemeFactory.create().pk,
            'networks': TrekNetworkFactory.create().pk,
            'usages': UsageFactory.create().pk,
            'web_links': WebLinkFactory.create().pk,
            'information_desk': InformationDeskFactory.create().pk,
            'topology': '{"paths": [%s]}' % path.pk,

            'trek_relationship_a-TOTAL_FORMS': '2',
            'trek_relationship_a-INITIAL_FORMS': '0',
            'trek_relationship_a-MAX_NUM_FORMS': '',

            'trek_relationship_a-0-id': '',
            'trek_relationship_a-0-trek_b': TrekFactory.create().pk,
            'trek_relationship_a-0-has_common_edge': 'on',
            'trek_relationship_a-0-has_common_departure': 'on',
            'trek_relationship_a-0-is_circuit_step': '',

            'trek_relationship_a-1-id': '',
            'trek_relationship_a-1-trek_b': TrekFactory.create().pk,
            'trek_relationship_a-1-has_common_edge': '',
            'trek_relationship_a-1-has_common_departure': '',
            'trek_relationship_a-1-is_circuit_step': 'on',
        }
Ejemplo n.º 55
0
 def setUp(self):
     self.path = PathFactory.create()
Ejemplo n.º 56
0
 def get_good_data(self):
     path = PathFactory.create()
     return {
         'organization': OrganismFactory.create().pk,
         'topology': '{"paths": [%s]}' % path.pk,
     }
Ejemplo n.º 57
0
 def test_show_delete_multiple_path_in_list(self):
     path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0)))
     PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)))
     POIFactory.create(paths=[(path_1, 0, 0)])
     response = self.client.get(reverse('core:path_list'))
     self.assertContains(response, '<a href="#delete" id="btn-delete" role="button">')
Ejemplo n.º 58
0
 def test_length(self):
     p1 = PathFactory.build()
     self.assertEqual(p1.length, 0)
     p2 = PathFactory.create()
     self.assertNotEqual(p2.length, 0)