Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nearest.raster.point

Find Pixel Nearest to a Given Point


Description

Given cartesian coordinates, find the nearest pixel.

Usage

nearest.raster.point(x,y,w, indices=TRUE)

Arguments

x

Numeric vector of x coordinates of any points

y

Numeric vector of y coordinates of any points

w

An image (object of class "im") or a binary mask window (an object of class "owin" of type "mask").

indices

Logical flag indicating whether to return the row and column indices, or the actual x,y coordinates.

Details

The argument w should be either a pixel image (object of class "im") or a window (an object of class "owin", see owin.object for details) of type "mask".

The arguments x and y should be numeric vectors of equal length. They are interpreted as the coordinates of points in space. For each point (x[i], y[i]), the function finds the nearest pixel in the grid of pixels for w.

If indices=TRUE, this function returns a list containing two vectors rr and cc giving row and column positions (in the image matrix). For the location (x[i],y[i]) the nearest pixel is at row rr[i] and column cc[i] of the image.

If indices=FALSE, the function returns a list containing two vectors x and y giving the actual coordinates of the pixels.

Value

If indices=TRUE, a list containing two vectors rr and cc giving row and column positions (in the image matrix). If indices=FALSE, a list containing vectors x and y giving actual coordinates of the pixels.

Author(s)

and Rolf Turner r.turner@auckland.ac.nz

See Also

Examples

w <- owin(c(0,1), c(0,1), mask=matrix(TRUE, 100,100))  # 100 x 100 grid
  nearest.raster.point(0.5, 0.3, w)
  nearest.raster.point(0.5, 0.3, w, indices=FALSE)

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.