Questions tagged [r-sf]

The motivation behind the `sf` package is to provide a complete, standardized implementation of simple features in R, with links to GDAL, GEOS and Proj.4. There is a also https://gis.stackexchange.com/ for spatial R questions.

sf is a new R package for handling and analyzing spatial data in R. While various R packages are available that provide classes and methods for spatial data (e.g. sp, rgdal and rgeos), sf, which is developed by Edzer Pebesma and others, is intended to gradually replace the well known sp package. The motivation behind this package is to provide a complete, standardized implementation of simple features in R, with links to GDAL, GEOS and Proj.4.

1940 questions
0
votes
0 answers

How can I access a matrix entries using a for loop in R?

I have a distance matrix with all distances between a all points in the data set. How can I access the individual distances in the matrix without using a for loop? This is a working example using a for loop: # Create a distance matrix of all…
Mikado8787
  • 35
  • 4
0
votes
1 answer

How can I filter out the small Hawaiian islands with get_acs?

Can you use the resolution argument in get_acs() to filter out the small islands in the Hawaiian archipelago? I might have found a bug in tidycensus, one of my favorite packages. I was mapping U.S congressional districts using tidycensus's get_acs()…
0
votes
1 answer

Assign an sf geometry for each R row with specific filter creteria: what's wrong with my current code?

Suppose I have a dataframe test. What I want to do is assign a random geometry to the rows that cly == 8. For the other rows, I just leave it as NA This is a reprex of my current…
Jingjun
  • 177
  • 7
0
votes
1 answer

Issue with country/province name from coordinates when points are on country coastal limits (in R)

I have a set of coordinates that most fall within or near the Iberian Peninsula. I'm interested in finding out the country name of a large set of coordinates and the province name. However, there are some problematic coordinates on the boundaries of…
J. Lan
  • 51
  • 4
0
votes
1 answer

Why R is Producing Weird and Not Total Row Number

I have a data frame produced from dput. Ideally, when running this dput, the test data frame should have 12 rows with row number 1:12. However, when running this, row 9 to 12 will be produced as row 5.1, 6.1, 7.1 and 8.1. I am sure that the contents…
Jingjun
  • 177
  • 7
0
votes
1 answer

ggspatial: geom_sf fails with certain xlim values in coord_sf

What I'm trying to do: plot spatial objects with ggspatial::geom_sf(), using coord_sf() or a combination of ggspatial::layer_spatial() and ggspatial::annotation_spatial() to specify the extent of the of the plot. This ggplot/ggspatial behavior has…
0
votes
2 answers

Convert regular lat/lon grid to polygons using R sf

I'm trying to convert a regular 1-degree by 1-degree geographic grid to polygons while maintaining the data associated with each grid point using the R sf package. Example code: library(tidyverse) library(sf) library(sfheaders) library(sfheaders) #…
JFD
  • 193
  • 1
  • 11
0
votes
0 answers

How to rescale Polygons in R (Canadian Data)

I have a dataset (2.7 million rows< ) which has given me geometries of various polygons which yields the visual below with this code: library(tidyverse) library(sf) dt %>% st_as_sf(wkt = "geometry")%>% ggplot()+ geom_sf() I am trying to use the…
Bensstats
  • 988
  • 5
  • 17
0
votes
2 answers

Intersection and difference of PostGIS data using R

I am an absolute beginner in PostgreSQL and PostGIS (databases in general) but have a fairly good working experience in R. I have two multi-polygon data sets of vulnerable areas of India from two different sources - one is around 12gb and it's in…
rm167
  • 1,185
  • 2
  • 10
  • 26
0
votes
0 answers

How to create an sf object which combines geometries to create a set of larger units (e.g., states from counties)

I have a shapefile (.shp) where each geographic unit is (the equivalent of) a county. I loaded it and called it gdfc. I would like to combine counties to create an sf object where each observation is a state. I have tried the following…
DOS
  • 29
  • 7
0
votes
1 answer

Can't read a list of shp file in R

I tried to open a list of shp file, using this code: path_par <- list.files(path = "E:\\core", full.names = T, pattern = "shp") parch <-path_par %>% map(read_sf) But I receive this error message: Error: Cannot open "E:\core\CorePO_Esc0.shp.xml";…
0
votes
0 answers

Error in sample.int(length(x), size, replace, prob) : invalid first argument in Shiny app

I'm trying to run data in RDS format in the Shiny app but I keep getting this error Error in sample.int(length(x), size, replace, prob) : invalid first argument When I tried to run the data as CSV file, it run the Shiny app with no error but not…
Reta
  • 363
  • 3
  • 4
  • 15
0
votes
1 answer

How to convert shapefile into vector geometry in R so it can be plotted?

I have a beginners question in R. I have a data frame (that contains data on some geographical regions) and I have a corresponding shapefile for those regions. I would like to plot the data from the data frame onto the geometry. Looking at some…
user1778351
  • 143
  • 7
0
votes
2 answers

Ggplot2 legend with actual values instead of log

I created a map using ggplot2 where I show the trade balance of European countries vis-a-vis the rest of the world, using the code below: library(ggplot2) library(sf) library(giscoR) data <- read.csv("~/Downloads/full202052…
Saïd Maanan
  • 511
  • 4
  • 14
0
votes
2 answers

How to properly plot sf object

I have data like the following: These data are obtained from a Stata dataset (.dta exported to .csv) and are intended to plot a map of shapefiles. I import it into R, drop rows with missing data, and convert to sf (I am not sure if this is the best…
bill999
  • 2,147
  • 8
  • 51
  • 103
1 2 3
99
100