New answers tagged

0

You can use functions in the raster package to avoid this problem library(raster) b <- brick("akhil.nc", var="hur") b


0

Have a look at my answer to this question: How to speed up raster to polygon conversion in R? In there, I have briefly described how to install Gdal on windows. If you had extra questions feel free to comment here.


1

1) It will be vastly easier if this works: library(raster) olr <- raster("t2m_50N70N.nc", varname = "var167") tm2 <- brick("t2m_50N70N.nc", varname = "var179") plot(olr[[1]])) ## first of nlayers(olr) bands If this kind of mapping of the data is what you are after, I'd re-focus and work on learning raster. You'll also need ncdf4 package installed....


1

I had to face the same errors when trying to import PostGIS geometries into R. I could manage to iterate readWKT() through the polygons with the help of the apply-function-family: All credits to: https://spacetimecereal.com/2015/01/13/loading-postgis-geometries-into-r-without-rgdal-an-approach-without-loops/ Connect to PostgreSQL DB: drv <- dbDriver("...


1

GDALinfo is a function in rgdal, and unless you compiled rgdal yourself against that installation of GDAL it won't have HDF4 - presumably you have the CRAN Windows binary, which isn't built with HDF (and some others). gdal_translate is not a function in rgdal, but you don't say what package/s you are using, so I don't know what that is (gdalUtils?). ...


3

Rather than looking for a specific package for raster time series you could look for functions for smoothing, and then use these with the calc function in the raster package. Here is an example for Savitzky-Golay: http://stackoverflow.com/questions/37843942/smoothen-rasterstack-using-the-savitzky-golay-sgolayfilt-signal-in-r/37846229#37846229


1

I seem to have resolved one issue, but another still persists so I will ask in another question. I think there were conflicts with 32-bit and 64-bit installs. Since ArcGIS runs python in 32-bit and I am on a 64-bit machine, initially, I assumed I would install the 64-bit builds for GDAL. When I installed the 32-bit versions and their python binaries, ...


1

I'd assumed the prefix path was correct because I didn't need to set it in the console version. Using print app.showSettings() showed me this was a false assumption. When running from R, it printed as: Application state: QGIS_PREFIX_PATH env var: Prefix: /usr/lib/R/bin Plugin Path: /usr/lib/R/bin/lib/qgis/plugins Package Data Path: /usr/...


1

Here is an approach. Some example data: library(dismo) # points n <- 10 set.seed(123) xy <- cbind(runif(n, -150, 150), runif(n, -50, 50)) # polygons p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20)) p2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0)) p3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45), c(-...


1

This is not really a question for GIS.SE but I would recommend to use strptime(). var <- strptime("10:30", "%H:%M") You can return the value as time: format(var, "%H:%M") # [1] "10:30" For further question just regarding R I would recommend stackexchange.


0

The buffer tool from the raster package lets you work with both rasters and Spatial* objects. To to create a buffer for a single point: library(raster) pt <- SpatialPointsDataFrame(data.frame(525000,9250000), data = data.frame('Pt1'), proj4string = CRS("+init=epsg:32736")) pt.buf <- buffer(pt, width = 500, ) It returns a spatial polygon: > ...


1

