I am a user of ArcGIS Pro. I am trying to convert a polygon shapefile into a raster dataset, then export a raster dataset to a PNG format via arcpy.RasterToOtherFormat_conversion.

From .shp to .tif

arcpy.PolygonToRaster_conversion("SingleArea.shp", "NAME", 
                             "MAXIMUM_AREA", cellsize = 0.25)   

from .tif to .png

                                 r"C:\Users\Documents\ArcGIS\Projects\Image", "PNG")

This is the area corresponding to the raster

enter image description here

This is the exported .png file.

enter image description here

It is only including the boundary and no any map features displayed along with it.

How can I get the imagery from the raster like a clipping from the map?

I tried to use extract by mask and code as below:

outExtractByMask = ExtractByMask(r"C:\Users\Documents\ArcGIS\Projects\Image\SingleArea.tif", \

Then saved the outraster into a new .tif and then export the new .tif into .png


The output is still the black image. Looks like it didn't include the basemap when exporting.

  • 3
    Raster to polygon does just what you see, if you want to export the map you will need to use arcpy.mp pro.arcgis.com/en/pro-app/arcpy/mapping/… to export to raster. Alternately if you want only to clip your ortho to your polygon you could use Extract by Mask (spatial analyst required). – Michael Stimson Dec 2 '18 at 23:21
  • @MichaelStimson thank you and if using arcpy.mp, the only way I can export a image from map is to make it into a layout or mapSeries but this could not be done by Python arcpy. Thanks for mentioning Extract by Mask. But when saving my raster dataset, I encountered an error that the raster dataset could not be saved under that folder with output format GRID. – LUSAQX Dec 2 '18 at 23:43
  • 1
    Try the raster "Clip" or "Extract by Mask" tools. I suggest outputting a TIF file rather than GRID. – Luke Dec 2 '18 at 23:49
  • @Luke Yep, I have sort out the troubleshooting but Extract_by_Mask in arcpy just help me to use .shp to define the boundary of the inraster and output a outraster. It does not change the black area appearance any. I will try Clip functions in arcpy – LUSAQX Dec 2 '18 at 23:52
  • Extract by Mask uses the extension, you have not supplied an extension so it assumes GRID which has very strict rules about naming and folder placement, Exract by Mask and provide extension for your output raster (.tif would work as @Luke said). Input your ortho, extract features is your shapefile and output full path to your output image with .tif extension. – Michael Stimson Dec 3 '18 at 0:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.