Batch Topo To Raster: With a Twist?

1877
1
04-21-2013 07:28 AM
PeterWilson
Occasional Contributor III
I've generated a File Geodatabase with an Index (Polygon) ; Spot Heights (Points) per index ; and Contours (Polylines) per index. I'm trying to generate a python script that will firstly generate a Feature Layer per index. The name of the Feature Layer needs to be based on the value within the field called TAG per index. The Feature Layer per index needs to be used as the Boundary within Topo To Raster. The associated Spot Height Point Feature Class based on the index name needs to be used as PointElevation within Topo To Raster ; and the Contour Polyline Feature Class per index needs to be used as Contour within Topo To Raster. The output DEM needs to be named after the Index name found within the TAG field.

I've attached print screens of the File Geodatabase, the Index Feature Class and Attribute Table within ArcMap to better understand what I'm trying to achieve.

The code that I've generated so far is below, either my sql expression is incorrect because it fails as soon as I try to use it within Make Feature Layer. I've not yet worked out how to get the TAG field value out in order for it to be used as the Feature Layer Name

>>> import arcpy
>>> arcpy.env.workspace = r'E:\Projects\H109009\Terrain.gdb'
>>> index = "Index10kSelected_5m_WGS84"
>>> with arcpy.da.SearchCursor(index,["TAG"]) as sCur:
...     for row in sCur:
...         sqlExp = """ {0} = '{1}' """.format(arcpy.AddFieldDelimiters(index,"TAG"),row.getValue("TAG")
...         arcpy.MakeFeatureLayer_management(index, To be replaced with "TAG" value,sqlExp)


Any assistance would be appreciated, please be warned, I've just started learning to code.

Regards
0 Kudos
1 Reply
by Anonymous User
Not applicable
Original User: curtvprice

I  my sql expression is incorrect because it fails as soon as I try to use it within Make Feature Layer.


Your AddFieldDelimiters first argument is a workspace, not a feature class. Also, you don't want to access a dataset involved in a currently accessed cursor - that's probably why your query actually failed.

Here are some ideas anyway...

import arcpy
arcpy.env.workspace = r'E:\Projects\H109009\Terrain.gdb'
index = "Index10kSelected_5m_WGS84"
lyr = arcpy.MakeFeatureLayer_management(index, "lyr")
tagField = arcpy.AddFieldDelimiters(arcpy.env.workspace,"TAG")

# best to get the list first
tags = []
with arcpy.da.SearchCursor(lyr, "TAG") as sCur:
    for row in sCur:
        tags.append(row.getValue(tagField))

# run through list of tags
for tag in tags:
    sqlExp = "{0} = '{1}' ".format(tagField, tagValue)
    arcpy.SelectLayerByAttribute(lyr, sqlExp)
    #...
    #topo to raster processing with input layer lyr
    # ( selected set is honored )
    #...


Hope this helps.

UPDATE: found the real problem - don't access layer inside cursor that is used in cursor!
0 Kudos