Difference between revisions of "GeoPackage Tips"

From Tuflow
Jump to navigation Jump to search
Line 132: Line 132:
 
== Increment a Layer ==
 
== Increment a Layer ==
 
This tool saves a copy of the active layer with a new filename. To use the tool:
 
This tool saves a copy of the active layer with a new filename. To use the tool:
:*Select the layer to increment in the Layers Panel.
+
<ol>
:*Click on the 'Increment Selected Layer' symbol from the TUFLOW Plugin toolbar.<br>
+
<li>Select the layer to increment in the Layers Panel.
 +
<li>Click on the 'Increment Selected Layer' symbol from the TUFLOW Plugin toolbar.<br>
 
<br>
 
<br>
 
:[[File:increment_layer.png]]<br>
 
:[[File:increment_layer.png]]<br>
 
<br>
 
<br>
 +
</ol>
 
There are three options for incrementing a layer:
 
There are three options for incrementing a layer:
 
<ol>
 
<ol>

Revision as of 10:04, 5 September 2023

Page Under Construction

Introduction

This page includes tips and tricks for working with the GeoPackage Vector format (supported since the TUFLOW 2023-03-AA Release). GeoPackage is a widely supported, open GIS database format, built upon an SQLite database (data is stored as a single file with the extension .gpkg).

This database format has several benefits, including:

  • Multiple GIS layers can be stored in the single file database. For example, all GIS input layers can be stored in a single GeoPackage file.
  • Supports spatial indexing, greatly reducing loading and viewing times making it much faster to work with in GIS packages.
  • Faster to write from TUFLOW than the shapefile format.

For more information see the 2023 Release Notes.

Database Organisation

There are many ways to organise model inputs when using GeoPackages. This allows modellers to decide how they structure their inputs files, for example some options include:

  • a single database for an entire project,
  • separate database for an existing or developed case, or
  • separate databases for each type of input (e.g. elevation, materials, culverts).

To define the database for TUFLOW to refer to the following command is used:
Spatial Database == /path/to/database

This command can be repeated multiple times throughout control files, TUFLOW will change which database it looks to based on the last time the above command has been referenced.

Referencing a GeoPackage Database

To reference a GeoPackage Database:

  1. To specify a GeoPackage Database for subsequent inputs, use the following command. A new database can be specified multiple times throughout control files, TUFLOW will change which database it looks to based on the last time the above command has been referenced. This command can be used in the .tcf, .ecf, .tbc, .tgc, .qcf, .tef.
    Spatial Database == gis\2d_zsh.gpkg ! Sets GeoPackage Database
    Read GIS Z Shape == 2d_zsh_L ! References the 2d_zsh_L layer from 2d_zsh.gpkg
    Spatial Database == gis\2d_mat.gpkg ! Sets GeoPackage Database
    Read GIS Mat == 2d_mat_R ! References the 2d_mat_R layer from 2d_mat.gpkg
  2. To specify a GeoPackage Database for the entire model, add the following command to the beginning of the .tcf. This database will then be the default for all inputs in all control files. There is no need to reference the database again in the other control files.
    Spatial Database == <path_to_database>

Note: The commands are localised to their relevant control file with the exception of the .tcf which acts as a global command (local spatial database will take precedence). If no database is referenced in the other control files, the database referenced in the .tcf will be used.

Referencing a GeoPackage Layer

There are many ways to reference a GeoPackage Layer. The following commands can be used in the .tcf, .ecf, .tbc, .tgc, .qcf and .tef.

  1. To specify a table in a .gpkg, use ">>":
    Read GIS Z Shape == gis\2d_zsh.gpkg >> 2d_zsh_L
  2. To specify more than one table in a .gpkg in the same command line, use "&&". This is similar to "|", however there is no need to reference the database again.
    Read GIS Z Shape == gis\2d_zsh.gpkg >> 2d_zsh_L && 2d_zsh_P
  3. "&&" can be used in conjunction with "|":
    Read GIS Z Shape == gis\2d_zsh_R.gpkg | gis\2d_zsh.gpkg >> 2d_zsh_L && 2s_zsh_P
  4. To specify a .gpkg file path only. It will assume the table name is the same as the .gpkg database name. The following are equivalent:
    Read GIS Z Shape == gis\2d_zsh_L.gpkg
    Read GIS Z Shape == gis\2d_zsh_L.gpkg >> 2d_zsh_L
  5. To specify all the tables in a .gpkg, use the command "USE ALL" with ">>":
    Read GIS Z Shape == gis\2d_zsh.gpkg >> USE ALL

If the GeoPackage Database is specified to use for subsequent inputs, the commands will become:
Spatial Database == gis\2d_zsh.gpkg ! Sets GeoPackage Database

  1. To specify a table:
    Read GIS Z Shape == 2d_zsh_L
  2. To specify more than one table in the same command line. The following are equivalent:
    Read GIS Z Shape == 2d_zsh_L | 2d_zsh_P
    Read GIS Z Shape == 2d_zsh_L && 2d_zsh_P

