I have a folder tree with many other folders in it containing many images. I have managed to make a script that will parse through the entire folder and find every image in it. It then uses raster domain to create a polygon shapefile of every footprint for each image.
The issue I am having is I need to have those footprints exported to a single folder named "index". The current script always exports the footprints to the same folder the image is located in. How can I change my script to export the raster domain footprints to the "index" folder instead of them being exported to the folder containing the imagery?
Here is my script:
import arcpy
import os
workspace = r”D:\Folder\Test”
outFile = r”D:\Folder\Index”
rasters = []
arcpy.CheckOutExtension(“3D”)
print ‘Processing’
for dirpath, dirnames, filenames, in arcpy.da.Walk(workspace, topdown=True, datatype=”RasterDataset”):
for filename in filenames:
rasters.append(os.path.join(dirpath, filename))
for raster in rasters:
outGeom = “POLYGON”
outPoly = raster[:-4]+”.shp”
arcpy.RasterDomain_3d(raster, outPoly, outGeom)
print rasters
print ‘Completed’
I'm pretty sure the answer lies with changing the "outPoly" parameter but anything I have tried resulted in an error. Any help would be much appreciated.
Thank you for your time.
Solved! Go to Solution.
If you are using ArcGIS pro then be aware...
Shapefiles cannot be added to the project Databases folder but must be stored in the project folder or a folder connection.
I am on ArcGIS 10.4. But it is indeed useful to know that about ArcPro for future reference.
Try the following:
for raster in rasters:
outGeom = "POLYGON"
outPoly = os.path.basename(raster)[:-4]+".shp"
arcpy.RasterDomain_3d(raster, os.path.join(outFile, outPoly), outGeom)
Beautiful Jake,
That seems to have worked. I'm guessing that os.path.basename(raster) stripped the path that was appended in the rasters =[] list? Anyways I think this should do. Thank you for your help. I'll just action this as correct as it did complete what I set out for.
Yes, the os.path.basename simply took the file name rather than the entire path.