Questions tagged [rgeos]

R bindings for the GEOS library

Filter by
Sorted by
Tagged with
1 vote
0 answers
130 views

Distance to forest edge in R

I have a raster layer consisting 41 forest polygons and would like to calculate the distance of forest pixels to the edge within each forest polygon. I tried the code below but the result looks like ...
2 votes
1 answer
791 views

Creating adjacent matrix with polygons in shapefile with R

I´m very new at these geospatial data analysis and manipulation in R. Right now I have a shapefile that you can find here: http://sina.conagua.gob.mx/sina/tema.php?tema=cuencas&ver=mapa&o=0&...
1 vote
2 answers
328 views

Preserving IDs when using gCentroid to find centroids of multiple polygons in R

This seems like it should be simple. I have multiple polygons contained in one shapefile, and I am using the gCentroid() function from rgeos to create a bunch of centroid points. The function has an ...
  • 47
1 vote
1 answer
357 views

Converting a SpatialPointsDataFrame into km units from m, in R

I read in a UTM shapefile to R using readOGR. I want to use the resulting SpatialPointsDataFrame to build a mesh in the INLA package, but I've been told that to help with numerical stability, I should ...
5 votes
1 answer
78 views

Unexpected buffer output

Using both R and QGIS I got unexpected output from the buffer function. I'm wondering if it has something to do with my coordinate reference system, USA Contiguous Albers Equal Area Conic, because the ...
0 votes
0 answers
61 views

Some polygons failing to fill with color

I have several Spatial Polygon Data Frames I am adding successively to a plot in R 4.0.2. The polygons represent US States, National Forests, National Parks, and wildfire perimeters. While it probably ...
0 votes
1 answer
719 views

crop wrld_simpl gives error after R update

This code was working for me before I updated R to 4.0, but now it throws an error. I get this error on a Mac and a PC. I updated gdal on my mac, but this did not help. I made sure the rgeos package ...
  • 303
0 votes
0 answers
175 views

Is there a metric projection that works everywhere in the world? If not, what's the smallest set of EPSG codes for that?

I'm doing some calculations per country, using rgeos library in R. For each country, I need to calculate the bounding box area. So I transform the country's bounding box in a sp object, project it ...
  • 755
1 vote
1 answer
110 views

Unable to process multiple polygons using SpatialPolygons object

I have a list with 4 objects, each object is a data frame. The data frame is the coordinate matrix of each polygon. I would like calculate the total area of the 4 polygons and then draw the voronoi ...
0 votes
1 answer
163 views

Calculating area between two SpatialLines using R

How do I calculate the area between two lines using R? The two lines have the same start and end location, but the number of vertices for each line can vary. I've tried to create a polygon from the ...
1 vote
0 answers
70 views

gIntersection results in a new dataframe with more rows

This is my first time using rgeos::gIntersection, and I have a dataset with that I rasterized using rasterFromXYZ, then turned into a spatial polygon dataframe. I wanted to intersect this SP dataframe ...
1 vote
0 answers
462 views

Updating PROJ GEOS and GDAL in R

I have been having trouble linking to GEOS 3.8.1, GDAL 3.0.4, PROJ 6.3.0. I have tried reinstalling sf, rgdal, raster, and rgeos packages. I still couldn't link to GEOS 3.8.1, GDAL 3.0.4, PROJ 6.3.0. ...
  • 13
2 votes
1 answer
107 views

Dissolved area of polygons using the gArea function of rgeos?

I am taking occurrence point data (in the form of individual Lat/Long points), and adding a 1km buffer around them using gBuffer() in R package rgeos. I'm then using the function gArea() to calculate ...
1 vote
1 answer
308 views

R spatial: add new attribute to S4 class object?

I am trying to check if my shapefile polygons have open edge or not. To have an open edge, the polygon either has no neighbors, or is >5 m taller than its neighbours. So, I want to add this new field ...
  • 3,306
2 votes
1 answer
173 views

Skipping TopologyException and continuing operation anyway using R

I'd like to see the result after an hour of working while substracting two shapefiles. This is the code, but don't ask me what in those files. Whatever it is, I'd like to know how to skip those errors ...
  • 407
2 votes
0 answers
445 views

Union anti-meridian "multipolygons" after re-centering world map

My goal is to create a world map (using ggplot2) with a Pacific perspective. I have managed to re-center the map, by following this solution. Code below: # world country layer sppolys <-...
2 votes
1 answer
393 views

