Questions tagged [sp]

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

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

points2grid error: (points,tolerance,round) - grid has empty columns/rows in dimension

I have seen answers to this on R-sig-geo, but I am still unclear on the solutions provided in different forums. Below, I am trying to convert a dataframe to a raster that can later be used in ArcMap (...
2
votes
1answer
599 views

Building multiple extents as polygons from lat/long list values in R

I have a loaded .csv table in R containing xlongl, xlongr, ylatb, ylatup values (EPSG:4326). Each row indicates with its combination of lat/long the extent of one rectangled polygon. > mydata ...
1
vote
1answer
38 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]]" ...
2
votes
1answer
431 views

Reproject global latlong into UTM slices

I'm working with a global shapefile in R that is latlong projected. I'd like to reproject it into the appropriate UTM projection for individual zones. But, I'd like to chop it up into those zones ...
2
votes
1answer
795 views

Removing attribute from SpatialPointsDataFrame with spdplyr::select() in R

I'm trying to drop columns/attributes from a SpatialPointsDataFrame, using spdplyr, like so: library(sp) library(spdplyr) x <- c(15.2, 15.3, 15.4, 15.5, 15.7) y <- c(50.4, 50.2, 50.3, 50.1, 50....
8
votes
3answers
5k views

Join spatial point data with multiple polygon data using R

I want to spatial join with SpatialPolygonsDataFrame and SpatialPointsDataFrame. get only one point data within multiple polygons, under the code. sp::over(meuse, srdf) Some points data into ...
6
votes
1answer
3k views

Creating empty Polygons or SpatialPolygons in R?

I'm working on a project where I'm looking at overlap in users circling an area in an image. Esentially, I make a SpatialPolygonsDataFrame where each user gets one row. Some users don't select ...
0
votes
1answer
612 views

How to change the coordinate scale of SpatialPolygons in R?

I hope to plot SpatialPolygons on satellite raster images. The coordinates of SpatialPolygons are converted to be in the range of x = [0,1] and y = [-1,0]. I know that this overlay plot can be done in ...
4
votes
1answer
907 views

Lapply function on raster iterating through SPDF polygons in R

I have a raster DTM and a SPDF. I'd need to mask a different elevation interval of the DTM within each overlaid polygon. I tried a for loop to iterate through the polygons, but as one might expect ...
2
votes
1answer
316 views

Error mapping categorical vector from spatial points data frame in R

I have had trouble mapping categorical points on to a map using rworldmaps or the maps package in R. The original data was Aragonite saturation levels in the ocean on an .adf file which was in ...
1
vote
0answers
45 views

Confirming accuracy of spatial match?

As a follow up to Correctly setting up CRS systems for the NUTS (Eurostat) geographies and Doogal's data? I have spatially matched a set of files, one with lat/long coordinates for postcodes ...
0
votes
3answers
659 views

I want to do SpatialLines programatically

This is my dataframe: df <- data.frame(ID = rep(1:100, each = 2), x =runif(200, 10, 90), y = runif(200, 10, 90)) For each ID I need to create SpatialLines, I haven't had good luck. I think I ...
2
votes
3answers
821 views

What are the coordinates on my rectangle of the closest point to a polygon in R?

I have a non-overlapping extent rectangle and a sample lake polygon. I can measure the distance from the rectangle to the polygon but I want to know which point on the rectangle is the closest to the ...
3
votes
1answer
2k views

Subset and sort a SpatialPolygonsDataFrame object by one variable

I took a sample of a spatial polygon dataframe with 2256 elements using: valdata <- ref_10[sample(ref_10@data$ID, length(ref_10)/3),] now I would like to sort my new spatial dataframe by my ID-...
3
votes
2answers
586 views

Seeking routing libraries in R?

I'm trying find libraries for R that would find the shortest route between two locations, given a SpatialLinesDataFrame representing the road network. All I could find was stplanr, which delegates the ...
1
vote
1answer
327 views

Export shapefile of a flow map with arrows indicating their direction in R

How can I insert arrows on flows and export flows map with arrows indicating their direction in R? I know that I can use the arrows command of the maptools library to "print" an arrow in line with ...
2
votes
1answer
1k views

How to subset a SpatialPoints object to get the points located on each side of a SpatialLines object using R?

I need to subset the SpatialPoints object to get the points located in the left or in the right side of the SpatialLines object (red line, see figure below). This is the code example in R: # Load ...
4
votes
2answers
2k views

