]> git.vanrenterghem.biz Git - R/project-wa-schools.git/commitdiff
Use newer library sf instead of rgdal.
authorFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Thu, 12 Oct 2017 12:05:03 +0000 (20:05 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Thu, 12 Oct 2017 12:05:03 +0000 (20:05 +0800)
WA_active_schools.R

index 394fa831bce70794f1eceabb20f44dfb7b9394eb..da884f9dc47354bbf0a9a65ba4c43098beb7d211 100644 (file)
@@ -1,6 +1,7 @@
 # install libgdal-dev on debian first
 # install libgdal-dev on debian first
-#install.packages("rgdal")
-library(rgdal)
+# install libudunits2-dev on debian first
+#install.packages("sf")
+library(sf)
 library(tidyverse)
 library(broom)
 #install.packages("OpenStreetMap")
 library(tidyverse)
 library(broom)
 #install.packages("OpenStreetMap")
@@ -8,12 +9,11 @@ library(OpenStreetMap)
 library(viridis)
 
 # Read the shapefile obtained from WA opendata (SLIP)
 library(viridis)
 
 # Read the shapefile obtained from WA opendata (SLIP)
-shape <- readOGR(dsn = "data/", layer = "CurrentActiveSchoolsSemester12017_PublicDET_014")
-# Suppress warning about no method existing for SpatialPointsDataframe - TODO use library sf
-shape.df <- suppressWarnings(tidy(shape))
-shape.df$latitude <- as.numeric(as.character(shape.df$latitude))
-shape.df$longitude <- as.numeric(as.character(shape.df$longitude))
-shape.df$totalschoo <- as.numeric(as.character(shape.df$totalschoo))
+#shape <- readOGR(dsn = "data/", layer = "CurrentActiveSchoolsSemester12017_PublicDET_014")
+shape.df <- st_read(dsn = "data/", layer = "CurrentActiveSchoolsSemester12017_PublicDET_014", stringsAsFactors = FALSE)
+shape.df$latitude <- as.numeric(shape.df$latitude)
+shape.df$longitude <- as.numeric(shape.df$longitude)
+shape.df$totalschoo <- as.numeric(shape.df$totalschoo)
 
 # filter out remote islands
 shape.df <- filter(shape.df,longitude > 100)
 
 # filter out remote islands
 shape.df <- filter(shape.df,longitude > 100)
@@ -65,7 +65,7 @@ shape.metro.df <- filter(shape.df, abs(latitude) <= max(abs(lat.metro)),
                          abs(longitude) >= min(abs(lon.metro)))
 mapLatLon.metro <- openproj(map.metro)
 autoplot(mapLatLon.metro) +
                          abs(longitude) >= min(abs(lon.metro)))
 mapLatLon.metro <- openproj(map.metro)
 autoplot(mapLatLon.metro) +
-  geom_point(data = shape.metro.df, 
+  geom_point(data = shape.metro.df, # geom_sf is not yet in ggplot2 on CRAN, so sticking to this for now
              aes(x = longitude, 
                  y = latitude,
                  color = totalschoo),
              aes(x = longitude, 
                  y = latitude,
                  color = totalschoo),