python 几何_使用Python写入几何

使用Python写入几何

写入几何

通过使用 插入和 更新游标,脚本可以在要素类中创建新要素或更新现有要素。脚本可以通过创建 点对象、填充要素属性和将要素放入 数组中来定义要素。然后,即可通过 面 (Polygon)、 折线 (Polyline)、 点几何 (PointGeometry) 或 多部件 (MultiPoint) 几何类使用该数组来设置要素几何。

import arcpy

fc = "c:/data/gdb.gdb/roads"

cursor = arcpy.da.InsertCursor(fc, ["SHAPE@"])

array = arcpy.Array([arcpy.Point(5997611.48964, 2069897.7022),

arcpy.Point(5997577.46097, 2069905.81145)])

polyline = arcpy.Polyline(array)

cursor.insertRow([polyline])

如上所示,单个几何部分可以由点数组定义。同样,可以使用同一游标从点数组的数组创建多部件要素,如下所示。

firstPart = arcpy.Array([arcpy.Point(5997624.6225, 2069868.8208),

arcpy.Point(5997674.94199, 2069833.81741)])

secondPart = arcpy.Array([arcpy.Point(5997616.44497, 2069862.32774),

arcpy.Point(5997670.57373, 2069824.67456)])

array = arcpy.Array([firstPart, secondPart])

multipartFeature = arcpy.Polyline(array)

cursor.insertRow([newGeometry2])

在写入点要素时,只有单个点对象用于设置点要素几何。使用 SHAPE@XY 令牌(以及 SHAPE@M 和 SHAPE@Z 令牌(如果需要的话)),也可更加轻松地创建点。

import arcpy

# fc is a point feature class

#

fc = "c:/data/gdb.gdb/stops"

cursor = arcpy.da.InsertCursor(fc, ["SHAPE@XY"])

xy = (5997594.4753, 2069901.75682)

cursor.insertRow([xy])

所有几何在写入要素类前都已经过验证。在插入几何前的几何简化过程中,将纠正各类问题(例如,不正确的环方向和自相交面以及其他问题)。

以下示例显示如何读取包含一系列线性坐标的坐标组(由 coordsList 定义),并使用它们创建新的要素类。

# Create a new line feature class using a text file of coordinates.

# Each coordinate entry is semicolon delimited in the format of ID;X;Y

import arcpy

import os

# List of coordinates (ID, X, Y)

#

coordsList = [[1, -61845879.0968, 45047635.4861],

[1, -3976119.96791, 46073695.0451],

[1, 1154177.8272, -25134838.3511],

[1, -62051091.0086, -26160897.9101],

[2, 17365918.8598, 44431999.7507],

[2, 39939229.1582, 45252847.3979],

[2, 41170500.6291, 27194199.1591],

[2, 17981554.5952, 27809834.8945],

[3, 15519011.6535, 11598093.8619],

[3, 52046731.9547, 13034577.2446],

[3, 52867579.6019, -16105514.2317],

[3, 17160706.948, -16515938.0553]]

# The output feature class to be created

#

outFC = arcpy.GetParameterAsText(0)

# Get the template feature class

#

template = arcpy.GetParameterAsText(1)

cur = None

try:

# Create the output feature class

#

arcpy.CreateFeatureclass_management(os.path.dirname(outFC),

os.path.basename(outFC),

"POLYLINE", template)

# Open an insert cursor for the new feature class

#

cur = arcpy.da.InsertCursor(outFC, ["SHAPE@"])

# Create an array object needed to create features

#

array = arcpy.Array()

# Initialize a variable for keeping track of a feature's ID.

#

ID = -1

for coords in coordsList:

if ID == -1:

ID = coords[0]

# Add the point to the feature's array of points

# If the ID has changed, create a new feature

#

if ID != coords[0]:

cur.insertRow([arcpy.Polyline(array)])

array.removeAll()

array.add(arcpy.Point(coords[1], coords[2], ID=coords[0]))

