Mapping

Show Only ...
Maps - Photos - Videos

The Real Powers of R Statistical Language for Map Making

There are two major — and distinct ways that the R Statistical language is a powerful tool for map making — either paired with QGIS or without.

When you should use R Statistical Language with QGIS

If you are looking for a more complicated map, one of the best ways to process and wrangle map data, Shapefiles and other geographic data is within R Studio. Much of the prep work for making a map is best down in R as you can type commands quickly, pipe and mutate data, dissolve and buffer shapes easily with R and the sf package. No mouse clicks required. It’s easy to save repeated processes in an R script.

Then once the data is ready to be mapped, export it to a geopackage or shapefile, usually which I store in the /tmp directory, as I don’t need to save the data as I can quickly re-create it with the R script. From there, I can load it into QGIS, then make the map look pretty, manipulate the styling and labeling in QGIS.

When you should use R Statistical Language Alone

R with ggplot is good for simple maps, and those you want to run off frequently with updated data, and aren’t concerned with pretty labeling. Basic, clear thematic maps where labels aren’t needed or the automatic labeling of ggrepel can be tolerated due to relatively few label overlaps. In many cases, for basic maps, ggplot makes a cleaner output, lines things up better and produces better output out of the box then what you might quickly throw together in QGIS from exported data in R.

Why I don’t use R scripting in QGIS directly

While it’s possible to do R scripting in QGIS, I would rather work in RStudio with it’s preview windows, code completion and other tools rather the use QGIS. It’s just easier to do the data wrangling and manipulation of shapefiles in RStudio, and then export to a Geopackage and load the final data in QGIS.

Creating Digital Surface Models GeoTIFF Using National Map Downloader, LiDAR Point Clouds and PDAL πŸ—Ί

Creating Digital Surface Models GeoTIFF Using National Map Downloader, LiDAR Point Clouds and PDAL πŸ—Ί

Find LiDAR Point Clouds on the National Map Downloader: https://apps.nationalmap.gov/downloader/#/

Select Find Elevation Source Data (3DEP) – Lidar, IfSAR

Search for LiDAR Point Cloud (LPC)

Click Export all results as a TXT file and save to a directory.

Then run this Unix command on the text file to download point clouds:

cat data.txt | tr -d '\n' | xargs -d '\r' -I {} wget -c -nc '{}'

Next create a pipeline.txt for pdal with the classification (For DSM, 1 are unclassified points like buildings and treetops, while 2 are ground points, if you want a DEM, you can also make them this way too with Classification of 2:2):

{ 
    "pipeline": [
        { 
            "type": "readers.las"
        },
        {
            "type": "filters.range",
            "limits": "Classification[1:1]"
        },
        {
            "gdaldriver":"GTiff",
            "resolution": 1.0,
            "output_type": "max",
            "type":"writers.gdal"
        }
    ]
}

Next convert the point clouds into digital surface model (GeoTIFF), you can use this shell command with xargs to go over each LAS file, using the above pipeline:

ls *.laz | xargs -I {} basename {} .laz | xargs -P3 -I {} pdal pipeline pipeline.txt --readers.las.filename={}.laz --writers.gdal.filename={}.tif

The above command can be somewhat slow depending on how many LAZ point clouds you need to go through and your selected resolution. -P3 sets the number of parallel process (3) which can help speed things up a bit.

Now we have the digital surface models raster that can be used in QGIS for hillshade for 3D.

Build a virtual raster (dsm.vrt) for easy loading into QGIS rather than loading separate files.

gdalbuildvrt dsm.vrt *.tif