# making a mask with arcmap 10

I have a grid layer and a shapefile representing a closed boundary. I need to make a new grid as big as my current grid but with values equal 1 inside the closed boundary shapefile and -999 for grids outside the closed boundary. Would any body help me with this using arcmap 10?

Thanks a lot.

-

If the shapefile is of polygon type, the procedure is simple because its need was anticipated by the GIS designers:

• Set the analysis environment parameters to match those of the current grid.

• Convert the shapefile to a grid. This gives every cell within the polygon(s) some numerical value and every cell outside the polygon(s) has a NoData value.

• Recalculate the values. There are many ways; one of the simplest is to check whether the cells are NoData or not:

``````Con(IsNull("My grid"), -999, 1)
``````

(This is a "map algebra" command that can be issued in the Raster Calculator, in a tool, or within a Python wrapper.)

If the shapefile is of polyline type--which, from the description, it may be--then you need to convert it to polygon type. I believe an ArcInfo license may come with a tool for that conversion, but I also believe the base ArcMap product does not enable that tool. Nevertheless, the conversion to polygon can be accomplished with map algebra. Begin as before by setting the analysis environment and converting the shapefile to a grid. Now, the grid has numerical values only along the polyline: that is, along the polygon's boundary. To identify the interior,

• Convert all NoData values to numeric values. Here, I chose 0:

``````Con(IsNull("My grid"), 0, 1)
``````
• RegionGroup the result. This identifies the inside(s) of the polygon(s), their boundaries, and the common exterior. Call this grid "RG", say.

• Note the identifier assigned to the common exterior by RegionGroup. As in the first solution, convert its values to -999 and all other values to 1. For instance, if the identifier of the exterior is 53, use

``````Con([RG]==53, -999, 1)
``````

It's a little disconcerting to involve a manual operation in what ought to be an automated workflow. However, a general solution requires some kind of user intervention, because the exterior of a closed polyline relative to a given grid extent is, in general, not uniquely defined. All we know is that the closed polygon divides that extent into two or more components, one of which we will elect to call its exterior. For example, this is a picture of a grid formed from a closed polyline feature. However, the grid's extent did not fully cover the extent of the feature:

Where is the exterior of this polygon? If you're having trouble telling, what do you think are the prospects that we could program an algorithm to find the exterior?

Here is a fuller picture of the situation. It reveals that the polyline is indeed the boundary of a multi-polygon feature.

The gray square shows the grid extent.

-

I'm going to expand on tharen's answer, only because there isn't an accepted answer yet and maybe you are looking for a little more detail. The polygon to raster tool is the way I would approach this using the Arc gui: Edit a copy of your bounding shapefile to include a second polygon that covers the extent of the area outside of your boundary for which you may want to see NoData values (-999). Add an attribute to this shapefile which will be the new raster cell value (Ex. "Raster_ID" = "1" for your original boundary, and "-999" for the outer polygon. Use the polygon to raster tool to convert this to a new raster using the new "Raster_ID" field for your cell values. Pay attention to the other variables as tharen indicates. This should give you your desired output.

-

By grid do you mean raster? If so I would suggest the polygon to raster tool. Be sure to set the cell size and snap raster environment variables. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Polygon_to_Raster/001200000030000000/

If by grid you mean a vector feature class of square polygons then use a spatial join or intersect overlay.

-

OK, I would do this in python. Obviously your grid can be looped through, so set up an array representing your grid, and loop through it, checking if the centre of the grid is, or its 4 corners are, within the area of the polygon, add -999 or 1 appropriately.

It should be quite simple. I do this with a netCDF grid, but the premise is the same.

-