pythonpycharmarcgisarcpyarcmap

Spatial join arcgis pro


I got this shape files Highway1,Highway2,Highway3 etc... The attribute tables are the same, they contain info about latitude, longitude , direction, shape_length and speed_allowed.

I want to make a script in python that would allow me to make a spatial join between every shape file that intersect other . For example if Highway1 intersect Highway2 , Highway12 and Highway22 i want 3 spatial join, every join should contain all the data from Highway 1 and where intersect the other highway, to have that info merged and where it does not intersect to have null values for the second highway.

Please help me write a script in order to automatically find if highway1 intersect other highway and if it does to make that kind of spatial join.


Solution

  • You should find what you need in the ESRI Documentation and in the ArcPy Documentation. Try their code samples, adapt it to your needs and then you are able to ask more specifically.

    Here's an example of ESRI's Intersect Docs:

    #Name: VegRoadIntersect.py
    # Purpose: Determine the type of vegetation within 100 meters of all stream crossings
    
    # Import system modules
    import arcpy
     
    # Set the workspace (to avoid having to type in the full path to the data every time)
    arcpy.env.workspace = "c:/data/data.gdb"    
        
    # Process: Find all stream crossings (points)
    inFeatures = ["roads", "streams"]
    intersectOutput = "stream_crossings"
    clusterTolerance = 1.5    
    arcpy.Intersect_analysis(inFeatures, intersectOutput, "", clusterTolerance, "point")
     
    # Process: Buffer all stream crossings by 100 meters
    bufferOutput = "stream_crossings_100m"
    bufferDist = "100 meters"
    arcpy.Buffer_analysis(intersectOutput, bufferOutput, bufferDist)
    
    # Process: Clip the vegetation feature class to stream_crossing_100m
    clipInput = "vegetation"
    clipOutput = "veg_within_100m_of_crossings"
    arcpy.Clip_analysis(clipInput, bufferOutput, clipOutput)
    
    # Process: Summarize how much (area) of each type of vegetation is found
    # within 100 meter of the stream crossings
    statsOutput = "veg_within_100m_of_crossings_stats"
    statsFields = [["shape_area", "sum"]]
    caseField = "veg_type"
    arcpy.Statistics_analysis(clipOutput, statsOutput, statsFields, caseField)