Get a raster composed of 0s and 1s

6948
10
Jump to solution
08-22-2018 08:50 PM
BaranISCEN
New Contributor II

Novice with ArcGis, I would like to convert my Polyline dataset to a Raster with only 0s and 1s

To this end, I used the Gis command "Polyline to Raster" and set the cell size small enough, so that the lines features might be captured.

However, the Raster Attribute table that I got contained only positively coded cells (i.e. those crossed by a line and whose values correspond to the ID of the line.) while I would have liked to get an attribute table with all the cells.

Thus, I thought about using the "Raster calculator" tool and the following command : Con(IsNull(raster), 0, 1). Unfortunately, this didn't work. I got a Raster with an attribute table containing 0 and 1 admittedly, but with only two values now.

Thus, I would like to ask for your help in order to be able to get a Raster with an Attribute table containing all the cells, coded as follows: 0 when no line crosses the cell, and 1 otherwise.

Thanks a lot,

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

When you did Polyline to raster, what field did you use for the classification? the OBJECTID field? some other field?

Polyline to Raster—Conversion toolbox | ArcGIS Desktop 

From there...

The input field type determines the type of output raster. If the field is integer, the output raster will be integer; if it is floating point, the output will be floating point.

If the input field contains string values, the output raster will contain an integer value field and a string field.

That raster can then be used in the Con tool to produce your indicator grid (ie 0s and 1s).

No other information from the first raster is brought over.

You should be using data in a projected coordinate system if you are expecting a raster with planar units (ie feet, meters).

Perhaps you can provide information on the raster extent, the cell size and other relevant steps that you took and maybe a screen grab of the resultant.  Do be aware that the raster may have a degraded appearance when viewed at full extent if you chose a small cell size relative to the screen resolution.  Gaps in the raster continuity or double cell widths/heights will result on occasion due to the cell size chosen.

View solution in original post

10 Replies
NeilAyres
MVP Alum

Sorry, but I don't understand. How is the result of the Con / IsNull calculation not what you want?

You have only 2 values, a bunch of zeros and a bunch of ones???

0 Kudos
DanPatterson_Retired
MVP Emeritus

When you did Polyline to raster, what field did you use for the classification? the OBJECTID field? some other field?

Polyline to Raster—Conversion toolbox | ArcGIS Desktop 

From there...

The input field type determines the type of output raster. If the field is integer, the output raster will be integer; if it is floating point, the output will be floating point.

If the input field contains string values, the output raster will contain an integer value field and a string field.

That raster can then be used in the Con tool to produce your indicator grid (ie 0s and 1s).

No other information from the first raster is brought over.

You should be using data in a projected coordinate system if you are expecting a raster with planar units (ie feet, meters).

Perhaps you can provide information on the raster extent, the cell size and other relevant steps that you took and maybe a screen grab of the resultant.  Do be aware that the raster may have a degraded appearance when viewed at full extent if you chose a small cell size relative to the screen resolution.  Gaps in the raster continuity or double cell widths/heights will result on occasion due to the cell size chosen.

BaranISCEN
New Contributor II

Infinitely many thanks for your answers!

In a few words, I have a dataset of digitized maps with country-borders by century, from 900 to 1900. My goal is to create a measure for each region of "how much the borders change historically".

Thus, I believed that the Raster tool would be a good strategy to this problem. More precisely, I did follow the steps below:

- converting all my digitized polygon maps with country-borders to polyline

- delete the coast-borders, not useful in the analysis

- rasterizing then the polyline dataset, with Polyline to Raster tool using the Object Field for classification.

I thought that I would obtain an attribute table with all the cells (I have chosen a relatively small cell size of 1000 to be able to capture the lines features) coded as follows: either 0 or null when no line crosses and the ID of the line when a line does cross the cell in question.

- However, as described above, I instead did get a Raster's attribute table composed only of cells coded positively. i.e. to my knowledge, those crossed by a line.

