0

I'm trying to turn a PNG that looks like this to a shapefile with polygons that keep the categories marked by the colors on the map.

enter image description here

I have several maps to process, so manually tracing the polygons is not a valid option.

I tried to do this with arcpy.RasterToPolygon, from here :

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.RasterToPolygon_conversion("zone", "c:/output/zones.shp", "NO_SIMPLIFY",
                                  "VALUE")

In this case "zone" is the input PNG, this layer is already georeferenced to its actual location. zones.shp is the filename where I want to store the new features.

I get the following error:

Runtime error  Traceback (most recent call last):   
File "<string>", line 5, in <module>   
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\conversion.py", line 337, in RasterToPolygon     
raise e ExecuteError: ERROR 010151: No features found in c:\gis\output\control_test.shp. 
Possible empty feature class. Failed to execute (RasterToPolygon).

Is it possible to fix this error or to use another function to get to my goal?

I have the original PNG as an SVG with vector drawn polygons if that helps.

  • Can you provide more details about your inputs and/or provide a code snippet? – GeoSharp Dec 2 '16 at 18:10
  • @GeoSharp sure, I made edits to the question to have more context on the inputs – buzoherbert Dec 2 '16 at 19:10
  • It would be more helpful if you showed your code rather than copying the snippet from the documentation... – GeoSharp Dec 2 '16 at 19:15
  • @GeoSharp I literally used the same code as the snippet, I don't know what other changes I can do to it to make it work – buzoherbert Dec 2 '16 at 19:29
  • @Paul Thanks! How can I execute the tool from desktop? If I only use the PNG, how will I be able to add the georeferencing to it? – buzoherbert Dec 2 '16 at 20:22
1

I just downloaded your image (no coordinates of course) and ran the following:

arcpy.RasterToPolygon_conversion("C:/temp/2baAg.png","in_memory/poly","NO_SIMPLIFY","Value")

Note the file extension on the image is required.

And here's the output: enter image description here

  • Thank you! I have the shapes now in ArcGIS, but the conversion didn't take into account the cloropeth categories on the original PNG. Is there a way to consider this? – buzoherbert Dec 2 '16 at 21:58

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.