Questions tagged [r]

Statistical computing language and software environment.

Filter by
Sorted by
Tagged with
8
votes
3answers
3k views

Remove clumps of pixels in R

I would like to remove isolated pixels (or clumps of pixels <9) from my raster image. library(raster) # create some raster data r <- raster(ncols=12, nrows=12) set.seed(0) r[] <- round(runif(...
8
votes
1answer
6k views

Raster spplot legend: how to add a title beside it

After studying for a while how to create a chart from a raster object, I got almost everything I needed except to add a title to spplot's legend. What I tried: to use mtext("XXX (m)", side=4), ...
8
votes
3answers
974 views

Identification of consecutive points within a specified buffer

I have a point file, hourly relocations of an animal, and I want to be able to place a buffer around each point and calculate the number of subsequent points which are within the buffer zone. I am ...
8
votes
1answer
10k views

Using resample vs. aggregate & extend in R to have rasters of matching resolution and extent

I have two rasters of different resolution and extent: > res(Elevation) [1] 0.002083333 0.002083333 > res(Ann_precip) [1] 0.008333333 0.008333333 > extent(Elevation) class : Extent ...
8
votes
3answers
3k 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 ...
8
votes
4answers
17k 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 ...
8
votes
2answers
2k views

Simple way to detect/select border polygons of a shapefile

I am looking for a simple way to detect/select border polygons of a shapefile. Border polygons are here polygons that are not completely surrounded by other polygons i.e. polygons located at the ...
8
votes
1answer
4k views

R raster Package Moran's I interpretation

I am using raster package to calculate the local Moran's I . The example gives the range of Moran's I between - 1 to 2.47. On my own data I have see the value range -3.070423 - 7.228558 How can Moran'...
8
votes
3answers
5k views

How to get count of non-NA raster cells within polygon using R

I've been running into all sorts of issues using ArcGIS ZonalStats and thought R could be a great way. Saying that I'm fairly new to R, but got a coding background. The situation is that I have ...
8
votes
1answer
3k views

How can I use roads from OSM data in R?

I need to use the roads to compare GPS positions to verify that they are no errors in the data. I downloaded the map.osm from a site that have information of City of Rome and had it transformed to ...
8
votes
1answer
3k views

Generating grid shapefile in R?

I have the following shapefile of a 10x10 degree latitude/longitude grid that I created in QGIS. I can read it into R using the rgdal package. Grid<-readOGR(".","GridShapeFile") It has the ...
8
votes
1answer
6k views

How to Export a Shapefile as KML Using R

All, I have exported an ESRI shapefile (polygon) to KML using R, but the resulting layer shows only the outer extent of the polygon. How can I fill in the area with a color? Any help is greatly ...
8
votes
1answer
2k views

Novel ways of filling in missing values in a raster

I am looking for robust ways to fill in missing values in some rasters. They all have a single layer. Missing values consist of single pixels to medium sized patches. Rasters are around 1000 x 1000 ...
8
votes
1answer
6k 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 ...
8
votes
3answers
330 views

spatial and spatiotemporal analyses

I have a dataset that consists of 247 mosquito traps placed in fixed positions and sampled weekly for 23 weeks. I also have dengue disease incidence data (indexed to home address) during the same time ...
8
votes
3answers
1k views

Calculating spatial lags per year in R

At the moment I am having some difficulties with calculating a spatial lag in R. I know how to calculate the lag in space-wide format but am unable to do it in long form, i.e. have repeated ...
8
votes
2answers
2k views

How do I call external files in Python Geoprocessing Service?

I have created a Python script which calls an R script and then reads the output back into Python. I can run this tool in ArcGIS Desktop (10.2.1) and it works fine. When I publish as a geoprocessing ...
8
votes
1answer
90 views

Visualising most likely direction of migration given points with ages using R?

I have a question about how best to visualise the predicted direction of migration given a set of points with estimated ages. Imagine I have a set of geo coordinates, representing communities. For ...
8
votes
1answer
800 views

How to get rpy2 for QGIS on OSX?

