<?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: Troubleshooting a Polygon to Raster conversion in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43728#M3440</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, want your data to be in projected coordinates rather than geographic, so I would start by reprojecting the original outline shapefile, before buffering, using the Project tool. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# project data&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.Project_management(infc, outfc, outCS)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Help file here: &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000007m000000" title="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000007m000000"&gt;ArcGIS Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Jun 2015 18:20:44 GMT</pubDate>
    <dc:creator>SepheFox</dc:creator>
    <dc:date>2015-06-09T18:20:44Z</dc:date>
    <item>
      <title>Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43725#M3437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been developing my program with just one dataset and I got all the bugs worked out from that one dataset.&amp;nbsp; Now, I am trying it on some other datasets to make sure everything is working as expected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having a problem in the setting-up-the-environments stage of my program.&amp;nbsp; The user inputs a polygon shapefile that contains a polygon representing the parcel outline.&amp;nbsp; This polygon is used to create a mask for future raster calculations.&amp;nbsp; The basic outline of this part of the program is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Buffer the outline polygon by 50 ft&lt;/LI&gt;&lt;LI&gt;Convert the buffered polygon into a raster&lt;/LI&gt;&lt;LI&gt;Set the raster as the mask and the snapraster for the remainder of the program&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An empty raster is created when converting the buffered polygon to a raster.&amp;nbsp; I tried doing it manually in GIS and had the same problem.&amp;nbsp; I added an integer field to my buffered shapefile and converted to a raster based on that integer field (rather than the ID or FID which were both 0.)&amp;nbsp; That didn't fix it.&amp;nbsp; After setting the processing extent to the same extent as my DEM, it worked.&amp;nbsp; I made those changes to my code and it still is not producing the expected results.&amp;nbsp; It's not giving me an error, but it tells me that the raster is empty and then keeps running through my code.&amp;nbsp; I've exhausted my troubleshooting abilities.&amp;nbsp; I also want to repeat: it works when I do it by hand in GIS but it isn't working via code for some reason.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code is printing out the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Preparing necessary files...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Checking for and creating output folders for GIS files...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Checking for and creating output space for tables...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Setting cell size to DEM cell size: 5.0 ft...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Creating an environment mask from the site outline shapefile...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;All cells in grid k:\gradwork\gis\colleg~1\cp\scratch\rastermask have NODATA value. VAT will not be built. (VatBldNew)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code is below. Line 84 is where things are going wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#### _______________IMPORT MODULES_________________###
print("Preparing necessary files...")
import os
import arcpy
import copy


### ______________INPUT FILES___________________###
outline = r"K:\GradWork\GIS\CollegePark\CP_outline.shp"
DA = r"K:\GradWork\GIS\CollegePark\CPDrainage.shp"
DAID = "Id"&amp;nbsp; # field in DA shapefile where unique DA values exist
soil = r"C:\Users\Rachael J\Documents\GradWork\Project Files\BMPGIS\soils\VB_Soils.shp"
WTin = r"K:\GradWork\GIS\CollegePark\CPGW_adj1"
DEMin = r"K:\GradWork\GIS\CollegePark\cpelev"
MapLoc = r"K:\GradWork\GIS\CollegePark\CP.mxd"
WT = arcpy.Raster(WTin)
DEM = arcpy.Raster(DEMin)


### ________________SET ENVIRONMENTS__________________###
# Check out extension and overwrite outputs
arcpy.CheckOutExtension("spatial")
arcpy.env.overwriteOutput = True


# Set Map Document
mxd = arcpy.mapping.MapDocument(MapLoc)


