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 ...
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")
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)
Error in ...
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, "...
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:
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:
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.
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.
# Compute distance to Seine river
dist_seine <- st_distance(seine_int, fr_departments_grid_int)
# Only minimum ...
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)]
the following worked out for me:
# 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 ...
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)
Simple feature collection with 10 features and 0 fields
geometry type: POINT
bbox: xmin: 1 ymin: 1 xmax: 10 ymax: 10
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 = "...
If I understand correctly, you are trying to subtract 1000 from the x coords. Here is how I would go about it:
p1 <- rbind(c(1000,1000), c(1000,2000), c(2000,2000), c(1000,1000))
pol_geom = st_sfc(pol, crs = 4326)
# Getting the coordinates of pol_geom
coords = st_coordinates(pol_geom)
new_coords = coords[,1:2]