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.
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:
for fc in fcs:
geometryType = arcpy.Describe(fc).shapeType
if geometryType == 'Point':
#Get feature class name
fcsname = os.path.basename(fc)
name = os.path.splitext(fcsname)
y = name.lstrip('.')
#For fields in some feature classes
fields = ["OID@", "LANDDISTRICT", "LANDLOT"]
#Make feature layers
for row in arcpy.da.SearchCursor(fc, fields):
if row is None:
arcpy.SelectLayerByLocation_management (fc_layer, 'INTERSECT', Dist_LL_lyr)
select_records = arcpy.da.SearchCursor(Dist_LL_lyr)
elif row is None:
Solved! Go to Solution.
Here is the error message that I receive.
Traceback (most recent call last):
File "U:\Models_Tools\Scripts related to Landlot and District\Populate Landlot and District.py", line 17, in <module>
AttributeError: 'module' object has no attribute 'MakeFeatureLayer'
No worries - I've made that error many times (especially when I haven't got adequate sleep, which is often). Pro tip: use the Python window in ArcMap/Pro or an IDE that offers some code completion to check your syntax if you are unsure.
Thanks again Micah,
I made the necessary changes but now I have an issue where the number of returned features exceeds that of the queried features. I am trying to figure out what is the best approach to this:
So what I am trying to do is basically extract values spatially from one feature and using those values to populate the null fields in another layer. It seemed simple enough, but for some reason it returns an inordinate amount of records, which exceeds that of the queried records.
What would be the best way to script this? I am fairly close but I am having trouble figuring out how to get a matching number of records from another layer.
I'm not 100% clear on what you're trying to accomplish. It might help if you post the latest version of your script. Can you help me understand your desired steps?
The points do fall inside the Dist_LL layer, and the Dist_LL layer has
populated values in the fields. The points that fall inside have the same
fields(though named differently) but are null. The points are a set of
different feature classes, and I'm trying to see if I can get the feature
classes that have null values in them get populated using values in the
fields in the Dist_LL layer. I don't have access to my updated script but I
will post it once I get back to the office tomorrow. I hoped this
explanation is a bit clearer.
I understand your workflow much better now. It sounds like you want to transfer attributes from a polygon layer to the point layers that fall within it, where the corresponding attributes (although they are named differently) are null. Using search cursors may be feasible, but I think using a spatial join will be easier, especially if you have lots and lots of points in each layer. Nested cursors are pretty slow to run, sadly. Here's what I'd recommend: