0

I split the single shapefile into the multiple shapefile based upon their attributes. Now I want to clip the raster file into the each split shapefile. How can I do it at once?

I am using ArcGIS version 10. I used spilt layers by attributes tools to split the shapefiles.

nmtoken
  • 13,355
  • 5
  • 38
  • 87
user28856
  • 1
  • 2
  • 1
    What software are you using? – evv_gis Apr 04 '14 at 21:16
  • Can you edit your Question to include your GIS software and version, and also to let us know the tool you used to "split by attributes" because that has two ways of being interpreted. – PolyGeo Apr 04 '14 at 21:18
  • Do you happen to have your individual shapefiles in the same directory? – evv_gis Apr 04 '14 at 21:23
  • I saved all the shape file into single directiory – user28856 Apr 04 '14 at 21:24
  • As far as I know, there is no Split Layer By Attributes tool in the ArcGIS for Desktop product - do you perhaps mean Split (Analysis) or maybe something additional that you have installed like the options mentioned here? Also, are you looking to do just all the clips in one step or the "split by attributes" that precedes it too? – PolyGeo Apr 04 '14 at 21:36
  • 1
    @PolyGeo, there is an ArcScripts tool that I know many people have turned to: http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=37AEB018-1422-2418-A036-CA6D9920F808 – evv_gis Apr 04 '14 at 21:59

2 Answers2

1

This answer is not intended for beginners to ArcGIS. Having some knowledge of Model Builder, especially iterators would be best.

I would use ModelBuilder to iterate through your shapefile directory, and run a clipping process.

If you have spatial analyst, I would recommend using Extract By Mask.

If not, you can use Clip, but you'll need to do an extra step.

Open ModelBuilder, right-click -> Iterators -> Iterate Feature Classes (this works on shapefiles too).

Specify the directory for the shapefiles as the input workspace.

Now if you use Extract by Mask, it's as easy as adding the Extract by Mask tool to the model, connecting the inputs for the in_raster (your raster) and in_mask_data (your iterated filed).

If you have to use Clip, add the Feature Envelope to Polygon tool. Make the output of this go to a separate directory than your input shapefiles. Essentially this will create a rectangle which is needed to perform the clip.

Now, you should have your iterated shapefile, your raster, and a rectangle - all necessary for the clip tool. Set in_raster to your raster, the output of the envelope to the rectangle, and set the in_template_dataset to the iterated shapefile. You will also want to change the clipping geometry to ClippingGeometry to mask the output to the iterated shapefile.

For both, I recommend using the %i% variable in combination with your output name to separately name your outputs (so nothing gets overwritten).

evv_gis
  • 3,200
  • 16
  • 24
1

You can always use a tool's batch functionality--just right-click on the tool > batch... and fill in the blanks. However, this type of operation is typically done in an automated fashion.

enter image description here

You do not have to create individual shapefiles from features in a shapefile. Instead, you can use a Search Cursor to access all of the features in the FC. This is how I would do it:

import arcpy, os

arcpy.CheckOutExtension("Spatial")

outws = r'C:\temp'
raster = r'C:\path\to\your\raster.img'
fc = r'C:\path\to\fc'

count = 0
with arcpy.da.SearchCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:
        out = os.path.join(outws, "raster" + str(count) + ".img")
        ebm = arcpy.sa.ExtractByMask (raster, row)
        ebm.save(out)
        count = count + 1
Aaron
  • 51,658
  • 28
  • 154
  • 317
  • Will this work even if I have a thousands of sub shapefile? Where should I make a changes in the script, such that the script works with the shapefile I have – user28856 Apr 06 '14 at 02:21
  • That is what this script is designed for. Simply replace 'C:\path\to\fc' with the path to your shapefile and do the same for raster = r'C:\path\to\your\raster.img'. Finally, add the path where you want the clipped output to go in outws. – Aaron Apr 06 '14 at 14:34