Using GDAL:
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 18 22:53:22 2017
@author: Baikal
"""
import os
def CreatClipBatFile(batchfile):
batchcreat = open(batchfile,'w')
# 获得待裁剪影像的存储路径以及文件名
list_file = os.listdir(r'G:\MASIE\2016.06\Mosaic/')
file_count = 0
for filename in list_file:
if filename.endswith('.tif'):
file_path_name = filename
outname = filename[:-4] + '_Clip.tif'
file_count = file_count + 1
GDAL_Processing_CMD = 'gdalwarp -overwrite -q -cutline G:/2016.06.MOD/MOD02/5Clip/Clip_Image_Shp/Clip_Image.shp -tr 1000.0 1000.0 -of GTiff ' + \
' G:/MASIE/2016.06/Mosaic/' + file_path_name + ' G:/MASIE_3573/2016.06/Clip/' + outname + ' -crop_to_cutline\r\n'
batchcreat.write(GDAL_Processing_CMD)
batchcreat.close()
CreatClipBatFile(r'G:\MASIE_3573\2016.06\Batch_Clip_MASIE.bat')
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 18 22:53:22 2017
@author: Baikal
"""
import os
def CreatClipBatFile(batchfile):
batchcreat = open(batchfile,'w')
# 获得待裁剪影像的存储路径以及文件名
list_file = os.listdir(r'G:\MASIE\2016.06\Mosaic/')
file_count = 0
for filename in list_file:
if filename.endswith('.tif'):
file_path_name = filename
outname = filename[:-4] + '_Clip.tif'
file_count = file_count + 1
GDAL_Processing_CMD = 'gdalwarp -overwrite -q -cutline G:/2016.06.MOD/MOD02/5Clip/Clip_Image_Shp/Clip_Image.shp -tr 1000.0 1000.0 -of GTiff ' + \
' G:/MASIE/2016.06/Mosaic/' + file_path_name + ' G:/MASIE_3573/2016.06/Clip/' + outname + ' -crop_to_cutline\r\n'
batchcreat.write(GDAL_Processing_CMD)
batchcreat.close()
CreatClipBatFile(r'G:\MASIE_3573\2016.06\Batch_Clip_MASIE.bat')
Using ArcPy[1]:
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 25 19:47:12 2018
@author: Baikal
"""
import arcpy
#from arcpy import env
def Clip_CIS( Raster_Shapefile_DIR, CIS_TIFF ):
shapefile = Raster_Shapefile_DIR + r'raster_domain.shp'
Clip_TIFF = Raster_Shapefile_DIR + r'64_15_03/CIS.tif'
rasterFormat = 'GTiff'
vectorFormat = 'ESRI Shapefile'
arcpy.Clip_management ( CIS_TIFF, in_template_dataset = shapefile,
out_raster = Clip_TIFF,
clipping_geometry = True )
CIS_DIR = r'G:\CIS_Sea_Ice_Chart_3573\2016/'
E_FILDER = 'EA_FMO_Segmentation'
W_FILDER = 'WA_FMO_Segmentation'
CIS_NAME = r'\cis_SGRDRWA_20160502T1800Z_pl_a_FMO_Segmentation.tif'
CIS_TIFF = CIS_DIR + W_FILDER + CIS_NAME
Raster_DIR = r'G:\201606Sen\scihub.copernicus.eu\201604/'
#待修改
S1_FOLDER = 'S1A_EW_GRDM_1SDH_20160429T140459_20160429T140559_011037_01099E_AFA2'
DIR = '\Composition/'
Raster_Shapefile_DIR = Raster_DIR + S1_FOLDER + DIR
Clip_CIS( Raster_Shapefile_DIR, CIS_TIFF )
Reference:
[1] https://gis.stackexchange.com/questions/139982/clipraster-with-three-inputs
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 25 19:47:12 2018
@author: Baikal
"""
import arcpy
#from arcpy import env
def Clip_CIS( Raster_Shapefile_DIR, CIS_TIFF ):
shapefile = Raster_Shapefile_DIR + r'raster_domain.shp'
Clip_TIFF = Raster_Shapefile_DIR + r'64_15_03/CIS.tif'
rasterFormat = 'GTiff'
vectorFormat = 'ESRI Shapefile'
arcpy.Clip_management ( CIS_TIFF, in_template_dataset = shapefile,
out_raster = Clip_TIFF,
clipping_geometry = True )
CIS_DIR = r'G:\CIS_Sea_Ice_Chart_3573\2016/'
E_FILDER = 'EA_FMO_Segmentation'
W_FILDER = 'WA_FMO_Segmentation'
CIS_NAME = r'\cis_SGRDRWA_20160502T1800Z_pl_a_FMO_Segmentation.tif'
CIS_TIFF = CIS_DIR + W_FILDER + CIS_NAME
Raster_DIR = r'G:\201606Sen\scihub.copernicus.eu\201604/'
#待修改
S1_FOLDER = 'S1A_EW_GRDM_1SDH_20160429T140459_20160429T140559_011037_01099E_AFA2'
DIR = '\Composition/'
Raster_Shapefile_DIR = Raster_DIR + S1_FOLDER + DIR
Clip_CIS( Raster_Shapefile_DIR, CIS_TIFF )
Reference:
[1] https://gis.stackexchange.com/questions/139982/clipraster-with-three-inputs
没有评论:
发表评论