[R-sig-Geo] Mapping contours from jpg map

Roger Bivand Roger.Bivand at nhh.no
Fri Jul 8 17:09:57 CEST 2011

On Fri, 8 Jul 2011, Barry Rowlingson wrote:

> On Fri, Jul 8, 2011 at 2:26 PM, Robert Hijmans <r.hijmans at gmail.com> wrote:
>> # now there are many ways to interpolate. See, e.g., the 'gstat' and
>> 'automap' packages. See raster::interpolate for an example with splines.
>> # using gstat and inverse distrance weighted interpolation:
>> library(gstat)
>> g <- gstat(id="level", formula = level~1, data=p, nmax=7, set=list(idp =
>> .5))
>> x1 <- interpolate(r, g)
> Statistical interpolation techniques may be right for this, but
> thinking about it last night made me realise that contours are more
> than just linear estimates of height at location. There's the
> implication that between any two contour lines of height H1 and H2
> there are no locations with height outside the bounds of (H1,H2).
> Otherwise there would be a contour line there.
> And this may not be so uncommon in elevation models. Consider a steep
> sided valley with a wide flood plain. You have close contours on
> either side with a big gap between. Would a "statistical"
> interpolation run down the valley side and plummet on down, then back
> up the other side, turning the flood plain into a deep rounded valley
> bottom? Sure it all depends on the parameters of the smoothing, but a
> method that knew it was dealing with contours would constrain the
> surface such that points between contour lines were always between the
> contour line values.
> I think at least one of the algorithms in GRASS-GIS does this by
> "drawing" the contour lines on the raster and then doing a 'flood
> fill' operation between them.
> I'll have to dig out some GIS books...

r.surf.contour in GRASS does what is required:


gives its description; the input is a raster of the contours where the 
non-missing cells take the contour elevation values. I have found that 
spline interpolation can create artefacts, and geostatistical 
interpolation (or IDW for obvious reasons) does not like many neighbouring 
data points along a contour line.


> Barry
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

More information about the R-sig-Geo mailing list