Im running my script in ArcGIS 10.2 and the dialog window says completed, but the empty fields in the 'SoilsType' row of the 'mSoils' Feature Class aren't getting populated with the values from the 'SoilsType' field from the 'mLanduse' Feature Class.
cur = arcpy.da.SearchCursor(mLanduse, lField)
for row in cur:
cur2 = arcpy.da.UpdateCursor(mSoils, sField)
for row2 in cur2:
if row2[0] == '' or row2[0] is None:
row2[0] = lField
cur2.updateRow(row2)
Solved! Go to Solution.
Hi Ernst,
It looks like you are trying to update the Soils feature class that have no value for the SoilType with values from a LandUse polygon. Instead of using an updateCursor, I would recommend using the Spatial Join tool. You can then join the output from this tool to the Soils feature class, and update the empty rows using the Field Calculator.
Hi Ernst,
It looks like you are trying to update the Soils feature class that have no value for the SoilType with values from a LandUse polygon. Instead of using an updateCursor, I would recommend using the Spatial Join tool. You can then join the output from this tool to the Soils feature class, and update the empty rows using the Field Calculator.
Hi Jake,
You are correct with my workflow, except the SoilType Field has values in the Landuse Polygon. My query is trying to retrieve just the blank fields in the SoilType Field in the Soils Polygon. Is my workflow wrong?
Are you sure your soil types contain blanks or null? (The geodatabase supports null values, unlike shapefiles.)
This query would select both blanks and those that have null values:
query = "SoilType = '' or SoilType IS NULL"
But I think your workflow is wrong, including your use of arcpy.UpdateCursor, the construct you are using with row[0] etc. is what you would use with arcpy.da.UpdateCursor, not the old (10.0) arcpy.UpdateCursor method. Where is the variable LandUse being populated?
I would go with Jake's suggestion.
Curtis,
I am not seeing any NULL values, and when I do a Definition Query and select Get Unique values '' is the first option, so only blank fields are present.
I am not currently populating the LandUse variable, do I need another MakeFeatureLayer for this?
The issue I'm seeing here is you seem to be trying to transfer land use variables over to your blank soil polygons, but you're not doing any spatial overlay in your script, unless I'm missing something. That's what Jake was getting at by suggesting the Join By Location tool.
If you have an ArcGIS Advanced ("ArcInfo") license you could probably solve this problem best with the Identity tool followed by some field calculations.
Isn't this the spatial overlay? ;
- # Make a layer and select soils which fall within the Landuse polygon
- arcpy.SelectLayerByLocation_management('Soils_lyr', 'within', Landuse)
I have ArcGIS Advanced, but I would like to do this in python. I have been referring to this website;
3.2.4 Retrieving records using a spatial query | GEOG 485: GIS Programming and Automation
That is just a spatial selection, you are trying to copy attribute data over. To do that you need to do a "real" spatial overlay to create a link between the soil and land use polygon features (ie a "join").
Identity (and related tools Intersect, Erase, etc) are tools you can run interactively or access from arcpy, see the examples in the help. (They require an ArcInfo license to run.)
But can't I use updateCursor to update existing fields in the table?;
3.3.1 Updating existing records | GEOG 485: GIS Programming and Automation
Yes, but where are you going to get the land use data value to update the soil polygon field? You need to somehow relate your blank soil polygons to the land use polygons that overlap it.