Creating a raster based on extent coordinates

09-05-2017 04:44 AM
New Contributor

Hi! I will highly appreciate your help in matter that I am struggling with since few days.  I would like to create a hazard map of selected area. I read that in order to do that, I need to create a raster and assign the values to each cell (and later add colors). I don't want to convert selected polygon to raster because I would like it to be visible when selected ( I would imagine it like showed on image in attachment). The process I started by creating an extent of the polygon in order to define Xmin, Xmax, Ymin and Ymax for future raster (see attachment). Later on I tried to calculate a length of raster sides and its area. I though that thanks to that I will be able to define cell size. Nevertheless when I run a script I receive errors about wrong parameter. I have to say that I am quite a beginner in python and I really don't know what I am doing wrong. I tried to change a code using many examples that I found but still errors occurred. Many thanks in advance for any opinions, suggestions, tips and comments!. 



My code:

class NetButton(object):
    """Implementation for NetButton.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        fc = ExcavationZone
        ExtentOutput="\\\\abc\\home\\xyz\\Documents\\moje dokumenty\\xxx\\arcgis\\ExtentOutput"
        mxd = arcpy.mapping.MapDocument ("CURRENT")
        sr = mxd.activeDataFrame.spatialReference #RD_NEW
        desc = arcpy.Describe(fc)
        extent = desc.extent
        pts = [arcpy.Point(extent.XMin, extent.YMin),
            arcpy.Point(extent.XMax, extent.YMin),
            arcpy.Point(extent.XMax, extent.YMax),
            arcpy.Point(extent.XMin, extent.YMax)]
        #print extent.XMin,extent.YMin,extent.XMax,extent.YMax
        print ("XMax:",extent.XMax,"YMax:",extent.YMax)
        print ("XMin:",extent.XMin,"YMin:",extent.YMin)
        print ("XMax:",extent.XMax,"YMin:",extent.YMin)
        print ("XMax:",extent.XMin,"YMax:",extent.YMax)
        #Create raster: my trial
        #CreateRasterDataset_management (out_path, out_name, {cellsize}, pixel_type, {raster_spatial_reference}, number_of_bands, {config_keyword}, {pyramids}, {tile_size}, {compression}, {pyramid_origin})
        RiskMapRaster="\\\\abc\\home\\xyz\\Documents\\moje dokumenty\\xxx\arcgis\\riskmapraster"
        print  c
        print d
        cellsize= int(c*d)
        print cellsize
        arcpy.CreateRasterDataset_management ("RiskMapRaster", "", "cellsize", "16_BIT_UNSIGNED", "sr", "1", "", "PYRAMIDS -1 NEAREST JPEG", "", "NONE", "")
        print "Done!"
0 Kudos
0 Replies