Esempio n. 1
0
 def test_multipolygon_bbox(self):
     geom = Multipolygon([[[(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
Esempio n. 2
0
 def test_multipolygon(self):
     g = Multipolygon([[[(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
Esempio n. 3
0
 def test_write_multipolygon(self):
     g = Multipolygon([[[(0,0), (2,2), (1,3)]],
                       [[(2,0), (4,2), (3,3)]],
                       [[(2,-2), (1,0), (-1,-1)]]], crs=LonLatWGS84)
     g.to_shapefile(os.path.join(TESTDIR, "data/multipoly"))
     for fnm in ("multipoly.shx", "multipoly.shx", "multipoly.dbf", "multipoly.prj"):
         self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
Esempio n. 4
0
 def test_multipolygon_bbox(self):
     geom = Multipolygon(
         [[[(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
Esempio n. 5
0
 def test_write_multipolygon(self):
     g = Multipolygon([[[(0,0), (2,2), (1,3)]],
                       [[(2,0), (4,2), (3,3)]],
                       [[(2,-2), (1,0), (-1,-1)]]], crs=LonLatWGS84)
     g.to_shapefile(os.path.join(TESTDIR, "data/multipoly"))
     for fnm in ("multipoly.shx", "multipoly.shx", "multipoly.dbf", "multipoly.prj"):
         self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
     return
Esempio n. 6
0
 def test_multipolygon(self):
     g = Multipolygon([[[(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_multipolygon_within_poly(self):
     np.random.seed(49)
     multipolygon = \
         Multipolygon([[np.array([[0,0],[3,0],[3,3],[0,3]])
                        + np.random.randint(-50, 50, (1, 2))]
                       for _ in range(50)])
     poly = Polygon([(-30, -40), (12, -30), (8, 22), (-10, 50)])
     within = multipolygon.within(poly)
     self.assertEqual(len(within), 8)
     return
 def test_multipolygon_touching_poly(self):
     np.random.seed(49)
     multipolygon = \
         Multipolygon([[np.array([[0,0],[3,0],[3,3],[0,3]])
                        + np.random.randint(-50, 50, (1, 2))]
                       for _ in range(50)])
     poly = Polygon([(-30, -40), (12, -30), (8, 22), (-10, 50)])
     touching = multipolygon.touching(poly)
     self.assertEqual(len(touching), 14)
     return
 def test_multipolygon_touching_line(self):
     np.random.seed(49)
     multipolygon = \
         Multipolygon([[np.array([[0,0],[10,0],[10,10],[0,10]])
                        + np.random.randint(-50, 50, (1, 2))]
                       for _ in range(50)])
     line = Line([(-40, -35), (-15, -30), (30, 5), (10, 32), (-15, 17)])
     touching = multipolygon.touching(line)
     self.assertEqual(len(touching), 10)
     return
Esempio n. 10
0
 def test_multipolygon_within_poly(self):
     np.random.seed(49)
     multipolygon = \
         Multipolygon([[np.array([[0,0],[3,0],[3,3],[0,3]])
                        + np.random.randint(-50, 50, (1, 2))]
                       for _ in range(50)])
     poly = Polygon([(-30, -40), (12, -30), (8, 22), (-10, 50)])
     within = multipolygon.within(poly)
     self.assertEqual(len(within), 8)
     return
Esempio n. 11
0
 def test_multipolygon_touching_poly(self):
     np.random.seed(49)
     multipolygon = \
         Multipolygon([[np.array([[0,0],[3,0],[3,3],[0,3]])
                        + np.random.randint(-50, 50, (1, 2))]
                       for _ in range(50)])
     poly = Polygon([(-30, -40), (12, -30), (8, 22), (-10, 50)])
     touching = multipolygon.touching(poly)
     self.assertEqual(len(touching), 14)
     return
Esempio n. 12
0
 def test_multipolygon_touching_line(self):
     np.random.seed(49)
     multipolygon = \
         Multipolygon([[np.array([[0,0],[10,0],[10,10],[0,10]])
                        + np.random.randint(-50, 50, (1, 2))]
                       for _ in range(50)])
     line = Line([(-40, -35), (-15, -30), (30, 5), (10, 32), (-15, 17)])
     touching = multipolygon.touching(line)
     self.assertEqual(len(touching), 10)
     return
Esempio n. 13
0
    def test_multipolygon_write(self):
        p = Multipolygon([[[(102, 2), (103, 2), (103, 3), (102, 3)]],
                          [[(100, 0), (101, 0), (101, 1), (100, 1)],
                           [(100.2, 0.2), (100.8, 0.2), (100.8, 0.8), (100.2, 0.8)]]],
                          crs=LonLatWGS84)
        s = p.as_geojson(urn="urn:ogc:def:crs:EPSG::5806")
        ans = """{"type": "Feature", "properties": {},"bbox": [100.0, 0.0, 103.0, 3.0], "geometry" : { "type": "MultiPolygon",
    "coordinates": [
      [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
      [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
       [[100.2, 0.2], [100.2, 0.8], [100.8, 0.8], [100.8, 0.2], [100.2, 0.2]]]
      ]
    }, "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::5806" } } }"""

        self.verifyJSON(s, ans)
Esempio n. 14
0
    def test_multipolygon_write(self):
        p = Multipolygon([[[(102, 2), (103, 2), (103, 3), (102, 3)]],
                          [[(100, 0), (101, 0), (101, 1), (100, 1)],
                           [(100.2, 0.2), (100.8, 0.2), (100.8, 0.8), (100.2, 0.8)]]],
                          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": "MultiPolygon",
    "coordinates": [
      [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
      [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
       [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
      ]
    } }"""

        self.verifyJson(s, ans)