Exploring spatial data

3478
2
02-24-2014 02:59 PM
JacobWagner
New Contributor
I have been working on this for hours and am getting increasingly frustrated. i do not know how to get these answers or what code to put in. I have followed through all of the lab walkthroughs and have searched online, nothing is providing me with a proper answer. I dont necessarily need someone to figure it out for me but i need something to put into arcMap python that will provide me with these answers. An explanation on what to do for each step with code to type in would be appreciated.

I have been provided with data from the lab exercise, however i would have to attach over 20 items to provide them. So as i said a code sequence to get me to where i need to be would work for me

Challenge 1:

Write a script that reads all the feature classes in a workspace and prints
the name of each feature class and the geometry type of that feature
class in the following format:
streams is a point feature class

Challenge 2:

Write a script that reads all the feature classes in a personal or file
geodatabase and copies only the polygon feature classes to a new file
geodatabase. You can assume there are no feature datasets in the existing
data, and the feature classes can keep the same name.
Tags (2)
0 Kudos
2 Replies
NeilAyres
MVP Alum
0 Kudos
XanderBakker
Esri Esteemed Contributor
'Challenge' 1:
import arcpy
arcpy.env.workspace = r'C:\Project\999999\myFGDB.gdb'  # example FileGeodatabase as workspace
arcpy.env.workspace = r'C:\Project\999999\mySHPfolder'  # example folder (with shapefiles) as workspace
fclasses = arcpy.ListFeatureClasses()

for fclass in fclasses:
    fctype = arcpy.Describe(fclass).shapeType
    print "{0} is a {1} feature class".format(fclass, fctype)



'Challenge' 2:
import arcpy, os
arcpy.env.workspace = r'C:\Project\999999\mySHPfolder'
fclasses = arcpy.ListFeatureClasses()

out_ws_all = r'C:\Project\999999\test_all.gdb'
out_ws_pol = r'C:\Project\999999\test_pol.gdb'

for fclass in fclasses:
    fctype = arcpy.Describe(fclass).shapeType
    newname = fclass
    if newname[-4:].upper() == ".SHP":
        newname = newname[:-4] # trim the .shp extension from the name
    out_fc = os.path.join(out_ws_all, fclass)
    arcpy.CopyFeatures_management(fclass, out_fc)
    if fctype == 'Polygon':
        out_fc = os.path.join(out_ws_pol, fclass)
        arcpy.CopyFeatures_management(fclass, out_fc)



Kind regards,

Xander
0 Kudos