In the future, please ask a good question by providing some example data as below: library(raster) cds <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45)) lines <- spLines(cds, cds-20, cds+20, attr=data.frame(Lid=1:3)) p1 <- rbind(c(180,20), c(140,-55), c(10, 0), c(140,60), c(180,20)) p2 <- rbind(c(-10,0), c(-140,-60), c(-160,0), c(-140,55), c(-...


1

One option would be to look at a multivariate regression in R. Let us assume that you have create a data.frame with your density, lat & lon. Then you can do something along these lines (rough outline taken from Quick-R): # Multiple Linear Regression fit <- lm(density ~ lat + lon, data=DensityDataFrame) summary(fit) # show results # Other useful ...


4

One approach that our amazing intern recently used, which turned out really well for us: Fill the DEM Calculate flow direction on the filled raster Accumulate the flow of the flow direction output Do a Con operation to set all cells with an accumulated flow over some threshold (that is meaningful for your geographic area and for your cell size) to be 1 and ...


2

The combine function (which is used in foreach) does not store the relevant components into the final randomForest object. See ?randomForest::combine: The confusion, err.rate, mse and rsq components (as well as the corresponding components in the test component, if exist) of the combined object will be NULL. But the predict method returns OOB ...


1

Updating R and sp to the released versions will resolve this. It was caused by a change in R's behavior on what nchar(NA) returns: see the help file of ?nchar, argument keepNA.


0

OP here, I can now answer my own question thanks to Rainer Stuetz :) The call was made from behind a proxy, and without proper login / password. Therefore, the proxy returned an HTTP page instead of an XML one, which in turn could not be parsed as XML (obviously). You can diagnose the problem with a call to osmar:::get_osm_data.api(api, box). If it does ...


2

Here's just one idea: Compute the voronoi diagram of the stations -- this is a partitioning of your city into polygons (also called Thiessen Polygons) where exactly 1 station is in each one. From here you can compute the area of each of the polygons. There are a couple R packages that will compute these polygons: see R function for Thiessen Polygons


0

As some commenters alluded, SQL is a good option for expressing rather complicated sets of constraints. The sqldf package makes it easy to use SQL's power in R without needing to set up a relational database yourself. Here's a solution using SQL. Before running, I had to rename your data's interval columns to startTime and endTime because the name from is ...


2

It would be helpful if you posted your code. There is now a special merge function that is called for sp class objects that addresses the sorting issues with base merge breaking the slot relationships. You can bring up help for the sp version of merge using ?sp::merge. The slot id should be the same as the rownames in the @data slot. As such, you can use ...


2

In your case, it is not necessary to create polygon buffers for your points. The raster::extract function has a buffer argument that will do exactly what you are after. library(raster) r <- raster(ncol=36, nrow=18) r[] <- 1:ncell(r) xy <- SpatialPoints(cbind(-50, seq(-80, 80, by=20))) extract(r, xy, buffer=1000000, fun=mean) For future ...


2

I found the solution a couple of seconds ago, it had to do with the column order.I changed the numbers into a decreasing sequence (first these were completely mixed). Now I get the correct output.


1

Accessing R symbols in packages that are syntactically invalid in Python can be done through __dict__. Here: r_as = methods.__dict__['as'] See the documentation for rpy2: http://rpy2.readthedocs.io/en/version_2.8.x/robjects_rpackages.html#importing-r-packages


1

I answer this assuming you'll be using rgdal to read the shapefile in as a spatial dataframe. Instead of worrying about cutting, you can make a join using the tigris package. You can use the function geo_join() to combine a spatial dataframe and a dataframe. To only include the subset of postal codes from the dataset, set the "how" option to "inner" to get ...


0

Found a work around, store the R function in a separate function: robject.r('''setAs<-function(rasterAs){ asRaster <<- as(rasterAs, "SpatialPixels") }''') Retrieve the function from the R global environment and call it: setAs = r.globalenv['setAs'] SpatialPixels = setAs(layerRaster)


0

A vectorized form would be MyFun <- function(x, y) { i <- x < 0 x[i] <- abs(x) * y x[!i] <- x * y x } But it might be more efficient (and certainly less error prone) to do MyFun <- function(x, y) abs(x) * y res <- overlay(x, y, fun = MyFun) Or simply res <- abs(x) * y


0

Under ArcMap: Toolbox\Multidimension tools\Make netCDF Raster Layer: Raster layer will appear in TOC of map document In ArcMap-document TOC: Right click the Raster layer entry and convert to e.g. TIFF-file. I do not think that you can convert straight away to ESRI-GRID-format Toolbox\Conversion tools\ToRaster\Raster to other format (multiple): choose ESRI ...


1

You could use ifelse as an alternative to if and else blocks in a function. You can nest multiple statements in an ifelse and if you are trying to vectorize a problem, it is much cleaner. Note that an absolute abs statement on a zero value still returns zero so, I just used a very small number as a constant. library(raster) x <- raster(nrows=100, ...


0

You do not seem to be trying the relevant function arguments to test if the eps argument is defined as euclidean distances. That said, it may help to look at the help for the fpc::dbscan implementation as the help is a bit more informative and the model specification/parameters almost identical. The dbscan package implementation is just an optimized version ...


1

There are many packages for computing DBSCAN: dbscan, fpc and others. Which do you use ? The unit of EPSG3301 is meter. From Wiki Books: Data Mining Algorithms In R/Clustering/Density-Based Clustering The elements of the database can be classified in two different types: the border points, the points located on the extremities of the cluster, ...


0

I have problem like this : source('G:/2016/WBS3/tes/teschl.r') Loading required package: sp rgdal: version: 1.1-10, (SVN revision 622) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.0.1, released 2015/09/15 Path to GDAL shared files: C:/Users/Acer/Documents/R/win-library/3.3/rgdal/gdal ...


0

One way is to draw in Orthographic and reproject. It's not very generalizable though, and I'm unsure how accurate this is at 1000skm scales. (Looks good for this example compared to Manifold's geog-circle). ## centre in longlat llcentre=c(0,60) library(rgdal) ocentre <- c(0, 0) t=seq(0,2*pi,0.005) r=2500000 ## this must be in the units of the map ...


0

An important caveat that you omit is, what OS are your using? The function may be parsing the path in a specific way. Have you tried your path without double separators? gdalUtils::gdalinfo("C:/Users/mydirectory/R/MOD13A3.A2015335.h13v03.005.2016007192527.hdf") You should also make sure that you are running the most current version of R and gdalUtils. ...


3

You could just coerce the extent into a SpatialPolygons object and then use "spTransfrom". library(sp) ( e <- raster::extent(-5559753, -4447753, -4447852, -3335852) ) e <- as(e, "SpatialPolygons") sp::proj4string(e) <- "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs" e.geo <- sp::...


0

Looks like this can be done using the raster package. There is a projectExtent function that returns a warped raster object. Then just need to extract extent(). extent(projectExtent(raster_object,"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")) Thanks to mdsumner's comment!


4

There are an extremely large number of approaches to clustering, and your question is not answerable, short of writing a textbook describing all possible methods. Therefore, the question I will answer is What information would help me select a clustering method? What is your problem domain? Or, to put it another way, what do the points represent? It could ...


2

This is because a hole should always belong to a non-hole - i.e. you cannot have a Polygons where the only ring is a hole. Note that the hole argument is not ignored by Polygon(), it is overridden and the coordinate order reversed by ?Polygons() - "In Polygons, if all of the member Polygon objects are holes, the largest by area will be converted to island ...


2

Here's a way, use the raster package. (If you really have data for this it's probably not a great idea to grid in longlat and then resample to Mollweide - but depends on your purpose). R library(raster) library(maptools) r <- raster(surface) data(wrld_simpl) prj <- "+proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84" w <- spTransform(wrld_simpl, CRS = ...


0

You can do the analysis described in your post without converting the raster to a polygon. Use the raster::extract function to extract the raster values to each polygon. You can then use lapply on the resulting list object with table to return cell counts of each class. For area of each raster class, you just use a standard conversion of cell area and counts....



Top 50 recent answers are included