[R-sig-Geo] jitter within polygon

Rolf Turner r.turner at auckland.ac.nz
Sun Jan 29 22:56:16 CET 2017


On 28/01/17 18:29, Paul Lantos wrote:

> I am trying to figure out how to randomly jitter points within an
> overlying polygon structure.
>
> I can easily jitter the points themselves, but I would like this to
> be constrained by the boundaries of polygons containing the points.
>
> This isn't for visualization - I can do that easily enough in GIS. I
> actually need to generate coordinates.

You can do this easily in spatstat by making each polygon into an object 
of class "owin" (see e.g. the "shapefiles" vignette) and then using the 
function rjitter() (with retry=TRUE).

Note that if you have a collection of polygons some of which are close
to being contiguous, it is possible (or at least conceivable) for a 
jittered point to "jump" to a location inside a different polygon. 
Hence if you were to represent your collection of polygons as a single
(disconnected) "owin" object you would run the risk of incurring this 
"jumping" phenomenon.  Hence it would be safer to bundle your collection 
of polygons into a list, and apply rjitter() to each list entry (using 
lapply()).

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-sig-Geo mailing list