概述
(1)从mdb格式中提取shp格式的面图层
# coding:utf-8
#encoding:gbk
import arcpy
import os
path=r'mdb格式输入路径'
for filename in os.listdir(path):
in_mdbpath=os.path.join(path,filename)
arcpy.env.workspace = in_mdbpath
lstFC = arcpy.ListFeatureClasses()
outlocation=r'输出路径'
arcpy.FeatureClassToShapefile_conversion(u'字段名',outlocation)
(2)合并shp文件,合并后shp文件最多2GB。
arcpy.env.workspace=r"文件所在路径"
fcs=arcpy.ListFeatureClasses()
lspt=[]
for fc in fcs:
lspt.append(fc)
arcpy.Merge_management(lspt,"输出名称")
(3)合并tif影像。
path = '输入影像'
outpath = '输出路径'
outname = '输出名称.tif'
tif_list=os.listdir(path)
raster_list=[]
for filename in tif_list:
in_path=os.path.join(path,filename)
raster_list.append(in_path)
#raster_list为要合并的影像,outpath为输出影像路径,outname为输出影像名称,“”输入投影可以为空,其他可对应argis该功能来看参数指的是什么
arcpy.MosaicToNewRaster_management(raster_list,outpath,outname,"",
"8_BIT_UNSIGNED","","1","LAST","FIRST")
(4)txt格式的点转换成lyr,并从影像上提取信息
import arcpy
import os
import shutil
from arcpy import env
from arcpy.sa import *
inpathicesat2="输入点的路径"
inpathpoint="输出点图层.lyr路径"
inpathdempoint="输出提取影像信息后的点路径"
inRaster = "输入影像路径"
#创建文件夹,如果文件夹存在则清空
if not os.path.exists(inpathpoint):
os.mkdir(inpathpoint)
else:
shutil.rmtree(inpathpoint)
os.mkdir(inpathpoint)
if not os.path.exists(inpathdempoint):
os.mkdir(inpathdempoint)
else:
shutil.rmtree(inpathdempoint)
os.mkdir(inpathdempoint)
mylists=os.listdir(inpathicesat2)
for list in mylists:
list=os.path.splitext(list)[0]
try:
list=os.path.basename(list)
in_Table = inpathicesat2+list+".txt"
x_coords = "Field1"
y_coords = "Field2"
z_coords = "Field3"
out_Layer = list+".lyr"
saved_Layer = inpathpoint+list+".lyr"
spRef = r"Coordinate Systems/Geographic Coordinate Systems/World/WGS 1984.prj"
# 把txt点信息转换成点.lyr
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords)
# Print the total rows
print arcpy.GetCount_management(out_Layer)
# Save to a layer file
arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)
#RASTERVALU如果存在,则替换
fieldName1 = "替换"
arcpy.AddField_management(in_Table, fieldName1, "FLOAT")
arcpy.CalculateField_management(in_Table, "替换",
"!RASTERVALU!",
"PYTHON_9.3")
arcpy.DeleteField_management(in_Table, "RASTERVALU")
# 点从影像提取信息
inPointFeatures = out_Layer
outPointFeatures = inpathdempoint+list+".shp"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute ExtractValuesToPoints
ExtractValuesToPoints(inPointFeatures, inRaster, outPointFeatures)
except:
# If an error occurred print the message to the screen
print arcpy.GetMessages()
(5)输出表格
out_xls = "表格路径.xls"
outLocation = "gdb路径"
outPointFeatures = "路径.shp"
arcpy.TableToTable_conversion(outPointFeatures, outLocation, out_xls)
(6) shp转tif
arcpy.env.workspace="shp文件输入路径"
output="输出路径"
shplist=arcpy.ListFeatureClasses()
for inFeature in shplist:
field="字段名"
outRaster=os.path.join(output,inFeature+".tif")
cellSize=1(自定义)
arcpy.FeatureToRaster_conversion(inFeature, field, outRaster, cellSize)
最后
以上就是小巧黑裤为你收集整理的关于Arcpy的一些笔记的全部内容,希望文章能够帮你解决关于Arcpy的一些笔记所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复