I am a new QGIS user, have installed QGIS on a Mac running Snow Leopard OSX 10.6.8 following all the instructions. QGIS seems to work well for everything other than when I boot up I get the message "...
7
votes
2answers
7k views

How to calculate area of 1 x 1 degree cells in a raster

I have a simple array (not geo-referenced in any way) in Matlab (which is not a language I know a huge amount about...so I can export it to other languages if needed) which has the dimensions 180 x ...
7
votes
3answers
1k views

Atmospheric correction algorithm in Python or R for Landsat 7 ETM+

I am looking for an algorithm which can be tuned in python or R for atmospheric correction for Landsat 7 ETM. Searching Google I have found only a few algorithms in ENVI or ERDAS which are not ...
7
votes
3answers
489 views

Best way to make a fake hillslope?

Anyone ever have to make a fake hill slope? or a fake digital elevation model (DEM)? What are the best methods for doing so? For more specifics, suppose I wanted to make a fake hill slope, that was ...
7
votes
2answers
2k views

How parallelize the extract function for raster files in R?

I´m trying to parallelize a simple "extract" operation like this: UseCores<-detectCores() -1 cl<- makeCluster(UseCores) registerDoParallel(cl) all.test.poly_period.test<-extract(stack.ts, ...
7
votes
3answers
10k views

Leaflet output is grey

I would like to implement leaflet in shiny with R. I try to go with the simple examples I found online: library(leaflet) library(ggmap) somePlace <- ggmap::geocode("Vienna") # Information from ...
7
votes
2answers
5k 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 ...
7
votes
2answers
3k views

Transforming geostationary satellite image to lon/lat

The ICARE Data and Services Center distributes the SEV_AERUS-AEROSOL-D3 product in HDF5 format (http://www.icare.univ-lille1.fr/archive/?dir=GEO/MSG+0000/SEV_AERUS-AEROSOL-D3.v1.03/). The main ...
7
votes
1answer
2k views

Given a Lat and Lon, identify if the point is over land or ocean?

In R, what is the quickest way to identify if a point is over land or ocean? e.g. for: set.seed(0) lat <- runif(10, -80, 80) lon <- runif(10, -180, 180) points <- expand.grid(lat, lon) How ...
7
votes
2answers
3k views

Creating a raster of the residuals of a regression between two rasters

I am trying to create a raster of the residuals of a regression between two rasters. i.e. I would like to carry out a regression of one raster against another of the same extent and plot the residual ...
7
votes
1answer
8k views

Plotting map resulted from kriging in R

I want to plot a map weighted by prices. I got a data frame of latitudes, longitudes and prices: > str(data) 'data.frame': 1253 obs. of 3 variables: $ lon : num 11.2 11.1 11 11 11.3 ... $ ...
7
votes
2answers
4k views

Strange spatial interpolation results from ordinary kriging

I'm using Ordinary Kriging to interpolate a set of spatial data. I'm working on different sets which represent different days of measurement. I get good results, apart from one specific set. Will post ...
7
votes
3answers
4k views

Per-pixel (statistical) calculations on a raster stack using GDAL

In R, it's relatively trivial to perform per pixel calculations based on a raster stack (e.g., get std.dev for each pixel on a 12 layer GeoTIFF). Unfortunately, the speed is less than desirable when ...
7
votes
1answer
10k views

Saving (converting) raster objects in R?

I want to save my raster plot that produced with R to ArcGIS raster (.img, .tif and ASCII) file.
7
votes
2answers
2k views

Split a line when it crosses a polygon in R

This should be a simple problem but I can't seem to find a solution. I have a line which crosses several polygons and I want to split it into multiple lines at the intersection of each polygon using ...
7
votes
1answer
3k views

ggmap: clip a map

I'm using ggmap to grab Washington DC and I have a shapefile that I downloaded from here: library(ggplot2) library(ggmap) library(maptools) dc = get_map(location = 'DC', zoom = 12) nhbds = ...
7
votes
3answers
4k views

Using sampleRandom() from large raster without NA values in R?

I have a number of vary large rasters which need to be randomly sampled with the return value being a matrix of x, y, and value. The raster package sampleRandom(raster,n, na.rm=TRUE, xy=TRUE) will do ...
7
votes
2answers
298 views

Calculating block statistics from land cover raster using R?

I have a raster (5 x 5 m resolution) representing land cover. Each cell contains a integer value (from 1 to 10) representing a total of ten land cover classes (e.g. 1-forest; 2-agricultural areas; 3-...
7
votes
1answer
9k views

How to create a continuous scale with distinct/custom color and value breaks with ggplot2 map

As stated in the title, I'm trying to create a continuous scale with distinct color and value breaks within the ggplot2 package in R. I'm using some dummy code to illustrate my problem: library(...
7
votes
6answers
4k views

Estimating river Channel Width using Python/ArcGIS/MATLAB/R?

I am trying to estimate the river channel width from digitized polygon or poly-lines shapefiles. To do so, I converted poly-line shape files to points.shp at regular intervals (at 1 cm). Later, I ...
7
votes
2answers
5k views

R function for Thiessen Polygons

For a point data set with temperature data I have, I want to create their Thiessen Polygons in R. So far, the only algorithm I have found is that of Carson Farmer (http://carsonfarmer.com/2009/09/...
7
votes
5answers
10k views

Reproduce raster with same extent, and same number of columns and rows?

I have two raster A and B. A and B have the same grid size but different extent. How can I make A have the same number of columns and rows, as well as the spatial extent of B?
7
votes
2answers
1k views

Is it possible to run an R script on a layer in QGIS?

I'd like to run an R script on a layer loaded in QGIS (to rotate a set of points created there using the Vector:Research Tools:Regular Points tool). I thought ManageR might work but cannot get it ...
7
votes
2answers
974 views

Robust Zonal stats in R and QGIS

Comparing results of zonal statistics in QGIS and R, I noticed that the results they both yield do somehow differ. Manually checking, I also found that both QGIS and R seem to partly produce erroneous ...
7
votes
1answer
7k views

Create a circle of defined radius around a point and then find the overlapping area on a shapefile

My use case is related to calculating the area of a polygon in a shapefile that is covered by another polygon. Specifically, I want to do the following: Create circles that have a 100m radius, from ...
7
votes
1answer
6k views

How to obtain openstreet API key for nominatim (r)?

I wanted to use r package nominatim for my program written in R. I tried to run very simple example osm_search('Cracow University of Economics'), however I got the following error: Please provide a ...
7
votes
3answers
14k views

Importing several GeoTiff files into R?

I think that must be a "simple" way to import several Geotiff files into R instead of copy and paste n times Rfd<-readGDAL() and then save them as individual objects. I found the following code in ...
7
votes
1answer
7k views

Finding clusters of points based distance rule using R? [duplicate]

I have some points that I need to divide into groups based on clusters of points: x <- c(-1.482156, -1.482318, -1.482129, -1.482880, -1.485735, -1.485770, -1.485913, -1.484275, -1.485866) y <- ...
7
votes
3answers
2k views

Kriging with barriers in R?

I wonder if there is a way to interpolate xyz points in a raster within certain bounds using R? In ArcGIS this is called interpolation with barriers. I wonder if there is something similar in R? I ...
7
votes
2answers
4k views

Open JPEG2000 (Sentinel 2) in R

Is there any way I can open Sentinel 2 JPEG2000 file (.jp2) using R? Or more specifically with the {raster} package in R? I keep getting the Error message that .jp2 is: not recognised as a ...
7
votes
1answer
2k views

Difference between raster() and readGDAL()?

I am new in working with rasters and after having trouble working with them i'd like to know the difference between those two import functions. for example i did this library(raster) s<-...
7
votes
2answers
5k views

How to write every raster from a list of rasters?

I have created a list of rasters - "norm" and run a several loops. Now I would like to write every created raster from "norm" (containing 1 layer) into one raster, having its specific name. # I can ...