POST
|
I am trying to extract time series EVI values in a crop land raster layer (1 = cropland) using Con statement in raster calculator, I am trying using below code, but it showed error. Any help appropriate try: import arcpy,arcinfo import sys import os if arcpy.CheckProduct("ArcInfo") == "Available": print "available" if arcpy.CheckExtension("Spatial") == "Available": arcpy.CheckOutExtension("Spatial") print "License is available" arcpy.env.workspace = r"H:/Bangladesh_Data/MODIS/MODIS_INDICES/YEAR_2000/CLIP_BD/EVI" rasterList = arcpy.ListRasters("*","TIF") for raster in rasterList: # ouput raster location outLoc = "H:\\Bangladesh_Data\\MODIS\\MODIS_INDICES\\YEAR_2000\\CROP_BD\\EVI\\"+raster # cropland raster inRast= "H:\\Bangladesh_Data\\BD_Cropland\\bd_cropland_250.tif" arcpy.gp.RasterCalculator_sa(Con(inRast == 1,raster), outLoc) except: print "failed." print arcpy.GetMessages()
... View more
09-24-2019
12:18 PM
|
0
|
0
|
190
|
POST
|
I am trying to use following got, it saved all files in BUTM directory, but not in respective sub-directories. import arcpy arcpy.env.workspace = r"G:/RemoteSensing_Data/Landsat/Landsat_05/Year_1989/Row_138/UTM" folders = arcpy.ListWorkspaces() inPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\UTM_zone_45_N.prj" outPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\BUTM.prj" for folder in folders: arcpy.env.workspace = folder print(folder) rastersList = arcpy.ListRasters("*_sr_*","TIF") for raster in rastersList: print(raster) projOutA="G:\\RemoteSensing_Data\\Landsat\\Landsat_05\\Year_1989\\Row_138\\BUTM\\"+raster arcpy.ProjectRaster_management(raster, projOutA, outPut_cs,"BILINEAR", inPut_cs)
... View more
12-04-2016
08:35 AM
|
0
|
0
|
295
|
POST
|
I try following code it can all rasters from 4 sub-folders UTM folder. I can re-project all files but I need save they in perspective sub-folders in the BUTM folder import arcpy arcpy.env.workspace = r"G:/RemoteSensing_Data/Landsat/Landsat_08/Year_2014/Path_136/UTM/" folders = arcpy.ListWorkspaces() for folder in folders: arcpy.env.workspace = folder rasters = arcpy.ListRasters("*_sr_*","TIF") print (rasters) [u'LC81360432014002LGN00_sr_band1.tif', u'LC81360432014002LGN00_sr_band2.tif', u'LC81360432014002LGN00_sr_band3.tif', u'LC81360432014002LGN00_sr_band4.tif', u'LC81360432014002LGN00_sr_band5.tif', u'LC81360432014002LGN00_sr_band6.tif', u'LC81360432014002LGN00_sr_band7.tif', u'LC81360432014002LGN00_sr_cloud.tif', u'LC81360432014002LGN00_sr_evi.tif', u'LC81360432014002LGN00_sr_ipflag.tif', u'LC81360432014002LGN00_sr_msavi.tif', u'LC81360432014002LGN00_sr_ndvi.tif', u'LC81360432014002LGN00_sr_savi.tif'] [u'LC81360432014082LGN00_sr_band1.tif', u'LC81360432014082LGN00_sr_band2.tif', u'LC81360432014082LGN00_sr_band3.tif', u'LC81360432014082LGN00_sr_band4.tif', u'LC81360432014082LGN00_sr_band5.tif', u'LC81360432014082LGN00_sr_band6.tif', u'LC81360432014082LGN00_sr_band7.tif', u'LC81360432014082LGN00_sr_cloud.tif', u'LC81360432014082LGN00_sr_evi.tif', u'LC81360432014082LGN00_sr_ipflag.tif', u'LC81360432014082LGN00_sr_msavi.tif', u'LC81360432014082LGN00_sr_ndvi.tif', u'LC81360432014082LGN00_sr_savi.tif'] [u'LC81360442014002LGN00_sr_band1.tif', u'LC81360442014002LGN00_sr_band2.tif', u'LC81360442014002LGN00_sr_band3.tif', u'LC81360442014002LGN00_sr_band4.tif', u'LC81360442014002LGN00_sr_band5.tif', u'LC81360442014002LGN00_sr_band6.tif', u'LC81360442014002LGN00_sr_band7.tif', u'LC81360442014002LGN00_sr_cloud.tif', u'LC81360442014002LGN00_sr_evi.tif', u'LC81360442014002LGN00_sr_ipflag.tif', u'LC81360442014002LGN00_sr_msavi.tif', u'LC81360442014002LGN00_sr_ndvi.tif', u'LC81360442014002LGN00_sr_savi.tif'] [u'LC81360442014082LGN00_sr_band1.tif', u'LC81360442014082LGN00_sr_band2.tif', u'LC81360442014082LGN00_sr_band3.tif', u'LC81360442014082LGN00_sr_band4.tif', u'LC81360442014082LGN00_sr_band5.tif', u'LC81360442014082LGN00_sr_band6.tif', u'LC81360442014082LGN00_sr_band7.tif', u'LC81360442014082LGN00_sr_cloud.tif', u'LC81360442014082LGN00_sr_evi.tif', u'LC81360442014082LGN00_sr_ipflag.tif', u'LC81360442014082LGN00_sr_msavi.tif', u'LC81360442014082LGN00_sr_ndvi.tif', u'LC81360442014082LGN00_sr_savi.tif'] [u'LC81360452014002LGN00_sr_band1.tif', u'LC81360452014002LGN00_sr_band2.tif', u'LC81360452014002LGN00_sr_band3.tif', u'LC81360452014002LGN00_sr_band4.tif', u'LC81360452014002LGN00_sr_band5.tif', u'LC81360452014002LGN00_sr_band6.tif', u'LC81360452014002LGN00_sr_band7.tif', u'LC81360452014002LGN00_sr_cloud.tif', u'LC81360452014002LGN00_sr_evi.tif', u'LC81360452014002LGN00_sr_ipflag.tif', u'LC81360452014002LGN00_sr_msavi.tif', u'LC81360452014002LGN00_sr_ndvi.tif', u'LC81360452014002LGN00_sr_savi.tif']
... View more
12-04-2016
05:36 AM
|
0
|
1
|
295
|
POST
|
Thanks. Yes, it does not contain sub-folders similar to UTM folders. I will try accordingly.
... View more
12-04-2016
05:24 AM
|
0
|
0
|
295
|
POST
|
Hi All, I am trying to reproject all surface bands of several Landsat 8 image to a local coordinate system. Following script works fine for all bands of a single sheet of image. But I would like to reproject all sheets by batch processing and saved them in a another folder with similar sub-folders name of input folder. My input folder structure like this: G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360432014002 G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360432014082 G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360442014002 G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360442014082 Output folder will be like this G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360432014002 G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360432014082 G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360442014002 G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360442014082 try: import arcpy arcpy.env.workspace = r"G:/RemoteSensing_Data/Landsat/Landsat_08/Year_2014/Path_136/UTM/LC81360432014002" rasterListA = arcpy.ListRasters("*_sr_*","TIF") print(rasterListA) # Projection files (.prj) inPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\UTM_zone_46_N.prj" outPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\BUTM.prj" #Projection for raster in rasterListA: projOutA="G:\\RemoteSensing_Data\\Landsat\\Landsat_08\\Year_2014\\Path_136\\BUTM\\Full\\LC81360432014002\\"+raster arcpy.ProjectRaster_management(raster, projOutA, outPut_cs,"BILINEAR", inPut_cs) except: print "Projection failed." print arcpy.GetMessages() I appreciated if some one help me out. Zia
... View more
12-04-2016
12:26 AM
|
0
|
4
|
862
|
POST
|
Hi, In my previous post, the problem I mentioned I have solved it using following three python scripts. Is there anyway to combine theses three scripts to make one? Zia # -----------------------------------------------
# Script_01: Create folders with file name
# Zia Ahmed
# ------------------------------------------------
try:
import glob, os, shutil
folder = r"J:\RapidEyr_Atcor\test\HDF"
for file_path in glob.glob(os.path.join(folder, '*.*')):
new_dir = file_path.rsplit('.', 1)[0]
os.mkdir(os.path.join(folder, new_dir))
shutil.move(file_path, os.path.join(new_dir, os.path.basename(file_path)))
except:
print "Folder creation failed."
print arcpy.GetMessages() # ---------------------------------------------------------------------------
# Script_02: Import HDF file as TIFF
# Description: Extract HDF to geotiff
# Zia Ahmed
# ---------------------------------------------------------------------------
try:
import arcpy
arcpy.env.workspace = r"J:\RapidEyr_Atcor\test\HDF"
# list all folders in a directory
folders = arcpy.ListWorkspaces()
for folder in folders:
arcpy.env.workspace = folder
rasterListA = arcpy.ListRasters()
for raster in rasterListA:
tifOutA=""+raster[15:46]
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B1"+".tif", "0")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B2"+".tif", "1")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B3"+".tif", "2")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B4"+".tif", "3")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B5"+".tif", "4")
except:
print "Extract Subdataset failed."
print arcpy.GetMessages() #--------------------------------------------------
# Scrit_03: Batch processing - Stack RapidEyes bands
# Written by Zia Ahmed, CIMMYT, Bangladeash
#--------------------------------------------------
try:
import arcpy, os
# Define working folder
arcpy.env.workspace = r'J:\RapidEyr_Atcor\test\HDF'
# list all folders in a directory
folders = arcpy.ListWorkspaces()
for folder in folders:
arcpy.env.workspace = folder
# Create a raster list
rasters = arcpy.ListRasters("*.tif")
# output file name
name = os.path.join(rasters[1].split("_")[1] +"_multi"+ ".tif")
arcpy.CompositeBands_management(rasters, name)
except:
print "Multiband failed."
print arcpy.GetMessages()
... View more
11-17-2015
09:32 PM
|
0
|
4
|
3424
|
POST
|
Hi Dan, I am able to extract bands from HDF, but I have to run three python scripts: (1) First one create folders based on the name of HDF files and import HDF files in respective folders (2) Then 2nd Script extract first 5 bands in folder and (3) 3rd one create a multi-tif file. This there anyway combine three scripts to make one? I am going post all codes in another threads, Thanks again Zia
... View more
11-17-2015
09:19 PM
|
0
|
1
|
1202
|
POST
|
Thank. I do not understand want you want to say, i asking help for how to use file names create folders in a loop.
... View more
11-17-2015
05:37 PM
|
0
|
3
|
1202
|
POST
|
Hi, I am processing 190s HDF files from a Folder (J:\RapidEyr_Atcor\HDF). Here is the example of file name: AtmosCorrected_4549227_2014-12-23_RE1_3A_278182.hdf AtmosCorrected_4549227_2015-02-15_RE1_3A_278163.hdf AtmosCorrected_4549227_2015-01-13_RE1_3A_278182.hdf AtmosCorrected_4549227_2015-03-23_RE1_3A_278102.hdf Each HDF file contains 13 bands. But I want to extract the first 5 bands from each of HDF file and save as TIFF files in a folder created with [16:46] characters of corresponding HDF file. Folder and files arrangement as like as below: J:\RapidEyr_Atcor\TIF \4549227_2015-02-15_RE1_3A_278163 4549227_2015-02-15_RE1_3A_278163_b1. tif, 4549227_2015-02-15_RE1_3A_278163_b2.tif, 4549227_2015-02-15_RE1_3A_278163_b3.tif, 4549227_2015-02-15_RE1_3A_278163_b4.tif, 4549227_2015-02-15_RE1_3A_278163_b5.tif J:\RapidEyr_Atcor\TIF \4549227_2015-01-13_RE1_3A_278182 4549227_2015-01-13_RE1_3A_278182_b1.tif 4549227_2015-01-13_RE1_3A_278182_b2.tif 4549227_2015-01-13_RE1_3A_278182_b3.tif 4549227_2015-01-13_RE1_3A_278182_b4.tif 4549227_2015-01-13_RE1_3A_278182_b4.tif I think, first I have to create a output folder and name it with [16:46] characters of one HDF file, then apply arcpy.ExtractSubDataset for selecting the first five bands (0:4) from the corresponding HDF file. And I have to run this process in a loop for all HDF files. If anyone help me to modify following codes to process all HDF files with batch mode. Thanks Zia import arcpy try: arcpy.env.workspace = r"J:\RapidEyr_Atcor\HDF" rasterListA = arcpy.ListRasters() for raster in rasterListA: tifOutA="J:\\RapidEyr_Atcor\\TIFF"+raster[16:46] arcpy.ExtractSubDataset_management(raster,tifOutA+"_B1"+".tif", "0") arcpy.ExtractSubDataset_management(raster,tifOutA+"_B2"+".tif", "1") arcpy.ExtractSubDataset_management(raster,tifOutA+"_B3"+".tif", "2") arcpy.ExtractSubDataset_management(raster,tifOutA+"_B4"+".tif", "3") arcpy.ExtractSubDataset_management(raster,tifOutA+"_B5"+".tif", "4") except: print "Extract Subdataset example failed." print arcpy.GetMessages()
... View more
11-17-2015
08:54 AM
|
0
|
5
|
5229
|
POST
|
Hi, I am processing 190s HDF files from a Folder (J:\RapidEyr_Atcor\HDF). Here is the example of file name in the HDF Folder: AtmosCorrected_4549227_2014-12-23_RE1_3A_278182.hdf AtmosCorrected_4549227_2015-02-15_RE1_3A_278163.hdf AtmosCorrected_4549227_2015-01-13_RE1_3A_278182.hdf AtmosCorrected_4549227_2015-03-23_RE1_3A_278102.hdf Each HDF file contains 13 bands. But I want to extract first 5 bands and convert to TIFF files and save them in a folder. Since 1 have 190 HDF files, I want to create 190 folders in J:\RapidEyr_Atcor\TIFF . Folder name should be like this: J:\RapidEyr_Atcor\TIF \4549227_2014-12-23_RE1_3A_278182, J:\RapidEyr_Atcor\TIF \4549227_2015-02-15_RE1_3A_278163 J:\RapidEyr_Atcor\TIF \4549227_2015-01-13_RE1_3A_278182 J:\RapidEyr_Atcor\TIF \4549227_2015-03-23_RE1_3A_278102 Each folder will be contained 5 tiff files. The file names would be: 4549227_2015-02-15_RE1_3A_278163_b1. tif, 4549227_2015-02-15_RE1_3A_278163_b2.tif, 4549227_2015-02-15_RE1_3A_278163_b3.tif, 4549227_2015-02-15_RE1_3A_278163_b4.tif, 4549227_2015-02-15_RE1_3A_278163_b5.tif Following in ArcPython Script works fine when input HDF files already have been in different sub folders according to the date and tiles. But I have problem to define Folder names and files names in the folder. If someone help me out, then it will be save me a lot of time. Thanks Zia #-------------
import arcpy
try:
arcpy.env.workspace = r"J:\RapidEyr_Atcor\HDF"
rasterListA = arcpy.ListRasters()
for raster in rasterListA:
tifOutA=" M:\\TIF\\"+raster[15:40]
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B1"+".tif", "0")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B2"+".tif", "1")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B3"+".tif", "2")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B4"+".tif", "3")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B5"+".tif", "4")
except:
print "Extract Subdataset example failed."
print arcpy.GetMessages()
... View more
11-17-2015
02:39 AM
|
0
|
1
|
3165
|
POST
|
Thanks. I have modified your codes. Now it works for all folders. I appreciate your help. Thanks again Zia #------------------------------------- import arcpy, os arcpy.env.workspace = r'E:\LandsatTest' # list all folders in a directory folders = arcpy.ListWorkspaces() for folder in folders: arcpy.env.workspace = folder rasters = arcpy.ListRasters("*_toa_band*.tif") chk4 = ['band{0}.tif'.format(i) for i in range(2, 8)] rasters = [a for a in rasters if a[-9:] in chk4] name = os.path.join(rasters[1].split("_")[0] + ".tif") print(rasters)
... View more
08-06-2015
12:58 AM
|
0
|
1
|
869
|
POST
|
Thanks Xander. It works fine if I work with only one folder that contains only 12 tif files as you mentioned in your code. But in my case, I have to work with 42 folders. Each folders contains following tif files and file names is different. I just I want list file *_toa_band2.tif, *_toa_band3.tif, *_toa_band4.tif,*_toa_band5.tif, *_toa_band6.tif, and *_toa_band7.tif from each folder. Thanks again Zia For example: Folder name: LC81360432015085-SC20150730095903 LC81360442015085-SC20150730095903 LC81360452015085-SC20150730095903 Files in a folder (LC81360432015085-SC20150730095903)
... View more
08-05-2015
09:28 PM
|
0
|
1
|
869
|
POST
|
Yes. I just want to list from LC81360432015069LGN00_toa_band2.tif to LC81360432015069LGN00_toa_band7.tif from each folder. Thanks Zia
... View more
08-05-2015
08:26 PM
|
0
|
3
|
869
|
POST
|
Dear All, I am trying to make a composite band of six raster files. I have do this for +40 scenes of Landsat 8 processed data. Each scene folder contains about +12 tif files, I want create multi-tif file with following bands using Arc-python batch mode: LC81360432015069LGN00_toa_band2.tif # Blue LC81360432015069LGN00_toa_band3.tif" # Green LC81360432015069LGN00_toa_band4.tif" # Red LC81360432015069LGN00_toa_band5.tif" # NIR LC81360432015069LGN00_toa_band6.tif # SWIR 1 LC81360432015069LGN00_toa_band7.tif" # SWIR 2 The following python script works fine when the folder contains only above six files. For this, I have to reorganize all 40 folders accordingly, I do not want to do this. This there any way to create a file list only with above six files? Help will be appreciated. Thanks Zia import arcpy, os arcpy.env.workspace = r'E:\Landsat8\Process_data_2015\' # list all folders in a directory folders = arcpy.ListWorkspaces() for folder in folders: arcpy.env.workspace = folder rasters = arcpy.ListRasters("*.tif") name = os.path.join(rasters[1].split("_")[0] + ".tif") arcpy.CompositeBands_management(rasters, name) print "Processing complete"
... View more
08-05-2015
07:01 AM
|
0
|
7
|
4198
|
Title | Kudos | Posted |
---|---|---|
1 | 03-01-2013 01:48 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|