Beispiel #1
0
 def projdist(self):
     """ Return the cumulative distances from the cast to cast.
     """
     cumulative = [0]
     a = Point(self.casts[0].coords, crs=LONLAT)
     for cast in self.casts[1:]:
         b = Point(cast.coords, crs=LONLAT)
         cumulative.append(cumulative[-1] + a.distance(b))
         a = b
     return np.asarray(cumulative, dtype=np.float64)
Beispiel #2
0
    def test_point(self):
        with self.assertRaises(TypeError):
            pt = Point((1, 2), properties=5, crs=WebMercator)

        # vertex must have 2-3 items
        with self.assertRaises(TypeError):
            pt = Point((1, 2, 3, 4), crs=WebMercator)

        with self.assertRaises(TypeError):
            pt = Point((1, ), crs=WebMercator)

        pt = Point((1, 2), properties={"id": 5}, crs=WebMercator)
        self.assertTrue(isinstance(pt, Point))
Beispiel #3
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])
Beispiel #4
0
    def test_distance(self):
        for crs in (SphericalEarth, LonLatWGS84):
            pt0 = Point((0.0, 0.0), crs=crs)
            pt1 = Point((-1.0, 1.0), crs=crs)

            pt2 = Point((-179.5, 0.0), crs=crs)
            pt3 = Point((179.5, 1.0), crs=crs)
            self.assertAlmostEqual(pt0.distance(pt1), pt2.distance(pt3), places=8)
 def test_polygon_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 = Polygon(pts)
     ans = Polygon(self.vertices, data={"p":range(len(pts))}, crs=LonLatWGS84)
     self.assertEqual(mp, ans)
     return
Beispiel #6
0
    def test_line_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 = Line(pts)
        ans = Line(self.vertices, data={"d": self.data}, crs=LonLatWGS84)
        self.assertEqual(mp, ans)
        return
Beispiel #7
0
    def test_polygon_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))
        ]
        poly = Polygon(pts, crs=LonLatWGS84)
        ans = Polygon(vertices, crs=LonLatWGS84)
        self.assertEqual(poly, ans)
Beispiel #8
0
    def test_line_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))
        ]

        line = Line([pt.vertex for pt in pts], crs=LonLatWGS84)
        ans = Line(vertices, crs=LonLatWGS84)
        self.assertEqual(line, ans)
Beispiel #9
0
    def test_nearest_to(self):
        casts = []
        for i in range(10):
            casts.append(
                Cast(pressure=[1, 2, 3],
                     temperature=[5, 6, 7],
                     coordinates=(-30.0 + i, 10.0 - 2 * i)))

        cc = CastCollection(casts)
        pt = Point((-26.2, 2.1), crs=LonLatWGS84)
        nearest, dist = cc.nearest_to_point(pt)
        self.assertEqual(nearest.coordinates.vertex, (-26.0, 2.0))
        self.assertAlmostEqual(dist, 24845.9422, places=4)
        return
Beispiel #10
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)
Beispiel #11
0
 def coordinates(self):
     return Point(self.properties["coordinates"], crs=LonLatWGS84)