Apply function from rgeos package to data sets

I am using gDistance function from rgeos package to calculate the nearest distance from points to a polygon. Originally I used for loop to calculate the distance for each row in my points data set, ...
2 votes
0 answers
99 views

Generating equal-distance band regards to one boundary of polygon in R? [closed]

I have a polygon that is made up of several points: Basically, this reflects the contour of a tumor tissue. Now I have another polygon, which is defined as 'front', means a region where tumor and ...
0 votes
0 answers
541 views

Error in RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance") : negative length vectors are not allowed

What does the error in the title mean? I'm fairly new to GIS and can't understand which negative length vectors R is talking about? Here is what I'm doing: I have a csv of lat/long locations of ...
1 vote
0 answers
607 views

Calculating nearest distance between points and Spatial Polygons in R? [closed]

So right now I have pretty large datasets, about 200,000 (lat,long) locations and a Large SpatialPolygonsDataFrame with a polygons list of length 428386 spread in a single city of around 450 square ...
1 vote
1 answer
1k views

How to build polygons from buffered points and merge overlapping ones using R?

I have a sample of 3 groups of points which are similarly spread within their groups. > pts x y [1,] 453067.5 364073.5 [2,] 453066.5 364072.5 [3,] 453068.5 364072.5 [4,] ...
  • 407
3 votes
1 answer
526 views

gIntersection error: linearRing not created

I am trying to do something relatively simple but with large shapefiles. I have a shapefile of protected areas in the USA: and watershed boundaries: I want to calculate the percentage and ...
0 votes
1 answer
111 views

Get intersects of indexed grouped polygons between 2 SpatialPolygonDataframes in R

I am testing 2 different methods (m2b & hmm) for classifying the movement behaviour of penguins to ultimately classify feeding behaviour from GPS points and from these create kernel polygons to ...
  • 1
0 votes
1 answer
1k views

Calculating euclidian distance in R between lines and points?

I have a large SpatialLinesDataFrame "o" (~500,000 roads) and ~3000 survey points "r", I'd like to calculate the distance to the nearest line for each survey point and extract relevant columns. My ...
0 votes
0 answers
1k views

Extract raster cell values by polygon field

I have a raster as a RasterLayer (raster) and a polygon layer (bound) with 38 individual polygons as a SpatialPolygonsDataFrame. I used the polygon to mask from a larger raster. Each polygon contains ...
1 vote
1 answer
587 views

Count number of points on a line in R

I have a SpatialLinesDataFrame and a SpatialPointsDataFrame. I want to calculate the number of points that fall on a line by a specific field in the lines data frame. Example: I have a river network ...
1 vote
0 answers
119 views

Divide irregularly shaped polygon into 3 equal parts

I have a polygon object of a transect line that I would like to divide into 3 equal parts that are one-after-the-other along the transect line. So far I have only been able to slice the polygon ...
1 vote
0 answers
97 views

Clipping polygons to existing plotting area

I have an existing plotting area onto which I want to add some polygons. In order to be sure the polygons' labels are displayed within the plotting area, I'd like to clip the polygons to this area so ...
1 vote
2 answers
207 views

Mismatch in area calculation using R and ArcMap?

I am new to spatial statistics using R. In this scenario, I am trying to calculate the polygons area with in a shapefile by usingrgeos::gArea and compared with ArcMap calculate geometry value. both ...
  • 267
0 votes
0 answers
141 views

reverse clip (erase) for spatial point data frame (R) [duplicate]

I am trying to recreate the suggestion from this link but instead of using it on a sPolygondf, to do the same for a sPointdf. All is well, but I get an unexpected output - when I do the difference ...
  • 276
0 votes
2 answers
629 views

Error with Intersecting Rasters and Lines in R

I'm trying to ''cut'' a spatial lines data frame object by a raster grid using R, raster::intersect(SLDF, grid) However, when I run this code I get, Error in as.vector(x) : no method for coercing ...
14 votes
2 answers
10k views

Reading Large Shapefile in R - alternatives to readOGR?

I am trying to read in a large shapefile using readOGR. The shapefile is 68837 features and 14 fields. It takes a considerably long time to read at >30min. I understand this is a well documented ...
2 votes
1 answer
4k views

Raster intersect and gIntersection give different results in R

I'm trying to clip a polygon shapefile (species distribution) with another polygon grid. The goal is to calculate the area occupied by the species within each grid cell. I was able to do it with ...
  • 73
3 votes
2 answers
585 views

