arcgis填坑_2

可以通过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()                          




在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值