Hot answers tagged

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 ...


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 ...


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


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::...


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


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.


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 = ...


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

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

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?). ...


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

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.


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

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

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 ...


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.


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

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 ...


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

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 ...


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

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, ...


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, ...



Only top voted, non community-wiki answers of a minimum length are eligible