Note: If the .gpkg for the model is referenced in the .tcf (using the 'Spatial Database' command), it does not need to be referenced again in the other control files. However, if the the model is not contained in a single .gpkg, the separate databases must be referenced accordingly.

Outputs

Result and check file vector outputs can be written into separate databases or grouped, with 'grouped' being the default. Grouped databases will group by output folder location, for example, the check file folder will contain one GeoPackage Database that contains all check file layers within it. Separate databases will group geometries together, for example, PLOT_P, PLOT_L, PLOT_R will be written to one database. The following command can be used to set the output to either separate or grouped:
Spatial Database Output == SEPARATE | {GROUPED}

This is a huge benefit in terms of file organisation. The below shows a TUFLOW 'Check' folder from a model using the GeoPackage (grouped). The same 'Check' folder for a model using Shapefile would have 44(!) items in it.


QGIS Tips & Tricks

Convert TUFLOW Model GIS Format

The Convert TUFLOW Model GIS Format tool has been developed to convert the GIS formats for an entire models (input files and control files). For example, if you have a model currently set up using the SHP vector format and FLT raster format, you can automatically convert it to GPKG and TIF. This tool works both ways for any TUFLOW supported format and will automatically show in the 'Processing Toolbox' if you have the TUFLOW Plugin installed.

Configuring a New Project

QGIS is used to configure TUFLOW projects with the TUFLOW plugin. To configure a new TUFLOW project with GeoPackage as the GIS format, use the TUFLOW plugin:

  1. Open the 'Configure TUFLOW Project' tool by selecting Plugins > TUFLOW > Editing > Configure / Create TUFLOW Project.
  2. Select the required CRS for the project.
  3. Click 'Browse...' to select the folder location containing the TUFLOW folder. This creates the default TUFLOW model directory and sub-folders.
  4. Click 'Browse...' to select the location of the TUFLOW single precision executable file.
  5. Select 'GPKG' as the GIS Format.
  6. Select the required TUFLOW Engine and box options.
  7. Click 'OK'. This will configure the TUFLOW project using GeoPackage.

    M01 GPKG Configure 01.PNG

Apply GeoPackage Layer Names

This tool will change the layer name (within the Layers Panel) to be the same as the layer name within the GeoPackage database. To use the tool:

  1. Drag and Drop the GeoPackage Database from File Explorer.
  2. Click on the 'Apply GPKG Layer Names' symbol from the TUFLOW Plugin toolbar.

    GPKG layer names a.png


Note: If the layers are opened from within the QGIS Browser Panel, they will automatically be named the same as within the GeoPackage database.

For more information, see the Updating a GPKG Layer Name

QGIS Browser Panel

The QGIS Browser Panel is the recommended location to view, access, open and edit layers with a GeoPackage Database. It is possible to:

  1. View layers inside a Geopackage Database.


  2. Move a layer from one GeoPackage Database to another.


  3. Move a shapefile into a GeoPackage Database. QGIS will automatically convert it to a Geopackage layer.


Note: The File Management Pluggin provides more options for handling GeoPackage databases in QGIS.

Setting a Brower Panel Favourite

For quick access, a project folder can be set as a favourite in the QGIS Browser Panel.

  1. Right click in the Toolbar panel and tick on 'Browser Panel' from the 'Panels' options.
  2. Within the QGIS Browser Panel, right click on 'Favorites' and select 'Add a Directory...'.
  3. Navigate to the project folder and select it.



Increment a Layer

This tool saves a copy of the active layer with a new filename. To use the tool:

  1. Select the layer to increment in the Layers Panel.
  2. Click on the 'Increment Selected Layer' symbol from the TUFLOW Plugin toolbar.

    Increment layer.png

There are three options for incrementing a layer:

  1. Increment layer only (default): This option will increment the filename and the .gpkg by 1. It will then close the old layer and open the new one. For example, the tool increments M01_001.gpkg to M01_002.gpkg and 2d_code_M01_001_R to 2d_code_M01_002_R.
    • Note: In the video below, the output database is manually changed back to M01_001.gpkg, however the if left as the default, the new layer would be added to a new gpkg, M01_002.gpkg.


  2. Increment layer and preserve database: This option will increment the filename of the selected layer and the .gpkg by 1. It will also copy all other layers from the .gpkg into the new .gpkg. For example, the tool makes a copy of M01_001.gpkg and increments it to M01_002.gpkg. All layers are copied across with their original filename, except the selected layer, which is incremented to 2d_code_M01_002_R.


  3. Save layer out into superseded folder: This option will increment the the filename of the selected layer by 1. It will then close the old layer and open the new one. The old layer will be moved into a new folder called 'ss'. For example, the tool increments 2d_code_M01_001_R to 2d_code_M01_002_R and moves 2d_code_M01_001_R to the 'ss' folder.


For more information, see the Increment Layer Tool.