Select to view content in your preferred language

Python scripts for Fish data intersecting ICES Blocks

963
3
04-28-2014 01:43 AM
IanCharlton
Deactivated User
Hello, I am trying to create a script that automates a task for me

I basically have two polygon shapefiles that contains data on spawning and nursing fish locations respectively within UK waters. Lets call them spawning.shp and nursing.shp. There is an attribute field that contains the species (Cod, Hake Plaice etc) which is what I want to extract for later.

There is then a shapefile which contains ICES Blocks within UK waters, which are basically large polygons in a kind of grid across UK waters.

Basically what I want to achieve is two output shapefiles that contains all the ICES Blocks in one attribute field, and then the other attribute fields containing all the fish species within the spawning and nursing shapefiles, with the data in the fields simply being a "Yes" or a "No", based on whether that fish species is present within that Block (one shapefile concerning spawning species, one concerning nursing species.)

I'm fairly sure this should be quite simple to do but I am new to python/currently useless at it, so any help would be fantastic

Many thanks

Ian
Tags (2)
0 Kudos
3 Replies
markdenil
Frequent Contributor
I don't know how your species shapefile tables are constructed,
but an ineger field for each species would be handy, calculated to 1 for presence.

Use a loop with Add field, if you have to add them:
fields = ["Cod", "Hake" "Plaice", "Wanda"]
for f in fields:
    arcpy.AddField_management (in_table, f, "SHORT")

Now use an update cursor to update each presence species

Use Union or Identity with the Blocks
so you have all the bolcks broken up by the presence areas.

Dissolve the overlay output on the bolck ID
summing the values in each species field, so that,
for example,
if SUM_Cod is > 0, then cod is present.
0 Kudos
Zeke
by
Honored Contributor
Maybe a pivot table would be useful.
0 Kudos
MattEiben
Deactivated User
I think before you start scripting the process out, it may be useful to figure out the geospatial analysis process first.  If I'm understanding what you want for an output, a spatial join may be something to look into. 

Essentially, you'd spatially joining each of the two layers, nursing.shp and spawning.shp, to the ICES Blocks.

Another option could be a Select By Location.  Select all the ICES Blocks that intersect each of your shp files, and assign a value to a field of your choice based on that selection.

Usually the spatial join would be the preferable way to go since is "costs" less as far as processing goes that a Select by Location.
0 Kudos