Questions tagged [sp]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
428 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
4k 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
2k 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
4k 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
2k 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
1k 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
2k 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[...
8
votes
1answer
5k 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
547 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
1k 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
4k 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
433 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
1k 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
15k 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
629 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
270 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
778 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
4k 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
125 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
283 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 ...
3
votes
1answer
628 views

Define cellsize from spsample in meters

I use a shapefile to create a regular grid using spsample, from sp package. Two problems here: (1) I would like to define the size of my grid cells in meters, but I've checked the documentation of sp ...
1
vote
1answer
955 views

How to remove zonal anisotropy from directional variogram using gstat in R?

I have a dataframe named seoul315 contains the 107 data of PM10 concentration at 1 march,2012,5.00 am. please, download. I have tried to plot semi-variogram for kriging bt the following code: library(...
1
vote
1answer
87 views

Spatial representation of Data in R?

I'm a new users of spatial analyses packages in R. I have created a SpatialPolygonsDataFrame which contains a number of rectangular polygons that i named "Square1" to "Square64". Until now there is no ...
3
votes
1answer
2k views

Find intersections between spatial lines and points using R

This question assumes that I'm using R with the sp and rgdal packages installed. Now that I have a set of spatial segments of class SpatialLinesDataFrame (called 'segmentData') and a set of spatial ...
2
votes
2answers
5k views

How to find the coordinates of the intersection points between two SpatialLines objects (or SpatialLines and SpatialPolygon edges)

I am try to find the co-ordinates of points where SpatialLines cross the edge of a SpatialPolygon. I have searched and searched, but can only find results such as over which tell me which lines cross ...
5
votes
3answers
1k views

Dissolving/Unifying Ill Behaved/Irregular Polygons in R

I'm working on a project involving bringing together multiple subjects circling difficult to find parts of an image. The output from users is pretty awesome. Cool, right? However, what I want is to ...
1
vote
0answers
741 views

Using R to find attributes of spatial neighbors, especially with big spatial polygon data frames [closed]

I have a specific question that leads to a more general one. First, the specific: I have an analysis involving census blocks and point level exposures (see here), where I'm doing work with ~200,000 ...
4
votes
4answers
1k views

Lines on reprojected sp objects with Mollweide projection

I'm having an odd problem such that when I reproject maps to a Mollweide projection in R using sp, I get additional lines stretching across the globe. What is going on here, and do you have any ...
1
vote
2answers
505 views

Aggregate SpatialPoint to form SpatialPolygon

Is it possible to convert SpatialPointDataFrame to SpatialPolygonDataFrame by some kind of generalization or aggregation function in R. how can i form polygons from points of similar color/classified ...
2
votes
2answers
2k views

R apply function in turn to each subset of a spatialPolygonsDataFrame

I'm trying to get the area of all the polygons in a SpatialPolygonsDataFrame: parcProj. library("rgeos") gArea(parcProj[2,]) works fine but: apply(parcProj,1,gArea) or sapply(parcProj@polygons,...
12
votes
2answers
3k views

How does spatial polygon %over% polygon work to when aggregating values in r?

I'm working on an environmental epidemiology project where I have point exposures (~ 2,000 industrial hog operations - IHOs). These IHOs spray on nearby fields, but the feces water droplets and smell ...
0
votes
1answer
830 views

Add Polygons to SpatialPolygons via loop / iteration using R?

Just out of interest: I'm creating a SpatialPolygon (R with package "sp") with a number of Polygons within. Is there a way to loop this task? I'm doing it manually as follows. The Polygons consist of ...
3
votes
1answer
1k views

constrain random points with a polygon in R using sp library

I have a map of London's waterways, which I've grided into a raster dataset to enable me to measure proximity to water from randomly generated points. What I'd like to do please is to constrain the ...
1
vote
1answer
1k views

resize map and add points to it using R

I am working with spatial data UK. The map is plotted here. I want to resize the map and make it bigger and clear! here is my code LA <- readOGR(dsn =".", "infuse_dist_lyr_2011_clipped") plot(...
2
votes
1answer
334 views

How to handle duplicate id's when using the as_sp function in the R osmar package

Sometimes when I want to convert a subset of ways from an osm file loaded with the osmar package, I run into an error complaining about duplicate row names. The following code run on this file in ...
8
votes
1answer
5k views

Distance to nearest point for every point same SpatialPointsDataFrame in R

I have a SpatialPointsDataFrame that I'm working with in R. I want to add a new vector to the dataframe that contains, for every point, the distance to the nearest other point in the ...
9
votes
2answers
7k views

buffer and union in R without reducing to a multi-polygon

I would like to perform a spatial overlay to identify the polygon within which a set of points fall. However I first want to buffer and dissolve the polygons, such that points falling anywhere within ...
2
votes
1answer
819 views

Incomplete intersection area using gIntersection in R

I have two SpatialPolygonsDataFrame, one of them is the deforested area in the Amazon and the other is the city of Vila Rica, which is in the same region. I would like to calculate the total ...
5
votes
3answers
1k views

How can I snap one set of points to another in R

I would like to snap one set of points (SpatialPoints* objects) to another in R using Euclidean distance. I'm hoping for a function like maptools::snapPointsToLines. The attributes of the points don'...
4
votes
2answers
9k views

Inserting a zoomed-in plot with a full scale plot in the sp package in R

I am using the sp package in R to plot sampled points along a river. However, I would like to zoom in to a sampled area of the entire river, and plot this zoomed area on the full length of the river. ...
3
votes
1answer
2k views

Extracting data, not colors, from geotiffs in R

I'm an experienced R user new to GIS, but finding my way. I've recently run into an issue that I haven't been able to find any satisfactory documentation on (but could just be searching poorly). I'm ...
1
vote
1answer
1k views

Adding a grid and selecting random cells from spatial polygon in r

I have a fairly similar question to this: Similar Question I am working with a map of Denmark or more a subset of a Denmark Map. This file comes from the Global administrative areas site GADM site ...
8
votes
4answers
16k views

Join CSV file to shapefile

I wanted to join a CSV file to a shapefile. When I identified a field to facilitate the join, e.g., map <- spChFIDs(map, as.character(map$ID)) it returned Error in spChFIDs(SP, x) : lengths ...
10
votes
3answers
16k views

Counting number of points in polygon using R?

I have two classes sharing the same CRS (Latitute and Longitude): bolognaQuartieriMap: a SpatialPolygonDataFrame containing data of a city boroughts. crashPoints: a SpatialPointsDataFrame containing ...
2
votes
0answers
388 views

spatialpolygons heatmap in R - NAs in grey?

I have a spatial polygon data-frame and I am trying to plot a heatmap via spplot. It's a map of Europe and the values for the heatmap are in a column of the data-frame. Plotting it works fine but I ...
1
vote
1answer
84 views

R SP library: identicalCRS and parameters in different order

The following returns FALSE: library(sp) points <- matrix(rnorm(30, 50, 10), ncol=2) proj1 <- CRS("+proj=utm +zone=10 +datum=WGS84 +ellps=WGS84 +units=m +no_defs +towgs84=0,0,0") proj2 <- ...