branched from https://community.esri.com/thread/207867-how-to-automate-selection-and-kml-conversion
Hi,
I need to do something similar but for areas.
However I have arcmap10.0 and I cannot get this script to work.
Could you please assist me.
I need to select multiple attributes that have the same name in the AA_area field and export them as a Kmz. I then need it to choose the next area and repeat.
EG. Alexandia is in the attribute table 10 times under AA_area and I would like it to export all 10 polygons into one kmz (this is a shapefile in need to convert from). I need to do this for all the different areas in the AA_area field.
Thank you for your help.
I just did a test run and it returned an error on the where clause and I noticed that I already had accounted for different types of input featureclasses. So the original where clause is the correct one:
where ="{0} = '{1}'".format(fld, trail_name)
It will generate 48 KMZ files:
If for some reason the problems persist, I can upload the generated KMZ files.
Hi,
Could you post the script again please.
Thank you so much for your help
Sure:
def main():
import arcpy
import os
arcpy.env.overwriteOutput = True
# settings: edit these
fc_in = r'C:\Users\Danuta\Desktop\CSS 2016-17\TEST\Agri\Agri_EC_working_data.shp'
fld_trail = 'AA_area'
out_folder = r'C:\Users\Danuta\Desktop\CSS 2016-17\TEST'
## fc_in = r'C:\GeoNet\ExportKMZ\Agri_EC_working_data.shp'
## fld_trail = 'AA_area'
## out_folder = r'C:\GeoNet\ExportKMZ\KMZ'
# create list of unique trail names
lst_trails = []
cursor = arcpy.SearchCursor(fc_in)
for row in cursor:
lst_trails.append(row.getValue(fld_trail))
del cursor
del row
lst_trails = list(set(lst_trails))
# loop through trails
for trail_name in lst_trails:
fld = arcpy.AddFieldDelimiters(fc_in, fld_trail)
where ="{0} = '{1}'".format(fld, trail_name)
print where
arcpy.MakeFeatureLayer_management(fc_in, "lyr", where)
kmz_file = os.path.join(out_folder, "{0}.kmz".format(trail_name))
print kmz_file
arcpy.LayerToKML_conversion("lyr", kmz_file)
if __name__ == '__main__':
main()
... and I have attached the resulting KMZ files too.
Hi danusha16@gmail.com , did the code work for you?
Hi,
I'm trying to use this script to do a similar task and I am creating KMZs that have ALL files in the original feature class, even though I have the where clause in my script.
I want to create a KMZ for each individual landowner on a set of properties, some landowners having multiple properties. Any suggestions?
Thank you
Morning,
Thanks for the help.
I ran the code, just copy and pasted.
Still got an error.
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000622: Failed to execute (Layer To KML). Parameters are not valid. ERROR 000625: layer_output_scale parameter has no default value.
Thanks for sending the kmz. The reason I need it to work is that I need to do this quite often with different files
Regards
Danuta
Hi Danuta Hodgson , I assume you can't update to a newer version of ArcGIS, right?
Since the code works on my computer using 10,6, there may have been a change in the arrangement of the parameters over versions. What I would like you to do, is to manually set a definition query, like this:
Go to your ArcToolbox and locate the Layer To KML tool and open it.
Select the layer you want to export, define the output file, leave all the other settings untouched and hit "OK":
After the tool has successfully finished the process, open the Results window:
In the Results windows find the process you just executed, right click on it and copy the python snippet:
In my case it looks something like this:
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "Agri_EC_working_data", "test_pol"
arcpy.LayerToKML_conversion(layer="Agri_EC_working_data", out_kmz_file="C:/GeoNet/ExportKMZ/Alexandria.kmz", layer_output_scale="0", is_composite="NO_COMPOSITE", boundary_box_extent="test_pol", image_size="1024", dpi_of_client="96", ignore_zvalue="CLAMPED_TO_GROUND")
Can you copy this in the thread, so I can see if there is something different with the definition of the parameters? If so, I can adapt the code correspondingly.
If not, then you should try again in a new session of ArcMap without any environment settings set to see if that works. If not, then there will be little I can do, then to urge you to upgrade, since 10.0 is no longer supported.(it was retired on Jan 1, 2016 see Esri Support 10.0 )