From d4ee26d74a52d4d5b4d5f0e933dbcd3ba178978a Mon Sep 17 00:00:00 2001 From: Frederik Vanrenterghem Date: Thu, 12 Oct 2017 20:05:03 +0800 Subject: [PATCH] Use newer library sf instead of rgdal. --- WA_active_schools.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/WA_active_schools.R b/WA_active_schools.R index 394fa83..da884f9 100644 --- a/WA_active_schools.R +++ b/WA_active_schools.R @@ -1,6 +1,7 @@ # 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") @@ -8,12 +9,11 @@ library(OpenStreetMap) 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) @@ -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) + - 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), -- 2.30.2