本文整理汇总了Python中karta.vector.geometry.Multipoint类的典型用法代码示例。如果您正苦于以下问题:Python Multipoint类的具体用法?Python Multipoint怎么用?Python Multipoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Multipoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multipoint_convex_hull_sph
def test_multipoint_convex_hull_sph(self):
# include a point which is in the planar convex hull but not the spherical one
vertices = [(-50, 70), (0, 71), (50, 70), (0, 50)]
mp = Multipoint(vertices, crs=SphericalEarth)
ch = mp.convex_hull()
self.assertTrue(np.all(np.equal(ch.vertices(), [(-50, 70), (0, 50), (50, 70)])))
return
示例2: test_multipoint_output
def test_multipoint_output(self):
p = Multipoint([(4, 2), (3, 5), (3, 2), (7, 3)])
sp = shapely.geometry.shape(p.geomdict)
x, y = p.coords()
self.assertTrue(np.all(x == np.array([el.x for el in sp])))
self.assertTrue(np.all(y == np.array([el.y for el in sp])))
return
示例3: test_write_collection_points
def test_write_collection_points(self):
mp = Multipoint([p.vertex for p in self.points])
mp0 = copy(mp)
mp1 = copy(mp.shift((4, 2)))
mp2 = copy(mp.shift((-2, 3)))
shp.write_shapefile([mp0, mp1, mp2], "data/points_collection")
return
示例4: test_multipoint_subset
def test_multipoint_subset(self):
mp = Multipoint(self.vertices, data=self.data)
line = Line(self.vertices)
ss1 = mp._subset(range(2,7))
ss2 = line._subset(range(2,7))
self.assertTrue(isinstance(ss1, Multipoint))
self.assertTrue(isinstance(ss2, Line))
return
示例5: test_multipoint_within_bbox
def test_multipoint_within_bbox(self):
vertices = [(float(x),float(y)) for x in range(-10,11)
for y in range(-10,11)]
ans = [v for v in vertices if (-5.0<v[0]<5.0) and (-4.0<v[1]<6.0)]
mp = Multipoint(vertices)
sub = mp.within_bbox((-5.0, -4.0, 5.0, 6.0))
self.assertEqual(sub, Multipoint(ans))
return
示例6: test_multipoint_within_radius
def test_multipoint_within_radius(self):
vertices = [(float(x),float(y)) for x in range(-10,11)
for y in range(-10,11)]
ans = [v for v in vertices if math.sqrt(v[0]**2 + v[1]**2) < 5.0]
mp = Multipoint(vertices)
sub = mp.within_radius(Point((0,0)), 5.0)
self.assertEqual(sub, Multipoint(ans))
return
示例7: test_add_route
def test_add_route(self):
route = Multipoint([(np.random.random(), np.random.random())
for i in range(10)], properties={"name":"route0"})
g = vector.gpx.GPX()
g.add_route(route)
expected = self.Route([self.Point(tuple(xy), {}, {}) for xy in route.vertices()],
{"name":"route0"}, {})
self.assertEqual(g.routes[0], expected)
return
示例8: test_write_collection_multipoint
def test_write_collection_multipoint(self):
mp = Multipoint(self.points)
mp0 = copy(mp)
mp1 = copy(mp.shift((4, 2)))
mp2 = copy(mp.shift((-2, 3)))
shp.write_shapefile(os.path.join(TESTDIR, "data/mp_collection.shp"),
mp0, mp1, mp2)
for fnm in ("mp_collection.shx", "mp_collection.shx", "mp_collection.dbf", "mp_collection.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
示例9: test_add_track
def test_add_track(self):
track = Multipoint([(np.random.random(), np.random.random())
for i in range(10)], properties={"name":"segment0"})
g = vector.gpx.GPX()
g.add_track(track)
expected = self.Track([self.Trkseg(
[self.Point(tuple(xy), {}, {}) for xy in track.vertices()],
{"name":"segment0"}, {})], {}, {})
self.assertEqual(g.tracks[0], expected)
return
示例10: test_empty_multipoint_bbox
def test_empty_multipoint_bbox(self):
mp = Multipoint([], crs=Cartesian)
bb = mp.bbox()
for item in bb:
self.assertTrue(np.isnan(item))
mp = Multipoint([], crs=LonLatWGS84)
bb = mp.bbox()
for item in bb:
self.assertTrue(np.isnan(item))
return
示例11: test_multipoint_convex_hull
def test_multipoint_convex_hull(self):
vertices = [(953, 198), (986, 271), (937, 305), (934, 464), (967, 595),
(965, 704), (800, 407), (782, 322), (863, 979), (637, 689),
(254, 944), (330, 745), (363, 646), (27, 990), (127, 696),
(286, 352), (436, 205), (88, 254), (187, 85)]
mp = Multipoint(vertices)
ch = mp.convex_hull()
hull_vertices = [(27, 990), (88, 254), (187, 85), (953, 198),
(986, 271), (965, 704), (863, 979)]
self.assertTrue(np.all(np.equal(ch.vertices(), hull_vertices)))
return
示例12: test_multipoint_convex_hull2
def test_multipoint_convex_hull2(self):
vertices = [(-158, 175), (-179, 230), (-404, -390), (259, -79), (32,
144), (-59, 355), (402, 301), (239, 159), (-421, 172), (-482, 26),
(2, -499), (134, -72), (-412, -12), (476, 235), (-412, 40), (-198,
-256), (314, 331), (431, -492), (325, -415), (-400, -491)]
mp = Multipoint(vertices)
ch = mp.convex_hull()
hull_vertices = [(2, -499), (431, -492), (476, 235), (402, 301), (314,
331), (-59, 355), (-421, 172), (-482, 26), (-400, -491)]
self.assertTrue(np.all(np.equal(ch.vertices, hull_vertices)))
return
示例13: test_pop
def test_pop(self):
ln = Multipoint([(3.0, 3.0, 2.0), (5.0, 1.0, 0.0), (3.0, 1.0, 5.0),
(4.0, 4.0, 6.0), (0.0, 1.0, 3.0)],
data=["red", "green", "blue", "chartreuse", "aquamarine"])
lnresult = Multipoint([(3.0, 3.0, 2.0), (5.0, 1.0, 0.0), (3.0, 1.0, 5.0),
(0.0, 1.0, 3.0)],
data=["red", "green", "blue", "aquamarine"])
pt = ln.pop(3)
ptresult = Point((4.0, 4.0, 6.0), data="chartreuse")
self.assertEqual(pt, ptresult)
self.assertEqual(ln, lnresult)
return
示例14: test_read_points
def test_read_points(self):
points = read_shapefile(os.path.join(TESTDATA, "shapefile", "points"))
self.assertEqual(len(points), 4)
pt = points[0]
self.assertTrue("+proj=lonlat" in pt.crs.get_proj4())
self.assertTrue("+a=6378137.0" in pt.crs.get_proj4())
self.assertTrue("+f=0.00335281" in pt.crs.get_proj4())
mp = Multipoint(points)
self.assertEqual(mp.d["species"], ['T. officianale', 'C. tectorum', 'M. alba', 'V. cracca'])
self.assertEqual(mp.d["ID"], ['0', '1', '2', '3'])
x, y = mp.coords()
self.assertTrue(np.all(x == np.array((1.0, 3.0, 4.0, 2.0))))
self.assertTrue(np.all(y == np.array((1.0, 1.0, 3.0, 2.0))))
示例15: test_multipoint_within_polygon
def test_multipoint_within_polygon(self):
np.random.seed(42)
x = (np.random.random(100) - 0.5) * 180.0
y = (np.random.random(100) - 0.5) * 30.0
xp = [-80, -50, 20, 35, 55, -45, -60]
yp = [0, -10, -8, -17, 15, 18, 12]
poly = Polygon(zip(xp, yp), crs=LonLatWGS84)
mp = Multipoint(zip(x, y), crs=LonLatWGS84)
subset = mp.within_polygon(poly)
excluded = [pt for pt in mp if pt not in subset]
self.assertTrue(all(poly.contains(pt) for pt in subset))
self.assertFalse(any(poly.contains(pt) for pt in excluded))
return