Reputation: 57
How can we transform "unit" of window between ppp objects and owin objects?
I am trying to analyze spatial data collected from open street map.
First, I get POI data around Singapore, then transform them to ppp
objects
if(!require("osmdata")) install.packages("osmdata")
library(osmdata)
q <- getbb("Singapore") %>%
opq() %>%
add_osm_feature("amenity")
places <- osmdata_sf(q)
police <- places$osm_points %>%
filter(amenity == "police") %>%
st_transform(., "+proj=utm +zone=19 +ellps=GRS80 +datum=NAD83")
police.sp <- as(police, "Spatial") # Create Spatial* object
police.ppp <- as(police.sp, "ppp") # Create ppp object
class(police.ppp)
Later on, I tried to insert a .shp object I found from the gov website to create a Singapore shape to input as Window() to police.ppp object.
s <- readOGR(".", "Region_Census2010")
sg <- as(s, "owin")
However, upon calling summary
of the two, I saw the two have really different ranges
summary(sg)
enclosing rectangle: [2637.87, 56396.44] x [15748.72, 50256.33] units
(53760 x 34510 units)
summary(police.ppp)
Window: rectangle = [1280705.4, 1323492.3] x [19833441, 19854045] units
(42790 x 20600 units)
As a result, all of the police points were out of the map when I try to plot the files.
Is there any way to adjust the units? Did I do any steps wrong there?
Please help!
Thank you!
Upvotes: 0
Views: 282
Reputation: 4507
Make sure you use the same CRS for both datasets. After reading in s
you should use st_transform
or spTransform
to convert to the same coordinate system (UTM zone 19) as the police points.
Upvotes: 2