Skip to main content
Solved

Reading Attributes from a File Geodatabase and create Features via Python


Hi,

 

I want to read only one Attribute(FGDB_ID) from a File Geodatabase with Python.The geometry is not required. The readout of the File Geodatebase works well, but no features are generated. 

The Attributes will be printed only in the log window, but no Features will be generated.

How can I create features from the individual values?

import fmeobjects
import arcpy
# Template Class
class FeatureCreator(object):
    def __init__(self):
        # Name der FC
        fc = "\\\\path\\gdb.gdb\\GK_ANNO"
        # Ergebnisliste
        FGDB_ID = []

        # ArcPy-Suchcursor erstellen und auf die entsprechende Spalte der FC
        # ansetzen.
        cursor = arcpy.SearchCursor(fc, """""FGDB_ID")

        # Spalte zeilenweise auslesen...
        for row in cursor:

        # ... und FGDB_ID an Ergebnisliste anhängen.
            FGDB_ID.append(row.FGDB_ID)

        #pprint(FGDB_ID)
        for id in FGDB_ID:
            print(id)
        pass
    def close(self):
        feature = fmeobjects.FMEFeature()
        self.pyoutput(feature)

And sorry for my bad english ;)

Best answer by david_r

Two things:

First, you are currently creating one feature in the close() method, but you do not set any attributes. 

Secondly, you create a local list object FGDB_ID in the __init__() method, but it is not visible outside that method. You can convert your local list object to a class instance object by prefixing it with "self."

Try something like this (untested) where we loop over the list in the close() method, and for each ID we create a new feature with an attribute "FGDB_ID":

import fmeobjects
import arcpy
# Template Class
class FeatureCreator(object):
    def __init__(self):
        # Name der FC
        fc = "\\\\path\\gdb.gdb\\GK_ANNO"
        # Ergebnisliste
        self.FGDB_ID = []
 
        # ArcPy-Suchcursor erstellen und auf die entsprechende Spalte der FC
        # ansetzen.
        cursor = arcpy.SearchCursor(fc, """""FGDB_ID")
 
        # Spalte zeilenweise auslesen...
        for row in cursor:
 
        # ... und FGDB_ID an Ergebnisliste anhängen.
            self.FGDB_ID.append(row.FGDB_ID)

    def close(self):
        for id in self.FGDB_ID:
            feature = fmeobjects.FMEFeature()
            feature.setAttribute('FGDB_ID', id)
            self.pyoutput(feature)
View original
Did this help you find an answer to your question?

2 replies

david_r
Celebrity
  • Best Answer
  • August 2, 2016

Two things:

First, you are currently creating one feature in the close() method, but you do not set any attributes. 

Secondly, you create a local list object FGDB_ID in the __init__() method, but it is not visible outside that method. You can convert your local list object to a class instance object by prefixing it with "self."

Try something like this (untested) where we loop over the list in the close() method, and for each ID we create a new feature with an attribute "FGDB_ID":

import fmeobjects
import arcpy
# Template Class
class FeatureCreator(object):
    def __init__(self):
        # Name der FC
        fc = "\\\\path\\gdb.gdb\\GK_ANNO"
        # Ergebnisliste
        self.FGDB_ID = []
 
        # ArcPy-Suchcursor erstellen und auf die entsprechende Spalte der FC
        # ansetzen.
        cursor = arcpy.SearchCursor(fc, """""FGDB_ID")
 
        # Spalte zeilenweise auslesen...
        for row in cursor:
 
        # ... und FGDB_ID an Ergebnisliste anhängen.
            self.FGDB_ID.append(row.FGDB_ID)

    def close(self):
        for id in self.FGDB_ID:
            feature = fmeobjects.FMEFeature()
            feature.setAttribute('FGDB_ID', id)
            self.pyoutput(feature)

  • Author
  • August 3, 2016

Thanks. It Works.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings