Пример #1
0
 def test_merge_multipoints_different_crs(self):
     mp1 = Multipoint(zip(np.arange(0, 5), np.arange(3, 8)),
                      data={
                          "A": np.arange(5),
                          "B": np.arange(10, 15)
                      },
                      crs=LonLatWGS84)
     mp2 = Multipoint(zip(np.arange(0, 5) + 1,
                          np.arange(3, 8) - 2),
                      data={
                          "A": np.arange(5),
                          "C": np.arange(15, 20)
                      },
                      crs=WebMercator)
     mp = Multipoint.merge(mp1, mp2, crs=WebMercator)
     self.assertTrue(len(mp), 10)
     self.assertEqual(set(mp.data.fields), set(["A"]))
     self.assertEqual(mp.crs, WebMercator)
     self.assertTrue(
         np.allclose(
             mp.coords(),
             np.array([[
                 0.00000000e+00, 1.11319491e+05, 2.22638982e+05,
                 3.33958472e+05, 4.45277963e+05, 1.00000000e+00,
                 2.00000000e+00, 3.00000000e+00, 4.00000000e+00,
                 5.00000000e+00
             ],
                       [
                           3.34111171e+05, 4.45640110e+05, 5.57305257e+05,
                           6.69141057e+05, 7.81182214e+05, 1.00000000e+00,
                           2.00000000e+00, 3.00000000e+00, 4.00000000e+00,
                           5.00000000e+00
                       ]])))
Пример #2
0
 def test_merge_multipoints(self):
     mp1 = Multipoint(zip(np.arange(0, 5), np.arange(3, 6)),
                      properties={
                          "a": 1,
                          "b": 2
                      },
                      data={
                          "A": np.arange(5),
                          "B": np.arange(10, 15)
                      })
     mp2 = Multipoint(zip(np.arange(0, 5) + 1,
                          np.arange(3, 6) - 2),
                      properties={
                          "a": 1,
                          "c": 3
                      },
                      data={
                          "A": np.arange(5),
                          "C": np.arange(15, 20)
                      })
     mp = merge_multiparts(mp1, mp2)
     self.assertTrue(len(mp), 10)
     self.assertEqual(set(mp.data.fields), set(["A"]))
     self.assertEqual(set(mp.properties.keys()), set(["a", "b", "c"]))
     self.assertEqual(mp.properties["a"], 1)
Пример #3
0
    def test_multipoint_from_points(self):
        pts = [Point((x, y), data={"d": d}, properties={"p":i}, crs=LonLatWGS84)
                for i,((x,y),d) in enumerate(zip(self.vertices, self.data))]

        mp = Multipoint(pts)
        ans = Multipoint(self.vertices, data={"p":range(len(pts))}, crs=LonLatWGS84)
        self.assertEqual(mp, ans)
        return
Пример #4
0
    def test_merge_points(self):
        pt1 = Point((1, 2), properties={"number": 16})
        mp1 = Multipoint([(5, 6), (5, 4), (4, 3)],
                         data={"number": [2, 76, 4]})
        pt2 = Point((3, 4, 5), properties={"number": 22, "temperature": "hot"})
        mp2 = Multipoint([(5, 6), (4, 7), (3, 9), (4, 9)],
                         data={"number": [4, 674, 32, 56],
                               "temperature": ["cool", "hot", "scorching", "mild"]})

        merged = Multipoint.merge(pt1, mp1, pt2, mp2)
        self.assertEqual(len(merged), 9)
        self.assertEqual(merged.vertices.asarray().shape, (9, 2))
        self.assertEqual(merged.d["number"], [16, 2, 76, 4, 22, 4, 674, 32, 56])
Пример #5
0
 def test_merge_multipoints(self):
     mp1 = Multipoint(zip(np.arange(0, 5), np.arange(3, 8)),
                      data={
                          "A": np.arange(5),
                          "B": np.arange(10, 15)
                      })
     mp2 = Multipoint(zip(np.arange(0, 5) + 1,
                          np.arange(3, 8) - 2),
                      data={
                          "A": np.arange(5),
                          "C": np.arange(15, 20)
                      })
     mp = Multipoint.merge(mp1, mp2)
     self.assertTrue(len(mp), 10)
     self.assertEqual(set(mp.data.fields), set(["A"]))
