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))
def test_point_geom_3d(self): """ + / \ / X \ + + """ p1 = PathFactory.create(geom=LineString((0, 0), (4, 4))) PathFactory.create(geom=LineString((4, 4), (8, 0))) poi = Point(3, 1, srid=settings.SRID) position, distance = Path.interpolate(p1, poi) self.assertAlmostEqual(0.5, position, places=6) self.assertAlmostEqual(-1.414, distance, places=2) # 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.assertAlmostEqual(0.5, poitopo.aggregations.all()[0].start_position, places=6) self.assertAlmostEqual(-1.414, poitopo.offset, places=2) # Resulting geometry self.assertAlmostEqual(3, poitopo.geom.x, places=6) self.assertAlmostEqual(1, poitopo.geom.y, places=6)
def test_interpolate_not_saved(self): p = Path() with self.assertRaisesRegex( ValueError, "Cannot compute interpolation on unsaved path"): p.interpolate(Point(0, 0))