Hey,
I'm trying to build a tool using model builder that I can use to input an Excel spreadsheet and create a shapefile and a KML that saves in the same folder and has the same file name. I want the KML file to automatically default to whatever my output is for the shapefile but i think I am going to have to use python to figure out this last part. I'm really new to this and just now learning writing script.
Can someone help me with the last portion of this script? I would really appreciate it.
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# ExcelToShpPlusKML.py
# Created on: 2015-08-13 20:50:17.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: ExcelToShpPlusKML <Input_Address_Locator> <Input_Table> <Output_Feature_Class>
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Script arguments
Input_Address_Locator = arcpy.GetParameterAsText(0)
Input_Table = arcpy.GetParameterAsText(1)
Output_Feature_Class = arcpy.GetParameterAsText(2)
# Local variables:
Output_Table__2_ = Output_Feature_Class
Output_Table = Output_Table__2_
Output_Layer = Output_Table
Output_File = Output_Layer
# Process: Geocode Addresses
arcpy.GeocodeAddresses_geocoding(Input_Table, Input_Address_Locator, "", Output_Feature_Class, "STATIC")
# Process: Delete Field
arcpy.DeleteField_management(Output_Feature_Class, "")
# Process: Delete Rows
arcpy.DeleteRows_management(Output_Table__2_)
# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Output_Feature_Class, Output_Layer, "", "", "")
# Process: Layer To KML
arcpy.LayerToKML_conversion(Output_Layer, Output_File, "0", "false", "DEFAULT", "1024", "96", "CLAMPED_TO_GROUND")
Looking at your logic it appears that you're doing the following
Could you explain why you're emptying the geocoded table? I'm guessing that some logic is missing and you're probably needing to delete certain rows that you don't need in the output table. I have pasted some logic below that should help you move forward with your task if you're still needing to do so, but I removed the logic you had in the middle because I don't fully understand what your business requirements are.
import arcpy from os import path arcpy.env.overwriteOutput = True locator = arcpy.GetParameterAsText(0) addrTable = arcpy.GetParameterAsText(1) out_class = arcpy.GetParameterAsText(2) ''' STEP ONE : Create your shapefile ''' # Geocode the table of addresses you've provided with your chosen locator locations = arcpy.geocoding.GeocodeAddresses(table, locator, "", out_class) ''' STEP TWO : Create your kml file next to your shapefile ''' # Create a layer object from your shapefile alias = path.basename(out_class).split(".")[0] layer = arcpy.management.MakeFeatureLayer(locations, '{0} Layer'.format(alias)).getOutput(0) # Create the kml file arcpy.conversion.LayerToKML(layer, out_class.replace(".shp", ".kmz"),0, False, "DEFAULT", 1024, 96, "CLAMPED_TO_GROUND") def userWorkflow(locator, table, out_class): # create your shapefile arcpy.geocoding.GeocodeAddresses(table, locator, "", out_class)
# Local variables: Output_Table__2_ = Output_Feature_Class Output_Table = Output_Table__2_ Output_Layer = Output_Table Output_File = Output_Layer
^ this makes 4 copies of Output_Feature_Class. I'm guessing that's not what you're going for.
Can you post an error message or more explanation as to what exactly is going wrong?