Questions tagged [r-sp]

An R package for spatial data. Questions on spatial data might be better asked on https://gis.stackexchange.com

691 questions
3
votes
1 answer

Why do rgeos/sp and terra give different values for polygon area?

I am converting several functions from the sp package to terra and I have encountered an inconsistency in the calculated area of polygons. The code sample below demonstrates my issue. x = seq(0, 2 * pi, length.out = 100) circle = cbind(sin(x),…
randr
  • 255
  • 1
  • 7
3
votes
3 answers

Mapping geom-cordinates to a map object in R

I am attempting to map some geom-points/cordinates to a map of the country Sri Lanka. I am able to map the district borders, and the population as expected, but I am having trouble plotting the geom points onto the map. Install…
NewBee
  • 990
  • 1
  • 7
  • 26
3
votes
1 answer

Generating random locations along the outer border of a .shp polygon using R

I am able to generate random points within the polygons using the package sp, however I am interested in generating points along the outline of the polygon. For example, if I have a shapefile of a lake I can use spsample(lake,n=10,type="random") to…
mchen
  • 31
  • 1
3
votes
1 answer

finding points with polygon in sf package

I'm trying to create a simple polygon in sf and select only points within that polygon. What am I doing wrong here? library(concaveman) library(ggplot2) foo.df <- data.frame("long"=c(136,137,137,136),"lat"=c(36,36,37,37)) foo.sf <-…
Mark R
  • 775
  • 1
  • 8
  • 23
3
votes
2 answers

rgeos::gBuffer shrink without loss of points

I need to be able to shrink a polygon of lat/lon data without loss of points; more the point, I need the points to be effectively "smooshed" in the correct direction. Typically, gBuffer works fine, but there is no assurance on the number of points…
r2evans
  • 141,215
  • 6
  • 77
  • 149
3
votes
3 answers

find the nearest polygon for a given point

I have a SpatialPointsDataFrame and a SpatialPolygons. I want to check for each point in SpatialPointsDataFrame, which polygon in the SpatialPolygons does it lie. I can do this using sp::over to achieve this: However for cases where some of the…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
3
votes
1 answer

How can a buffer around a point not be a circle? (Or, strange behavior of rgeos::gBuffer() )

I've switched from package sp to sf for many of my geo-things in R, and only now I noticed a strange behavior in sp/rgeos. Here it is: library(sp) library(sf) library(rgeos) # crs WGS84M = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84…
djas
  • 973
  • 8
  • 24
3
votes
1 answer

Error when trying to plot SpatialLinesDataFrame using tmap in R

I'm attempting to plot a SpatialLinesDataFrame using the R package tmap. However I keep getting this error message: Error in CPL_geos_is_empty(st_geometry(x)): Evaluation error: IllegalArgumentException: point array must contain 0 or >1…
3
votes
3 answers

R: change raster values where spatial points overlay

Consider the following data: library(sp) library(raster) # create raster r <- matrix(c(1.8, 1.2, 1.8, 1.2, 2.5, 2.7, 8.5, 7, 2), 3,3) r <- raster(r) extent(r) <- c(45,46,54,55) projection(r) <- "+proj=utm +zone=33 +ellps=GRS80 +units=m…
yPennylane
  • 760
  • 1
  • 9
  • 27
3
votes
1 answer

add state borders to the output of leaflet where the input is counties shapefile

I downloaded the county shapefile off of data.gov. I can use them in leaflet as follows to plot counties in WA, ID and OR. I would like to make the state borders thicker. How can I do that? counties <- readOGR(paste0(dir,…
OverFlow Police
  • 861
  • 6
  • 23
3
votes
2 answers

How do I combine a dataframe with a spatial dataframe when receiving errors with both left_join and merge?

I am attempting to merge a dataframe containing data on hospital visits ("Hospital_Visits_df") with a shapefile/spatial*dataframe containing ZIP/ZCTA polygons and coordinates ("shp", downloaded from the Census Bureau). Both dataframes contain a…
3
votes
0 answers

Shiny and Leaflet integration is really slow - how can I speed it up?

Right now i'm almost certain that my current use of shiny and leaflet is sub-optimal. At a high level my current approach looks like this: Generate a leaflet. Create a reactive dataframe on user input. Create a reactive dataframe of lat lon…
Davide Lorino
  • 875
  • 1
  • 9
  • 27
3
votes
2 answers

Why does spplot take so much time for multiple panels

I am plotting multiple shapefiles using spplot. Here's a data to construct that library(raster) library(randomcoloR) my.shp <- getData('GADM', country = 'BRA', level = 2) my.shp$ID<- 1:nrow(my.shp) My data consists of a variable X for 10 years as…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
3
votes
1 answer

Subset Spatial Points to Extract those inside of a Polygon (Countries Borders)

I have a data.frame with lat long coordinates: df<-data.frame( lat=c(40, 30, 40.864), lon=c(0, 20, 1.274) ) And the border of a country (Spain), library(raster) border <- getData("GADM",country="Spain",level=0) I would like to select…
Javi_VM
  • 505
  • 2
  • 10
3
votes
0 answers

R spplot error: invalid 'nrow' value (too large or NA)

I am trying to plot 4 point shapefiles. They are close to identical: each is a SpatialPointsDataFrame, each with: CR="+proj=longlat +datum=WGS84" each with 4 variables. The first has 312 points, the second 337, the third 948, and the fourth 345…
Leah Bevis
  • 317
  • 1
  • 11