<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python script for Layer to KML in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-layer-to-kml/m-p/763106#M24836</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;poly_kmz = os.path.join("C:\\Craig\\Working\\07282010\\KML\\", os.path.splitext(os.path.basename(infile))[0] + '.kml')&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Aug 2010 20:28:38 GMT</pubDate>
    <dc:creator>JasonScheirer</dc:creator>
    <dc:date>2010-08-24T20:28:38Z</dc:date>
    <item>
      <title>Python script for Layer to KML</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-layer-to-kml/m-p/763105#M24835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Howdy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've been working on a Python script to convert a bunch of .shp files to .kmz files using gp.MakeFeatureLayer_management, followed by gp.LayerToKML_3d. It's been pretty straighforward and the script only requires a few lines of code. However, I'm getting stuck when it comes to maintaining original filenames. I'd like to have the numbers correspond, i.e. 'poly15.shp' is spatially the same in ArcMap as 'poly15.kmz' is in Google Earth. As of now, the script succeeds in converting the files, however they don't match up.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Windows stores its files in numerical order, i.e. 'poly1, poly2, poly3, etc.' ... however, I see in ArcCatalog that files are listed in the form of 'poly 0, poly 1, poly 10, poly 100, etc.' . Does this have something (everything) to do with it? I decided to use variable 'i' to append each name, as the two geoprocesses ask you to name the file as part of the parameters. I'm using my Python knowledge from college here . . . there's got to be an easy fix that I'm just not wrapping my brain around.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's what I've got:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting, glob&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create the Geoprocessor object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("3D")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Load required toolboxes...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/3D Analyst Tools.tbx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;path = 'C:/Craig/Working/07282010/tiles'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;i = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for infile in glob.glob(os.path.join(path, '*.shp')):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Local variables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_Layer = "poly_Layer" + str(i)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_kmz = "C:\\Craig\\Working\\07282010\\KML\\poly" + str(i) + ".kmz"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tiles = "C:\\Craig\\Working\\07282010\\tiles"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Make Feature Layer...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management(infile, poly_Layer, "", tiles)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Layer To KML...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.LayerToKML_3d(poly_Layer, poly_kmz, "20000", "false", "DEFAULT", "1024", "96")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm assuming I need to get rid of the i variable as well as the str() naming...but how do I get the processes to automatically name the files based on the original file being converted? Right now, 'poly1.shp' is in Tennessee, and 'poly1.kmz' is in New York. It's not as if it's a projection problem, it's just that the loop is converting files in an order that is different from what I'd expect.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;CM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Aug 2010 19:07:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-layer-to-kml/m-p/763105#M24835</guid>
      <dc:creator>CraigMalkmes</dc:creator>
      <dc:date>2010-08-24T19:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python script for Layer to KML</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-layer-to-kml/m-p/763106#M24836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;poly_kmz = os.path.join("C:\\Craig\\Working\\07282010\\KML\\", os.path.splitext(os.path.basename(infile))[0] + '.kml')&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Aug 2010 20:28:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-layer-to-kml/m-p/763106#M24836</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2010-08-24T20:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python script for Layer to KML</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-layer-to-kml/m-p/763107#M24837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jason,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Makes sense... it's iterating correctly now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Much appreciated,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Craig&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Aug 2010 12:39:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-layer-to-kml/m-p/763107#M24837</guid>
      <dc:creator>CraigMalkmes</dc:creator>
      <dc:date>2010-08-25T12:39:46Z</dc:date>
    </item>
  </channel>
</rss>

