0

I am using ArcMap Version 10.6.

I am having a problem with the ListFeatureClasses() function in arcpy. I am wanting access to all the feature classes in my datasets within a geodatabase. The following code when run only gives me access to the feature_type="Point"

def geoProcessing(database):
        ap.env.workspace = database
        datasets = ap.ListDatasets("*", feature_type="Feature")
        for dataset in datasets:
            for fc in ap.ListFeatureClasses(feature_dataset=dataset):
                do stuff…..

When I specify a feature type such as "Polygon" it gives me access to the polygon type feature classes.

def geoProcessing(database):
        ap.env.workspace = database
        datasets = ap.ListDatasets("*", feature_type="Feature")
        for dataset in datasets:
            for fc in ap.ListFeatureClasses(                    
                         feature_type="Polygon",feature_dataset=dataset):
                do stuff…..

Does anyone know what the problem is? It doesn't seem to make sense. I have tried including a wildcard and that doesn't fix the issue.

1

If you want to be able to access all feature types, you'll need to set feature_type to be:

for fc in ap.ListFeatureClasses(feature_type="All", feature_dataset=dataset):

Even though this is the default setting, I believe it only applies when using the geoprocessing tool, and not when using ArcPy directly.

See the tool documentation here.

  • a) Ok thanks, I did actually try that and that still didn't work. I spose I may have to send each feature_type to another function and process there. – ozzyzig May 22 '18 at 21:54
  • b) you wrote "I believe it only applies when using the geoprocessing tool, and not when using ArcPy directly." Are you saying this may work when run as a script within ArcGIS rather than a standalone python script importing arcpy? – ozzyzig May 22 '18 at 21:55
  • Well, the ListFeatureClasses tool doesn't have a geoprocessing equivalent for use in the general ArcMap environment. However, it does work in ModelBuilder as an iterator (Iterate Feature Classes), so if you can build out your script in ModelBuilder, maybe you can fix the issue. – JonR May 23 '18 at 23:49
  • Ok great thanks for your help. I was looking at the memory address for the feature class objects and it didn't make sense as two objects had same address which it could understand. I was populating geodatabase by iterating through a dictionary so maybe that was confusing it as normally it would be done from a list?? Not sure though. I could be wrong. My solution was to get describe shape type to get polygons, points and lines and send separately to another function. That worked. Cool thanks for your help though. Cheers – ozzyzig May 24 '18 at 3:29
1

Using ArcGIS Desktop 10.6 I am unable to reproduce what you are describing when running the test below:

import arcpy

if arcpy.Exists(r"C:\Temp\test.gdb"):
    arcpy.Delete_management(r"C:\Temp\test.gdb")
arcpy.CreateFileGDB_management(r"C:\Temp","test.gdb")
arcpy.CreateFeatureDataset_management(r"C:\Temp\test.gdb","TestFD")
arcpy.CreateFishnet_management(r"C:\Temp\test.gdb\TestFD\TestPoly",
                               "0 0", "0 1", 1, 1, 1, 1,
                               None, "LABELS", "DEFAULT",
                               "POLYGON")

arcpy.env.workspace = r"C:\Temp\test.gdb"
datasets = arcpy.ListDatasets("*", feature_type="Feature")
for dataset in datasets:
    for fc in arcpy.ListFeatureClasses(feature_dataset=dataset):
        print(fc)

The code creates a point feature class named TestPoly_label and a polygon feature class called TestPoly.

You seem to be saying that my test would only print TestPoly_label when it should print TestPoly_label and TestPoly.

As you can see below it prints both.

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
========================== RESTART: C:\Temp\test.py ==========================
TestPoly
TestPoly_label
>>> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.