Title: | Easy Spatial Tools for R |
---|---|
Description: | Provide a series of functions designed to make complicated spatial operations in R much easier. Applications are focused on aquatic distance related uses, with built in functionality for the Sacramento San Joaquin Delta. Users can calculate in-water distances between points, move points outside a shapefile to the closest location within the shapefile, and cluster points within a given radius. More functions will be added in the future. |
Authors: | Sam Bashevkin [aut, cre] |
Maintainer: | Sam Bashevkin <[email protected]> |
License: | GPL-3 |
Version: | 0.0.0.9000 |
Built: | 2025-02-23 03:31:25 UTC |
Source: | https://github.com/sbashevkin/spacetools |
Shapefile of delta waterways
Delta
Delta
a sf tibble with 282 rows and 10 columns.
Area.
Perimeter.
HYDRO_POLY.
HYDRO_PO_1.
HYDRO_24K_.
HNAME.
Shape_Length
Shape_Area.
Shapefile polygon coordinates.
Calculate a distance matrix for a set of points based on in-water distances, using a raster-based approach.
GGdist( Water_map, Points, EndPoint = NULL, Latitude_column, Longitude_column, PointID_column, Points_crs = 4326, Water_map_transitioned = NULL, Calculation_crs = 32610, Grid_size = 75 )
GGdist( Water_map, Points, EndPoint = NULL, Latitude_column, Longitude_column, PointID_column, Points_crs = 4326, Water_map_transitioned = NULL, Calculation_crs = 32610, Grid_size = 75 )
Water_map |
Object of class sf representing a map of all waterways in your region of interest |
Points |
A dataframe of points with latitude and longitude which you would like to calculate distance to a given reference point. |
EndPoint |
A dataframe containing a single point with latitude and longitude. Defaults to a point 92 m East of the Golden Gate (37.819539, -122.477). Latitude and longitude column names must be the same as the points data frame. This point must fall within the bounds of the |
Latitude_column |
The unquoted name of the column in the |
Longitude_column |
The unquoted name of the column in the |
PointID_column |
The unquoted name of the column in the |
Points_crs |
Coordinate reference system for your |
Water_map_transitioned |
A rasterized, transitioned, and geo-corrected version of the water map. This is optional to save time if you will be running this function frequently with the same base map. |
Calculation_crs |
Coordinate reference system used for the calculation. If a latitude/longitude system are used, errors may be returned since some calculations assume a planar surface. Defaults to |
Grid_size |
Grid size (in meters) used to rasterize the map. Defaults to 75. |
A tibble with 1 column for the PointID_column values and another with the distances from the EndPoint.
library(tibble) Points <- tibble(Latitude = c(38.23333, 38.04813, 38.05920, 37.94900, 38.23615, 38.47387), Longitude = c(-121.4889, -121.9149, -121.8684, -121.5591, -121.6735, -121.5844), ID = c("EMP NZP02", "FMWT 508", "FMWT 513", "FMWT 915", "FMWT 723", "FMWT 796")) ## Not run: distance<GGdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID) # Including a pre-transitioned map to save time. # See Maptransitioner for creating this pre-transitioned map. distance<-GGdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID, Water_map_transitioned = Delta_transitioned) ## End(Not run)
library(tibble) Points <- tibble(Latitude = c(38.23333, 38.04813, 38.05920, 37.94900, 38.23615, 38.47387), Longitude = c(-121.4889, -121.9149, -121.8684, -121.5591, -121.6735, -121.5844), ID = c("EMP NZP02", "FMWT 508", "FMWT 513", "FMWT 915", "FMWT 723", "FMWT 796")) ## Not run: distance<GGdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID) # Including a pre-transitioned map to save time. # See Maptransitioner for creating this pre-transitioned map. distance<-GGdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID, Water_map_transitioned = Delta_transitioned) ## End(Not run)
Rasterize and transition a shapefile for input into Waterdist
Maptransitioner( Water_map, Calculation_crs = 32610, Grid_size = 75, Process_map = TRUE, Plot = FALSE )
Maptransitioner( Water_map, Calculation_crs = 32610, Grid_size = 75, Process_map = TRUE, Plot = FALSE )
Water_map |
Object of class sf representing a map of all waterways in your region of interest |
Calculation_crs |
Coordinate reference system used for the calculation. If a latitude/longitude system are used, errors may be returned since some calculations assume a planar surface. Defaults to |
Grid_size |
Grid size (in meters) used to rasterize the map. Defaults to 75. |
Process_map |
Should the |
Plot |
Should the rasterized map be plotted for inspection? |
A rasterized, transitioned, and geo-corrected map.
## Not run: Map <- Maptransitioner(spacetools::Delta) ## End(Not run)
## Not run: Map <- Maptransitioner(spacetools::Delta) ## End(Not run)
Cluster points within a given distance of one another
Pointcluster( Points, Distance, In_water_distance = FALSE, Latitude_column, Longitude_column, PointID_column, Points_crs = 4326, Calculation_crs = 32610, Water_map = NULL, Water_map_transitioned = NULL, Grid_size = 75, Expand = TRUE )
Pointcluster( Points, Distance, In_water_distance = FALSE, Latitude_column, Longitude_column, PointID_column, Points_crs = 4326, Calculation_crs = 32610, Water_map = NULL, Water_map_transitioned = NULL, Grid_size = 75, Expand = TRUE )
Points |
A dataframe of points with latitude and longitude |
Distance |
Clustering distance in meters. |
In_water_distance |
Should clustering be based on in-water distance? If yes, in-water distances will be calculated with |
Latitude_column |
The unquoted name of the column in the |
Longitude_column |
The unquoted name of the column in the |
PointID_column |
The unquoted name of the column in the |
Points_crs |
Coordinate reference system for your |
Calculation_crs |
Coordinate reference system used for the calculation. If a latitude/longitude system are used, errors may be returned since some calculations assume a planar surface. Defaults to |
Water_map |
Object of class sf representing a map of all waterways in your region of interest |
Water_map_transitioned |
A rasterized, transitioned, and geo-corrected version of the water map. This is optional to save time if you will be running this function frequently with the same base map. |
Grid_size |
Grid size (in meters) used to rasterize the map. Defaults to 75. |
Expand |
Should data be expanded at the end? If |
The parameters Water_map
, Water_map_transitioned
and Grid_size
will be ignored unless In_water_distance = TRUE
.
A tibble relating each point to its assigned cluster. The returned Latitude and Longitude values represent the mean values across all points in each cluster.
library(tibble) Points <- tibble(Latitude = c(38.07194, 38.09306, 38.11722, 38.11528, 38.07020, 38.09383, 38.11783, 38.06481, 38.11400, 38.06750, 38.11556), Longitude = c(-122.0961, -122.0692, -122.0472, -122.0519, -122.0941, -122.0697, -122.0418, -122.0978, -122.0462, -122.0956, -122.0424), ID = c("EMP NZ022", "EMP NZ024", "EMP NZ028", "EMP NZ030", "FMWT 416", "FMWT 418", "FMWT 602", "TNS 418", "TNS 602", "twentymm 418", "twentymm 602")) Points_clust<-Pointcluster(Points, 1000, FALSE, Latitude, Longitude, ID, Expand=TRUE)
library(tibble) Points <- tibble(Latitude = c(38.07194, 38.09306, 38.11722, 38.11528, 38.07020, 38.09383, 38.11783, 38.06481, 38.11400, 38.06750, 38.11556), Longitude = c(-122.0961, -122.0692, -122.0472, -122.0519, -122.0941, -122.0697, -122.0418, -122.0978, -122.0462, -122.0956, -122.0424), ID = c("EMP NZ022", "EMP NZ024", "EMP NZ028", "EMP NZ030", "FMWT 416", "FMWT 418", "FMWT 602", "TNS 418", "TNS 602", "twentymm 418", "twentymm 602")) Points_clust<-Pointcluster(Points, 1000, FALSE, Latitude, Longitude, ID, Expand=TRUE)
Move points to closest location within shapefile
Pointmover(Data, Attribute, Shapefile)
Pointmover(Data, Attribute, Shapefile)
Data |
Dataframe of points with sf geometry column and an attribute column with NAs for points that need to be moved. |
Attribute |
Name of the column in Data that indicates points that need to be moved (by the presence of NAs) |
Shapefile |
Object of class sf representing the shapefile you want all points to fall within. |
## Not run: library(tibble) library(dplyr) library(sf) Points <- tibble(Latitude = c(38.23333, 38.04813, 38.05920, 37.94900, 38.23615, 38.47387), Longitude = c(-121.4889, -121.9149, -121.8684, -121.5591, -121.6735, -121.5844), ID = c("EMP NZP02", "FMWT 508", "FMWT 513", "FMWT 915", "FMWT 723", "FMWT 796"))%>% st_as_sf(coords=c("Longitude", "Latitude"), crs=4326)%>% st_transform(crs=32610) Map <- st_union(spacetools::Delta)%>% st_as_sf()%>% mutate(Inside=TRUE)%>% rename(geometry = x)%>% st_transform(crs=32610) Points_joined <- st_join(Points, Map, join = st_intersects) Points_fixed<-Pointmover(Points_joined, Inside, Map) ## End(Not run)
## Not run: library(tibble) library(dplyr) library(sf) Points <- tibble(Latitude = c(38.23333, 38.04813, 38.05920, 37.94900, 38.23615, 38.47387), Longitude = c(-121.4889, -121.9149, -121.8684, -121.5591, -121.6735, -121.5844), ID = c("EMP NZP02", "FMWT 508", "FMWT 513", "FMWT 915", "FMWT 723", "FMWT 796"))%>% st_as_sf(coords=c("Longitude", "Latitude"), crs=4326)%>% st_transform(crs=32610) Map <- st_union(spacetools::Delta)%>% st_as_sf()%>% mutate(Inside=TRUE)%>% rename(geometry = x)%>% st_transform(crs=32610) Points_joined <- st_join(Points, Map, join = st_intersects) Points_fixed<-Pointmover(Points_joined, Inside, Map) ## End(Not run)
This package contains functions for easy spatial operations in R, focused on aquatic distance related applications. Internal datasets for the Sacramento San Joaquin Delta are also included to make operations very easy for this location.
Zooplankton sampling stations in the Sacramento San Joaquin Delta from the zooper package.
Stations
Stations
a tibble with 362 rows and 3 columns
Sampling station name
Latitude in decimal degrees
Longitude in decimal degrees
Calculate a distance matrix for a set of points based on in-water distances, using a raster-based approach
Waterdist( Water_map, Points, Latitude_column, Longitude_column, PointID_column, Points_crs = 4326, Water_map_transitioned = NULL, Calculation_crs = 32610, Grid_size = 75 )
Waterdist( Water_map, Points, Latitude_column, Longitude_column, PointID_column, Points_crs = 4326, Water_map_transitioned = NULL, Calculation_crs = 32610, Grid_size = 75 )
Water_map |
Object of class sf representing a map of all waterways in your region of interest |
Points |
A dataframe of points with latitude and longitude |
Latitude_column |
The unquoted name of the column in the |
Longitude_column |
The unquoted name of the column in the |
PointID_column |
The unquoted name of the column in the |
Points_crs |
Coordinate reference system for your |
Water_map_transitioned |
A rasterized, transitioned, and geo-corrected version of the water map. This is optional to save time if you will be running this function frequently with the same base map. |
Calculation_crs |
Coordinate reference system used for the calculation. If a latitude/longitude system are used, errors may be returned since some calculations assume a planar surface. Defaults to |
Grid_size |
Grid size (in meters) used to rasterize the map. Defaults to 75. |
Distance matrix.
library(tibble) Points <- tibble(Latitude = c(38.23333, 38.04813, 38.05920, 37.94900, 38.23615, 38.47387), Longitude = c(-121.4889, -121.9149, -121.8684, -121.5591, -121.6735, -121.5844), ID = c("EMP NZP02", "FMWT 508", "FMWT 513", "FMWT 915", "FMWT 723", "FMWT 796")) ## Not run: distance<-Waterdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID) # Including a pre-transitioned map to save time. # See Maptransitioner for creating this pre-transitioned map. distance<-Waterdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID, Water_map_transitioned = Delta_transitioned) ## End(Not run)
library(tibble) Points <- tibble(Latitude = c(38.23333, 38.04813, 38.05920, 37.94900, 38.23615, 38.47387), Longitude = c(-121.4889, -121.9149, -121.8684, -121.5591, -121.6735, -121.5844), ID = c("EMP NZP02", "FMWT 508", "FMWT 513", "FMWT 915", "FMWT 723", "FMWT 796")) ## Not run: distance<-Waterdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID) # Including a pre-transitioned map to save time. # See Maptransitioner for creating this pre-transitioned map. distance<-Waterdist(Water_map = spacetools::Delta, Points = Points, Latitude_column = Latitude, Longitude_column = Longitude, PointID_column = ID, Water_map_transitioned = Delta_transitioned) ## End(Not run)