Pretty new at working with python and am Stuck...I have a "for" Loop that looks in a folder and, based on a criteria (Homes valued over 500k), creates .kmz's with symbology for each of the .shp files in the folder. The script effectively creates the layers based on criteria and applies symbology. However I need help carrying the Name (fNAME) into the kmz's. Can anyone help me complete this script?


Script: ~~~~~~~~~~~~~~~~~

import arcpy

from arcpy import env

# Variables
env.workspace = r"C:\Work\TEST\HOMES"

fcs = arcpy.ListFeatureClasses("D*", "Point")



for fc in fcs:

    fNAME = arcpy.Describe(fc).basename+"_Green"
    arcpy.MakeFeatureLayer_management(fc,fNAME,"\"PRICE\" > 500000","","")    
    arcpy.LayerToKML_conversion(fNAME, ????.kmz, "12000", "false", "DEFAULT", "1024", "96", "CLAMPED_TO_GROUND")


  • Can you not just go arcpy.LayerToKML_conversion(fNAME, str(fNAME) + ".kmz", "12000", ...... – dklassen Jan 29 '14 at 16:55
  • str(fNAME)+".kmz worked great!!!....can you tell me how to send this output to its own folder. Right now its sending it to the same folder as the shapefile (env.workspace)..I'd like to send it to a folder called KMZ. Thanks! – Matthew Jan 29 '14 at 17:19

You can do the following to name the kmz file and place it in the folder you want:

arcpy.LayerToKML_conversion(fNAME, "c:\\temp\\" + str(fNAME) + ".kmz", "12000", .....

or in the env.workspace but a new subfoler - if it exists:

arcpy.LayerToKML_conversion(fNAME, "KMZ\\" + str(fNAME) + ".kmz", "12000", .....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.