# Create project folder and set workspace
print("Checking for and creating output folders for GIS files...")
WorkPath = MapLoc[:-4]
if not os.path.exists(WorkPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(WorkPath)
arcpy.env.workspace = WorkPath


# Create scratch workspace
ScratchPath = str(WorkPath) + r"\scratch"
if not os.path.exists(ScratchPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(ScratchPath)
arcpy.env.scratchWorkspace = ScratchPath


# Create GDB
path, filename = os.path.split(MapLoc)
GDB = filename[:-4] + ".gdb"
GDBpath = MapLoc[:-4] + ".gdb"
if not os.path.exists(GDBpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFileGDB_management(path, GDB)


# Create output table folder if it does not exist and create project folder
print("Checking for and creating output space for tables...")
TabPath = r"C:\outputtable" "\\"
ProjFolder = TabPath + filename[:-4]
if not os.path.exists(TabPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(TabPath)
if not os.path.exists(ProjFolder):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(ProjFolder)


### _____________SET PROCESSING EXTENTS____________ ###
# Set cell size
description = arcpy.Describe(DEM)
cellsize = description.children[0].meanCellHeight
print("Setting cell size to DEM cell size: " + str(cellsize) + " ft...")
arcpy.env.cellSize = cellsize
arcpy.env.extent = arcpy.Describe(DEM).extent


# Create buffer around outline to use as mask
# Buffer distance is in feet
print("Creating an environment mask from the site outline shapefile...")
maskshp = arcpy.Buffer_analysis(outline, ScratchPath + r"\outline_buff", "50 Feet", "", "", "ALL",)
arcpy.AddField_management(maskshp, "RID", "SHORT")
with arcpy.da.UpdateCursor(maskshp, ["RID"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = 8
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)


# Convert buffer to raster
mask = arcpy.Raster(arcpy.PolygonToRaster_conversion(maskshp, "RID", ScratchPath + r"\rastermask"))
mask.save(ScratchPath + r"\rastermask")


# Set raster mask and snap raster
print("Setting raster mask and snap raster for project...")
arcpy.env.mask = mask
arcpy.env.snapRaster = mask&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp; Changing line 69 to "&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;SPAN style="background-color: #e4e4ff;"&gt;arcpy&lt;/SPAN&gt;.env.extent = DEM.extent&lt;/SPAN&gt;" did not solve the problem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT 2:&amp;nbsp; My files aren't in the same coordinate system!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:40:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43725#M3437</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2021-12-10T21:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43726#M3438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible that your outline shapefile is in a different projection than your DEM?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 17:51:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43726#M3438</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-09T17:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43727#M3439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;:U&amp;nbsp; OH NO!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My DEM is a projected coordinate system (NAD 1983 HARN VA State Plane South) but my buffer is in a GCS, NAD 1983 HARN.&amp;nbsp; How do I resolve this discrepancy in Python?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:12:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43727#M3439</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-06-09T18:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43728#M3440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, want your data to be in projected coordinates rather than geographic, so I would start by reprojecting the original outline shapefile, before buffering, using the Project tool. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# project data&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.Project_management(infc, outfc, outCS)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Help file here: &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000007m000000" title="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000007m000000"&gt;ArcGIS Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:20:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43728#M3440</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-09T18:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43729#M3441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All I had to do was set an output coordinate system and it worked! Yay!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="background-color: #e4e4ff;"&gt;arcpy&lt;/SPAN&gt;.env.outputCoordinateSystem = &lt;SPAN style="background-color: #e4e4ff;"&gt;arcpy&lt;/SPAN&gt;.Describe(DEM).spatialReference&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course, now I'm getting a different error but hopefully it's unrelated to this one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:21:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43729#M3441</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-06-09T18:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43730#M3442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Would it be just as good to set my output CS to the projected system my DEM is in and have GIS take care of the conversion automatically? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:22:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43730#M3442</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-06-09T18:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43731#M3443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you mean the output from buffering? Honestly, you're playing with fire anytime you start with data that is not all in the same projected coordinate system. For instance, your buffers are being created from shapes that are in a different CS, so there could be unexpected results. It's best practice to get everything into the same PCS before you start any geoprocessing, and the Project tool is the only sure way to do that correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:27:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43731#M3443</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-09T18:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43732#M3444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I meant setting my environments so the output CS is the same as my DEM CS, so that the output of any tool results in PCS.&amp;nbsp; But, it probably is better to write a code block that checks projections before the code actually starts.&amp;nbsp; Thanks for the tip!&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:35:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43732#M3444</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-06-09T18:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshooting a Polygon to Raster conversion</title>
      <link>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43733#M3445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, I really would recommend checking and the Projecting anything that is different as the first step. Sometimes there can be subtle effects you may not realize.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:38:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshooting-a-polygon-to-raster-conversion/m-p/43733#M3445</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-09T18:38:20Z</dc:date>
    </item>
  </channel>
</rss>

