本文整理汇总了Python中karta.vector.geometry.Polygon.to_shapefile方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.to_shapefile方法的具体用法?Python Polygon.to_shapefile怎么用?Python Polygon.to_shapefile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karta.vector.geometry.Polygon
的用法示例。
在下文中一共展示了Polygon.to_shapefile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestShapefile
# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import to_shapefile [as 别名]
class TestShapefile(unittest.TestCase):
def setUp(self):
self.points = [Point((1, 1), data={"species": "T. officianale"}, crs=LonLatWGS84),
Point((3, 1), data={"species": "C. tectorum"}, crs=LonLatWGS84),
Point((4, 3), data={"species": "M. alba"}, crs=LonLatWGS84),
Point((2, 2), data={"species": "V. cracca"}, crs=LonLatWGS84)]
self.multipoint = Multipoint([(1,1), (3,1), (4,3), (2,2)],
data={"species": ["T. officianale", "C. tectorum",
"M. alba", "V. cracca"]},
crs=LonLatWGS84)
self.line = Line([(1.0,5.0),(5.0,5.0),(5.0,1.0),(3.0,3.0),(1.0,1.0)],
properties={"geom_id": 27, "name": "test line"},
crs=LonLatWGS84)
self.polygon = Polygon([(1.0,5.0),(5.0,5.0),(5.0,1.0),(3.0,3.0),(1.0,1.0)],
crs=LonLatWGS84)
self.points3 = [Point((1, 1, 0), crs=LonLatWGS84),
Point((3, 1, 3), crs=LonLatWGS84),
Point((4, 3, 2), crs=LonLatWGS84),
Point((2, 2, -1), crs=LonLatWGS84)]
self.line3 = Line([(1,5,2),(5,5,-1),(5,1,3),(3,3,1),(1,1,0)], crs=LonLatWGS84)
self.polygon3 = Polygon([(1,5,2),(5,5,-1),(5,1,3),(3,3,1),(1,1,0)], crs=LonLatWGS84)
testfiles = ["points.shp", "line.shp", "polygon.shp"]
if any(not exists(join(TMPDATA, "shapefiles/", fnm)) for fnm in testfiles):
self.saveTestData()
return
def saveTestData(self):
testfiles = [(self.multipoint, "points"),
(self.line, "line"),
(self.polygon, "polygon")]
os.makedirs(os.path.join(TMPDATA, "shapefiles"))
for (geom, fnm) in testfiles:
geom.to_shapefile(os.path.join(TMPDATA, "shapefiles", fnm))
return
def assertGeomEqual(self, this, that):
self.assertTrue(np.all(this.get_vertices() == that.get_vertices()))
try:
self.assertEqual(this.crs.get_proj4(), that.crs.get_proj4())
except AttributeError:
print("warning: crs equality not established")
return
def test_writepoint(self):
point = self.points[0]
point.to_shapefile(os.path.join(TESTDIR, "data/point"))
for fnm in ("point.shx", "point.shx", "point.dbf", "point.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_writepoints(self):
points = self.points
shp.write_shapefile(os.path.join(TESTDIR, "data/points.shp"), *points)
for fnm in ("points.shx", "points.shx", "points.dbf", "points.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_writemultipoint(self):
mp = Multipoint(self.points)
mp.to_shapefile(os.path.join(TESTDIR, "data/multipoint"))
for fnm in ("multipoint.shx", "multipoint.shx", "multipoint.dbf", "multipoint.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_writeline(self):
self.line.to_shapefile(os.path.join(TESTDIR, "data/line"))
for fnm in ("line.shx", "line.shx", "line.dbf", "line.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_writepoly(self):
self.polygon.to_shapefile(os.path.join(TESTDIR, "data/polygon"))
for fnm in ("polygon.shx", "polygon.shx", "polygon.dbf", "polygon.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_writepoints3(self):
mp = Multipoint(self.points3)
mp.to_shapefile(os.path.join(TESTDIR, "data/multipointz"))
for fnm in ("multipointz.shx", "multipointz.shx", "multipointz.dbf", "multipointz.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_writeline3(self):
self.line3.to_shapefile(os.path.join(TESTDIR, "data/linez"))
for fnm in ("linez.shx", "linez.shx", "linez.dbf", "linez.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_writepoly3(self):
self.polygon3.to_shapefile(os.path.join(TESTDIR, "data/polygonz"))
for fnm in ("polygonz.shx", "polygonz.shx", "polygonz.dbf", "polygonz.prj"):
#.........这里部分代码省略.........
示例2: TestShapefile
# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import to_shapefile [as 别名]
class TestShapefile(unittest.TestCase):
def setUp(self):
self.points = [Point((1, 1), data={"species": "T. officianale"}, crs=LonLatWGS84),
Point((3, 1), data={"species": "C. tectorum"}, crs=LonLatWGS84),
Point((4, 3), data={"species": "M. alba"}, crs=LonLatWGS84),
Point((2, 2), data={"species": "V. cracca"}, crs=LonLatWGS84)]
self.multipoint = Multipoint([(1,1), (3,1), (4,3), (2,2)],
data={"species": ["T. officianale", "C. tectorum",
"M. alba", "V. cracca"]},
crs=LonLatWGS84)
self.line = Line([(1.0,5.0),(5.0,5.0),(5.0,1.0),(3.0,3.0),(1.0,1.0)],
crs=LonLatWGS84)
self.polygon = Polygon([(1.0,5.0),(5.0,5.0),(5.0,1.0),(3.0,3.0),(1.0,1.0)],
crs=LonLatWGS84)
self.points3 = [Point((1, 1, 0), crs=LonLatWGS84),
Point((3, 1, 3), crs=LonLatWGS84),
Point((4, 3, 2), crs=LonLatWGS84),
Point((2, 2, -1), crs=LonLatWGS84)]
self.line3 = Line([(1,5,2),(5,5,-1),(5,1,3),(3,3,1),(1,1,0)], crs=LonLatWGS84)
self.polygon3 = Polygon([(1,5,2),(5,5,-1),(5,1,3),(3,3,1),(1,1,0)], crs=LonLatWGS84)
testfiles = ["points.shp", "line.shp", "polygon.shp"]
if any(not exists(join(TESTDATA, "shapefiles/", fnm)) for fnm in testfiles):
self.saveTestData()
return
def saveTestData(self):
testfiles = [(self.multipoint, "points"),
(self.line, "line"),
(self.polygon, "polygon")]
for (geom, fnm) in testfiles:
geom.to_shapefile(os.path.join(TESTDATA, "shapefiles", fnm))
return
def assertGeomEqual(self, this, that):
self.assertTrue(np.all(this.get_vertices() == that.get_vertices()))
self.assertEqual(this._crs, that._crs)
return
def test_writepoints(self):
mp = Multipoint([p.vertex for p in self.points])
mp.to_shapefile("data/points_shp")
return
def test_writeline(self):
self.line.to_shapefile("data/line_shp")
return
def test_writepoly(self):
self.polygon.to_shapefile("data/polygon_shp")
return
def test_writepoints3(self):
mp = Multipoint([p.vertex for p in self.points3])
mp.to_shapefile("data/pointsz_shp")
return
def test_writeline3(self):
self.line3.to_shapefile("data/linez_shp")
return
def test_writepoly3(self):
self.polygon3.to_shapefile("data/polygonz_shp")
return
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
def test_write_collection_lines(self):
line0 = copy(self.line)
line1 = copy(self.line.shift((4, 2)))
line2 = copy(self.line.shift((-2, 3)))
shp.write_shapefile([line0, line1, line2], "data/line_collection")
return
def test_dbase_type(self):
self.assertEqual(shp.property_field_type(1.0), "N")
self.assertEqual(shp.property_field_type(1), "N")
self.assertEqual(shp.property_field_type(np.float32(1.0)), "N")
self.assertEqual(shp.property_field_type(np.int16(1)), "N")
#self.assertEqual(shp.property_field_type(1.0), "O")
#self.assertEqual(shp.property_field_type(1), "I")
#self.assertEqual(shp.property_field_type(np.float32(1.0)), "O")
#self.assertEqual(shp.property_field_type(np.int16(1)), "I")
#self.assertEqual(shp.property_field_type(True), "L")
#self.assertEqual(shp.property_field_type(False), "L")
self.assertEqual(shp.property_field_type("pale ale"), "C")
self.assertEqual(shp.property_field_type(datetime.date(1986, 8, 17)), "D")
#.........这里部分代码省略.........