4

I am using ArcGIS Desktop 10 and Python 2.6.5.

i have created a "test.lyr" file, now i want to convert it either to shape file or raster file. i have created the "test.lyr" from "test0.tif" and added symbology from "test0.lyr" files as follows.

 arcpy.MakeRasterLayer_management(tifFile,tmpFile,"#","","#")
 arcpy.SaveToLayerFile_management(tmpFile,curFile)
 arcpy.ApplySymbologyFromLayer_management(curFile,symbologyLayer)

the curFile in the above code is the test.lyr file obtained.

Can anyone show how to convert it to "test1.shp" or "test1.tif" file using arcpy?

2 Answers 2

3

You can use the Feature Class to Shapefile geoprocessing tool to convert a lyr to a shp (see code example below).

BASEMAP_LOADER_Counties_lyr = "C:\\Temp\\BASEMAP.LOADER.Counties.lyr"
Temp__2_ = "C:\\Temp"

# Process: Feature Class To Shapefile (multiple)...
gp.FeatureClassToShapefile_conversion("C:\\Temp\\BASEMAP.LOADER.Counties.lyr", Temp__2_)

And you can use the Feature to Raster tool to convert a lyr to raster (see code sample below).

Feature_2_tif = "C:\\Temp\\Feature_2.tif"
BASEMAP_LOADER_Counties_lyr__2_ = "C:\\Temp\\BASEMAP.LOADER.Counties.lyr"

# Process: Feature to Raster...
gp.FeatureToRaster_conversion(BASEMAP_LOADER_Counties_lyr__2_, "OBJECTID", Feature_2_tif, "4832.40368")
5
  • hi both arcpy.FeatureClassToShapefile_conversion and arcpy.FeatureToRaster_conversion did not work...
    – thm
    Aug 1, 2011 at 12:10
  • in most of the cases it says: The value is not a Feature Layer. i opened my a.lyr file with arcmap 10, it shows everything fine...
    – thm
    Aug 1, 2011 at 12:21
  • for the shapefile conversion exactly it says the following: ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Feature Layer. Failed to execute (FeatureClassToShapefile).
    – thm
    Aug 1, 2011 at 12:24
  • @thm, My two examples were from using ArcGIS 9.3.1. What happens if you try another different lyr using both tools, same error?
    – artwork21
    Aug 1, 2011 at 14:49
  • The OPs input data is not a featureclass layer, it's raster layer - i have created the "test.lyr" from "test0.tif"
    – user2856
    Sep 24, 2020 at 23:43
0

I converted a polygon KML to a layer by KMLtoLayer in ArcGIS 10.5... I only could convert this layer to shp by the following procedure:

# Final shp path (Example)
shape_path = r'E:\40\00_SOL_PONTUAIS\20200922_Rangel_Consalter_REGULADOR\SHP\teste.shp'

# setting workspace
arcpy.env.workspace = r'D:\' # folder where u saved your layer

# Converting to shapefile
arcpy.FeatureToPolygon_management(r'LAYER_NAME\Polygons',
                                  shape_path, '#', 'ATTRIBUTES', '#')
### OBS --> replace 'LAYER_NAME' be the name of your layer name

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.