I need some help to create a script.
Imagine that I'm using 3 shapes: 1 point and 2 polygons. When I create a new point I want it to assume some attributes of the polygons in which that point is inserted.
Any idea?
|
I need some help to create a script. Imagine that I'm using 3 shapes: 1 point and 2 polygons. When I create a new point I want it to assume some attributes of the polygons in which that point is inserted. Any idea? |
||||
|
|
|
Loop through your points (search cursor), then loop though you polygons (search cursor). Once you find the point is in the polygon (polygon.contains(point), then as you are already in the record of the polygon and point, just update by setting the attribute in the point, equal to the attribute you require from the polygon. simply then update the row in the point table, exit the polygon loop, then load the next point, etc. If you can wait until monday, I can write some arcpy for you; it's very, very easy and I think I did the very same thing last week.
Or there, or there abouts! |
|||||||||||||
|
|
What you're trying to do is called a "point in polygon" search. Python I'm guessing you're trying to script it using python given your tag.
A google search for Spatial Database Alternately you can offload the processing to a spatial database, i.e. spatialLite. You store your polygons in there and then when a new point is created you use some SQL to get the attributes for whichever polygons its within. https://code.google.com/p/xenia/wiki/SpatialLite - has a little more information Python Libaries There are also some python GIS libraries out there which could allow you to offload it to them rather than roll your own. Unfortunately I don't know any of their names. :-S |
|||
|
|
|
I'm not sure that that is possible, or the best way to approach the problem. I would imagine a better way is to create all the points first, or load them into your GIS somehow, and then update the desired fields in the points shape based on which polygon they are in, which is very possible in most GIS software, including open-source. State the software you intend to you use if you need more pointers. |
|||
|
|
|
How about:
|
|||
|
|
|
In ArcGIS you can simply use Spatial Join or Identity (ArcInfo only) to join attributes from one layer to another. Both tools will create new point layer. If you don't want create new layer and have greater control on selection method, here's the script similar to @Hairy's script but uses Feature Layers and Select By Location:
|
|||||||||||
|