def test_poly_bounds(self): # create a lopsided PolyLine to test bounding box loclist = [ Location(0, 0), Location(400000000, 0), Location(350000000, 300000000), Location(450000000, 450000000), Location(1000, 450000000) ] expected_rect = Rectangle(Location(0, 0), Location(450000000, 450000000)) computed_rect = PolyLine(loclist).bounds() self.assertEqual(expected_rect, computed_rect) # now test again but with a Polygon loclist = [ Location(0, 0), Location(400000000, 0), Location(350000000, 300000000), Location(450000000, 450000000), Location(1000, 450000000) ] expected_rect = Rectangle(Location(0, 0), Location(450000000, 450000000)) computed_rect = Polygon(loclist).bounds() self.assertEqual(expected_rect, computed_rect)
def test_polyline_to_shapely_linestring(self): polyline1 = PolyLine( [Location(-1000, -1000), Location(0, 0), Location(5000, 8000)]) linestring1 = geometry.polyline_to_shapely_linestring(polyline1) test_against = shapely.geometry.LineString([(-1000, -1000), (0, 0), (5000, 8000)]) self.assertEqual(linestring1, test_against)
def test_overlaps_polyline(self): loclist = [ Location(0, 0), Location(400000000, 0), Location(350000000, 300000000), Location(450000000, 450000000), Location(1000, 450000000) ] loclist2 = [Location(1, 1), Location(2000, 3000)] polygon = Polygon(loclist) polyline0 = PolyLine(loclist2) self.assertTrue(polygon.overlaps_polyline(polyline0))
def test_intersects_polyline(self): loclist = [ Location(-3, -3), Location(-2, -2), Location(-1, -1), Location(0, 0), Location(1, 1), Location(2, 2), Location(3, 3) ] loclist2 = [ Location(-3, 3), Location(-2, 2), Location(-1, 1), Location(0, 0), Location(-1, 1), Location(-2, 2), Location(-3, 3) ] polyline = PolyLine(loclist) polyline2 = PolyLine(loclist2) self.assertTrue(polyline.intersects_polyline(polyline2))
def test_poly_length(self): loclist = [Location(0, 0), Location(5000000, 5000000)] polyline = PolyLine(loclist, deep=True) self.assertEqual(78626, int(polyline.length())) loclist2 = [Location(0, 0), Location(20000000, 20000000)] polyline = PolyLine(loclist2, deep=True) self.assertEqual(314474, int(polyline.length()))
def test_polyline_compression(self): loclist = [Location(1, 1), Location(2, 2), Location(5, 5)] correct_polyline = PolyLine(loclist, deep=True) test_polyline = geometry.decompress_polyline( correct_polyline.compress()) self.assertEqual(correct_polyline, test_polyline) loclist = [ Location(382117269, -1193153616), Location(382117927, -1193152951), Location(382116912, -1193151049), Location(382116546, -1193151382), Location(382116134, -1193150734), Location(382115440, -1193151494) ] correct_polyline = PolyLine(loclist, deep=True) test_polyline = geometry.decompress_polyline( correct_polyline.compress()) self.assertEqual(correct_polyline, test_polyline)