How to create spatial data using shiny and leaflets - r

I want to create spatial data (shp data, gpkg data, geojson) using shiny and leaflet.
For example, in QGIS, I want to implement the function of Create Layer> newVectorLayer New> Shapefile Layer ... with shiny.
The geometry type I want to create is a polygon.
Therefore, I want to hit a pin on the map and create spatial data with the hit pin as the outer circumference.
Please let me know if you have a reference web page.

Related

Click on a spatialpolygons map and get details in R

I would like to be able to click on a specific location (cell polygon) and store details in order to investigate the relation between some of my variables.
Is it possible with shapefile?
I can not export the spatialPolygonsDataframe (dput does not work)
the spatialPolygons structure with each grid cell representing the polygons.
:

How to store polygons created by addDraw in variables as sf data

How to store polygons created by addDrawToolbar in variables as sf data
By using addDrawToolbar, I was able to draw polygons on the map. Is it possible to store this polygon in a variable as sf format?
In the subsequent processing, I intend to combine (st_union) with the existing polygon (Administrative district data).
Therefore, I am looking for a way to save it as sf format data.
If you know or have a web page that you can refer to, please let me know.

Plotting points onto a JPG raster map in R

I have a fictional map and want to plot points onto it.
The map is a fictional map from a fantasy book, so has no spatial reference.
The points will show where events from the book have taken place.
I essentially wish to create an interactive map, that displays main events from the book on the fictional map.
Similar to the one created for Lord of the Rings here
http://lotrproject.com/map/#zoom=3&lat=-1315.5&lon=1500&layers=BTTTTT
Would this be possible in R and if so, how?

Changing the extent and resolution of raster layers in R for successful stacking

I am trying to create a species distribution model in R. I have created raster layers in ArcMap and have imported them into R. They cannot be stacked unless the extents are exactly the same and they all have the same number of rows and columns.
However, when I alter these factors to successfully stack them they lose all their values and my stacked data frame is just filled with NAs.
Does anyone know how I can alter the extent and resolution of my raster layers so they can be successfully stacked -- so I can then attach environmental info to presence points.
Cheers
One way to do this is to choose a raster that has the projection and extent that you want and use that as a template for the others
For example, if you have rasterA and rasterB. You can use projectRaster() to make a new version of rasterA with the same extent and resolution as rasterB. You should then be able to stack new.rasterA & rasterB.
new.rasterA <- projectRaster(rasterB, rasterA) # define the projection and extent
r.stack <- stack(new.rasterA, rasterB) # add them to a raster stack object
I had the same issue and I solved this in arcgis by snapping each raster to a mask of my study area.
This can be done by clicking geoprocessing -> environments -> processing extent - then select a layer you want to snap to in the snap raster box. I did this before I extracted (clipped) each layer and it worked perfectly. You can check the extent in properties when you are done for each layer you do to double check before you upload them into R.

How to create interactive online map with contour (filled) plot layer?

I would like to create an online interactive map with filled contour plot layer like the ones can be seen on openweathermaps (I would like to use my own data for the plots).
What I need is also similar to the Leaflet heatmap (heatmap.js) but without dynamically changing the colors and the extent of the graphical objects (as in case of heatmap.js). Let's call them static heat maps.
I would like to know which mapping code/library can be used to produce such maps.
I am really newbie to these things, so please bear with me.
I tried Leaflet but did not find any plugin which would create filled contour map layers (static heatmap). I created the following map with Leaflet where the rectangles are geojson polylines and the color is based on some assigned values to every rectangle (elevation)
my leaflet attempt
The problem with this approach is that if higher resolution (smaller and more rectangles) is needed the site would really slow down.
I checked OpenLayers but did not see any similar examples.
I have the data in a matrix format:
Lat; Long; Value
.
.
Values are given in every gridpoints.
(if needed I would convert into other formats, like in case of the above attempt into geojson format)
The data is static, would be saved on the server.
So what I basically want to accomplish is a site where some spatial data is represented as filled contour map (static heatmap) and it is plotted over a map.
Here is my solution to the problem using open-source programs and free, online service:
(1) Processing the data in a GIS program. I used QGIS. I interpolated my data which is in grid points to get a high resolution raster map.
(2) Save the post-processed raster map as a georeferenced *.tif image.
(3) Import the image into TileMill. Remove the basemap and keep only the image as the only layer (style it).
(4) Export the 'map' from TileMill as MBTiles. This will save numerous *.png files (tiles) corresponding to different zoom levels. These are the same type as google or openstreetmap use for their online maps.
(5) Create a free account at Mapbox and create a new map project. Upload the MBTiles created by TileMill (can be directly uploaded from it). Style it.
(6) Use the Map ID corresponding to your created project to embed the map into html sites, e.g. the javascript code:
// Provide your access token
L.mapbox.accessToken = 'Mapbox will generate this for you';
// Create a map in the div #map
var map = L.mapbox.map('map', 'username.mapid', {
minZoom: 5,
maxZoom: 10
}).setView([47, 20], 8);
Example hosted on Mapbox
Sample image(I do not how long will the above link live):
In retrospect, the question would have been better fit to GIS stack exchange.

Resources