예제 #1
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={"p":range(len(pts))}, crs=LonLatWGS84)
        self.assertEqual(mp, ans)
        return
예제 #2
0
    def test_merge_lines(self):
        ml1 = Multiline([[(1, 2), (3, 4), (5, 6)], [(3, 4), (2, 3)]])
        ln1 = Line([(5, 6, 1), (5, 4, 2), (4, 3, 0)])
        ml2 = Multiline([[(4, 2), (8, 4), (1, 5)], [(2, 4), (8, 6)]])
        ln2 = Line([(5, 6), (4, 7), (3, 9), (4, 9)])

        merged = Multiline.merge(ml1, ln1, ml2, ln2)
        self.assertEqual(len(merged), 6)
        self.assertEqual(merged.vertices[0].asarray().shape, (3, 2))
        self.assertEqual(merged.vertices[1].asarray().shape, (2, 2))
예제 #3
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(pts, crs=LonLatWGS84)
        ans = Line(vertices, crs=LonLatWGS84)
        self.assertEqual(line, ans)
예제 #4
0
    def test_multiline_from_lines(self):
        lines = []
        for i in range(5):
            sub = []
            for j in range(5):
                sub.append((2 * j + i, -1.5 * j + 2 * i))
            lines.append(Line(sub, properties={"d": i * j}))

        g = multipart_from_singleparts(lines)
        self.assertEqual(g.d["d"], [0, 4, 8, 12, 16])
        return
예제 #5
0
    def test_multiline_from_lines(self):
        lines = []
        for i in range(5):
            sub = []
            for j in range(5):
                sub.append((2 * j + i, -1.5 * j + 2 * i))
            lines.append(Line(sub, properties={"d": i * j}, crs=LonLatWGS84))

        g = Multiline(lines)
        self.assertEqual(g.d["d"], [0, 4, 8, 12, 16])
        self.assertEqual(g.crs, LonLatWGS84)
예제 #6
0
    def test_multiline_from_lines_constructor(self):
        lines = []
        for i in range(5):
            sub = []
            for j in range(5):
                sub.append((2 * j + i, -1.5 * j + 2 * i))
            lines.append(Line(sub, crs=LonLatWGS84))

        g = Multiline(lines)
        for l, l_ in zip(g, lines):
            self.assertTrue(np.all(l.vertices() == l_.vertices()))
        self.assertEqual(g.crs, LonLatWGS84)
예제 #7
0
 def setUp(self):
     x = [
         -17.41933333, -17.42628333, -17.42573333, -17.4254, -17.42581667,
         -17.42583333, -17.4269, -17.4437, -17.44126667, -17.44416667,
         -17.44673333, -17.46633333, -17.48418333
     ]
     y = [
         80.07101667, 80.0878, 80.09245, 80.10168333, 80.10895, 80.11108333,
         80.11398333, 80.12305, 80.12928333, 80.1431, 80.1534, 80.16636667,
         80.16741667
     ]
     depth = [
         102.0, 95.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 170.0,
         160.0, 140.0, 130.0
     ]
     self.bathymetry = Bathymetry(depth,
                                  Line(list(zip(x, y)), crs=LonLatWGS84))
     return
예제 #8
0
    def add_bathymetry(self,
                       bathymetry,
                       vertices,
                       maxdistance=200.0,
                       maxdepth=None,
                       **kwargs):
        """ Add bathymetry from a Bathymetry object to a section plot.

        Arguments:
        ----------
        bathymetry      a Bathymetry2d instance
        vertices        a CastCollection, karta.Line, or list of points
                        defining a path

        Keyword arguments:
        ------------------
        ax              specific Axes to use
        maxdistance     the maximum distance a bathymetric observation
                        may be from a point in `vertices` to be plotted

        Additional keyword arguments are sent to `plt.fill_between`
        """
        if hasattr(vertices, "get_vertices"):
            vertices = vertices.get_vertices()
        elif hasattr(vertices, "coordinates"):
            vertices = vertices.coordinates.get_vertices()

        cruiseline = Line(vertices, crs=LonLatWGS84)
        xalong, xacross = bathymetry.project_along_cruise(cruiseline)
        depth_ = bathymetry.depth
        mask = ~np.isnan(depth_) * (xacross < maxdistance)
        depth = depth_[mask]
        xalong = xalong[mask]
        xacross = xacross[mask]

        if maxdepth is None:
            maxdepth = np.nanmax(depth)
        plotbase = maxdepth * np.ones_like(depth)

        kwargs.setdefault("color", "0.0")
        kwargs.setdefault("zorder", 8)
        return self.fill_between(xalong, depth, plotbase, **kwargs)
예제 #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_multipoint_zip_init(self):
     x = range(-10, 10)
     y = [_x**2 for _x in x]
     Line(zip(x, y))
     return