本文整理汇总了Python中karta.vector.geometry.Line.shift方法的典型用法代码示例。如果您正苦于以下问题:Python Line.shift方法的具体用法?Python Line.shift怎么用?Python Line.shift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karta.vector.geometry.Line
的用法示例。
在下文中一共展示了Line.shift方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestShapefile
# 需要导入模块: from karta.vector.geometry import Line [as 别名]
# 或者: from karta.vector.geometry.Line import shift [as 别名]
#.........这里部分代码省略.........
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"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_write_collection_multipoint(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(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)))
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(os.path.join(TESTDIR, "data/line_collection.shp"),
line0, line1, line2)
for fnm in ("line_collection.shx", "line_collection.shx", "line_collection.dbf", "line_collection.prj"):
self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm)))
return
def test_read_points(self):
points = read_shapefile(os.path.join(TESTDATA, "shp_input", "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'])
self.assertEqual(mp.coordinates, ((1.0, 3.0, 4.0, 2.0), (1.0, 1.0, 3.0, 2.0)))
def test_read_line(self):
line = read_shapefile(os.path.join(TESTDATA, "shp_input", "line"))[0]
self.assertTrue("+proj=lonlat" in line.crs.get_proj4())
示例2: TestShapefile
# 需要导入模块: from karta.vector.geometry import Line [as 别名]
# 或者: from karta.vector.geometry.Line import shift [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")
#.........这里部分代码省略.........