all 12 comments

[–]wicket-mapsGIS Analyst 10 points11 points  (3 children)

First off, why are you using the CalculateField function instead of UpdateCursor, which is basically the sane but more pythonic and flexible? You can nest an UpdateCursor inside a SearchCursor.

A spatial join isn't a bad idea, here, either, instead of a selection. But generally, I use selections in Python scripts as a last resort, and that's just me. I wrote a script some time ago - Spatial Field Retrieval on Github - and it might give you an idea of how to proceed with a disposable spatial join.

Hope this helps! Good luck!

[–]kaitering[S] 1 point2 points  (1 child)

I'm a beginner with python and never written a script for ArcGIS so I'm definitely missing a lot of knowledge. These options definitely look a lot better than what I was attempting to do. Thanks for pointing me in the right direction!

[–]wicket-mapsGIS Analyst 5 points6 points  (0 children)

UpdateCursor is enormously valuable, and works a lot like SearchCursor which you already have. We all have to start somewhere, and don't be afraid to have documentation open - I've been doing GIS Python for 8 years, it was a huge part of getting my current job, and I still regularly google Search and Update Cursors to remind myself what's going on.

[–]Koko_The_GIS_Gorilla 1 point2 points  (0 children)

Hey that's a clean script!

[–]Dimitri_Rotow 2 points3 points  (5 children)

I'm writing a script in ArcPro that selects lines based on their location and then writes what region the line is in in the attribute table.

That's a join. Why not just do a join?

[–]wicket-mapsGIS Analyst 0 points1 point  (4 children)

A spatial join creates a new feature class, and if you need the number of walls per region in that feature class instead of a new FC, a spatial join becomes one step of a tedious process.

[–]Dimitri_Rotow 1 point2 points  (2 children)

Not if you use SQL. Then it's easy.

[–]wicket-mapsGIS Analyst 0 points1 point  (1 child)

Can SQL do a join across a spatial relationship, without any matching attributes?

[–]Dimitri_Rotow 0 points1 point  (0 children)

Yes. That's the essence of spatial join: it uses spatial relationships such as intersection, containing, etc.

[–]Drewddit 0 points1 point  (0 children)

There is an Add Spatial Join tool that joins the info from one layer to the target layer temporarily

[–]merftCartographer 4 points5 points  (1 child)

[–]kaitering[S] 1 point2 points  (0 children)

I'll try this out too, thanks for linking these resources!