New answers tagged

0

This is not the workflow that I would use, but not far off. I think, in this case, that your best option for coercing "mare" to a raster is fasterize::fasterize, which incidentally is a great name for a package. You will need a template raster to run fasterize, which you can produce using raster like you did above. Simply create a raster with the same ...


1

Combine your two shapes into a list, then name them with layer.name. This is listed in their advanced section of documentation mapview(list(path,places), layer.name = c("path","Points of Interest"))


1

Your sp object is a MULTIPOLYGON - lets break it into POLYGON objects and see if there's something afoot: > sp2 = st_cast(sp$geometry,"POLYGON") > length(sp2) [1] 40 Its 40 separate POLYGON units. At this point plot(sp2) works and looks fine. Now transform those 40 units and plot: > sp2t = st_transform(sp2, 4326) > plot(sp2t) Error in ...


1

You've opened an SQLite database connection, which is the "vanilla" SQLite database without the spatial functions which are implemented in SQLite "loadable extensions". If you know where the spatialite extension module is you can load it in. On my system, its in /usr/lib/x86_64-linux-gnu/mod_spatialite.so, hence I can do: > res <- dbSendQuery(con, "...


0

Here is an example of how you can do this, I'm using the significant urban areas shapefile from the Australian Bureau of Statistics. Firstly this is what my pnts variable looks like: x y <dbl> <dbl> 1 -34.92 138.62 2 -34.93 138.58 3 -34.95 138.52 4 -27.63 152.71 5 -27.57 153.01 6 -33.9 150.73 7 -33.92 150.99 And here is my code: ...


2

You can use the sp.kde function in the spatialEco package for a weighted or "unweighted" kernel density estimate (KDE). However, a kde on polygon centroids is not valid because the polygon sets represent areas of various sizes.


2

The answer was actually straightforward. With a MULTILINESTRING object, a distance is computed between each raster cell of the grid and each segment. If interested into the closest distance, the minimum distance has to be extracted. Therefore: # Compute distance to Seine river dist_seine <- st_distance(seine_int, fr_departments_grid_int) # Only minimum ...


1

Compute distance from grid points to shape border. Border is converted to linear geometry because distance from point to polygon for points inside polygon=0. > d = st_distance(grid, st_cast(shp,"MULTILINESTRING")) Select grid points further than 10km from border: > gridin2 = grid[d[,1]>units::set_units(10,km)] Gives: > plot(shp$geometry) >...


1

the following worked out for me: library(rgdal) library(geosphere) library(rgeos) # crs projection for standardizing: crs.geo <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") SP <- spTransform(SP, crs.geo) rintersect3 <- spTransform(rintersect3, crs.geo) rintersect3$info <- 1:nrow(rintersect3) # for matching row number of each polygon # adding ...


3

Short answer: st_coordinates. Starting with a data frame: > pts = data.frame(1:10,1:10) and making a spatial points data frame like yours: > spts = st_as_sf(data.frame(pts),coords=1:2) > spts Simple feature collection with 10 features and 0 fields geometry type: POINT dimension: XY bbox: xmin: 1 ymin: 1 xmax: 10 ymax: 10 epsg (...


1

you have to pass the parameter "show.legend = 'polygon'" to geom_sf(); since you are not "mapping" a variable to the polygon's fill, but using 4 geom_sf() calls, you have to adjust scale_fill_manual to refer to the colors and polygons, first referring them on the geom_sf call: geom_sf(data = level3, aes(fill = "A"), alpha = .5, show.legend = "...


1

Simple example: library(sf) nc <- st_read(system.file("shape/nc.shp", package="sf")) nc1 <- st_transform(nc[1, ], 32617) nc2 <- st_geometry(nc1) - c(1000, 0) plot(nc1[0], axes = T, reset = F) plot(nc2, add = T, col = NA, border ='red') See sf Vignette #3's section on Affine Transformations for more tricks.


2

If I understand correctly, you are trying to subtract 1000 from the x coords. Here is how I would go about it: library(sf) p1 <- rbind(c(1000,1000), c(1000,2000), c(2000,2000), c(1000,1000)) pol <-st_polygon(list(p1)) pol_geom = st_sfc(pol, crs = 4326) # Getting the coordinates of pol_geom coords = st_coordinates(pol_geom) new_coords = coords[,1:2] ...


Top 50 recent answers are included