Need help refining a script, need to be able to accept user input layers

404
2
08-21-2013 09:54 AM
StephenBugge
New Contributor
Can anyone help me refine a Python Script? I'm developing a tool to generate a simulated list of Applications to a city for Cannabis Facilities authorized under Initiative 502 so that city planning staff have a chance to test application procedures before live applications start coming in.

So far I have a working model using fixed files and drive locations, however I'm having some difficulty getting it to work when using user defined parameters.

(Data I am using to test is from a class project we did for the City of Mukilteo)

The code so far:
# Title: I-502 Cannabis Facility application simulator
# Purpose: To generate a batch of Hypothetical I-502 Applications to allow agencies to test procedures
# Author: Steve Bugge 
# Required Licenses: 3D Analyst or Spatial Analyst, ARCGIS for Desktop 10.1 Advanced recommended

# Import arcpy module
import arcpy
import os
import random
from arcpy import env
from arcpy.sa import *
arcpy.CheckExtension("Spatial")

# Local variables:

Workspace = arcpy.GetParameterAsText(0)
CityLimits = arcpy.GetParamterAsText(1)
Points = arcpy.GetParameterAsText(2)
Parcels = "MukilteoAreaParcelsCurrentAPR2013"
StatCombinedExclusionZones = "StatCombinedExclusionZones"
EligibleZones = "EligibleZones"
RandomPoints = "F:\\GISPython\\I-502ApplicationSimulatorProject\\502Workspace.gdb\\RandomPoints"
MukilteoAreaParcelsCurrentAPR2013__2_ = "MukilteoAreaParcelsCurrentAPR2013"
ApplyingParcels = "F:\\GISPython\\I-502ApplicationSimulatorProject\\502Workspace.gdb\\ApplyingParcels"
ApplicationParcels = "F:\\GISPython\\I-502ApplicationSimulatorProject\\502Workspace.gdb\\ApplicationParcels"
EligibleApplications = "F:\\GISPython\\I-502ApplicationSimulatorProject\\502Workspace.gdb\\EligibleApplications"

# Process: Create Random Points
arcpy.CreateRandomPoints_management(Workspace, "RandomPoints", CityLimits, "", Points, "0 Feet", "POINT", "0")

# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(Parcels, "CONTAINS", RandomPoints, "", "NEW_SELECTION")

# Process: Copy Features
arcpy.CopyFeatures_management(MukilteoAreaParcelsCurrentAPR2013__2_, ApplyingParcels, "", "0", "0", "0")

# Process: Erase
arcpy.Erase_analysis(MukilteoAreaParcelsCurrentAPR2013__2_, StatCombinedExclusionZones, ApplicationParcels, "")

# Process: Intersect
arcpy.Intersect_analysis("EligibleZones #;F:\\GISPython\\I-502ApplicationSimulatorProject\\502Workspace.gdb\\ApplicationParcels #", EligibleApplications, "ALL", "", "INPUT")


Once I get the the script to accept parameters supplied by the user I would also like to add and populate some fields with simulated data (application date, facility type, applicant name) to the final table.  I have ideas but would love suggestions.
Tags (2)
0 Kudos
2 Replies
TimDonoyou
Occasional Contributor
Hi there,

in the code you need to get the parameter as text:

parameter1 = arcpy.GetParameterAsText(n) ## n is the position of the parameter in the list defined below starting at 0

then you add the script to ArcToolbox...

http://resources.arcgis.com/en/help/main/10.1/index.html#/Adding_a_script_tool/00150000001r000000/

hope this helps

cheers

Tim
0 Kudos
StephenBugge
New Contributor
Tim,

Syntax help is great, I was starting to go that way myself it is nice to have confirmation.  I'll update and try it out and update on how it goes.

Thanks!
0 Kudos