- Thus, I tried to rectify this by using the command Con(IsNull(raster), 0, 1) but this time I got only two values in my Attribute Table: 0 and 1.

- Moreover, I tried another strategy which is using the Reclassify tool in Gis. I first checked that the Old and New values were identical, set equal. Then, I set the New Value of No Data to be 0. This time, I got my original (only positively coded) attribute table with only one more 0 cell.

This is not satisfying because at the end of the day I would like to get for each rasterized-century-map an attribute table with the entire and identical cells, whose code depends on whether in the century a line crossed the cell or not.  Lastly, after having set to 0 the null size and 1 the cells greater than 0, I would like to sum all the rasters, to get a certain measure of the stability of the cells (i.e. the number should be high if the cell was stable and always crossed by a line). Before using Zonal Statistics to get an average measure per region.

I hope that this was legible and would be happy to answer to your questions in order to be able to move forward on this problem, as I need it.

A polyline

the polyline rasterized (with objectif ID as classification and 1000 of cell size)the attribute table that I get while using the command con(isnul(raster),0,1) with only two cells

Infinitely many thanks again for your help!!

0 Kudos
AlfonsoYañez_Morillo
New Contributor III

I guess you want to track border changes. I deduced that you have digitized all the maps (900 - 1900) in the same polygon layer. What you need is to have one binary raster for each century map. If you have an attribute that identifies the century, use it to make sequentially selections to create the individual rasters for centuries. Then convert them into a binary raster. The process you followed to create the binary raster is the correct, with the conditional function.

Once you have your 10 binary maps, combine them (Combine function). As a result you will have a raster which attribute table have 10 fields, one for raster. Something like this:

ValueCountYr900Yr1000Yr1900
11000000
2100111
324110
432011
……

Then you can identify cells that never changed (all ones), and cells for the time they change (when pass from 1 to 0 and vice-versa).

BaranISCEN
New Contributor II

Thanks so much !!! That's precisely what I was trying to do from the beginning but I was confused by the Attribute Table of the Raster (and expected to get something like the attribute table of a vector line or polygon). Infinitely many thanks again !!

0 Kudos
BaranISCEN
New Contributor II

Thank you very much for this answer. Actually, that's precisely the point. I don't understand why although I've created one polyline for each of the 10 maps (and successively a raster) I get this weird result and don't manage to get a binary raster

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you have 10 maps with the exact same cell size and the same extent with nothing but 0 and 1 as integers (not floats), then you simply need to use Combine, only if you are interested in the combinations of the years where things changed OR more simply... add them together.  Any cell with a value of 10, means that the border has not changed at that location.  A value of 0 means that a border never traversed the cell.  Everything else in between

If you do this process in an incremental fashion, then you will get a temporal pattern.

For example... add year 1 and year 2... you cells will either be classed as 0, 1 or 2

Now add year 3 to the previously summed raster that will give you 0, 1, 2, or 3... 3 being, border stationary.

Repeat.

When you say you are getting 'weird' results, perhaps you had better explain your expectations and your process.

Are you skipping the incremental procedure?

What do you expect the values to be?

Have you confirmed that the rasters conform to the guidelines in the first line of this thread?

Elaborate on the above points might provide some clarity as to your ongoing issues with this problem

BaranISCEN
New Contributor II

Thanks so much Dan! To be honest, I had this in mind from the beginning and converted all my rasters to binary ones. 

However, I was deeply confused by the Attribute Table of the Raster. i.e with only two values 0 and 1 and the Count. I guess it's because I was thinking in terms of "vector line or polygone" and expected an attribute table with all the cells being coded (which is certainly absurd given the potential very huge amount of data).

Then, to come back to my goal which getting a measure of how borders change historically within region, I simply used Zonal Stats with a current shapefile at the regional level as Zone.

Thank you again and sincerely sorry for the bothering!

0 Kudos
DanPatterson_Retired
MVP Emeritus

Baran... you should move this to the Spatial Analyst s‌ince it has nothing to do with installation

0 Kudos