This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
library(ggmap) | |
library(RColorBrewer) | |
## Get data from OpenPV. Open this URL: | |
## https://openpv.nrel.gov/search?&state=CA&minsize=100&maxsize=30600&pagenum=1&nppage=25 | |
## and export the results as a CSV file named "californiaOpenPV.csv" | |
caPV <- read.csv('californiaOpenPV.csv') | |
## Longitude and Latitude are the names of columns where the spatial information is stored. | |
## With the coordinates<- method caPV is now an SpatialPointsDataFrame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
library(ggmap) | |
## latticeExtra must be loaded after ggmap because both ggplot2 and | |
## latticeExtra define a 'layer' function. We need the definition from | |
## latticeExtra. | |
library(latticeExtra) | |
## We only need maptools to get an example | |
library(maptools) | |
SIDS <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], | |
IDvar="FIPSNO", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
polygonizer <- function(x, outshape=NULL, gdalformat = 'ESRI Shapefile', | |
pypath=NULL, readpoly=TRUE, quietish=TRUE) { | |
# x: an R Raster layer, or the file path to a raster file recognised by GDAL | |
# outshape: the path to the output shapefile (if NULL, a temporary file will be created) | |
# gdalformat: the desired OGR vector format | |
# pypath: the path to gdal_polygonize.py (if NULL, an attempt will be made to determine the location | |
# readpoly: should the polygon shapefile be read back into R, and returned by this function? (logical) | |
# quietish: should (some) messages be suppressed? (logical) | |
if (isTRUE(readpoly)) require(rgdal) | |
if (is.null(pypath)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Main code based on https://www.r-spatial.org//r/2018/10/25/ggplot2-sf-3.html | |
library("ggplot2") | |
theme_set(theme_bw()) | |
## Requires up to date gdal | |
## (e.g., from https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa) | |
library("sf") | |
library("rworldmap") | |
library("rworldxtra") |