ANUSPLIN后續(xù)處理以及python os,sys應(yīng)用

轉(zhuǎn)載畫(huà)長(zhǎng)空_yin的文章

os.sep

為了不同系統(tǒng)下例如Windows or Lunix 寫(xiě)路徑時(shí)候的代碼在不同的平臺(tái)上都能運(yùn)行,os.sep 根據(jù)你所處的平臺(tái),自動(dòng)地采用相應(yīng)的分割符號(hào)。

批量定義金字塔

import arcpy
arcpy.env.workspace = "E:/MODIS/溫度" #設(shè)置工作空間
tifflist = arcpy.ListRasters("","tif") #將該目錄下的tif格式的影像全部創(chuàng)建金字塔,tif可換成其他格式
for tiff in tifflist:
    arcpy.BuildPyramids_management(tiff) 
# **基于python的grd格式批量轉(zhuǎn)為tif格式**
grd格式是傳統(tǒng)的arcinfo格式,需要將grd轉(zhuǎn)換為tif格式,本文采用arcgis自帶的python批量轉(zhuǎn)換。
import arcpy
arcpy.env.workspace="D:\\chazhi\\"  #存放數(shù)據(jù)的文件夾
a=arcpy.ListRasters("*","grd")  #得到文件夾下所有的grd名稱
for i in a:
    arcpy.RasterToOtherFormat_conversion(i,"D:\\chazhi\\tif\\","TIFF")

基于Python的批量定義投影

應(yīng)用場(chǎng)景:MODIS NDVI/EVI數(shù)據(jù)需要轉(zhuǎn)換為跟自己數(shù)據(jù)一致的投影

定義坐標(biāo)系信息

可以先定義一個(gè)Shpfile的投影信息,然后把它的.prj文件用記事本打開(kāi),記得修改里面的符號(hào)“為'。

#柵格圖像的投影定義
import arcpy
# 設(shè)置工作空間
arcpy.env.workspace="E:\\GPP\\test2"
# 得到所有tif格式影像
rasterlist = arcpy.ListRasters("*", "tif")   
# 定義坐標(biāo)系統(tǒng)
Coordinate_System = "PROJCS['WGS_1984_Albers',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',105.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',47.0],PARAMETER['latitude_of_origin',0.0],UNIT['Meter',1.0]]"
# 循環(huán)
for raster in rasterlist:
    print str(raster)
    arcpy.DefineProjection_management(raster, Coordinate_System)
print("OK!")   # 運(yùn)行完畢,顯示OK。
# 要素類的投影定義
import arcpy
##### 設(shè)置工作空間
arcpy.env.workspace="E:\\GPP\\test2"
# 得到所有要素
featurelist = arcpy.ListFeatureClasses()  
# define coordinate system
Coordinate_System = "PROJCS['WGS_1984_Albers',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['false_easting',0.0],PARAMETER['false_northing',0.0],PARAMETER['central_meridian',105.0],PARAMETER['standard_parallel_1',25.0],PARAMETER['standard_parallel_2',47.0],PARAMETER['latitude_of_origin',0.0],UNIT['Meter',1.0]]"
#循環(huán)
for ft in featurelist:
    print str(ft)
    arcpy.DefineProjection_management(ft, Coordinate_System)
print("OK!")
# os 文件路徑及對(duì)字符串操作
import sys, os
import arcpy
dir_file = r"C:\Users\Administrator\Desktop\ANUSPLIN\grd"
files = os.listdir(dir_file)
for f in files:
    if os.path.splitext(f)[1] == '.grd':
        Input_raster_file = dir_file + os.sep + f
print Input_raster_file
Raster_Format = "TIFF"
Output_Workspace = r"C:\Users\Administrator\Desktop\ANUSPLIN\grd"
basename = os.path.splitext(f)[0]
Output_raster = Output_Workspace + os.sep + basename + ".tif"
arcpy.RasterToOtherFormat_conversion(Input_raster_file, Output_Workspace, Raster_Format)
print Out_raster

感謝原創(chuàng)作者提供的內(nèi)容,僅供學(xué)習(xí)借鑒參考

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容