可以通过sql表达式选出需要更新(平移)的要素
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 6 12:23:36 2019
@author: hgh
"""
import arcpy
import os
def adjust(fc, TranslationAmount_X, TranslationAmount_Y, selectSQL):
point = arcpy.Point()
array = arcpy.Array()
feacount = 0
with arcpy.da.UpdateCursor(fc, ["SHAPE@", "FID"], where_clause=selectSQL) as cursor:
for row in cursor:
feacount += 1
# 要素
polycount = 0
for pts in row[0]:
polycount += 1
# listpts = []
# 单点
for pt in pts:
if(pt is None):
# v = 1
pass
else:
point.X = pt.X + TranslationAmount_X
point.Y = pt.Y + TranslationAmount_Y
# matrix = np.array([[1, 2, 1], [1, 1, 1], [1, 1, 1]])
# matrix_ = np.dot(np.array([pt.X, pt.Y, 1]), matrix)
# point.X, point.Y = matrix_[0], matrix_[1]
array.add(point)
array.add(array.getObject(0))
polygon = arcpy.Polygon(array)
array.removeAll()
# Append to the list of Polygon objects
#
# featureList.append(polygon)
row[0] = polygon
#row.setValue("SHAPE@", polygon)
cursor.updateRow(row)
def main():
try:
fc = arcpy.GetParameterAsText(0)
fc = u'{}'.format(fc)
arcpy.env.workspace = os.path.dirname(fc)
fc = os.path.basename(fc)
TranslationAmount_X = float(arcpy.GetParameterAsText(1)) if arcpy.GetParameterAsText(1) else 0
TranslationAmount_Y = float(arcpy.GetParameterAsText(2)) if arcpy.GetParameterAsText(2) else 0
selectSQL = arcpy.GetParameterAsText(3)
adjust(fc, TranslationAmount_X, TranslationAmount_Y, selectSQL)
except arcpy.ExecuteError:
arcpy.AddMessage("{}".format(arcpy.GetMessages()))
if __name__ == '__main__':
main()