lundi 29 juin 2015

Would anyone be willint to critique my unfinished script? [on hold]


I am working on a script that selects different amenities that fall into a country boundary and export into their own feature class. I have print statement just for error checking and plan to remove them once the script works. I also have to put in a loop for the amenities, but have not figured that out yet.

import arcpy
arcpy.env.overwriteOutput = True
# Set up country and amenity to examine.
amenity = ['school', 'hospital', 'place of worship']
country = 'El Salvador'

# Set up paths to the datasets I want to use.
countries = r"C:\WCGIS\Geog485\Lesson3\Project 3\CentralAmerica.shp"
points = r"C:\WCGIS\Geog485\Lesson3\Project 3\OSMpoints.shp"

# Set up the workspace where I want to save output.
arcpy.env.workspace = r"C:\WCGIS\Geog485\Lesson3\Project 3"

# Create a feature layer of the country I want to work with.
try:
    countrySelection = '"NAME" ='+"'"+ country + "'"
    arcpy.MakeFeatureLayer_management(countries, 'country',      countrySelection)

except:
    print ("An error occurred one")

# Create feature layers of  the amenities.
try:
    amenitySelection = '"amenity" ='+"'" + amenity +"'"
    arcpy.MakeFeatureLayer_management(points, 'schoolpoints',  amenitySelection)
    for amenity in amenity:
        ## Not sure how to do this.
    except:
    print ("An error occured two")

# Select the amenity of interest within the country.
try:
    arcpy.SelectLayerByLocation_management('schoolpoints', "WITHIN", 'country')

except:
    print ("An error occured three")
    # Create an output path preping to run the Copy Features.
outputFile = amenity + ".shp"
arcpy.CopyFeatures_management('schoolpoints', outputFile)

# Add a new field labeled "Source", populate the field with "OpenStreetMap".
arcpy.AddField_management(points, "Source", "TEXT", field_length =15)

with arcpy.da.UpdateCursor(points, ("Source",)) as cursor:
    row[0] = "OpenStreetMap"

# Delete feature classes no longer needed.
arcpy.Delete_management("countries")
arcpy.Delete_management("points")


Aucun commentaire:

Enregistrer un commentaire