Search code examples
rgispostgisgeoserverwms

Generate colored map layers with R for Leaflet


I work on a personal project, witch stands to collect and store weather data (temperature, CO2, Humidity ...) in a MySQL database (I've tried PostgreSQL with post PostGIS) from some working weather stations.

In front-end, I'm using a Laravel based web application with Leaflet to show mapped data (Laravel request the database and return GeoJSON files to Leaflet).

To make a better visualisation I decide to do some interpolation to cover missing data then generate a colorated layer for leaflet to show.

In first step I did some R scripting using IDW and Kriging interpolation algorithms, ploting the result in R was looking good, but the problem is that i need to generate shape or geoJSON file to pass it to Leaflet instead of images.

After some research I realized that i need to work with a layer server like geoserver(WMS) and to Postgres instead of MySQL ...

In this point I still so confused what to do.

Note: I need to my maps appears like those in this site: http://www.irceline.be/

please help, and thanks in advance.


Solution

  • You can implement everything on the R side like this:

    library(mapview)
    library(sp)
    library(htmlwidgets)
    
    ## point data
    data(meuse)
    coordinates(meuse) <- ~x+y
    proj4string(meuse) <- CRS("+init=epsg:28992")
    
    ## grid data
    data(meuse.grid)
    coordinates(meuse.grid) <- ~x+y
    proj4string(meuse.grid) <- CRS("+init=epsg:28992")
    gridded(meuse.grid) <- TRUE
    
    ## map it
    m <- mapview(meuse.grid, zcol = "dist") + meuse
    m
    
    ## save it
    saveWidget(m@map, file = "/path/to/file.html")
    

    meuse would be your points, meuse.grid your gridded data resulting from interpolation.