今天把最近遇到的一些问题和解决方法和大家进行分享,方便自己后面的回顾,也希望帮助大家解决自己的问题。后期如果大家需要的话,我会出一个关于Anusplin插值软件的一个详细教程,免费分享给大家。 arcpy可以在Arcgis自带的python2.7版本中使用,不需要再下载python。
1. 批量格式转换(grd to tiff)
import arcpy
arcpy.env.workspace="E:\\ANUSSPLIN\\90DEM2\\"
a=arcpy.ListRasters("*","grd")
for i in a:
arcpy.RasterToOtherFormat_conversion(i,"E:\\ANUSSPLIN\\90DEM2\\tif\\","TIFF")
2. 批量定义投影(Albers)
import arcpy
arcpy.env.workspace = "E:\\ANUSSPLIN\\1000mTEM"
rasters = arcpy.ListRasters("*","tif")
Coordinate_System = "E:\\ANUSSPLIN\\1000mPRE\\coordinateSystem.tif"
for raster in rasters:
print str(raster)
arcpy.DefineProjection_management(raster,Coordinate_System)
print("OK!!!")
3. 批量投影转换(WGS 1984 to WGS 1984 Albers)
import arcpy
arcpy.env.workspace = " "
rasters = arcpy.ListRasters("*","tif")
for raster in rasters:
print str(raster)
out = ""
arcpy.ProjectRaster_management(raster,out,"PROJCS["China_Albers_Equal_Area_Conic",
GEOGCS["GCS_WGS_1984",
DATUM["WGS_1984",
SPHEROID["WGS_1984",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]],
PROJECTION["Albers_Conic_Equal_Area"],
PARAMETER["False_Easting",0],
PARAMETER["False_Northing",0],
PARAMETER["longitude_of_center",105],
PARAMETER["Standard_Parallel_1",25],
PARAMETER["Standard_Parallel_2",47],
PARAMETER["latitude_of_center",0.0],
UNIT["Kilometer",.001],
AUTHORITY["ACASIAN","001"]]")
print("ok!!!")
4. ArcPy批量裁剪
import arcpy
arcpy.CheckOutExtension("spatial")
arcpy.env.workspace = "E:\\ANUSSPLIN\\1000mPRE"
rasters = arcpy.ListRasters("*","tif")
mask = "E:\\China_map\\长株潭垃圾站点信息\\长沙.shp"
for raster in rasters:
print str(raster)
out = "E:\\ANUSSPLIN\\PRE_output\\" + raster
arcpy.gp.ExtractByMask_sa(raster, mask, out)
print("ma_" + raster + "has done!")
print("ok!!!")
5. ArcPy批量镶嵌
import arcpy
import os
arcpy.CheckOutExtension("spatial")
base = r"E:\Download\2020年中国行政区划边界SHP数据-省、市\安徽省.shp"
out_coordSystem = arcpy.Describe(base).spatialReference
dataType = arcpy.Describe(base).DataType
piexlType = arcpy.Describe(base).pixelType
cellWidth = arcpy.Describe(base).meanCellWidth
bandCount = arcpy.Describe(base).bandCount
arcpy.env.workspace = "E:\\Download\\2020年中国行政区划边界SHP数据-省、市\\005-2020年中国行政区划边界-省、市-Shp\\2020年中国行政区划边界-省、市-Shp\\省边界(包含子区域)\\"
rasters = arcpy.ListRasters("*","shp")
outFolder = r"E:\Download\2020年中国行政区划边界SHP数据-省、市\output"
arcpy.MosaicToNewRaster_management(rasters, outFolder,"result.shp",
out_coordSystem,"16_BIT_SIGNED",
cellWidth,bandCount,"LAST","FIRST")
|