LabelPointsWithinPolygons: Labels points located inside a polygon

Description Usage Arguments Details Value See Also Examples

View source: R/02_label_points_within_polygons.R

Description

LabelPointsWithinPolygons() identifies which points lie inside each polygon and labels them accordingly.

Usage

1
LabelPointsWithinPolygons(lng, lat, polygon.boundaries)

Arguments

lng

A numeric vector of non-NA longitudinal points.

lat

A numeric vector of non-NA latitudinal points.

polygon.boundaries

Either a coordinate pair matrix or a named list of coordinate pair matrices obtained from GetPolygonBoundaries.

Details

If points fall exactly on polygon boundaries, the default NULL gives arbitrary assignments. For more information, please see the bound argument within splancs::inpip().

Value

If polygon.boundaries is a coordinate pair matrix, a logical vector will be returned identifying those points which lie in the polygon; otherwise, a character vector will be returned identifying the polygon each coordinate pair lies in.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
## SpatialPolygonsDataFrame, one polygon example ## -----

# load necessary data ----
data("city_boundary_spdf")
data("cps_sy1819")

# obtain boundaries for the City of Chicago ----
boundaries <-
  GetPolygonBoundaries(my.polygon = city_boundary_spdf)

# identify which schools lie within the City of Chicago -----
cps_sy1819$citywide <-
  LabelPointsWithinPolygons(lng = cps_sy1819$school_longitude
                            , lat = cps_sy1819$school_latitude
                            , polygon.boundaries = boundaries)

## SpatialPolygonsDataFrame, multipolygon polygon example ## -----

# load necessary data ----
data("community_areas_spdf")
data("cps_sy1819")

# obtain boundaries for each of the 77 Chicago community areas ----
boundaries <-
  GetPolygonBoundaries(my.polygon = community_areas_spdf
                       , labels = community_areas_spdf$community)

# identify the schools which lie within each of the 77 Chicago community areas -----
cps_sy1819$community <-
  LabelPointsWithinPolygons(lng = cps_sy1819$school_longitude
                            , lat = cps_sy1819$school_latitude
                            , polygon.boundaries = boundaries)


## sf, one polygon example ## -----

# load necessary package ----
library(sf)

# load necessary data ----
data("city_boundary_sf")
data("cps_sy1819")

# obtain boundaries for the City of Chicago ----
boundaries <-
  GetPolygonBoundaries(my.polygon = city_boundary_sf)

# identify which schools lie within the City of Chicago -----
cps_sy1819$citywide <-
  LabelPointsWithinPolygons(lng = cps_sy1819$school_longitude
                            , lat = cps_sy1819$school_latitude
                            , polygon.boundaries = boundaries)
                            


## sf, multipolygon polygon example ## -----

# load necessary package ----
library(sf)

# load necessary data ----
data("community_areas_sf")
data("cps_sy1819")

# obtain boundaries for each of the 77 Chicago community areas ----
boundaries <-
  GetPolygonBoundaries(my.polygon = community_areas_sf
                       , labels = community_areas_sf$community)


# identify the schools which lie within each of the 77 Chicago community areas -----
cps_sy1819$community <-
  LabelPointsWithinPolygons(lng = cps_sy1819$school_longitude
                            , lat = cps_sy1819$school_latitude
, polygon.boundaries = boundaries)

pointdexter documentation built on May 1, 2019, 10:29 p.m.