Last data update: 2014.03.03

R: Find Polygons that Contain Events
findPolysR Documentation

Find Polygons that Contain Events

Description

Find the polygons in a PolySet that contain events specified in EventData.

Usage

findPolys (events, polys, maxRows = 1e+05, includeBdry=NULL)

Arguments

events

EventData to use.

polys

PolySet to use.

maxRows

estimated maximum number of rows in the output LocationSet.

includeBdry

numeric: determines how points on boundaries are handled:
if NULL then report all points on polygon boundaries (default behaviour);
if 0 then exclude all points on polygon boundaries;
if 1 then report only the first (lowest PID/SID) polygon boundary;
if 2,...,n then report the last (highest PID/SID) polygon boundary.

Details

The resulting data frame, a LocationSet, contains the columns EID, PID, SID (if in polys), and Bdry, where an event (EID) occurs in a polygon (PID, SID) and SID does not correspond to an inner boundary. The Boolean variable Bdry indicates whether an event lies on a polygon's edge. Note that if an event lies properly outside of all the polygons, then a record with (EID, PID, SID) does not occur in the output. It may happen, however, that an event occurs in multiple polygons. Thus, the same EID can occur more than once in the output.

If an event happens to lie at the boundary intersection of two or more polygons then one EID will be associated with two or more polygons. A user can choose to manipulate this result by setting the argument includeBdry to a numeric value that constrains the association of a boundary event to 0 or 1 polygon (see argument description above).

Value

LocationSet that links events with polygons.

See Also

combineEvents, findCells, locateEvents, locatePolys, LocationSet, makeGrid.

Examples

local(envir=.PBSmapEnv,expr={
  oldpar = par(no.readonly=TRUE)
  #--- create some EventData: a column of points at X = 0.5
  events <- data.frame(EID=1:10, X=.5, Y=seq(0, 2, length=10))
  events <- as.EventData(events, projection=1)
  #--- create a PolySet: two squares with the second above the first
  polys <- data.frame(PID=c(rep(1, 4), rep(2, 4)), POS=c(1:4, 1:4),
    X=c(0, 1, 1, 0, 0, 1, 1, 0),
    Y=c(0, 0, 1, 1, 1, 1, 2, 2))
  polys <- as.PolySet(polys, projection=1)
  #--- show a picture
  plotPolys(polys, xlim=range(polys$X)+c(-0.1, 0.1),
    ylim=range(polys$Y)+c(-0.1, 0.1), projection=1);
  addPoints(events, col=2);
  #--- run findPolys and print the results
  print(findPolys(events, polys))
  par(oldpar)
})

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(PBSmapping)

-----------------------------------------------------------
PBS Mapping 2.69.76 -- Copyright (C) 2003-2016 Fisheries and Oceans Canada

PBS Mapping comes with ABSOLUTELY NO WARRANTY;
for details see the file COPYING.
This is free software, and you are welcome to redistribute
it under certain conditions, as outlined in the above file.

A complete user guide 'PBSmapping-UG.pdf' is located at 
/home/ddbj/local/lib64/R/library/PBSmapping/doc/PBSmapping-UG.pdf

Packaged on 2015-04-23
Pacific Biological Station, Nanaimo

All available PBS packages can be found at
http://code.google.com/p/pbs-software/

To see demos, type '.PBSfigs()'.
-----------------------------------------------------------


> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/PBSmapping/findPolys.Rd_%03d_medium.png", width=480, height=480)
> ### Name: findPolys
> ### Title: Find Polygons that Contain Events
> ### Aliases: findPolys
> ### Keywords: manip
> 
> ### ** Examples
> 
> local(envir=.PBSmapEnv,expr={
+   oldpar = par(no.readonly=TRUE)
+   #--- create some EventData: a column of points at X = 0.5
+   events <- data.frame(EID=1:10, X=.5, Y=seq(0, 2, length=10))
+   events <- as.EventData(events, projection=1)
+   #--- create a PolySet: two squares with the second above the first
+   polys <- data.frame(PID=c(rep(1, 4), rep(2, 4)), POS=c(1:4, 1:4),
+     X=c(0, 1, 1, 0, 0, 1, 1, 0),
+     Y=c(0, 0, 1, 1, 1, 1, 2, 2))
+   polys <- as.PolySet(polys, projection=1)
+   #--- show a picture
+   plotPolys(polys, xlim=range(polys$X)+c(-0.1, 0.1),
+     ylim=range(polys$Y)+c(-0.1, 0.1), projection=1);
+   addPoints(events, col=2);
+   #--- run findPolys and print the results
+   print(findPolys(events, polys))
+   par(oldpar)
+ })
   EID PID Bdry
1    1   1    1
2    2   1    0
3    3   1    0
4    4   1    0
5    5   1    0
6    6   2    0
7    7   2    0
8    8   2    0
9    9   2    0
10  10   2    1
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>