Python point neighbor processing ideas?

4821
13
Jump to solution
04-30-2015 06:38 AM
ClintonCooper1
New Contributor III

I know a bit about python scripting, but am having some trouble figuring out where to get started on creating a script.

I need to loop down through a dataset (about 10,000 records), and select all points within a certain distance of the current point in the loop (it doesn't have to be a selection, but it must be within a spatial distance of the current point I just figured a selection would be good because it would limit the number of points that are queried).  After I create the selection of points,I need to count the number of points that satisfy 2 criteria:  1) have a value in another field 1 that is the same as the value in of the current point's field 1; 2) have values in field 2 that are greater than the current point's field 2.  I also have to do anther count that has the same above criteria of 1), but instead of greater than, I need to count those that are less than the current point's value in field 2.   I then need to print those counts (both greater than and less than) as well as the current point's  id  so I can go back and put them in another table for analysis.

I guess I would kind of be looking for an outline or some code that might be able to help get me started writing it.  Thanks!

(Curtis Price edited title [originally: "Python Script help"] (4/29/2015))

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

You do most of your task using Spatial Join on the point file itself, as both Target and Join Features, ONE_TO_MANY, WITHIN your distance. In the output, select and delete points where TARGET_FID = JOIN_FID (that is the point joined to itself). You can then select the matching rows which meet your criteria, and count using Summary Statistics, grouping on TARGET_FID.

View solution in original post

13 Replies
SepheFox
Frequent Contributor

Have you made any kind of a start at all? Generally with a Python script task, I will start by googling for similar scripts, as well as cutting and pasting from the ArcMap tool help, or grabbing the python snippets from the tools themselves. Most people on this forum prefer that a poster has made some attempts, but run into specific road blocks that they need help with, rather than starting from nothing. I am not trying to be rude, but just giving you some tips about how to get the help you need.

0 Kudos
ClintonCooper1
New Contributor III

I understand that, but I am not sure if a for search cursor loop would work for this than a list loop.  I know you are not trying to be crass, but I am having troubles getting even a starting point.  Thanks

0 Kudos
NeilAyres
MVP Alum

What version of Arc do you have, and access level (basic, advanced etc).

0 Kudos
ClintonCooper1
New Contributor III

10.3 Advanced

0 Kudos
NeilAyres
MVP Alum

I ask this because "Generate Near Table" would be a good starting point, with your distance (or a little more) as your max distance. You can put the same point feature as the input and the near features.

Then to process this you will probably need some python again...

0 Kudos
ClintonCooper1
New Contributor III

Thanks for the ideas, but I am running into some issues with this.  I think Search Cursor is the way to go, but am having some issues with grabbing the current feature the loop is on, and selecting that, so then to run the select by location. 

0 Kudos
curtvprice
MVP Esteemed Contributor

The help isn't very clear about the differences between Generate Near Table (which I think is a new tool) and Point Distance (which has been around since ArcInfo 4!). It seems similar but it has a lot more options on what to add to the output table.

Would be interesting to know whether there is a performance difference or something else that would guide you to use one or the other.

UPDATE

Feeling old...

NeilAyres
MVP Alum

That sounds complicated!

There may be cleverer ways but I would probably force this through an iterative loop as a dictionary.

Buffer each point, and search for within. This would mean that you would read your 10,000 points, 10,000 times of course.

Do you mind me asking why you need to do this?

0 Kudos
ClintonCooper1
New Contributor III

Looping though our bus stops, and looking for where we have too many stops too close together.  This is also going to be used as a metric for a model to calculate the value of the bus stop, so we can start to thin some of them out.

0 Kudos