ID = coords[0]

# Add the last feature

#

cur.insertRow([arcpy.Polyline(array)])

except Exception as e:

print e.message

finally:

# Cleanup the cursor if necessary

#

if cur:

del cur

通过创建由数组构成的数组并将其传递到 Polygon 类和 Polyline 类,可以创建多部分面要素和折线要素以及带有内部环的面要素。

使用Python写入几何 相关文章

树介绍(二叉树,二分搜索树)

1、为什么要使用树结构 将数据使用树结构存储后,出奇的高效。 2、常用的数结构 二分搜索树(Binary Search Tree) 平衡二叉树: AVL; 红黑树 堆; 并查集 线段树; Trie(字典树,前缀树) 3、二叉树 和链表一样,动态数据结构 对于每一个节点,最多有两个

unittest用例编写

1、第一步:创建python用例文件 2、第二步:创建用例类 3、第三步:写测试用例 import unittestclass TestDemo(unittest.TestCase): """定义测试类""" def test_01_login(self): print("这是一条测试登录的用例") def test_02_register(self): print("这是一

如何使用一个域名配置多个Laravel项目

每天进步一点点... 这是自己在学习过程中遇到的一个问题。申请了一个二级域名(api.demo.com),想实现(api.demo.com/blog)就是我博客项目,(api.demo.com/test)就是我测试项目,奈何技术有限,又是首次接触nginx,捣鼓了很久才弄好。 我用的是宝塔面板

C++/C++11中头文件cmath的使用

参考链接: C++ lround() math.h是C标准函数库中的头文件。在C++中一般用cmath。此头文件中声明了一系列函数来计算常见的数学运算和变换:? std::abs: 计算绝对值,包括整数类型;? std::fabs: 计算绝对值,不包括整数类型;? std::fma(x,y,z):x*y+z;? std::

C++/C++11中头文件cmath的使用

参考链接: C++ scalbln() math.h是C标准函数库中的头文件。在C++中一般用cmath。此头文件中声明了一系列函数来计算常见的数学运算和变换:? std::abs: 计算绝对值,包括整数类型;? std::fabs: 计算绝对值,不包括整数类型;? std::fma(x,y,z):x*y+z;? std:

使用kube-backup来备份K8s的资源

K8s里面的各种资源yaml文件,建议还是需要定期备份的。 之前我们是在外部机器上 用的kubectl get xx遍历后,存下来,然后再git commit 提交到gitlab去备份。 最后空闲,研究了下之前运维同学部署在K8s里面的kube-backup这个备份方式,发现大体逻辑和我之前的

Go语言map的使用

初始化map // 第一种声明方式var user_profile = map[string]string{ "name":"wuxiaoshi", "address":"北京市朝阳区"}// 也可以这样声明,只是变量声明的一种简洁方式user_profile1 := map[string]string{ "qq": "1045216729"} // 第二种声明方式user_profil

关于CSS中函数的使用----var()函数 与 attr()函数

1 关于var()函数使用注意点: 这个函数的作用获取自定义属性的值 关于自定义属性: 1 出现位置 要么在 style body{ --self-property: 1; } /style 要么在 div style="--self-property: 1"/div 总之必须要在style中 2 格式要求: 自定义属性必须要加上 -- 前缀来

centos 7下安装xampp,并使用wordpress搭建站点

根据拼客学院陈鑫杰《零基础如何学习Web安全渗透测试推荐这份史上最详细的自学路线图

PYQT5 in Python

目录 1. PyQt5基础 1.1 GUI编程学什么 1.2 PyQT是什么 1.3 PyQT的优势 1.4 开发环境的安装 1.5 第一个pyqt5桌面应用 2. QtDesigner的使用 2.1 安装和配置 2.2 快速入门 2.3 将ui文件转换成py文件 2.4 水平布局 2.5 垂直布局 2.6 同时使用水平布局和垂直布局

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值