用Arcpy读取shapefile
来源:互联网 发布:sql sa登陆失败233 编辑:程序博客网 时间:2024/04/27 13:42
本文主要从两个部分介绍:
1. shapefile文件属性表的读取
2. shapefile内每个元素的坐标信息读取
属性表读取
分这几步走:
1. arcpy.ListFields函数解析shp文档所在路径,并返回列名数组
2. arcpy.da.SearchCursor读取列名下的属性表内容
inputLayer = 'C:\Users\Wu823\Desktop\data_test\starbucks.shp;'theFields = arcpy.ListFields(inFC)for Field in theFields: FieldsArray.append(Field.aliasName)for row in arcpy.da.SearchCursor(inFC, FieldsArray): print row
坐标信息读取
坐标信息也是通过arcpy.da.SearchCursor函数来获取。和上面不同的是,列名需要换成几何令牌
ArcGIS Manual上面的解释内容如下:
- SHAPE@XY —A tuple of the feature’s centroid x,y coordinates.
- SHAPE@TRUECENTROID —A tuple of the feature’s true centroid x,y coordinates.
- SHAPE@X —A double of the feature’s x-coordinate.
- SHAPE@Y —A double of the feature’s y-coordinate.
- SHAPE@Z —A double of the feature’s z-coordinate.
- SHAPE@M —A double of the feature’s m-value.
- SHAPE@JSON — The esri JSON string representing the geometry.
- SHAPE@WKB —The well-known binary (WKB) representation for OGC geometry. It provides a portable representation of a geometry value as a contiguous stream of bytes.
- SHAPE@WKT —The well-known text (WKT) representation for OGC geometry. It provides a portable representation of a geometry value as a text string.
- SHAPE@ —A geometry object for the feature.
- SHAPE@AREA —A double of the feature’s area.
- SHAPE@LENGTH —A double of the feature’s length.
- OID@ —The value of the ObjectID field.
我这里主要用到SHAPE@XY和SHAPE@两个令牌
- SHAPE@XY:返回几何要素的中心坐标
- SHAPE@:返回一整个几何要素
第一个很好理解,就是个二元数组。
第二个,整个几何要素。
几何要素包含点线面等。根据个人实际操作经验,几何要素其实就是多维数组。点是一维,面和线是三维(点->部分->记录)。searchCursor的返回值也确实如此。
# A list of features and coordinate pairsfeature_info = [[[1, 2], [2, 4], [3, 7]], [[6, 8], [5, 7], [7, 2], [9, 5]]]for row in arcpy.da.SearchCursor(inFC, 'SHAPE@'): for part in row: for pnt in part: print pnt.X print pnt.Y
参考来源:http://pro.arcgis.com/en/pro-app/arcpy/get-started/reading-geometries.htm
0 0
- 用Arcpy读取shapefile
- 读取shapefile格式文件
- 读取shapefile格式文件
- shapefile文件格式的读取
- IDL读取Shapefile文件
- Java读取shapefile
- 读取shapefile文件格式
- geotools读取shapefile文件
- 教你读取shapefile格式文件
- shapefile文件(shp)读取
- shapelib读取shapefile坐标点
- shapefile文件中单点的读取
- 使用GeoTools读取和绘制Shapefile格式
- 找了一个C库读取shapefile
- 读取postgis中数据写入shapefile-1
- 读取postgis中数据写入shapefile-2
- 读取postgis中数据写入shapefile-3
- GeoTools读取ESRI ShapeFile中文乱码解决方法
- 如何用matlab,frontcon函数画出有效市场边缘和资本市场线
- hdu1418抱歉(欧拉公式)
- Python趣味代码整合之提升学生编程兴趣
- test
- kA*与(kA)*的行列式计算
- 用Arcpy读取shapefile
- 文章标题
- 软件开发管理新模式
- 基于SVN的SCM简单总结
- UVa11809
- 365读书
- misc
- virtualbox从命令行获取虚拟机ip地址
- 欢迎使用CSDN-markdown编辑器