AnsweredAssumed Answered

Return a list of attributes properties

Question asked by mthornton@blm.gov_BLM_EGIS on Aug 14, 2019
Latest reply on Aug 27, 2019 by rdhulipudiesriaustralia-com-au-esridist

I am attempting to write arcpy script that will iterate through an .sde connection database, finds all datasets containing polygons and the text "FFO" in the title, then selects for those and iterates through the feature_layers contained within.

 

I can do this with :

 

import arcpy
import csv
import os


csvname = r"U:\My Documents\ArcGIS\ArcPyOutputFiles\TestFile4.csv"
headers = 'Name', 'Path'
createCSV(headers, csvname, 'wb') 

 

arcpy.env.workspace = r"V:\tools\ArcSDE\Database Connections\5 NMSO ilmnmso3gi1 ilmnmsoclass1 (Type 1) Default.sde"

 

datasets = arcpy.ListDatasets("*FFO*", "Feature")
datasets = [''] + datasets if datasets is not None else []

for ds in datasets:
      for fc in arcpy.ListFeatureClasses("*FFO*", "Polygon", feature_dataset=ds):

         path = os.path.join( ds, fc)
         #print(path).

 

But there are multiple polygons in each feature layer, so I want to iterate through those as well. Which I can do with arcpy.da.SearchCursor() as long as the feature layers contain a similar field_name. But not all contain the word  "NAME". So I thought this would work.

   

   

arcpy.env.workspace = r"V:\tools\ArcSDE\Database Connections\5 NMSO ilmnmso3gi1 ilmnmsoclass1 (Type 1) Default.sde"

datasets = arcpy.ListDatasets("*FFO*", "Feature")
datasets = [''] + datasets if datasets is not None else []

 

for ds in datasets:
      for fc in arcpy.ListFeatureClasses("*FFO*", "Polygon", feature_dataset=ds):

            path = os.path.join( ds, fc)
            #print(path)

 

            desc = arcpy.Describe(fc)

            if hasattr(desc, 'name'):

              with arcpy.da.SearchCursor(fc, ['NAME']) as sc:
                  for row in sc:
                        Name = row[0]
                        Path = row[1]
                        data = Name, path
                        createCSV(data, csvname)

 

But it doesn't work. I want to load a csv file with a path to the data and an identifying name of each polygon contained in the feature layers, contained in the datasets. Thank you.

Outcomes