[GRASS-user] filling inter-contour area with constant value

Dear All,

We are trying some morphological DEM interpolation algorithm which
requires rasterized contour maps with constant values in intercontour
areas. For example I like to fill the area between 10 and 20 meter,
20-30 meter vector contour lines with 15, 25m as constant value and
save the output as a raster map.

Is there an easy and fast way to do that in GRASS? Filling contour area
using GNUplot [1] and exporting data as an image maybe one option,
but I am wondering if there is another way.

Best

Venka

[1] http://stackoverflow.com/questions/20977368/filled-contour-plot-with-constant-color-between-contour-lines

On 28/04/14 06:07, Venkatesh Raghavan wrote:

Dear All,

We are trying some morphological DEM interpolation algorithm which
requires rasterized contour maps with constant values in intercontour
areas. For example I like to fill the area between 10 and 20 meter,
20-30 meter vector contour lines with 15, 25m as constant value and
save the output as a raster map.

Is there an easy and fast way to do that in GRASS? Filling contour area
using GNUplot [1] and exporting data as an image maybe one option,
but I am wondering if there is another way.

Best

Venka

[1]
http://stackoverflow.com/questions/20977368/filled-contour-plot-with-constant-color-between-contour-lines

This stackoverflow question is about colors, not values. Which are you looking for exactly ?

For values, one option might be playing with r.grow.distance and its value= parameter.

Moritz

On Mon, Apr 28, 2014 at 9:46 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
...

This stackoverflow question is about colors, not values. Which are you
looking for exactly ?

For values, one option might be playing with r.grow.distance and its value=
parameter.

Perhaps of interest:
http://grasswiki.osgeo.org/wiki/Contour_lines_to_DEM

Markus

Hi Moritz,

On 2014/04/28 16:46, Moritz Lennert wrote:

[1]
http://stackoverflow.com/questions/20977368/filled-contour-plot-with-constant-color-between-contour-lines

This stackoverflow question is about colors, not values. Which are you looking for exactly ?

