Solved! Go to Solution.
def getSpeciesCount(speciesFields): speciesCount=0 for speciesField in speciesFields: if str(speciesField)!="0": #should handel sting and interger inputs speciesCount+=1 return speciesCount
getSpeciesCount([!Frogs!, !Goats!, !Deer!])
Have you tried the feature to Raster tool? In ArcToolbox -> Conversion Tools: http://resources.arcgis.com/en/help/main/10.1/index.html#//00120000002v000000 (assuming you are using ArcGIS version 10.1)
To better assist you and general curiosity: What do you intend to use the raster for? Comparison with another raster? Analysis?
http://resources.arcgis.com/en/help/main/10.1/index.html#/Polygon_to_Raster/001200000030000000/
What does your shapefile look like?
Are ther several different shapefiles?
Or are there multiple features on top of each other?
Or is there a remark in the attribute table you can use to get the count.
If you have a value in a field jou could use polygon to raster (http://resources.arcgis.com/en/help/main/10.1/index.html#//001200000030000000).
But a bit more info is needed to give a good answer.
Greets Paul
Hello thiago021,
You'll need to do this in two steps.
1) Prepare an attribute you want in raster form. I think you want total number of species. In other words a count of non-zero fields for a specific polygon.
First open the shapefile's attribute table and create a new field (make sure its a number type like ShortInteger). Then right click on that new field and click Field Calculator. Enter in a formula to calculate number of species. I would use something like this (using Python😞
Pre-Logic Script Code: (make sure Show Codeblock is checked)def getSpeciesCount(speciesFields): speciesCount=0 for speciesField in speciesFields: if str(speciesField)!="0": #should handel sting and interger inputs speciesCount+=1 return speciesCount
numSpecies=getSpeciesCount([!Frogs!, !Goats!, !Deer!])
2) Convert to raster using the Polygon to Raster tool, set the field value to the attribute created above.
Let me know if you get it working. Good luck!
Hi
The reason it didn't work was becouse of the multipleoverlapping polygons.
I have tried to solve it using some data I have made myself that simulates your situation.
What is critical is that a species does not have overlapping polygons.
If it does you should first dissolve (http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000005n000000) your layer on the species so you have one (or more but without overlapping) polygon(s), make shure not to create multiparts.
First you preform a union (http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000000s000000) on your shape (it is allowed to do so on one shapefile), this will make small pieces of overlapping data clipping the data on each other.
Then you need to add three columns to the attribute table of the union shapefile:
- X "double"
- Y "double
- compare "text" (minimum of 50 characters)
In X you calculate the x coördinate of the polygon using the calculate geomitry function in the attribute table (http://resources.arcgis.com/en/help/main/10.1/index.html#//005s00000027000000)
In Y you calculate the y coördinate in the same way.
In compare you make a combination of the X and Y fields to get the combination of the two, becouse of the overlapping parts the union makes you need tis so you have a unique code for that specific location. All the overlapping parts are identical so the centrers are identical.
You can paste this in your field calculator:&"_"&
(so X and Y are seprarated with an underscore).
With this done you need to first summarize the compare field (http://resources.arcgis.com/en/help/main/10.1/index.html#//005s00000055000000) this creates a table with a count of the values, no need to assess other fields just specify the output location and name and click OK (add it to the map).
Then dissolve (http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000005n000000) the shapefile with the compare field.
This will bring it down to a single feature layer per location.
Where almost there 😉
Join the data from the summarized table to the dissolved shapefile (based on the compare field) and it will add the number of counts to your shapefile from the summarized table.
To permanently fuse the data rightclick your joined shape and click export data (all features) and save it again.
This makes a shape with a count field of the overlapping polygons, you can now run the polygon to raster tool with the value of the count field (http://resources.arcgis.com/en/help/main/10.1/index.html#//001200000030000000).
It looks like a lot but it are just a few steps.
I hope this works for you, it did it for me.
Greets Paul