Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sp]

R package with classes and methods to create and manipulate spatial data

0
votes
1answer
29 views

Measure distance for spatialLine in R returns bad value

I have this spatialLine in R: library(sp) library(maptools) library(SDraw) library(leaflet) x <- c(153.9, 152.67072,147.9879,144.25364,135.45557,116.03998,76.92708,45.10622,37.02522,36.76888,36....
2
votes
1answer
28 views

Calculate distance between buffer and geographic points for grouped subsets (and get tally)

The data I used can be found here. After importing my data, I select a subset of points (Nest2017 in column type) to create 30 m buffers around: library(dplyr) nests<-df %>% filter(type %...
0
votes
1answer
27 views

How to create and empty SpatialLinesDataFrame in R

I need to create and SpatialLinesDataFrame with a predefined structure (9 fields). I'm performing a function over a list of shp which I want to append to this empty spatiallinesdataframe. I already ...
1
vote
0answers
31 views

over function in R not working [closed]

I am trying to find the number of pubs for each London LSOA. I do this with London's LSOA boundaries shapefile which I imported as a SpatialPolygonsDataFrame and a SpatialPointsDataFrame of pubs ...
0
votes
1answer
39 views

Rearrange plotorder of SpatialPolygonsDataframe

I have a SpatialPolygonDataframe (loaded with readOGR) I want to plot in either tmap or leaflet. A lot of the polygons are overlapping, and the smaller polygons are completely covered by larger ...
0
votes
1answer
37 views

Simplifying a SpatialPointsDataFrame in ggplot world

I've been working on a map showing lines running across Europe. Each line is coming from a GPX file, parsed in like so: spdf <- readOGR("data/file.gpx", layer = "track_points") Now, if I plot the ...
0
votes
0answers
11 views

Overlaying points sampled from polylines with original polylines, null set returned, why?

I am using R to create sample points along a SpatialLines using spsample(), then I want to know which line feature each point lies on. When I use the over() to overlay the two layers, I get a null ...
0
votes
1answer
66 views

Legend Key for discrete values in spplot

I have a shapefile with various attributes. I want to plot the shapefile using `spplot'. I first read the shapefile A <- readOGR('myshapefile.shp') I am using the following command: p <- ...
1
vote
1answer
25 views

spplot R and order of panels for Lattice plots

I have a shapefile with various attributes. I want to plot the shapefile using `spplot'. I first read the shapefile A <- readOGR('myshapefile.shp') I am using the following command: p <- ...
1
vote
0answers
28 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 ...
0
votes
2answers
81 views

Extracting non-spatial data from imported KML file using R?

I have a KML file which was created using Google's My Maps. The original file can be downloaded here: Google My Maps Using R, I can import this using the "readOGR" function of the rgdal library ...
0
votes
1answer
32 views

Setting fill to a variable based on data within SpatialPolygonsDataFrame?

I'm currently on the cusp of getting done what I want to get done - but having a slight problem with referring to my data from within R's sp SpatialPolygonDataFrame object. The issue is how ggplot2 ...
1
vote
1answer
34 views

Using R to create a choropleth generated from lat/lon lists - with data generated internally

a friend referred me here as opposed to the regular Stack Overflow site, as this community maybe better able to help! My issue is largely with the syntax and framework of ggmap,ggplot, and the sp ...
0
votes
1answer
55 views

Connect points from two SpatialPointsDataFrames in R, considering the closest distance

I have two SpatialPointsDataFrames. In SpatialPointsDataFrame one (dat1) I have three points (A, B and C). In SpatialPointsDataFrame two (dat2), I have eight points with temperature measurements. I ...
1
vote
0answers
19 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
0answers
27 views

Swapping raster bands on disk efficiently using R

I have two raster files, each with RGB bands and an alpha layer. I would simply like to swap one of the raster's alpha bands for another, but to do so as efficiently as possible (these are very big ...
1
vote
1answer
63 views

Generating lines from coordinate file using R?

I have got an excel sheet with X and Y coordinates, actually Y is constant, since it is a straight line. I want a Shapefile with as many features as distance between points. I only get one line from ...
3
votes
1answer
71 views

sf appears to truncate a projection string

Curious how folks deal with this type of thing where sf appears to trim the spatial projection: library(sf) library(sp) nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) ...
5
votes
1answer
201 views

R spTransform polygon that crosses dateline

I have created polygons with CRS = UTM (see here), which I need to transform to latitude/longitude. Some of my polygons cross the dateline, which causes the transformation to create a polygon that ...
2
votes
1answer
46 views

How can / should sf spatial objects be translated (i.e. moved within same projection)?

Big fan of the sf (and previously, sp) spatial packages in R. I see spTransform and st_transform as methods to reproject a spatial object into a new space. However, I have a case where I have a ...
0
votes
1answer
126 views

Mapping data: error in classIntervals: var is not numeric

When executing the 'classIntervals' command I got the error while mapping data from Eurostat. library(rgdal) library(RColorBrewer) library(sp) library(GISTools) library(classInt) library(maptools) ...
1
vote
2answers
149 views

Creating lines between pairs of points

I have a sf dataframe table_sf as: Classes ‘sf’, ‘tbl_df’, ‘tbl’ and 'data.frame': 12251 obs. of 5 variables: $ ID : int 1 2 3 4 5 6 7 8 9 10 ... $ NOMBRE : chr "AL011900" "AL011900" "...
0
votes
2answers
151 views

Creating empty SpatialPoints or SpatialPointsDataFrame in R?

I have been trying to create an empty SpatialPoints in R but have not found the way yet. I have tried with this formula: SpatialPoints(as.matrix(data.table(x = numeric(), y = numeric()))) But it ...
1
vote
1answer
432 views

Kriging example with sf object

I am new to geo spacial analysis. I would like to learn kriging from a simple example. Say, we have four points with some z value. library(sf) library(gstat) library(tidyverse) dt<-tibble::...
0
votes
2answers
78 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 ...
2
votes
1answer
56 views

Find overlay between polygons excluding boundary

I want to find which polygons in a spatialpolygonsdataframe overlay each polygon in another spatialpolygonsdataframe. I have tried to use the function over from the package sp and it works fine... ...
0
votes
1answer
35 views

spTransform produces unexpected results

I am struggling to plot points using WGS84 co-ordinates on a map of the UK using the OSGB 1936 / British National Grid CRS. I'm using the rgdal package in R. Here is my reproducible example, using ...
0
votes
1answer
53 views

Find tree whose closest to the greatest variety of other trees using sf and R

Given a large spatial database of trees (600,000) find the tree that within radius r encircles the greatest variety of types of trees. Looking at an answer by andyteucher I've simulated some tree ...
1
vote
0answers
76 views

Length of the boundary intersection between two polygons in R

I am trying to find the length of the border shared by two polygons. I have run cleangeo on these shapefiles. There were no flags that came up. I have looked through several other posts on the topic ...
0
votes
0answers
204 views

plot coordinates as points with spplot in R

I want to do something that I thought should be relatively simple, but it doesn't seem to work... I have a SpatialPointsDataframe and a SpatialPolygonsDataframe. I want to plot all the points I have ...
0
votes
0answers
125 views

spTransform doesn't seem to actually reproject my data

I'm trying to create spatial point data and lay it over a shapefile. I'm starting out with simple LatLons, converting to sp using Coordinates(), changing the CRS to the same as the shapefile, and then ...
0
votes
0answers
24 views

Select one point in each polygon from spatialpolygonsdataframe and get the attributes from it to create a table with the coordinates

I have a spatialpolygonsdataframe with 3 attributes. I want to select one point in each polygon and get the attributes from it in order to create a table with the coordinates of the point, and the ...
0
votes
1answer
123 views

change ggmap to sp.: Create circle where radius represents distance (km)

I am trying to made multiple concentric circles of multiple radii in kms scaled to a map, similar this post was using the post here (ggmap: create circles). map.sp<-readShapeSpatial("C:file.shp") ...
0
votes
0answers
206 views

How do I count the number of intersections within one SpatialLines object?

I have one SpatialLines object where I would like to find and count the total number of intersections between linear features. I have tried using gIntersects() to determine whether lines have points ...
3
votes
1answer
35 views

determine whether location of fish is wrong based on boat speed and time of last capture

I have a series of coordinates for fish caught from a boat at different datetimes and different trips. How do I determine whether the coordinates of a fish are likely to be incorrect (e.g. due to ...
2
votes
1answer
109 views

sf equivalent of R maptools package's SpatialLinesMidPoints

I've been moving most of my workflow to using the sf package in R, and I'm trying to find the equivalent to the maptools package SpatialLinesMidPoints function - I've used this function frequently ...
1
vote
1answer
353 views

Converting projected coordinates from bbox into long/lat using R?

I have a DEM file in QGIS and would like to import the the satellite image for the same region into R. According to QGIS, the CRS used in the DEM file is: Layer Spatial Reference System +proj=...
0
votes
1answer
134 views

r-Mapview non reponsive with large simple feature dataframe

Im trying to visualize a large sf dataframe with around 1000 rows containing linestrings with mapview::mapview() in R. Unfortunately a warning comes up when I perform the command: mapview(data....
3
votes
2answers
172 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 (...
1
vote
1answer
759 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 ...
0
votes
0answers
46 views

Obtain a sp object from a KML+PNG file in R

I have a bunch of files to deal with in R. I have KML files, with a point (and associated coordinates), and an associated PNG file, representing a shape. I need to convert them in a sp (or sf) file in ...
2
votes
1answer
85 views

Orphaned Holes after Mercator-Projection in R

In R I want to apply the Mercator-Projection to a SpatialPolygonsDataFrame before plotting it with ggplot. I dont want to use ggplot::coord_map() since the map is supposed to be the "canvas" for a ...
3
votes
2answers
2k views

Create spatial polygon grid from spatial points in R

I am trying to recreate a map in R. I need 2 by 5 degree grid cells across the contiguous United States, but plotted in Albers Equal Area. The result is a grid with curved lines and slightly variable ...
8
votes
1answer
2k views

equivalent of sp package's point in polygon / overing using sf

I am migrating code from sp package to the newer sf package. My previous code I had a polygon SpatialDataFrame (censimentoMap) and a SpatialPointDataFrame (indirizzi.sp) and I got the polygon cell id (...
0
votes
1answer
248 views

Why did spTransform fail here?

I'm trying to convert a map I found here into lat/lon compatible with another data set I created from Google Maps lat/lons. From the directory with that .shp file, I run: library(rgdal) SG = readOGR(...
2
votes
1answer
1k views

Package sp : coordinates function error no numeric matrix

I am trying to use coordinates function from sp package to transform my data in spatial data. I made sure I deleted all the NAs values and that all my data is numeric, however, i still get the same ...
1
vote
2answers
916 views

How to use rbind with SPDFs when the number of columns of arguments do not match?

I'm looking to use rbind to combine the SPDFs of different European countries. However, I'm looking to use SPDFs of different levels of regions. Unfortunately, I'm getting the following error: ...
0
votes
2answers
245 views

ggplot2 adding extra polygons

So, I'm working with a dataset of polygons generated at different levels of sensitivity to error from a citizen science project. I have been trying to visualize how my sensitivity threshold changes ...
2
votes
1answer
448 views

Error While Converting UTM data to Lat-Long Coordinate

I have a a dataset of Vancouver,BC where Coordinate values are projected in UTM Zone 10 . Now I can convert it using spTransform by the following piece of code and looks like the it correctly ...
1
vote
1answer
1k views

Converting Spatial Points to Neighbours List using R?

I am trying to convert some spatial points into a listw object to run the moran.mc function on my data. The data are not adjacent but the points cluster in spatial patterns. Here is how I have tried ...