Work flow and looping questions

145
4
08-28-2019 12:09 PM
GrantPalmer
New Contributor II

Hi all,

Working on large data sets and I want to get started off on the right foot before I begin to implement any changes to the Attribute Table so I am looking for some help in order to efficiently implement the task at hand. I am new to python but have some experience in C++ and a little Java. 

 

I am trying to assign a HUC 12 Watershed ID number to NHD flowlines that are located within said HUC 12 Watershed. This is just the first step in a larger goal with the data set but what I learn here will be able to apply to the rest of the project. 

 

First off I have a file with the HUC 12 (sub-watershed) polygons, each has their own unique ID number labeled HUC_12 in the attribute table. I also have a file with the NHD Flowlines (stream lines) lines, this file needs to have the data added to it.

So I start off by singling out one HUC 12 e.g. 020700090303 by just clicking on it/selecting it. Then I run Select Layer By Location with my input being the Flowline file; Relationship: Within; Selecting Features: HUC_12; Run.

This gives me all of the Flowlines within this HUC 12 sub-watershed. I wish to now add the HUC 12 ID of 020700090303 to the 31 different flowlines that were selected within the watershed. How do I go about doing this? Is it as simple as a Calculate Field? I want to create some sort of code or script to easily apply this answer to the 11,000 subwatersheds and 250,000 flowlines I have to link in the most time saving way.

Maybe I need to create some sort of loop to execute for all unique HUC_12 ID codes but I just do not know how to go about it on this large of a scale.

 

Cheers,

gpalmer_geo92

0 Kudos
4 Replies
JoshuaBixby
MVP Esteemed Contributor

This appears to be a classic use of Spatial Join—Help | ArcGIS Desktop 

0 Kudos
GrantPalmer
New Contributor II

You're right for that portion, a simple spatial join got me to the next portion of my work flow. I need to sum all of the lengths of the Flowlines that have the same HUC 12 ID value. For example, one HUC has anywhere between 1 and 50+  flowlines in it and i need to sum their lengths and store it in a field in the attribute table and do that for all of the unique HUC 12 values. I've been trying to find a function to help with this, sounds like Excels SUMIF function however my dataset is too much to be exported into excel. Can this tactic be implemented in python in ArcGIS Pro

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

The classic geoprocessing set-based approach would be to use Summary Statistics—Help | ArcGIS Desktop and then join the output table back to the original to update a field with the values.  There is a cursor based approach, but I don't have time to dive into the specifics at the moment.

0 Kudos
GrantPalmer
New Contributor II

Excellent, I was able to do what I needed with your help so far with this linear dataset and the polygon subwatershed. Now I must perform a similar analysis using the same HUC 12 polygon file but this time also using a raster dataset, specifically the NLCD (National Land Cover Database) 2016. I have already masked it down to the extent of the HUC12 polygon shapefile and reclassified the values to ones that are required of me. 

Not sure this will fall under the same Python stuff I was thinking of doing before but maybe you can still help me out.

So, there are 3 classes being displayed in the raster data set, I must find the % area of 'Forest', 'Agriculture', 'Urban', and 'Other' within each unique subwatershed (polygon dataset). Each cell has a 30m by 30m size and if I could just find the could of each different value in the polygon then it could be done.

0 Kudos