You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/tutorials/spatial_point_pattern/index.Rmd
+18-4Lines changed: 18 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,15 @@ params:
11
11
cellsize: 20
12
12
---
13
13
14
-
In this example we focus on a set of 10450 coordinates in a small area. The goal is to estimate the local density of points, expressed as the number of point per unit area. The raw coordinates are given in [WGS84 (EPSG:4326)](https://epsg.io/4326), which is a geodetic coordinate system. That is not suited for calculating distances, so we need to re-project the points into a local projected coordinate system. In this case we use [Lambert72 (EPSG:3170)](https://epsg.io/31370). Next we calculate the density. To visualise the density, we have to transform the results back in to WGS84.
14
+
In this example we focus on a set of 10450 coordinates in a small area.
15
+
The goal is to estimate the local density of points, expressed as the number of points per unit area.
16
+
The raw coordinates are given in [WGS84 (EPSG:4326)](https://epsg.io/4326), which is a geodetic coordinate reference system.
17
+
That is not suited for calculating distances, so we need to re-project the points into a local projected coordinate reference system.
18
+
In this case we use [Belgian Lambert72 (EPSG:3170)](https://epsg.io/31370).
19
+
Next we calculate the density.
20
+
To visualise the density, we have to transform the results back to WGS84.
15
21
16
-
The data used in this example is real data by centred to a different location for privacy reasons. The dataset is available on [GitHub](https://github.com/ThierryO/my_blog/tree/master/data/20170628).
22
+
The data used in this example is real data but centred to a different location for privacy reasons. The dataset is available on [GitHub](https://github.com/ThierryO/my_blog/tree/master/data/20170628).
17
23
18
24
First we must read the data into R. Plotting the raw data helps to check errors in the data.
19
25
@@ -116,7 +122,12 @@ ggmap(map) +
116
122
)
117
123
```
118
124
119
-
Using `leaflet` to generate a map was a bit more laborious. Using the `data.frame dens_wgs`directly failed. So we converted the `data.frame` in a `SpatialPolygonsDataframe`, which is a combination of a `SpatialPolygons` and a `data.frame`. The `SpatialPolygons` consists of a list of `Polygons`, one for each row of the `data.frame`. A `Polygons` object consist of a list of one or more `Polygon` object. In this example a single polygon which represents the grid cell.
125
+
Using `leaflet` to generate a map was a bit more laborious.
126
+
Using the `data.frame dens_wgs`directly failed.
127
+
So we converted the `data.frame` to a `SpatialPolygonsDataframe`, which is a combination of a `SpatialPolygons` and a `data.frame`.
128
+
The `SpatialPolygons` consists of a list of `Polygons`, one for each row of the `data.frame`.
129
+
A `Polygons` object consists of a list of one or more `Polygon` objects.
130
+
In this example it is a single polygon which represents the grid cell.
120
131
121
132
```{r convert-to-Spatial-Polygons}
122
133
dens_sp <- lapply(
@@ -137,7 +148,10 @@ dens_sp <- lapply(
137
148
)
138
149
```
139
150
140
-
`leaflet` requires a predefined function with a colour pallet. We use `leaflet::colorNumeric()` to get a continuous pallet. Setting `stroke = FALSE` removes the borders of the polygon. `fillOpacity` sets the transparency of the polygons.
151
+
`leaflet` requires a predefined function with a colour palette.
152
+
We use `leaflet::colorNumeric()` to get a continuous palette.
153
+
Setting `stroke = FALSE` removes the borders of the polygon.
154
+
`fillOpacity` sets the transparency of the polygons.
141
155
142
156
```{r leaflet, fig.cap = "Dynamic map of density"}
0 commit comments