Calculate distance of points - SpatialPoints object - along a path - SpatialLines object - using R

I have a SpatialPoints object and a SpatialLines object. I want to calculate all the distances from the start point (first coordinate of the SpatialLines object) to every point in the SpatialPoints ...
3
votes
1answer
4k views

Plotting bubbles on top of OpenStreetMap in R

I can plot points on top of OpenStreetMap like this: library(OpenStreetMap) library(rgdal) subscr<-data.frame(lat=c(10.1237,10.2161,10.2993), lon=c(59.7567,59.7527,59.6863), pop=c(58,12,150)) ...
4
votes
2answers
1k views

How to sort points from a SpatialPoints object over a SpatialLines object according to line direction using R?

I have a very big dataset of points (SpatialPoints object) over a line (SpatialLines object). I need to sort these points following the line direction. Note: the number of points and coordinates ...
8
votes
2answers
5k views

Re-projecting raster in R: gives warning that projected point(s) not finite?

1. Question I have encountered a warning using the projectRaster() function in the raster package in R. A full reproducible example is pasted below. Warning message: In rgdal::rawTransform(...
2
votes
1answer
521 views

R and osmar : How to merge two adjacent osm files with overlapping nodes and ways?

Due to a problem loading large osm files in osmar, I have decided to split my osm file in small parts, load them individually and the merge them. I currently face two problems : The code splitting ...
4
votes
2answers
382 views

“Downsample” a dense grouping of points onto a sparse grid

I have a SpatialPointsDataFrame with thousands of datapoints in a relatively small geographic area. The points are grouped around regions of physical measurements and are hence irregularly spaced: ...
3
votes
1answer
868 views

Understanding resolution when rasterizing in R?

I'm creeping into building surfaces - useful for a number of public health projects - and can't seem to make sense of what's happening with the resolution and raster building process to get what I ...
0
votes
1answer
1k views

Convert SpatialPolygonsDF boundaries to SpatialLinesDF keeping information on polygons

I have a SpatialPolygonsDataFrame and I need to convert polygon boundaries into a SpatialLinesDataFrame retaining the attributes of the 2 polygons The structure of the SPDF looks like this 'data....
0
votes
1answer
1k views

Don't understand error : Error in if (nchar(projargs) == 0) projargs <- as.character(NA) :

When I run two different scripts from examples (which seem to work where I took them from) I get an error in both cases. Something seems to be wrong in my general set up or something. But I have no ...
1
vote
1answer
86 views

Merge external table with GIS SpatialLinesDataFrame file in R for attribute table

I have a SpatialLinesDataFrame file named "Sldf" which lacks attributes for each line (see table of sample data below). I have a separate data.frame (from a .csv) named "fsub" with attributes that I ...
5
votes
2answers
918 views

How to efficiently convert origin-destination coordinates into lines in R

Reproducible example to show what I mean: # Create origins and destinations odf = data.frame(fx = 1:5, fy = 1:5, tx = 0:4, ty = rep(1, 5)) The challenge is to convert this into straight lines ...
1
vote
1answer
379 views

“Hole” argument ignored in call to Polygon function

I am working with a dataset consisting of a list of coordinates for a set of polygons. Some of these polygons are holes. However, the dataset does not follow the convention of listing the coordinates ...
0
votes
2answers
603 views

mapping with spplot

This question should be easy! I am using spplot for visualizing a map with suitable results. However, I would like to know how to set the limits of z, because the values are not being discriminated. ...
1
vote
1answer
5k views

Using 'sp' method to subset SpatialPointsDataFrame with SpatialPolygon returns error in parLapply()

I have numerous very large data sets of ship tracking data (Automated Information System; AIS). These are originally in a file geodatabase and can be downloaded here (this is a smaller file for ...
1
vote
2answers
3k views

Remove lines from inside a polygon (shapefile) in r

I have this code which prints the Galápagos Islands. But inside the islands, there are lines that I want to get rid off. How is this possible in R? library(rgdal) library(ggplot2) URL <- "https:/...
5
votes
3answers
6k views

Converting SpatialLinesDataFrame to SpatialPointsDataFrame in R?

In R I have a SpatialLinesDataFrame (for example from a coastline shapefile) and I want to convert it to a SpatialPointsDataFrame. I want to keep all the vertices from the line shapefile to become ...
2
votes
1answer
3k views

How to use latitude/longitude with projection in R [duplicate]

I am using the SABS dataset: http://nces.ed.gov/surveys/sdds/sabs/ In particular, let's say I am using the "SABS_1314_High" layer. (This provides the school attendance boundaries for many US school ...
2
votes
2answers
2k views

R use data in SpatialGrid to create SpatialPoints

I am trying to make a grid of points to overlay on a raster of vegetation of Kansas, U.S.A. My idea is to use the points as a sort of centroid for the raster pixels, which are 30m resolution. When I ...
2
votes
1answer
3k views

How to update selected rows of spatial data frame in R

I have a SpatialPointsDataFrame read via rgdal::readOGR require(rgdal) my_sp_layer <- readOGR(dsn="my_dsn", layer="my_layer_file") # select rows using col_attrib column my_sp_layer@data[...
10
votes
1answer
9k views

Remove certain polygon from SpatialPolygonDataFrame

I am using R maptools library to parse the shapefile into a list of polygons. The function readShapeSpatial shp <- readShapeSpatial("<path to my shapefile>") gives me a ...
0
votes
2answers
659 views

SpatialPointsDataFrame too slow FOR LOOP

I've run into a small problem where my for loop has been running for 3.5 hrs+. I have a Geodataset in SQL Server with a field called Shape that stores co-ordinates in geometry data type. Firstly, I ...
1
vote
2answers
2k views

Automatically convert from latlon to planar

I work with library(sp) and points in latitude longitude, with this projection: proj4string(pts) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") But some functions (such as sp::spample) require ...
1
vote
1answer
5k views

Convert xy spatial points into spatial lines

I have produced a SpatialPoints object (named v3) in R from the function gIntersection (package rgeos). The SpatialPoints object v3 has the following structure and is represented by red points on the ...
1
vote
2answers
711 views

Attaching data to SpatialPolygonsDataFrame

As this is a more GIS related question (and maybe solvable with ogr/gdal functions I'm not aware of), I try it here first, although working with R. What I want to achieve: I have some data, based on ...
4
votes
1answer
2k views

buffer in spsample for distance between randomly selected points

I wanted to know if there is a way to add a buffer in the function spsample in the sp package. I am randomly selecting points within 28 polygons and would like to specific a minimum distance the ...
16
votes
3answers
22k views

Merge a list of spatial polygon objects in R

I have a list of spatial buffers (30000 buffers) that I built with the function lapply: buff.pts <- lapply(1:nrow(pts.prj), FUN=function(l){ buff <- gBuffer(pts.prj[l,], width=1000) ## 1km ...
2
votes
0answers
928 views

Adding a custom color scale for a sp.points layer to levelplot() legend

I'm wondering how I can add a customized color palette that I used to display a sp.points layer in a call to levelplot (lattice plotting) in the rasterVis package in R. I used a function that Dave X ...
1
vote
0answers
351 views

Spplot SpatialPolygonDataFrame and SpatialGridDataFrame

I have to plot in the same graph something like this: Then, I have elements from SpatialPolygonDataFrame class and others elements from SpatialGridDataFrame class. When I try to plot them in the same ...
2
votes
3answers
2k views

Use function spplot

Does anybody know how to plot with "spplot" fuction two elements of diferents classes?. One element from "SpatialPolygonDataFrame" class and other from "raster" class.
4
votes
2answers
6k views

Add a point on a spplot in R

I have to add a point on a existing spplot in R. I need it only for a visual purpose. I have the coordinates of the point, but I don't know how to change the code in order to add the point. This is ...
2
votes
1answer
4k views

When aggregating points by polygons with sp::over function, how do I include attribute data from both the points and polygons? [duplicate]

Data: Zipped ea.ml1 shapefile can be found here, and the country outline can be downloaded here at the GADM site. I've been using the Ethiopia ESRI shapefile. Branch locations are here. I have a ...
3
votes
1answer
199 views

Two rows of data.frame for one polygon

I am new in R and I am facing a problem. I have a list with many SpatialPolygonsDataFrames. Some of them are like this example This is a SpatialPolygonsDataFrame. My "problem" is that the data.frame ...
4
votes
4answers
350 views

Representation of spatial lines with altitude

Is there any R data structure that supports spatial lines that include height information? I'm looking for something like SpatialLinesDataFrame with support for altitude in the lines. Associating a ...