def test_multiline_bbox(self): geom = Multiline([[(1,2), (3,4), (3,2)], [(6,8),(2,6),(3,0)], [(-3,-4), (7, -1), (3, 2), (2, -3)]], crs=LonLatWGS84) self.assertEqual(geom.bbox, (-3, -4, 7, 8)) return
def test_multiline_write(self): p = Multiline([[(100, 0), (101, 1)], [(102, 2), (103, 3)]], crs=LonLatWGS84) s = p.as_geojson(urn="urn:ogc:def:crs:EPSG::5806") ans = """{"type": "Feature", "properties": {}, "geometry" : { "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::5806" } }, "type": "MultiLineString", "coordinates": [ [ [100.0, 0.0], [101.0, 1.0] ], [ [102.0, 2.0], [103.0, 3.0] ] ] } }""" self.verifyJson(s, ans)
def test_write_multiline(self): g = Multiline([[(0,0), (1,1), (2,2)], [(1,0), (2,1), (3,2)], [(2,0), (1,1), (0,2)]], crs=LonLatWGS84) g.to_shapefile(os.path.join(TESTDIR, "data/multiline")) for fnm in ("multiline.shx", "multiline.shx", "multiline.dbf", "multiline.prj"): self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm))) return
def test_multiline_coords(self): g = Multiline([[(0, 1), (1, 2), (2, 3), (3, 4)], [(5, 3), (4, 2), (3, 1), (2, 0)]]) lists = g.coords() self.assertTrue( np.all(lists[0] == np.array([[0, 1, 2, 3], [1, 2, 3, 4]]))) self.assertTrue( np.all(lists[1] == np.array([[5, 4, 3, 2], [3, 2, 1, 0]]))) return
def test_multiline_within_poly(self): np.random.seed(49) multiline = Multiline([ 10 * np.random.rand(10, 2) + np.random.randint(-50, 50, (1, 2)) for _ in range(50) ]) poly = Polygon([(-30, -40), (12, -30), (8, 22), (-10, 50)]) within = multiline.within(poly) self.assertEqual(len(within), 8) return
def test_multiline_touching_poly(self): np.random.seed(49) multiline = Multiline([ 10 * np.random.rand(10, 2) + np.random.randint(-50, 50, (1, 2)) for _ in range(50) ]) poly = Polygon([(-30, -40), (12, -30), (8, 22), (-10, 50)]) touching = multiline.touching(poly) self.assertEqual(len(touching), 12) return
def test_multiline_touching_line(self): np.random.seed(49) multiline = Multiline([ 10 * np.random.rand(10, 2) + np.random.randint(-50, 50, (1, 2)) for _ in range(50) ]) line = Line([(-30, -40), (11, -30), (10, 22), (-10, 50)]) touching = multiline.touching(line) self.assertEqual(len(touching), 4) return
def test_transform_multiline(self): g = Multiline([[(0, 0), (1, 1), (1, 2)], [(-3, 2), (-2, -1), (0, 1)]]) pi = math.pi gnew = g.apply_transform( np.array([[math.cos(0.5 * pi), -math.sin(0.5 * pi), 0], [math.sin(0.5 * pi), math.cos(0.5 * pi), 0]])) l1, l2 = gnew.vertices() self.assertTrue(np.allclose(l1, np.array([(0, 0), (-1, 1), (-2, 1)]))) self.assertTrue(np.allclose(l2, np.array([(-2, -3), (1, -2), (-1, 0)]))) gnew2 = gnew.apply_transform(np.array([[2, 0, 0], [0, -3, 0]])) l1, l2 = gnew2.vertices() self.assertTrue(np.allclose(l1, np.array([(0, 0), (-2, -3), (-4, -3)]))) self.assertTrue(np.allclose(l2, np.array([(-4, 9), (2, 6), (-2, 0)]))) return