Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a set of polygons and I want to add a field with the name of the streets (from another feature class of streets) that are within each polygon. Using Select Features by Location, I select streets that are within the polygons, but I can't think of a way (using python) to automate the process of populating each polygon with the name of the street that falls within it. I don't have a matching field for either feature class to base a join on. Is this possible or is it something that would have to be done manually?

share|improve this question
1  
What software package are you working with? –  lynxlynxlynx Dec 19 '12 at 17:24
    
arcmap .......... –  Kevin Dec 19 '12 at 21:58
1  
What are you wanting to see when "populating each polygon with the name of the street that falls within it"? I could show you how to add the streets in a polygon as a comma delimited list but I would imagine that could be a very long field if there are hundreds of streets in some polygons. Alternatives could be to use a spatial join to create a table listing for each street what polygon(s) it is in or to do an Intersect which can pull the polygon attributes onto the streets that pass through it. –  PolyGeo Dec 19 '12 at 23:07

2 Answers 2

Try something to do with this, it is the idea, but it mostly untested, but i am sure it good and it's should work: This "your_streets" and "your_polygons" are your feature classe.

cursor=arcpy.SearchCursor(your_streets)

for street in cursor:

name_of_street=street.Name 
ID_line=street.OBJECTID

if arcpy.Exists(street_layer):
    arcpy.Delete_management(street_layer)
arcpy.MakeFeatureLayer_management(your_streets,street_layer)
arcpy.SelectLayerByAttribute_management(street_layer, "NEW_SELECTION", "\"OBJECTID\" = "+str(ID_line))

if arcpy.Exists(polygons_layer):
    arcpy.Delete_management(polygons_layer)
arcpy.MakeFeatureLayer_management(your_polygons,polygons_layer)

arcpy.SelectLayerByLocation_management(polygons_layer,"WITHIN",street_layer) 

cursor_1=arcpy.UpdateCursor(polygons_layer) 
for polygon in cursor_1:
    polygon.Name_street=name_of_street
share|improve this answer

The analysis that you want to do, might be a bit strange, as you may have lots of streets passing trough your polygons, and it might be complicated put all that in a single field, but I do not know your dataset, so it might be perfectly reasonable.

A quite easy way would be to use the following algorithm that you can process in a Python Script:

  • Use Spatial join using Polygons as "Target features" and street as "Join Features", set the merge rule for streets field name to join (use ", " as separator) and intersects in the "matching";
  • Make Feature Layer from your Polygons
  • Add Join between Polygons Layer and the output of the Spatial Join using the original FID
  • Add field Streets_Name (text 255)
  • Calculate Field Streets_Name from the joined table Join_Street_Name Field
  • Remove Join
  • Delete (Management) Spatial Join Output

Remember that if the join of the street names from any polygon is bigger than 155 character you will have problems...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.