【问题标题】:What is a layer in a shapefile什么是 shapefile 中的图层
【发布时间】:2017-04-03 02:41:49
【问题描述】:

我开始了解 GIS 数据。我有兴趣使用 Python 查看这些数据。我目前正在学习 shapefile。我正在学习 osgeo/ogr。我遇到了GetLayer() 方法。现在我无法理解 shapefile 中的图层是什么。是否需要向图层添加特征?

当我尝试如下创建多个图层时:

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) 返回 None 我还得到了对应于customs1 的 shapefile 因此,我能够检索添加到 customs 的功能,而不是通过从第一个 shapefile 读取第二层,而是通过从第二个 shapefile 读取第一层

【问题讨论】:

  • 您能否提供一些有关您在哪里找到GetLayer() 函数(哪个库、软件等)的背景信息? Shapefiles 本身没有图层,我想你有些困惑。我稍后会尝试解释,或者其他人可以。
  • 查看OGRDataSource class 的文档,它说OGRDataSource 可能 由许多OGRLayer 对象组成。另请参阅 Python osgeo.ogr.DataSource 文档。

标签: python gis


【解决方案1】:

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

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

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

【讨论】:

  • 好的,我现在明白了。我还想知道的是,在使用 osdeo.odr.DataSource 时,创建具有多个图层的 shapefile 是否有意义
  • @user3282758 这是个好问题。我无法立即回答。也许您可以编辑/重新表述您的问题以明确您的要求,或者提出一个单独的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-05
  • 2017-05-11
  • 2011-01-24
  • 1970-01-01
  • 1970-01-01
  • 2013-11-05
相关资源
最近更新 更多