Python实现Arcgis 相关批量操作
作者:互联网
1、 批量实现ASCII转栅格
#ASCII转栅格
import arcpy
import os
#批量处理文件的路径
path = 'C:/Users/sdriver/arcgis/ASCII/'
files = os.listdir(path)
for i in files:
#以txt为后缀的文件
if os.path.splitext(filename)[1] == '.txt':
inASCII = path + i
#输出数据类型
rasterType = "FLOAT"
#输出文件的路径
outRaster ="C:/Users/sdriver/arcgis/ASCII_ToRaster/%s.tif"%i
arcpy.ASCIIToRaster_conversion(inASCII, outRaster, rasterType)
2、批量实现定义投影
#定义投影
import arcpy
import os
#需修改定义投影的tif文件路径
path = "C:/Users/sdrive/arcgis/"
files = os.listdir(path)
#此处定义坐标为GCS_WGS_1984,具体看下方链接
Coordinate_System = arcpy.SpatialReference(4326)
for i in files:
adress = path+i
arcpy.DefineProjection_management(adress, Coordinate_System)
定义坐标系只需要修改Coordinate_System = arcpy.SpatialReference()括号中的数字,有关坐标系名称和工厂代码的详细信息,可以参阅 ArcGIS 文档,下方为链接。
3、批量实现栅格转点
#栅格转点
import arcpy
import os
input_path = "C:/Users/sdrive/arcgis/inout/"
output_path = "C:/Users/sdrive/arcgis/out/"
filenames = os.listdir(input_path)
for i in filenames:
if os.path.splitext(i)[1] == '.tif':
inRaster = path + filename
#取后缀前的文字作为文件命名
basename = os.path.splitext(filename)[0]
outPoint = output_path + basename + '.shp'
field = "VALUE"
arcpy.RasterToPoint_conversion(inRaster,outPoint,field)
4、批量实现按分区提取表格
#按分区提取表格
import arcpy
from arcpy import env
from arcpy.sa import *
import os
#输入栅格数据
shp = 'C:/Users/sdriver/arcgis/shp/water.shp'
#输入区域字段
zone_field = "GRIDCODE"
#赋值栅格路径
path = 'C:/Users/sdriver/arcgis_relation/input/'
filenames = os.listdir(path)
for filename in filenames:
if os.path.splitext(filename)[1] == '.tif':
#输入赋值栅格
raster= path + filename
output = "C:/Users/sdriver/arcgis/output/" + '%s.dbf'%filename
#统计类型,可以在'MEAN'处修改ALL、SUM等
ZonalStatisticsAsTable(shp,zone_field,raster,output, "DATA", "MEAN")
如果觉得有帮助就点个赞呗~
标签:Users,批量,arcgis,Python,os,Arcgis,import,path,arcpy 来源: https://blog.csdn.net/yytswxhbc/article/details/121309637