Select to view content in your preferred language

EXTRACT DATA WITHIN LAYERS

1397
1
01-06-2022 02:16 PM
RobinsonMyers
New Contributor

I need help on how to extract data from my files.  I have layers where I have a "boundary" drawn around 4 houses that I have obtained addresses for; then within that boundary, I have items added that will serve those 4 houses.  I do this throughout the neighborhood.  If it helps, this is for telecom to determine where each home will be served.  I need to extract the data to give me a list of the addresses contained within the boundary as well as the terminal I placed to serve them.  Is there a way to extract all the data within several boundaries on a map?  I am attaching a picture that shows the green boundaries, with the triangle(terminal) and house symbols inside the green boundary.  Notice there are several green boundaries that only cover 4 homes.  Can I get all the info I am asking for from extracting the data?  If so, how?

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

It is absolutely possible. What you need to do:

  • intersect boundaries and houses: this returns a point layer with addresses and boundary names
  • intersect boundaries and stations: this returns a point layer with station names and boundary names
  • use a way to connect the two layers using the common attribute boundary name

A basic implementation of these steps in Python (assuming you work with ArcMap or ArcGIS Pro: open the Python window, paste and edit the code below, execute):

# names of the 3 layers
boundary_layer = "Boundaries"
station_layer = "Stations"
house_layer = "Houses"
# names of the fields you want to extract
boundary_field = "BoundaryID"
station_field = "StationID"
house_field = "Address"

# intersect boundaries and stations
station_intersect = arcpy.analysis.Intersect([boundary_layer, station_layer], "memory/station_intersect")
# intersect boundaries and houses
house_intersect = arcpy.analysis.Intersect([boundary_layer, house_layer], "memory/house_intersect")
# read boundary data: [boundary_field]
boundaries = [row[0] for row in arcpy.da.SearchCursor(boundary_layer, [boundary_field])]
# read station data: [ [boundary_field, station_field] ]
stations = [row for row in arcpy.da.SearchCursor(station_intersect, [boundary_field, station_field])]
# read house data: [ [boundary_field, house_field] ]
houses = [row for row in arcpy.da.SearchCursor(house_intersect, [boundary_field, house_field])]

# connect station data and house data: 
# {boundary_field: {"stations": [station_field], "houses": [house_field]}}
boundary_dict = {b: {"stations": [s[1] for s in stations if s[1] == b], "houses": [h[1] for h in houses if h[0] == b]} for b in boundaries}

import pprint
pprint.pprint(boundary_dict)

 

If you want to extract the data for only a few boundries, select those boundaries before you run the code.


Have a great day!
Johannes
0 Kudos