python画长方形zm坐标_求助arcGIS中Python编程批处理问题——坐标XYZM转shape图层

#参考来源:http://www.faqssys.info/creating-shp-from-txt-files-using-arcpy/#comments

import os, sys, arcpy

InFile = sys.argv[1]

OutShp = sys.argv[2]

EPSG   = sys.argv[3]

try:

SR = arcpy.SpatialReference(int(EPSG))

# create a spatial reference from EPSG definition

except:

arcpy.AddWarning(arcpy.GetMessages())

arcpy.AddError("Unable to create spatial reference with code %s" % EPSG)

sys.exit(0)

#break up OutShp to folder and name

OutFolder = os.path.dirname(OutShp)

OutName   = os.path.basename(OutShp)

# Create the output feature class/创建函数

arcpy.CreateFeatureclass_management(OutFolder,OutName,"POINT",has_z="ENABLED",spatial_reference=SR)

# add fields to store the values

arcpy.AddField_management(OutShp,"PntID","INTEGER")

arcpy.AddField_management(OutShp,"Xcoord","DOUBLE")

arcpy.AddField_management(OutShp,"Ycoord","DOUBLE")

arcpy.AddField_management(OutShp,"Zcoord","DOUBLE")

with open(InFile,'r') as srcFile:

with arcpy.da.InsertCursor(OutShp,["SHAPE@","PntID","Xcoord","Ycoord","Zcoord"]) as InsCur:

for fileLine in srcFile:

# split the line up into a list

# 1 337172.8 4278952.4 85.7334909091 becomes [1,337172.8,4278952.4,85.7334909091]

# try a few common delimiters: tab, space, comma, pipe../确定数据间隔符类型:tab、空格、逗号

lSplit = fileLine.split("t")

if len(lSplit) == 1:

lSplit = fileLine.split(" ")

if len(lSplit) == 1:

lSplit = fileLine.split(",")

if len(lSplit) == 1:

lSplit = fileLine.split("|")

if len(lSplit) > 1:

# more than just one word on the line

pointsOK = True

try:

ID     = int(lSplit[0])

Xcoord = float(lSplit[1])

Ycoord = float(lSplit[2])

Zcoord = float(lSplit[3])

except:

arcpy.AddWarning("Unable to translate points")

pointsOK = False

if pointsOK:

# create a point geometry from the 3 coordinates

newGeom  = arcpy.PointGeometry(arcpy.Point(Xcoord,Ycoord,Zcoord))

newGeom.spatial_reference = SR # set spatial reference

# you could project here using newGeom.projectAs(SpatialRef)

# if you needed them in a different spatial reference

InsCur.insertRow([newGeom,ID,Xcoord,Ycoord,Zcoord])# insert this point into the feature class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值