Is their an equivalent of SpChFIDS for a spatial POINTS data frame?

This code: seattle <- spChFIDs(seattle.shp, paste("seattle.shp", row.names(seattle.shp), sep=".")) Results in this error: Error in (function (...
  • 980
3 votes
1 answer
4k views

Adding labels to spatial grid in leaflet using R?

Problem: I am trying to add grid cell labels to a leaflet map in R using shapefiles provided by TIGER/Line Census Data. The desired result is a leaflet map displaying the raster ID layer labelled ...
2 votes
0 answers
300 views

Calculating combined area of multiple polygons by counting overlapping area only once in R?

I'm using a shapefile in which polygons represent the geographic distribution of species. I need to calculate the combined range of several species sets, but the overlapping areas should be counted ...
2 votes
1 answer
562 views

Does the inputs extent have to be identical for raster::intersect to crop a RGB GEOTiff?

Background: I have a shapefile with multiple polygons over a large area and then I also have GEOTiff image files. I want to crop the TIFF files with each of the polygons. The problem is that when I ...
0 votes
2 answers
1k views

gUnaryUnion from rgeos packge fails randomly

I am using gUnaryUnion() function from the rgeos package to "melt" administrative regions into bigger units. At times I do get the expected result, and other times (seemingly randomly, so I suspect ...
1 vote
1 answer
977 views

Why does projection not affect answer calculated by rgeos::gArea?

I am trying to calculate the area of various polygons from a shapefile containing areas of land with mining rights is South Africa. Through this site and posts like: Understanding unit of area sizes ...
1 vote
1 answer
557 views

raster::intersect not working in R

I have a SpatialPointsDataFrame and a raster for a region. I would like to retain only those points that occur within the elevational limits of the raster. Unfortunately, no points are being filtered. ...
  • 1,302
2 votes
2 answers
140 views

Missing 1.6% of expected area after buffering SpatialPoints from vector of widths

Goal: I am buffering a random set of points (i.e. centroids) with different widths from a vector of predefined areas to make a random null model of polygons in a given extent. I am iterating through a ...
  • 23
0 votes
1 answer
897 views

spatial filtering data in R between two vectors

I have two shapefiles in R. One contains a vector of coastline (called coastline) and the other file of parcels (called parcels). I want to filter the parcel data for only those parcels within 1 mile ...
  • 1
11 votes
1 answer
3k views

Euclidean and Geodesic Buffering in R

In Understanding Geodesic Buffering, The Esri Geoprocessing Development Team distinguish between Euclidean and Geodesic Buffering. They conclude with "Euclidean buffering performed on projected ...
0 votes
0 answers
106 views

Reclass a landuse shapefile based on another shapefile using R

I have a landuse shapefile that I want to modify based on another shapefile. In this example I have three classes in landuse shapefile A. Say I'd know that everything within one of the small ...
  • 165
3 votes
0 answers
517 views

How to apply a rectangular buffer on spatial polygons in R/qGIS

I am trying to find a way to apply a rectangular buffer on my spatial polygon dataframe in R. At the end, I would like to be able to shrink my polygons by specified units on both sides. So far, I have ...
  • 117
1 vote
1 answer
758 views

Understanding unit of area sizes calculated via rgeos::gArea?

I'm interested in finding the unit for the obtained area size of the polygons without refererring to the externally available documentation. Example A suite of shapefiles is imported as follows: ...
  • 331
1 vote
0 answers
180 views

Creating an offset line with the rgeos package

I discovered the ST_OffsetCurve function in PostGIS, it is based on GEOS. I'd like to compute the same in the R software, using the package rgeos. I couldn't find a same-named function though. Has ...
  • 447
1 vote
2 answers
6k views

Simplifying and plotting polygons in Leaflet package in R?

I was finding the plotting of shapefiles very slow in R. After reading this (How to speed up the plotting of polygons in R?) I found all the tips were helpful for plotting in base R. The second one (...
  • 11
1 vote
0 answers
836 views

gIntersects with large spatial data

I am using the gIntersects function from the rgeos package to check whether a river layer (polyline) intersects with a species maps (polygons). However, it is taking ages to do the calculations, ...
1 vote
1 answer
41 views

Spatialdataframe from a multipoligon array column

i have a df with a character colum that contains an arrays of wgs84 coordinates. > head(df$Multipoint) [1] "[[11.038156,44.525654],[9.768989,45.620678],[7.923145,45.060564]]" ...
  • 409