Script for creating KMZ files from features in shapefile

4104
9
Jump to solution
07-07-2016 05:55 PM
MarleneSanchez
New Contributor

Can someone please throw me a code sample to iterate through features in a Shapefile and export each as a KMZ?

I've been able go through a list of Shapefiles in a Data Frame and convert those to KMZs but cant get the syntax right to go through the individual features of a Shapefile and convert those to KMZs.

Thank you!

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

ahhh you want a search cursor (see code examples) to get the shapes prior to making them a temporary layer, then out to kml

SearchCursor—Help | ArcGIS for Desktop

View solution in original post

9 Replies
DanPatterson_Retired
MVP Emeritus

so this is the tool you are using Layer To KML—Help | ArcGIS for Desktop  currently?

What code do you have since you will need to create a layer file for each feature or convert the kmz to kmls... can't remember but this is in my bookmarks

convert *.kmz to *.kml

0 Kudos
MarleneSanchez
New Contributor

I wasn't able to find a way to list the features in the Shapefile like you can list the Shapefiles in the Data Frame.

Taking the important parts from a larger script:

import arcpy

from arcpy import env

import os

activeoutputfolder= "C:\\Users"

mxd=arcpy.mapping.MapDocument("CURRENT")   # The active Arcmap file

df= arcpy.mapping.ListDataFrames(mxd,"")[0] # "Layers"

lyr=arcpy.mapping.ListLayers(mxd,"",df)[0] # first thing in "Layers"

#------kmz export part

for x in range (0,3):

    namea= arcpy.mapping.ListLayers(mxd,"",df).name

    outputfile= str(activeoutputfolder)+"\\"+str(namea)+".kmz"

    inputa= arcpy.mapping.ListLayers(mxd,"",df)

    arcpy.LayerToKML_conversion(str(inputa), str(outputfile), "0", "false", "DEFAULT", "1024", "96", "CLAMPED_TO_GROUND")  

0 Kudos
DanPatterson_Retired
MVP Emeritus

ahhh you want a search cursor (see code examples) to get the shapes prior to making them a temporary layer, then out to kml

SearchCursor—Help | ArcGIS for Desktop

RavendraSingh
New Contributor II

Please check my software Lidar viewer 1.0 free version . it will convert POI into kml file. After providing correct geodetic information.

LINK--  LidarViewer

RebeccaStrauch__GISP
MVP Emeritus

Ravendra....getting a 403 error when trying to download. 

0 Kudos
RavendraSingh
New Contributor II

hello Rebecca,

in my computer it is easily downloadable. please try again on this link.

http://docs.google.com/uc?export=download&id=0B8sX5C0TZa-GeEJiSHY0TWZUUW8

hope it is working.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

not for me, but maybe it's blocked on my network

0 Kudos
RavendraSingh
New Contributor II

hello ,

sorry its my fault . it did not activate the link in google drive. now link is ok.

http://docs.google.com/uc?export=download&id=0B8sX5C0TZa-GeEJiSHY0TWZUUW8

please try it. and thanks for downloading.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

download worked now.

0 Kudos