您的位置:首页 > 其它

将在txt中的点数据批量arcgis插值后再输出为excel格式--未完

2017-06-02 16:41 549 查看
任务:储存在txt中的点数据进行插值,然后将插值输出成带有经纬度的excel文件。

这个步骤我分解成5步

①将点数据转换成shp文件

②对shp文件进行插值后生成栅格文件

③栅格转点,还是shp文件

④对shp文件的表进行操作,增加XY坐标

⑤表转excel输出

如果是一个txt或者excel文件,

①首先在arcgis里面可以通过将“文件”——“添加数据”——“添加xy数据”的方法将点数据导入,然后在Layer图层栏,点鼠标右键“数据”——“导出”为点Shape文件;

②在“ArcToolBox”——“Spatial Analyst”——“插值工具”

Idw (in_point_features, z_field, {cell_size}, {power}, {search_radius}, {in_barrier_polyline_features})

③“转换工具箱”——“由栅格转出”——“栅格转点”

RasterToPoint_conversion (in_raster, out_point_features, {raster_field})

④“数据管理”——“要素工具集”——“添加XY坐标”

AddXY_management (in_features)

⑤“转换工具箱”——“excel”——“表转excel”

方法一:利用模型构建器ModelBuilder

第一步还是采用python转成shp,

然后卡在批量shp进行插值,因为反距离权重法要求输入是一个shp文件,不是数据集,不知道这个怎么解决,遂放弃。

对于要素选择 要素类

(下班了,此处未写完)

希望有看到的网友指导一下。

方法二:利用python

这个网址很有用http://resources.arcgis.com/zh-cn/help/main/10.1/index.html#/na/009z0000006m000000/

第一步:将txt点文件转shp文件,搜索网页发现虎贲提供了代码,

http://blog.sina.com.cn/s/blog_79c7105501015o6m.html

帮助解决了这个问题,并打开了思路,后续步骤都可以利用python脚本来实现,再次表示感谢,谢谢无私分享!

import arcgisscripting, sys, string, os
gp = arcgisscripting.create()
try:
pathin="E:/wttdata/InputTxt"
pathout="E:/wttdata/Output/Point2Shp"
files=os.listdir(pathin)
for name in files:
in_Table = pathin+"/"+name
in_x = "nodeLon"
in_y = "nodeLat"
temp=name.strip(".txt")
out_Layer =temp.replace("-","_")
spref = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"
gp.MakeXYEventLayer(in_Table, in_x, in_y, out_Layer, spref)
pDSC = gp.describe(out_Layer)
print gp.getcount(out_Layer)
gp.FeatureClassToShapefile(out_Layer,pathout)
except:
print gp.GetMessages()
print "ok"


第二步:对shp文件进行插值,此处采用IDW进行插值

这里对小F福表示感谢!http://blog.csdn.net/u010603297/article/details/46535943

import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.env.workspace="E:/wttdata/Output/Point2shp"
fcs=arcpy.ListFeatureClasses("*.shp")

outFeaturePath="E:/wttdata/Output/tiffiels/TIF"

for fc in fcs:
arcpy.CheckOutExtension("Spatial")

inFeature=fc
zField="prec"
cellSize=0.08
power=2
searchRadius = RadiusVariable(12,150000 )
outIdw= Idw(inFeature,zField, cellSize, power, searchRadius)
outIdw.save(outFeaturePath+fc[0:14]+".tif")

print("ok")


第三步:栅格转点

import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.env.workspace="E:/wttdata/Output/Tiffiels"
rasterList=arcpy.ListRasters("*","tif")

outRasterPath="E:/wttdata/Output/Raster2Point/p"

for raster in rasterList:
arcpy.CheckOutExtension("Spatial")
inRaster=raster
outPoint=outRasterPath+raster[3:17]
arcpy.RasterToPoint_conversion(raster, outPoint, "VALUE")
print("ok")


第四步:增加XY坐标,第一步采用地理坐标系wgs_1984后,此处执行添加 XY 坐标 (数据管理),则 POINT_X 和 POINT_Y 分别表示经度和纬度。

import arcpy
from arcpy import env
env.workspace = "E:/wttdata/Output/Raster2Point"
fcs=arcpy.ListFeatureClasses("*.shp")

for fc in fcs:
arcpy.CheckOutExtension("Spatial")
in_data= fc
in_features = fc[0:14]+"XY.shp"
arcpy.Copy_management(in_data, in_features)
arcpy.AddXY_management(in_features)
print("ok")


第五步:表转excel

import arcpy
from arcpy import env
env.workspace = "E:/wttdata/Output/Raster2Point"
fcs=arcpy.ListFeatureClasses("*XY.shp")
print fcs
for fc in fcs:

arcpy.CheckOutExtension("Spatial")
inTable= fc
outExcel = fc+".xls"

arcpy.TableToExcel_conversion(inTable,outExcel)
print("ok")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  arcgis excel 插值