Пример #6
0
    def test_multipoint_from_points(self):
        x = range(-5, 5)
        y = [x_**2 for x_ in x]
        vertices = list(zip(x, y))
        data = [x_ * y_ for (x_, y_) in vertices]

        pts = [
            Point((x, y), properties={"p": i}, crs=LonLatWGS84)
            for i, ((x, y), d) in enumerate(zip(vertices, data))
        ]

        mp = Multipoint(pts)
        ans = Multipoint(vertices,
                         data={"p": range(len(pts))},
                         crs=LonLatWGS84)
        self.assertEqual(mp, ans)
Пример #7
0
 def test_merge_multipoints_different_crs(self):
     mp1 = Multipoint(zip(np.arange(0, 5), np.arange(3, 6)),
                      properties={
                          "a": 1,
                          "b": 2
                      },
                      data={
                          "A": np.arange(5),
                          "B": np.arange(10, 15)
                      },
                      crs=LonLatWGS84)
     mp2 = Multipoint(zip(np.arange(0, 5) + 1,
                          np.arange(3, 6) - 2),
                      properties={
                          "a": 1,
                          "c": 3
                      },
                      data={
                          "A": np.arange(5),
                          "C": np.arange(15, 20)
                      },
                      crs=WebMercator)
     mp = merge_multiparts(mp1, mp2, crs=WebMercator)
     self.assertTrue(len(mp), 10)
     self.assertEqual(set(mp.data.fields), set(["A"]))
     self.assertEqual(set(mp.properties.keys()), set(["a", "b", "c"]))
     self.assertEqual(mp.properties["a"], 1)
     self.assertEqual(mp.crs, WebMercator)
     self.assertTrue(
         np.allclose(
             mp.coordinates,
             np.array([[0.0, 1.11319491e+05, 2.22638982e+05, 1.0, 2.0, 3.0],
                       [
                           3.34111171e+05, 4.45640110e+05, 5.57305257e+05,
                           1.0, 2.0, 3.0
                       ]])))
Пример #8
0
    def test_multipoint_datadict(self):
        # create a line
        vertices = [(2.0, 9.0, 9.0), (4.0, 1.0, 9.0), (4.0, 1.0, 5.0),
                    (2.0, 8.0, 0.0), (9.0, 8.0, 4.0), (1.0, 4.0, 6.0),
                    (7.0, 3.0, 4.0), (2.0, 5.0, 3.0), (1.0, 6.0, 6.0),
                    (8.0, 1.0, 0.0), (5.0, 5.0, 1.0), (4.0, 5.0, 7.0),
                    (3.0, 3.0, 5.0), (9.0, 0.0, 9.0), (6.0, 3.0, 8.0),
                    (4.0, 5.0, 7.0), (9.0, 9.0, 4.0), (1.0, 4.0, 7.0),
                    (1.0, 7.0, 8.0), (9.0, 1.0, 6.0)]

        data0 = [99.0, 2.0, 60.0, 75.0, 71.0, 34.0, 1.0, 49.0, 4.0, 36.0, 47.0,
                 58.0, 65.0, 72.0, 4.0, 27.0, 52.0, 37.0, 95.0, 17.0]

        data1 = [54.0, 40.0, 77.0, 18.0, 84.0, 91.0, 61.0, 92.0, 19.0, 42.0,
                 50.0, 25.0, 11.0, 80.0, 59.0, 56.0, 32.0, 8.0, 88.0, 76.0]

        Multipoint(vertices, data={'d0':data0, 'd1':data1})
        return
Пример #9
0
def benchmark():
    θ = np.linspace(0, 2 * np.pi, 361)[:-1]
    r = np.sin(θ * 20) + 1.5
    x = np.cos(θ) * r
    y = np.sin(θ) * r

    polygon = Polygon(zip(x, y))
    line = Line([(-2, -3), (0, 3)])

    for seg in polygon.segments:
        x = seg.intersections(line)

    bbox = Polygon([(-1, -1), (-1, 1), (1, 1), (1, -1)])

    points = []
    for pt in polygon:
        if bbox.contains(pt):
            points.append(pt)

    multipoint = Multipoint(points)
    hull = multipoint.convex_hull()

    print("bbox contains", len(multipoint), "out of", len(polygon), "vertices")
    return polygon, line, bbox, multipoint, hull
Пример #10
0
 def test_empty_multpoint(self):
     mp = Multipoint([])
     self.assertEqual(len(mp), 0)
     return
Пример #11
0
 def coordinates(self):
     return Multipoint([c.coordinates for c in self], crs=LonLatWGS84)