Questions tagged [r-sp]

An R package for spatial data. Questions on spatial data might be better asked on https://gis.stackexchange.com

691 questions
4
votes
2 answers

Optimizing spatial query in R - crown-distributed biomass in forest

I am trying to calculate the area of tree crowns overlapping squared grid cells in a forest plot. Hereafter, a reproducible example: # A. Define objects require(sp) require(raster) require(rgdal) require(rgeos) require(dismo) …
Ervan
  • 174
  • 12
4
votes
3 answers

Fill raster holes in R or Grass GIS

Sample data x <- raster(x=matrix(data=1:36, nrow=6), xmn=-1000, xmx=1000, ymn=-100, ymx=900) x[c(8, 15, 16, 17, 22, 25, 26, 30, 31)] <- NA plot(x) The problem How do I distinguish (algorithmically) the holes in the raster i.e., the area bounded by…
shekeine
  • 1,445
  • 10
  • 22
4
votes
2 answers

Create a grid from regular sampling points in R

My knowledge of R is still pretty basic and I need help with something. I am trying to create a grid over a study area. I would like the cells of the grid to be centered on sampling points that I generated on a spatial polygon with the spsample…
user6094832
4
votes
1 answer

Spatial interpolation error using idw in R

I am trying to spatially interpolate a dataset of seawater pH by lat & long: sample<-read.csv(file="Station locations 2016.csv", header=TRUE, sep=",", strip.white=T) head(sample) Station lat long pH 1 B17 -23.49174…
Rebecca
  • 79
  • 9
4
votes
1 answer

Map Australian cities - R spatial

I want to draw a map of Australia and represent each city as a dot. Then highlight the cities with a high population (>1M) library(sp) library(maps) data(canada.cities) head(canada.cities) I have checked the sp package where this can be done for…
Jay
  • 357
  • 1
  • 3
  • 12
4
votes
2 answers

Plot ggplot polygons with holes with geom_polygon

There are questions out there about the fact that ggplot2 can't plot polygon shapes that have holes. That is because, if the order of points is not OK, the end graph looks bad, usually with clipping/trimming lines inside the donut shape. I have read…
natario
  • 24,954
  • 17
  • 88
  • 158
4
votes
2 answers

Detect if raster is within, without, or intersecting a SpatialPolygons object

I have many rasters for which I'd like to check if they are contain fully within a spatial polygon, fully without the spatial polygon, or intersecting with the spatial polygon (this could mean the polygon is fully within the raster, or the polygon…
Tedward
  • 1,652
  • 15
  • 19
4
votes
2 answers

Plotting Cities on a GADM map with R

I am trying to draw detailed maps of States/Districts of India with GADM data and using R. I have used the following code # Load required libraries library(sp) library(RColorBrewer) #…
Calcutta
  • 1,021
  • 3
  • 16
  • 36
4
votes
1 answer

R: Subsetting and plotting a SpatialPoints object

It seems this question has been asked a couple of times in different forms, but I could't find the right solution. I have a SpatialPoint object with several Polygons and would like to subset and plot one polygon using the slot "ID". Using the…
Ratnanil
  • 1,641
  • 17
  • 43
4
votes
1 answer

How to add a hole to a polygon within a SpatialPolygonsDataFrame?

I have a list of polygons in a SpatialPolygonsDataFrame and need to set one of them as a hole in an other. I've found in the help of set_Polypath how a hole can be defined on a newly created polygon but how to set the "hole" flag on an existing…
cmbarbu
  • 4,354
  • 25
  • 45
4
votes
3 answers

Using a simple for loop on spatial data

I'm sorry this is going to be a for loop 101 question. I am struggling to write a simple for loop to generate a table of distances between cities based upon longitude-latitude data locations <-read.csv("distances.csv") locations returns the…
RichS
  • 659
  • 12
  • 19
4
votes
2 answers

How to resolve warning messages (metadata object not found; SpatialLinesNULL class not exported) in my R package which extends S4 classes

This is my first question post on StackOverflow, so please correct any protocol errors I make. But I have already benefitted greatly from answers to many other questions on the site, so before I go further I would like to thank the community that…
Geoff
  • 596
  • 2
  • 11
4
votes
2 answers

Create square polygons from single centre coordinates and area in R

I am having issues plotting true to geographic extent pixels in R. the files come with a list of daily single coordinates and pixel size (area). There is also a Z element separate from this. The data structure looks this way: X <- c(1,3,6,7) Y <-…
Joke O.
  • 515
  • 6
  • 29
4
votes
1 answer

get an empty SpatialPolygonsDataFrame via subset?

I'm looking to subset a SpatialPolygonsDataFrame by an attribute, but I want to allow it to return an empty SpatialPolygonsDataFrame. If we are to treat objects of type SpatialPolygonsDataFrame like data.frames, as discussed here, we should be able…
emudrak
  • 789
  • 8
  • 25
4
votes
3 answers

How to plot a specific column from a SpatialPolygonDataframe with leafletR?

I would like to create a choropleth map using leafletR::leaflet. My data comes in a SpatialPolygonsDataFrame, and I would like to choose a specific column to be plotted. With sp::spplot, this is easy-peasy, since the argument zcol allows me to…
chamaoskurumi
  • 2,271
  • 2
  • 23
  • 30