Theil-Sen estimated median change in rain normalised soil moisture 2001-2016, Indonesia

Map: Theil-Sen estimated median change in rain normalised soil moisture 2001-2016, Indonesia

Projection system setup:
Part 1 setup_db

Introduction

When you work with Karttur’s GeoImagine Framework you must have a predefined geographic region linking to an also predefined projection system. You can always work with any of the predefined projection systems, including the MODIS sinusoidal grid or any of the three ease-GRID systems. But you might also want to work with more specific regional projection systems. This post explains how to add a custom regional projection system to the Framework. As an example the post uses the national Swedish mapping system SWEREF99, with the EPSG code 3006. While it is possible to even use a customised projection (i.e. a projection system not having any EPSG definition), this is not covered in this post.

Prerequisites

To create a customised projection system you must have setup the database and also setup processes.

setup projection system

For a projection system to be applicable in the Framework, the data belonging to the system must be defined in its own database schema and all the system specific processes must be opened up for the novel projection system. Projection system schema typically include the following tables:

  • compdef
  • compprod
  • tilelayer
  • regionlayer
  • mask
  • tilecoords
  • regions

If you have datasets that are specifically linked to the project system and want to import these layers directly to the system, rather than via the system ancillary, also the following tables are required:

  • dscompid
  • datasets
  • dslayers
  • authors

All the system specific processes able to operate on spatial data belong to the defined projection system must then be defined in the schema.table process.procsys. The new projection system and its EPSG code must also be added to the support table system.systemepsg.

System schema and tables

The system specific schema and its tables must be setup from the python package setup_db. The package contains a predefined module called setup_db_sweref, for setting up the projection system for the national Swedish mapping grid. Using that module as an example, and this post as a tutorial, it is fairly easy to create any custom projection system based on EPSG defined projections.

The setup includes two json processes, one for defining the schema and all the tables, and one for adding the new projection system to the processes. The former is straight forward both to run and also to alter for any other custom system. Opening spatial processes to include a novel system is a bit more complex and requires generating the records to insert in the table process.procsys. The latter is the topic of the next section, whereafter follows the actual database construction.

NOTE that you can also generate the system specific schema and its tables from the package setup_processes. As the setup is described in this tutorial that setup alternative is redundant, but it nevertheless runs through the postgres database and checks the existence of the schema and the required tables in the process DefineCustomSystem. For now (March 2022), I will just leave it like that.

Generate records for opening processes

The module setup_db_sweref contains the routine TemplateProcessSystem. Calling it requires 5 variables:

  • prodDB [the production database]
  • templateSystem [an existing projection system to use as template]
  • newSystem [the name of the new projection system]
  • templateEPSG [the EPSG integer code of the existing template projection system]
  • newEPSG [the EPSG integer code of the new projection system]

The default projection system ease2n (ease2s or ease2t) is probably the most suitable projection system to use as a template. The alternative is to use the MODIS sinusoidal grid (modis) projection system, but the modis system includes a large number of processes that are specific for the MODIS data products. If you chose to use modis as your template you should edit the values before inserting them.

To generate the records to insert for your projection system, run the routine TemplateProcessSystem. As noted above, the json code generated from the routine TemplateProcessSystem might need some editing, and then it must be saved as a .json file. For the example in this post, the generated code must saved in the file SWEREF_insert-procsys_v090_sql.json. If you use the default directory structure and paths as the original Framework the file should be saved under the directory jsonsql.

Create schema and tables

The json commands for creating the schema and tables for the SWEREF99 projection system are in the file SWEREF_schema+tables_v090_sql.json. If you want to create another custom projection system you only need to change the name of schema:

"schema": "sweref"

to

"schema": "your_system"

by a search and replace.

json commands

With the “tableinsert” json commands for your projection system defined and saved as a json file, you can run the database processes that will create both the schema and tables and then insert the records.

In the __main__ section of the module remove the comment signs (#) that points to the projFPN db_karttur_setup-sweref_20220121.txt and the routine SetupSchemasTables:

  projFPN = path.join('doc','db_karttur_setup-sweref_20220121.txt')
  SetupSchemasTables(projFPN,prodDB)

The text file db_karttur_setup-sweref_20220121.txt points to the two json command files also linked above:

\# Install schema+tables for SWEREF
SWEREF_schema+tables_v090_sql.json

\# Insert table data for process systems
SWEREF_insert-procsys_v090_sql.json

Run the python module to create all the updates to your postgres database.

The next post in this series covers how to define the new projection system boundary and tiling, define a default region for the new system and then create a user specific project and tract.