前言:
目前咱们对“python dbfread”大约比较着重,看官们都需要知道一些“python dbfread”的相关知识。那么小编在网摘上网罗了一些有关“python dbfread””的相关内容,希望看官们能喜欢,朋友们一起来学习一下吧!本文整理汇总了Python中shapefile.Writer方法的典型用法代码示例。如果您正苦于以下问题:Python shapefile.Writer方法的具体用法?Python shapefile.Writer怎么用?Python shapefile.Writer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapefile的用法示例。
在下文中一共展示了shapefile.Writer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def __init__(self, filename=None, shapeType=1, hasShx=True): self.filename = filename self.hasShx = hasShx # Count records for metadata self.count = 0 # Maximum number of records before disk flush self.max = 1000 self.started = False self.minx = 0 self.miny = 0 self.maxx = 0 self.maxy = 0 self.numRecs = 0 self.tmpShp = cStringIO.StringIO() if self.hasShx: self.tmpShx = cStringIO.StringIO() self.tmpDbf = cStringIO.StringIO() self.shp = open("%s.shp" % self.filename, "wb") if self.hasShx: self.shx = open("%s.shx" % self.filename, "wb") self.dbf = open("%s.dbf" % self.filename, "wb") self.dbfHdrLen = 0 self.w = shapefile.Writer(shapeType)示例2: _point_file
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def _point_file(test_file): with shapefile.Writer(test_file, shapefile.POINT) as shp: shp.field('name', 'C') shp.point(0, 0) shp.record('point1') shp.point(0, 1) shp.record('point2') shp.point(1, 1) shp.record('point3') shp.point(1, 0) shp.record('point4')示例3: _polygon_file
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def _polygon_file(test_file): with shapefile.Writer(test_file, shapefile.POLYGON) as shp: shp.field('name', 'C') shp.poly([ [[.25, -.25], [.25, .25], [.75, .25], [.75, -.25]], ]) shp.record('polygon1') shp.poly([ [[.25, .75], [.75, .75], [.5, 1.25]] ]) shp.record('polygon2')示例4: _polyline_file
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def _polyline_file(test_file): with shapefile.Writer(test_file, shapefile.POLYLINE) as shp: shp.field('name', 'C') n = 5 x = np.repeat(np.linspace(0, 1, n), 2) y = np.tile([0.375, 0.625], n) shp.line([list(zip(x, y))]) shp.record('line1')示例5: test_bad_points
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def test_bad_points(): shp = BytesIO() shx = BytesIO() dbf = BytesIO() w = shapefile.Writer(shp=shp, shx=shx, dbf=dbf) w.shapeType = 3 w.field("spam", "N") w.line([[[5, 5], [10, 10]]]) w.record(37) w.line([[[5, 0], [5, 5]]]) w.record(100) w.line([[[5, 5], [0, 10]]]) w.record(239) w.close() # pass a line shapefile here insted. p_shp = BytesIO() p_shx = BytesIO() p_dbf = BytesIO() p_w = shapefile.Writer(shp=p_shp, shx=p_shx, dbf=p_dbf) w.shapeType = 3 p_w.field("spam", "N") p_w.line([[[5, 5], [10, 10]]]) p_w.record(37) p_w.line([[[5, 0], [5, 5]]]) p_w.record(100) p_w.line([[[5, 5], [0, 10]]]) p_w.record(239) p_w.close() with raises(ValueError): read_shapefile(shp, dbf=dbf, points_shapefile=p_shp, points_dbf=p_dbf)示例6: test_points_but_too_far
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def test_points_but_too_far(): shp = BytesIO() shx = BytesIO() dbf = BytesIO() w = shapefile.Writer(shp=shp, shx=shx, dbf=dbf) w.shapeType = 3 w.field("spam", "N") w.line([[[5, 5], [10, 10]]]) w.record(37) w.line([[[5, 0], [5, 5]]]) w.record(100) w.line([[[5, 5], [0, 10]]]) w.record(239) w.close() # make a p_shp = BytesIO() p_shx = BytesIO() p_dbf = BytesIO() p_w = shapefile.Writer(shp=p_shp, shx=p_shx, dbf=p_dbf) p_w.shapeType = 1 p_w.field("eggs", "N") p_w.point(5, 0) p_w.record(2) p_w.point(5, 5) p_w.record(4) p_w.point(0, 10) p_w.record(8) p_w.point(12, 10) p_w.record(6) p_w.close() with raises(ValueError): read_shapefile(shp, dbf=dbf, points_shapefile=p_shp, points_dbf=p_dbf)示例7: test_points_but_not_one_one
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def test_points_but_not_one_one(): shp = BytesIO() shx = BytesIO() dbf = BytesIO() w = shapefile.Writer(shp=shp, shx=shx, dbf=dbf) w.shapeType = 3 w.field("spam", "N") w.line([[[5, 5], [10, 10]]]) w.record(37) w.line([[[5, 0], [5, 5]]]) w.record(100) w.line([[[5, 5], [0, 10]]]) w.record(239) w.close() # make a p_shp = BytesIO() p_shx = BytesIO() p_dbf = BytesIO() p_w = shapefile.Writer(shp=p_shp, shx=p_shx, dbf=p_dbf) p_w.shapeType = 1 p_w.field("eggs", "N") p_w.point(5, 0) p_w.record(2) p_w.point(5, 5) p_w.record(4) p_w.point(0, 10) p_w.record(8) p_w.point(10, 10) p_w.record(6) p_w.point(10, 10) p_w.record(7) p_w.close() with raises(ValueError): read_shapefile(shp, dbf=dbf, points_shapefile=p_shp, points_dbf=p_dbf)示例8: test_points_but_one_missing
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def test_points_but_one_missing(): shp = BytesIO() shx = BytesIO() dbf = BytesIO() w = shapefile.Writer(shp=shp, shx=shx, dbf=dbf) w.shapeType = 3 w.field("spam", "N") w.line([[[5, 5], [10, 10]]]) w.record(37) w.line([[[5, 0], [5, 5]]]) w.record(100) w.line([[[5, 5], [0, 10]]]) w.record(239) w.close() # make a p_shp = BytesIO() p_shx = BytesIO() p_dbf = BytesIO() p_w = shapefile.Writer(shp=p_shp, shx=p_shx, dbf=p_dbf) p_w.shapeType = 1 p_w.field("eggs", "N") p_w.point(5, 0) p_w.record(2) p_w.point(5, 5) p_w.record(4) p_w.point(0, 10) p_w.record(8) p_w.close() with raises(ValueError): read_shapefile(shp, dbf=dbf, points_shapefile=p_shp, points_dbf=p_dbf)示例9: write_shapefile
# 需要导入模块: import shapefile [as 别名]# 或者: from shapefile import Writer [as 别名]def write_shapefile(df, filename, geomtype='line', prj=None): """ create a shapefile given a pandas Dataframe that has coordinate data in a column called 'coords'. """ import shapefile df['Name'] = df.index # create a shp file writer object of geom type 'point' if geomtype == 'point': w = shapefile.Writer(shapefile.POINT) elif geomtype == 'line': w = shapefile.Writer(shapefile.POLYLINE) elif geomtype == 'polygon': w = shapefile.Writer(shapefile.POLYGON) # use the helper mode to ensure the # of records equals the # of shapes # (shapefile are made up of shapes and records, and need both to be valid) w.autoBalance = 1 # add the fields for fieldname in df.columns: w.field(fieldname, "C") for k, row in df.iterrows(): w.record(*row.tolist()) w.line(parts=[row.coords]) w.save(filename) # add projection data to the shapefile, if prj is None: # if not sepcified, the default, projection is used (PA StatePlane) prj = os.path.join(ROOT_DIR, 'swmmio/defs/default.prj') prj_filepath = os.path.splitext(filename)[0] + '.prj' shutil.copy(prj, prj_filepath)
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #python dbfread