shapefi中的层是什么

2024-05-16 23:52:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始学习地理信息系统数据。我有兴趣使用Python查找这些数据。我现在正在学习shapefile。我正在学习osgeo/ogr。我遇到了一个GetLayer()方法。我现在不明白什么是形状文件。是否有必要将要素添加到图层?在

当我尝试按如下方式创建多个层时:

shapeData = driver.CreateDataSource('customer_points.shp')
layer = shapeData.CreateLayer('customs', spatialReference, osgeo.ogr.wkbPoint)
layer = shapeData.CreateLayer('customs1', spatialReference, osgeo.ogr.wkbPoint)

我得到的是与只有一层的customer_points相对应的shapefile----GetLayer(0)起作用,但是GetLayer(1)返回{} 我还得到了对应于customs1的shapefile 所以我能够检索添加到customs的特性,不是从第一个shapefile读取第二层,而是从第二个shapefile读取第一层


Tags: 数据layercustomerpointsshapefile地理信息系统customsogr
1条回答
网友
1楼 · 发布于 2024-05-16 23:52:32

的确,ESRI shapefile格式不支持将特性分组到单独的层中。在

然而,OGR以osgeo.ogr.DataSource的形式为向量数据提供了一个抽象源,它假定特征被分组到一个或多个层中。层从0开始编号,osgeo.ogr.DataSource.GetLayer(self, iLayer=0)函数提供了一个方便的默认值,用于从第一层提取数据,当数据源是shapefile时,第一层恰好是唯一的层。在

如果您想将矢量数据保存到shapefile中,根据OGR模型,您必须使用osgeo.ogr.DataSource.CreateLayer(self, *args, **kwargs)创建一个图层,并向该图层对象添加要素。在

相关问题 更多 >