「Python@arcpy」批量偏移点线面
webgis 2020-02-02
python
arcpy
因为最近在处理一些数据的时候用到 spatial adjustment 这个工具,就想着能否通过 arcpy 来实现整体图形偏移,目前的代码只实现了根据一个固定的经纬度差值或者墨卡托差值来做整体偏移
import arcpy
from arcpy import env
env.workspace = r'F:\gisdata\arcpy_test\spatialAdjust'
point = arcpy.Point()
array = arcpy.Array()
with arcpy.da.UpdateCursor('polygon2.shp',['SHAPE@','FID']) as cursor:
for row in cursor:
g = row[0]
for pts in g:
print list(pts)
for pt in pts:
if pt is not None:
point.X = pt.X + 0.315567
point.Y = pt.Y - 0.055089
array.add(point)
print '%s 数据处理完成'% row[1]
geometry = arcpy.Polygon(array, arcpy.SpatialReference(4326))
if g.type==u'polygon':
array.add(array.getObject(0)) # 最后一个点位和第一个点位相同组合成一个polygon
geometry = arcpy.Polygon(array, arcpy.SpatialReference(4326))
array.removeAll()
row[0] = geometry
cursor.updateRow(row)
print '%s 图形更新完成' % row[1]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29