首页 > 其他分享 >[933] In ArcPy, how to get the geometry of a feature from a shapefile

[933] In ArcPy, how to get the geometry of a feature from a shapefile

时间:2023-11-02 10:45:19浏览次数:28  
标签:access get shapefile feature cursor geometry your

In ArcPy, you can get the geometry of a feature from a shapefile using the SearchCursor or UpdateCursor and the SHAPE@ token to access the geometry of each feature. Here's how you can do it:

import arcpy

# Set the workspace (folder containing your shapefile)
arcpy.env.workspace = "C:/path/to/your/workspace"

# Specify the shapefile you want to work with
shapefile = "your_shapefile.shp"

# Create a cursor to iterate through the features
with arcpy.da.SearchCursor(shapefile, ["SHAPE@"]) as cursor:
    for row in cursor:
        # Access the geometry of the feature
        geometry = row[0]

        # You can now work with the geometry object
        # For example, you can print the geometry type
        print(f"Geometry Type: {geometry.type}")

        # Or you can access other properties and methods of the geometry object

# Don't forget to clean up and delete the cursor
del cursor

In the code above, we first set the workspace to the folder containing your shapefile. Then, we specify the shapefile you want to work with. We use a SearchCursor to iterate through the features of the shapefile and access the SHAPE@ field to get the geometry of each feature.

You can replace ["SHAPE@"] with a list of field names if you want to access other attributes of the features as well.

Remember to replace the file path and shapefile name with the actual path and name of your shapefile.

标签:access,get,shapefile,feature,cursor,geometry,your
From: https://www.cnblogs.com/alex-bn-lee/p/17804863.html

相关文章

  • 问题记录 <VSCode Copilot 连接问题:Extension activation failed: "getaddrinfo EAI_A
    问题描述VSCode使用Copilot时遇到如下问题:Extensionactivationfailed:"getaddrinfoEAI_AGAINapi.github.com"解决方式笔者尝试了修改hosts、代理、重装插件等方法,但没有起效。下面的方法解决了问题(在VSCode中设置proxy)打开代理,查看代理http地址,复制;打开VSCode,打......
  • getter/setter(访问器/设置器)
    classStudent{privateintid;privateStringname;Student(intid,Stringname){this.id=id;this.name=name;}publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;......
  • 浅析Flie类getAbsolutePath()方法
    开发中,常常需要上传文件,并将文件存于远程服务器(如minio)或者本地,当存于本地时对存储路径的指定是常见的问题。当然,你可以在本地写死静态资源路径,如"D:\static\fileUpload\img",但这样只能适用于你的计算机,如果换一个人,他的电脑可能不是D盘而是E盘,如果是Linux环境,甚至没有D、E盘,导致......
  • vulntarget漏洞靶场系列(三)
    本次推荐的模拟环境如下:https://www.hackthebox.com/                  扫描客服微信 获取课件完整PDF ......
  • vulntarget漏洞靶场系列(二)
    本次推荐的模拟环境如下:https://www.hackthebox.com/                      扫描客服微信 获取课件完整PDF   ......
  • Shell脚本操作OSS服务:PUT、GET(纯shell脚本无sdk)
    Shell脚本操作OSS服务:PUT、GET(纯shell脚本无sdk)前提:一般情况下对OSS操作都会通过SDK,但是很多情况下对OSS进行简单的上传下载的操作,那么SDK就显得有些臃肿,先要下载sdk包,然后再写些简单的操作脚本,而通过shell脚本就会简单很多。而且很多场景:线上网站、数据库等,生产出来的网站数据、......
  • .NET 反序列化 GetterSettingsPropertyValue 攻击链
    0x01 链路1 SettingsPropertyValueSettingsPropertyValue位于命名空间 System.Configuration,用于应用程序存储和检索设置的值,此类具有Name、IsDirty、Deserialized、PropertyValue、SerializedValue等多个公共成员,其中SerializedValue属性用于获取或者设置序列化的值,便于持久......
  • QTreeWidget 的搜索实时显示功能
    QTreeWidget的子条目很多时候需要提供实时的搜索功能,以便能快速找到所需要的条目。代码如下://1.创建当输入框文本变化时的信号槽。connect(ui.lineEditSearch,&QLineEdit::textChanged,this,&Demo01_GUI::OnFindItem);//2.槽函数实现检索时,实时显示符合要求的QTre......
  • QTreeWidget 添加右键菜单
    有时需要为QTreeWidget的子条目添加右键菜单功能,主要有两种方案来实现:方案一该方案比较通用,通过为QTreeWidget建立信号槽,在接受itemPressed的信号时会被触发,然后判断当前是否为鼠标右键,若为鼠标右键则创建添加对应的菜单栏,并提供相应的功能。//1.QTreeWidget*tree为......
  • postgresql数据库经纬度转geometry
    postgresql数据库经纬度转geometry1、在postgresql数据库中,如果字段类型是geometry,更新该字段为经纬度(坐标),可以尝试采取以下脚本:注意:108.658463代表经度34.1437代表纬度中间没有逗号updatetablesetgeom=ST_GeomFromText('POINT(108.65846334.1437)',4490)wh......