AnsweredAssumed Answered

Trouble with selecting features by location using arcpy?

Question asked by RP.CObb on Oct 3, 2019
Latest reply on Oct 4, 2019 by RP.CObb

Hi,

 

So I am trying to figure out how to get the date for a selected feature using the spatial location using arcpy. I keep running into an issue where the MakeFeatureLayer keeps returning an error and I am not sure as to why. I followed several examples and yet I still keep getting an error. I would greatly appreciate any help with this.

import arcpy
import os

workspace = r'Database Connections\Some Connection.sde'
fcs = []
walk = arcpy.da.Walk(workspace, datatype="FeatureClass")

Dist_LL = "Database Connections\Some.sde\FeatureClass"
for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        fcs.append(os.path.join(dirpath, filename))

for fc in fcs:
    geometryType = arcpy.Describe(fc).shapeType
    print geometryType
    if geometryType == 'Point':

        #Get feature class name
        fcsname = os.path.basename(fc)
        name = os.path.splitext(fcsname)
        y = name[1].lstrip('.')
        print y

        #For fields in some feature classes
        fields = ["OID@", "LANDDISTRICT", "LANDLOT"]

        #Make feature layers
        arcpy.MakeFeatureLayer(fc, 'fc')
        arcpy.MakeFeatureLayer(Dist_LL, 'Dist_LL')
       
        for row in arcpy.da.SearchCursor(fc, fields):
            if row[1] is None:
                arcpy.SelectLayerByLocation_management (fc_layer, 'INTERSECT', Dist_LL_lyr)
                select_records = arcpy.da.SearchCursor(Dist_LL_lyr)
                print select_records
                print row
            elif row[2] is None:
                print row
            else:
                continue

Robert

Outcomes