使用 Python 将自定义功能属性添加到 ESRI Shapefile
我正在寻找一种方法来获取具有 200 个国家/地区功能集的现有 ESRI Shapefile。每个国家/地区特征都有一个属性“NAME”。我的目标是创建一个 Python 脚本,添加任意(目前)附加属性,例如“人口”。
当然,我安装了 OSGeo 和 GeoDjango 模块。我的问题是:
from osgeo import ogr
infile = ogr.Open('sample.shp', 1) #'sample.shp' is a pre-existing ESRI shapefile described above
inlyr = infile.GetLayerByIndex(0)
我是否缺少一个 OGR 函数,该函数允许我将特征属性字段插入现有的 Shapefile 中?
I am seeking a way to take an existing ESRI Shapefile that has a Feature set of 200 countries. Each country Feature has an attribute of "NAME." My objective is to create a Python script that adds an arbitrary (for now) additional attribute, say, "POPULATION".
Of course I have the OSGeo and GeoDjango modules installed. I'm as far as:
from osgeo import ogr
infile = ogr.Open('sample.shp', 1) #'sample.shp' is a pre-existing ESRI shapefile described above
inlyr = infile.GetLayerByIndex(0)
Am I missing an OGR function that will allow me to insert Feature attribute fields into an existing Shapefile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要添加字段,您必须创建 OGRFieldDefn,然后调用 inlyr.CreateField
To add a field you have to create an OGRFieldDefn and then call inlyr.CreateField