Split Feature in Topographic Production Toolbox

265
3
04-28-2021 02:33 PM
Labels (1)
KateRose
New Contributor III

I'm trying to split about 20 polygon features in a file gdb with another multipart polygon, but don't have the Topographic Production license. I've modified the Example 2 python script here (https://pro.arcgis.com/en/pro-app/latest/tool-reference/topographic-production/split-features.htm) but I think it's failing because I don't have the license. Is there a way to do this without that extension? I've also read that checking the license out or in is only necessary if you're a concurrent user, but I'm a named user.

I'm a Python beginner using ArcPro 2.6.2

Any help is much appreciated! Thanks!

Here's my modified code:

# Name: SplitFeatures_sample2.py
# Description: Gets all feature classes in a geodatabase and splits them on the selected cutting feature

# Import System Modules
import arcpy
import os

# Check Out Extensions
arcpy.CheckOutExtension('Foundation')

# Setting Local Variables
cutting_features = r'C:\Users\kate.rose\GIS\GOM_CMECS\CMECS_GC_XWALK.gdb\CMECS_AS_MEOW_GMX'
target_database = r'C:\Users\kate.rose\GIS\GOM_CMECS\CMECS_Feature_split.gdb'

# Getting feature classes from the target geodatabase that are managed in a feature dataset
target_features = r''
arcpy.env.workspace = target_database
datasets = arcpy.ListDatasets('*', 'Feature')
for dataset in datasets:
fclasses = arcpy.ListFeatureClasses('*', '', dataset)
for fclass in fclasses:
desc = arcpy.Describe(fclass)
if desc.shapeType in ('Polygon', 'Polyline'):
target_features += os.path.join(target_database, dataset, fclass) + ';'
target_features = target_features[:-1]

# Setting selection on cutting features
selected_feature = arcpy.management.MakeFeatureLayer(cutting_features, 'AOI').getOutput(0)
arcpy.management.SelectLayerByAttribute(selected_feature, 'NEW_SELECTION', "PRODUCT_ID = 'V795X16573'")

# Splitting all features in a database based on the selected cutting feature
arcpy.topographic.SplitFeatures(selected_feature, target_features, 'DONT_USE_TARGET_Z')

# Check In Extensions
arcpy.CheckInExtension('Foundation')

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

@KateRose 

Code formatting ... the Community Version - Esri Community makes it easier to read the code.

Also, what is the error message?

If you don't have the extension, it should have said so. especially since you used the same line in the selectbyattributes without modification.  It works with a selected feature as the cutter

Split Features (Topographic Production)—ArcGIS Pro | Documentation

Alternatives, if you can get the cutter polygons formatted properly

Split (Analysis)—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
KateRose
New Contributor III

Thanks for the links- I'm now subscribed!

The code again:

# Name: SplitFeatures_sample2.py
# Description: Gets all feature classes in a geodatabase and splits them on the selected cutting feature

# Import System Modules
import arcpy
import os

# Check Out Extensions
arcpy.CheckOutExtension('Foundation')

# Setting Local Variables
cutting_features = r'C:\Users\kate.rose\GIS\GOM_CMECS\CMECS_GC_XWALK.gdb\CMECS_AS_MEOW_GMX'
target_database = r'C:\Users\kate.rose\GIS\GOM_CMECS\CMECS_Feature_split.gdb'

# Getting feature classes from the target geodatabase that are managed in a feature dataset
target_features = r''
arcpy.env.workspace = target_database
datasets = arcpy.ListDatasets('*', 'Feature')
for dataset in datasets:
    fclasses = arcpy.ListFeatureClasses('*', '', dataset)
    for fclass in fclasses:
        desc = arcpy.Describe(fclass)
        if desc.shapeType in ('Polygon', 'Polyline'):
            target_features += os.path.join(target_database, dataset, fclass) + ';'
target_features = target_features[:-1]

# Setting selection on cutting features
selected_feature = arcpy.management.MakeFeatureLayer(cutting_features, 'AOI').getOutput(0)
arcpy.management.SelectLayerByAttribute(selected_feature, 'NEW_SELECTION', "PRODUCT_ID = 'V795X16573'")

# Splitting all features in a database based on the selected cutting feature
arcpy.topographic.SplitFeatures(selected_feature, target_features, 'DONT_USE_TARGET_Z')

# Check In Extensions
arcpy.CheckInExtension('Foundation')

And the error message:

ExecuteError                              Traceback (most recent call last)
In  [3]:
Line 29:    arcpy.management.SelectLayerByAttribute(selected_feature, 'NEW_SELECTION', "PRODUCT_ID = 'V795X16573'")

File c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py, in SelectLayerByAttribute:
Line 8754:  raise e

File c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py, in SelectLayerByAttribute:
Line 8751:  retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))

File c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py, in <lambda>:
Line 511:   return lambda *args: val(*gp_fixargs(args, True))

ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).

The 'AOI' was created, but I have no idea what the SelectLayerByAttribute is supposed to do. I tried Google and the search on this site but couldn't come up with anything that I could understand. 

 

I did see the Split (Analysis) option but don't want to end up with individual polygons... 

0 Kudos
DanPatterson
MVP Esteemed Contributor

skip google... the help files are very good

Select Layer By Attribute (Data Management)—ArcGIS Pro | Documentation

Well your featureclass is supposed to have a field in it and you would be querying for this

"PRODUCT_ID = 'V795X16573'"

So, that appears to be the exact lines from the example in the Split tool, so I am not sure that you have that field or its value.  

The code was an example... in a perfect replica of the parameters and the data that went into the example it would work.  If you are emulating the code with your own data, you have to get stuff correct.


... sort of retired...
0 Kudos