We need a raster map filled with unique values in inter-contour areas.
(would be ok if

For values, one option might be playing with r.grow.distance and its value= parameter.

Moritz
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Hi Moritz and Markus,

On 2014/04/28 16:54, Markus Neteler wrote:

On Mon, Apr 28, 2014 at 9:46 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
...

This stackoverflow question is about colors, not values. Which are you
looking for exactly ?

Need to fill unique values for inter-contour area between each contour interval.
(was thinking of vector color fill and subsequent saving as raster where colors
could be assigned unique category values)

For values, one option might be playing with r.grow.distance and its value=
parameter.

Can you elaborate a bit on how to use r.grow.distance for this
purpose. My input map would be a contour raster map.

Perhaps of interest:
http://grasswiki.osgeo.org/wiki/Contour_lines_to_DEM

Yes, I tried several of the interpolation options, but our data is huge and
interpolation takes a long time (r.surf.contour has been running for several days
now), so we are looking for a simple unique value fill solution that could work
faster.

Best

Venka

On 28/04/14 10:12, Venkatesh Raghavan wrote:

Hi Moritz and Markus,

On 2014/04/28 16:54, Markus Neteler wrote:

On Mon, Apr 28, 2014 at 9:46 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
...

This stackoverflow question is about colors, not values. Which are you
looking for exactly ?

Need to fill unique values for inter-contour area between each contour
interval.
(was thinking of vector color fill and subsequent saving as raster where
colors
could be assigned unique category values)

For values, one option might be playing with r.grow.distance and its
value=
parameter.

Can you elaborate a bit on how to use r.grow.distance for this
purpose. My input map would be a contour raster map.

Using r.grow.distance with the value output option gives you a map where each pixel has the value of the closest non-null pixel. So, if you have 10m, 20m, etc contour values you will get areas of 10m, 20m pixel values centered on the contours. I know that this is not exactly what you were looking for. In order to get from your contours to 5m, 15m, etc areas you would have to probably interpolate your data and then create new contours at those levels, but you alreay said that this is not an option because of the time involved. But maybe the 10m, 20m areas are already close enough to what you are looking for.

Another option would be to go the vector route. Brainstorming:

- transform your raster contours to vector lines (r.to.vect)
- transform those to boundaries (v.type)
- if necessary, add a line at the edge of the region and patch that with your contour lines to close polygons (v.in.region, v.patch)
- add centroids to create areas (v.centroids)
- for each boundary get the category values of areas on each side of the boundary (v.to.db)
- then, through query of the attribute table, get for each area, the average of the contour values surrounding that area

Moritz

[Please keep threads on the list]

On 29/04/14 00:33, John Ciolek wrote:

Hi Moritz.

What do you mean by the following suggestion?

On Apr 28, 2014, at 2:45 AM, Moritz Lennert wrote:

- if necessary, add a line at the edge of the region and patch that
with your contour lines to close polygons (v.in.region, v.patch)

Are you suggesting that you can close a contour (connect the beginning
point to the ending point) using v.in.region or v.patch?

No, not the beginning point to the end point. Either you have closed contours or your contours go over the edge of your current region, meaning that some contours are not closed. So, in order to close them, you can do so arbitrarily at the edge of your region by patching in a line that represents that edge. This line can be created with v.in.region.

Moritz

Venka,

Let’s say you have the elevation field in your shapefile and the contour interval is 2 meters.

Import your shapefile into GRASS

v.in.ogr dsn=contours.shp output=contours type=boundary

Add centroids to the imported boundaries to make areas

v.centroids input=contours output=contourareas

Convert the contour areas to raster filling inter-contour areas with contour elevations

v.to.rast input=contourareas output=contourareas use=attr attrcolumn=elevation

Now you want to add a half of the contour interval to get what you want

r.mapcalc expression=“contoursteps=contourareas+1”

contoursteps is what you need, I think.

Regards,
Huidae

···

On Tue, Apr 29, 2014 at 4:19 AM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

[Please keep threads on the list]

On 29/04/14 00:33, John Ciolek wrote:

Hi Moritz.

What do you mean by the following suggestion?

On Apr 28, 2014, at 2:45 AM, Moritz Lennert wrote:

  • if necessary, add a line at the edge of the region and patch that
    with your contour lines to close polygons (v.in.region, v.patch)

Are you suggesting that you can close a contour (connect the beginning
point to the ending point) using v.in.region or v.patch?

No, not the beginning point to the end point. Either you have closed contours or your contours go over the edge of your current region, meaning that some contours are not closed. So, in order to close them, you can do so arbitrarily at the edge of your region by patching in a line that represents that edge. This line can be created with v.in.region.

Moritz


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Ah… if you have two adjacent contour lines that are farther than the contour interval from each other, my method doesn’t work. For example, 100, 102, and 106 will become 101, 103, and 107, not 101, 104, and 107 (what should the max value be?).

···

Huidae

On Wed, Apr 30, 2014 at 2:50 PM, Huidae Cho <grass4u@gmail.com> wrote:

Venka,

Let’s say you have the elevation field in your shapefile and the contour interval is 2 meters.

Import your shapefile into GRASS

v.in.ogr dsn=contours.shp output=contours type=boundary

Add centroids to the imported boundaries to make areas

v.centroids input=contours output=contourareas

Convert the contour areas to raster filling inter-contour areas with contour elevations

v.to.rast input=contourareas output=contourareas use=attr attrcolumn=elevation

Now you want to add a half of the contour interval to get what you want

r.mapcalc expression=“contoursteps=contourareas+1”

contoursteps is what you need, I think.

Regards,
Huidae

On Tue, Apr 29, 2014 at 4:19 AM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

[Please keep threads on the list]

On 29/04/14 00:33, John Ciolek wrote:

Hi Moritz.

What do you mean by the following suggestion?

On Apr 28, 2014, at 2:45 AM, Moritz Lennert wrote:

  • if necessary, add a line at the edge of the region and patch that
    with your contour lines to close polygons (v.in.region, v.patch)

Are you suggesting that you can close a contour (connect the beginning
point to the ending point) using v.in.region or v.patch?

No, not the beginning point to the end point. Either you have closed contours or your contours go over the edge of your current region, meaning that some contours are not closed. So, in order to close them, you can do so arbitrarily at the edge of your region by patching in a line that represents that edge. This line can be created with v.in.region.

Moritz


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Huidae, Moritz and all,

Many thanks for you suggestions for filling inter-contour area with constant value.
I will try them out and report back.

Best

Venka

On 5/1/2014 4:03 AM, Huidae Cho wrote:

Ah.. if you have two adjacent contour lines that are farther than the
contour interval from each other, my method doesn't work. For example, 100,
102, and 106 will become 101, 103, and 107, not 101, 104, and 107 (what
should the max value be?).

Huidae

On Wed, Apr 30, 2014 at 2:50 PM, Huidae Cho <grass4u@gmail.com> wrote:

Venka,

Let's say you have the elevation field in your shapefile and the contour
interval is 2 meters.

# Import your shapefile into GRASS
v.in.ogr dsn=contours.shp output=contours type=boundary

# Add centroids to the imported boundaries to make areas
v.centroids input=contours output=contourareas

# Convert the contour areas to raster filling inter-contour areas with
contour elevations
v.to.rast input=contourareas output=contourareas use=attr
attrcolumn=elevation

# Now you want to add a half of the contour interval to get what you want
r.mapcalc expression="contoursteps=contourareas+1"

contoursteps is what you need, I think.

Regards,
Huidae

On Tue, Apr 29, 2014 at 4:19 AM, Moritz Lennert <
mlennert@club.worldonline.be> wrote:

[Please keep threads on the list]

On 29/04/14 00:33, John Ciolek wrote:

Hi Moritz.

What do you mean by the following suggestion?

On Apr 28, 2014, at 2:45 AM, Moritz Lennert wrote:

  - if necessary, add a line at the edge of the region and patch that

with your contour lines to close polygons (v.in.region, v.patch)

Are you suggesting that you can close a contour (connect the beginning
point to the ending point) using v.in.region or v.patch?

No, not the beginning point to the end point. Either you have closed
contours or your contours go over the edge of your current region, meaning
that some contours are not closed. So, in order to close them, you can do
so arbitrarily at the edge of your region by patching in a line that
represents that edge. This line can be created with v.in.region.

Moritz
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user