1

I am trying to transform a kml to shapefile via ArcPy with the following code:

import arcpy # Variables KML to Shapefile: KML = r"C:\Test\Polygons.kml" Output_Location = r"C:\Test" Polygons_lyr = "Polygons_lyr" Polygons_geo = r"C:\Test\Polygons_geo.shp" Polygons_shape = r"C:\Test\Polygons.shp" Polygons_gdb = Output_Location Polygons_lyr = "Polygons_example" Polygon_select = Polygons_gdb # Process: KML_To_Layer arcpy.KMLToLayer_conversion(KML, Output_Location, Polygons_lyr, "NO_GROUNDOVERLAY") # Process: Select_Data arcpy.SelectData_management(Polygons_gdb, "Placemarks\\Polygons") # Process: Select arcpy.Select_analysis(Polygon_select, Polygons_geo, "") # Process: Project arcpy.Project_management(Polygons_geo, Polygons_shape, "PROJCS['WGS_1984_UTM_Zone_19S',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['false_easting',500000.0],PARAMETER['false_northing',10000000.0],PARAMETER['central_meridian',-69.0],PARAMETER['scale_factor',0.9996],PARAMETER['latitude_of_origin',0.0],UNIT['Meter',1.0]]", "", "", "NO_PRESERVE_SHAPE", "") 

When I run it, it performs the gdb and the layer:

enter image description here

But when (it seems) when selecting the file in the GDB, the problem occurs. It gives me the following error:

Traceback (most recent call last): File "c:/Test/KML_to_shapefile.py", line 17, in arcpy.SelectData_management(Polygons_gdb, "Placemarks\Polygons") File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 4310, in SelectData raise e arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000800: The value is not a member of KML_to_shapefile.py | Polygons.kml | Polygons_example.gdb | Polygons_example.lyr. Failed to execute (SelectData).

The error is in line 17, that is in the "arcpy.SelectData_management" function.

How is it possible to fix it?

3
  • What is arcpy.SelectData_management? I do not see that as an arcpy tool. Commented Feb 18, 2022 at 16:54
  • What is it you're doing exactly? Why do you need to select the data that is created? The output creates a feature class you could simply project. Note, per the SelectData help: This tool is intended for use in ModelBuilder and not in Python scripting. Commented Feb 18, 2022 at 17:24
  • There is a select data because I got the geoprocess directly from model builder (MB)(export script). But because of this, I realized that you can't always replicate an MB geoprocess to an arcpy script. Commented Feb 18, 2022 at 23:53

1 Answer 1

3

From your code snippet, I think your task is to convert a KML and reproject it. You do not need to perform any sort of select. Your code can simply be the two geoprocessing tools:

# Process: KML_To_Layer result = arcpy.KMLToLayer_conversion(KML, Output_Location, Polygons_lyr, "NO_GROUNDOVERLAY") GDB_FC = result.getOutput(1) + "\\Placemarks\\Polygons" # Process: Project arcpy.Project_management(GDB_FC, Polygons_shape, "PROJCS['WGS_1984_UTM_Zone_19S',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['false_easting',500000.0],PARAMETER['false_northing',10000000.0],PARAMETER['central_meridian',-69.0],PARAMETER['scale_factor',0.9996],PARAMETER['latitude_of_origin',0.0],UNIT['Meter',1.0]]", "", "", "NO_PRESERVE_SHAPE", "") 

Note the tool, SelectData is a ModelBuilder tool. From the help:

This tool is intended for use in ModelBuilder and not in Python scripting.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.