Skip to content

Instantly share code, notes, and snippets.

@AlexArcPy
Created March 6, 2016 06:57
Show Gist options
  • Save AlexArcPy/823091f66f562a6a3a8e to your computer and use it in GitHub Desktop.
Save AlexArcPy/823091f66f562a6a3a8e to your computer and use it in GitHub Desktop.
OOP approach for arcpy: class instance
gdb = Geodatabase(path=r"C:\ArcTutor\Editing\Zion.gdb",initialize=True)
print gdb.featureClassesFullPaths
#[u'C:\\ArcTutor\\Editing\\Zion.gdb\\Springs',
#u'C:\\ArcTutor\\Editing\\Zion.gdb\\Tracts',
#u'C:\\ArcTutor\\Editing\\Zion.gdb\\Trails',
#u'C:\\ArcTutor\\Editing\\Zion.gdb\\Roads']
fcs = gdb.feature_classes_objects
print fcs
#[<__main__.FeatureClass object at 0x0C6D0A50>,
#<__main__.FeatureClass object at 0x0C3B49F0>,
#<__main__.FeatureClass object at 0x0C6737D0>,
#<__main__.FeatureClass object at 0x0CBC96F0>]
print [(fc.fcPath,fc.shapeType) for fc in fcs]
#[(u'C:\\ArcTutor\\Editing\\Zion.gdb\\Springs', u'Point'),
#(u'C:\\ArcTutor\\Editing\\Zion.gdb\\Tracts', u'Polygon'),
#(u'C:\\ArcTutor\\Editing\\Zion.gdb\\Trails', u'Polyline'),
#(u'C:\\ArcTutor\\Editing\\Zion.gdb\\Roads', u'Polyline')]
print [fc.fcPath for fc in fcs if fc.shapeType == 'Polyline']
#[u'C:\\ArcTutor\\Editing\\Zion.gdb\\Trails',
#u'C:\\ArcTutor\\Editing\\Zion.gdb\\Roads',
#u'C:\\ArcTutor\\Editing\\Zion.gdb\\Streams']
springs_fc = [fc.fcFeatures for fc in fcs if fc.baseName == 'Springs'][0]
springs_feats = springs_fc.features
print springs_fc.fields
#[u'OBJECTID', u'Shape', u'ComID', u'FDate', u'Resolution', u'GNIS_ID',
#u'GNIS_Name', u'ReachCode', u'FType', u'FCode']
print springs_feats[0:3]
#[(228, (305711.4726999998, 4156967.8816), 33034429, datetime.datetime(2002, 2, 6, 0, 0), 2, None, None, None, 458, 45800),
#(229, (305315.84750000015, 4156801.4681), 33034431, datetime.datetime(2002, 2, 6, 0, 0), 2, None, None, None, 458, 45800),
#(230, (305697.4517000001, 4156837.429199999), 33034433, datetime.datetime(2002, 2, 6, 0, 0), 2, None, None, None, 458, 45800)]
print springs_fc.attribute_table[0:3]
#[{u'ComID': 33034429,
#u'FCode': 45800,
#u'FDate': datetime.datetime(2002, 2, 6, 0, 0),
#u'FType': 458,
#u'GNIS_ID': None,
#u'OBJECTID': 228,
#u'Resolution': 2,
#u'Shape': (305711.4726999998, 4156967.8816)},
#{u'ComID': 33034431,
#u'FCode': 45800,
#u'FDate': datetime.datetime(2002, 2, 6, 0, 0),
#u'FType': 458,
#u'GNIS_ID': None,
#u'OBJECTID': 229,
#u'Resolution': 2,
#u'Shape': (305315.84750000015, 4156801.4681)},
#{u'ComID': 33034433,
#u'FCode': 45800,
#u'FDate': datetime.datetime(2002, 2, 6, 0, 0),
#u'FType': 458,
#u'GNIS_ID': None,
#u'OBJECTID': 230,
#u'Resolution': 2,
#u'Shape': (305697.4517000001, 4156837.429199999)}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment