Skip to content

Instantly share code, notes, and snippets.

@dandelany
Last active April 13, 2021 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dandelany/6c39ec7183276705768bd121a1f16a93 to your computer and use it in GitHub Desktop.
Save dandelany/6c39ec7183276705768bd121a1f16a93 to your computer and use it in GitHub Desktop.
Process for generating CNC maps using QGIS

Data Download

DEM (terrain, raster) data

  • Get DEM files from National Map download tool
  • Set Area of Interest: Selectable Polygon -> Select... -> US State or Territory
    • then click a state on map to select it
  • Or Set Area of Interest: Map Extent/Geometry -> Click Extent -> Draw a rectangle on map
  • After area selected, search for:
    • Elevation Products (3DEP) -> 1/3 arc-second or 1 arc second
  • Click search products
  • Download TIF Files manually OR...
    • Click TXT icon to download text file with list of data URLs
    • remove all lines that are not tifs manually or with regex: ^((?!.tif$).)*$\n
    • install and open uGet (https://sourceforge.net/projects/urlget/)
    • File -> Batch -> Open TXT File
    • Use "Mark By Filter..." to filter & only download TIF files

State outlines

Data Transformation

Split state outlines (vectors) into separate files

  • The file cb_2018_us_state_500k has all states - need to split into several files
  • Create QGIS Project
  • Add vector layer -> cb_2018_us_state_500k.shx (state outlines downloaded above)
  • Vector -> Data Management Tools -> Split Vector Layer & set NAME as unique ID field

Merge state DEM files

  • Drag all the TIF files downloaded above into QGIS
  • Raster -> Misc -> Merge
  • Select all layers, set High Compression and save to file

Reproject to final CRS

  • Decide on a projection - ESRI:102003 is good for US states (Albers Contiguous US)
  • Reproject merged raster layer in QGIS: Raster -> Projections -> Warp (reproject)
  • Enter desired target CRS

Downscale raster

  • If size is unmanageable, downscale at this step
  • (ie. after reproject, ideally, because reproject loses resolution)
  • Raster -> Raster calculator -> modify # of rows/columns

Raster terrain exaggeration

  • DEMto3D supports exaggeration up to 10x
  • If you want more than that, precalculate it here with raster calculator
  • Raster -> Raster Calculator -> "layer@1" * 5 (for 5x exaggeration)

Reproject vector layer

  • Add state outline vector to project
  • Vector -> Data management -> Reproject
  • set target to same projection as raster

trim terrain tiles to vector outline

  • Add state file from above as a new vector layer in same project as raster data
  • Raster -> Extraction -> Clip by Mask layer
  • Select mask (state vector) and raster (combined terrain) layers, set high compression, save to file

Export as image

  • Open clipped file from above in new QGIS project, or hide/remove other layers
  • Confirm your CRS setting (USA_Contiguous_Albers_Equal_Area_Conic or desired projection)
  • Set project background color to black
  • Set terrain layer min to 0 (sea level) or whatever you want
  • Project -> Import/Export -> Export map to image

Merged/Clipped raster to G-code

Option 1 - PixelCNC

  • Can import raster data directly into PixelCNC and generate G-code
  • However, as of now (v1.43) PixelCNC does not have a post-processor for Easel
  • Coming soon in v1.44
  • Could use standard GRBL post with different G-code sender (Candle, UGS)

Option 2 - DEMto3D to Fusion 360 to G-code

  • Install QGIS DEMto3D plugin using QGIS Plugin Manager
 // didn't take detailed notes on using DEMto3D - but this is my preferred method
 // read the DEMto3D docs and tweak settings to your liking
 // consider terrain exaggeration - anything more than ~6-7x exaggeration looks implausibly spiky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment