Shapefile Automation

394
2
02-24-2014 12:41 AM
SimonTarr
New Contributor
Hello. Firstly, please accept my apologies if I have posted this in the wrong sub-forum...I'm not sure where the best place is to post this sort of question! Anyway, here is my problem (in two parts) and I'm really hoping someone can help me out automating it...to do this manually will take such a long time, so any help would be fantastic.

I am working on a project regarding lizards in North America. I currently have a shapefile with all the species present on the continent. What I would like to do is:

1) Take the range of each species in the 'master' shapefile and split this into an individual shapefile for each species. Each shapefile and associated files would need to go into a separate folder in ascending order (so the first species on my list Abriona aurita would go into  'Folder 1' then Abriona bogerti would go in 'Folder 2' etc). My list of lizard species in North America currently stands at 467 so you can probably see why I wish to automate this!

2) Once I have each individual species as a shapefile, I need to convert this into a raster using ArcGIS's built in Polygon -> Raster conversion tool. Again, would it be possible to automate this job as well by pointing to each folder and asking the software to dump a raster image in there as well.

Many thanks in advance for your help. Any assistance would be greatly appreciated.

Simon

EDIT- An alternative method, I suppose, would cut out stage 1 to some extent and just create a raster from each polygon in the master shapefile. I have no idea how to do this, however!
0 Kudos
2 Replies
WilliamCraft
MVP Regular Contributor
The best way to get an answer to this would be to post your Shapefile to this forum thread inside a ZIP file.  In general, you'll need a Python script that will select record by attribute based on species value, then export a shape file based on the selected records, then convert the output shape file to a raster file.  This would be automated for each of the species. 

What format are you expecting for your raster images (e.g., TIFF, GRID, JPG)?  Which version of the ArcGIS software are you using?  Which version of Python do you have installed?
0 Kudos
KaraManseau1
New Contributor II
Hi,

Here is a code sample for what you may be looking for:

[PHP]import arcpy
import os

unique= []
input = r"C:\Users\Username\Lizards\TestData.gdb\Lizards"

cursor = arcpy.SearchCursor(input, '', '','LizardType')
for row in cursor:
    if row.LizardType not in unique:
        unique.append(row.LizardType)

print unique

for x in unique:
    selectionvalue = str(x)
    query = '"LizardType" = ' + "'" + selectionvalue + "'"
    print query
    arcpy.SelectLayerByAttribute_management("Lizards", "NEW_SELECTION", query)
    dissolveout = os.path.join("C:\Users\Username\Lizards", x, "test" + str(int(x)) + ".shp")
    dissolveoutraster = os.path.join("C:\Users\Username\Lizards", x, "raster" + str(int(x)))
    arcpy.CopyFeatures_management("Lizards", dissolveout)
    arcpy.PolygonToRaster_conversion(dissolveout, "CellValue", dissolveoutraster, "CELL_CENTER", "CellValue", "")[/PHP]
0 Kudos