I need to make a python toolbox that takes a Lat, Long, buffer distance and returns a list of addresses. I'm getting hung up on the spatial reference right now. The buffer is created, but has no SR... hmmm... what am I doing wrong here?
import arcpy
import os
WKID = 4326 # WGS-1984
sr = arcpy.SpatialReference()
sr.factoryCode = WKID
sr.create()
arcpy.env.outputCoordinateSystem = sr
class Toolbox(object):
def __init__(self):
self.label = "Get Nearby Addresses"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [GetNearbyAddresses]
class GetNearbyAddresses(object):
def __init__(self):
self.label = "Get Nearby Addresses"
self.description = "Get Nearby Addresses within a buffer."
self.canRunInBackground = False
def getParameterInfo(self):
params = []
param0 = arcpy.Parameter(
displayName = "Latitude",
name = "lat",
datatype = "Long",
parameterType = "Required",
direction = "Input")
params.append(param0)
param1 = arcpy.Parameter(
displayName = "Longitude",
name = "lon",
datatype = "Long",
parameterType = "Required",
direction = "Input")
params.append(param1)
param2 = arcpy.Parameter(
displayName = "Buffer Distance",
name = "distance",
datatype = "Long",
parameterType = "Required",
direction = "Input")
params.append(param2)
param3 = arcpy.Parameter(
displayName = "Address List",
name = "addresses",
datatype = "GPString",
parameterType = "Derived",
direction = "Output")
params.append(param3)
return params
def execute(self, parameters, messages):
try:
arcpy.env.workspace = r'E:\gis\default.gdb'
arcpy.env.overwriteOutput = True
lat = parameters[0].valueAsText
lon = parameters[1].valueAsText
distance = parameters[2].valueAsText
inpoint = arcpy.Point(X=lon, Y=lat)
ptGeometry = arcpy.PointGeometry(inpoint)
arcpy.Buffer_analysis(ptGeometry, 'buffer', distance, \
"FULL", "ROUND", "NONE", "")
print 'made the buffer.'
except Exception, ErrorDesc:
sErr = "ERROR:\n" + str(ErrorDesc)
messages.addErrorMessage(sErr)
return