How to configure a default legend for GeoTIFFs on the Geoshare

From Tygron Preview Support Wiki
Jump to navigation Jump to search

GeoTIFF data on the Geoshare can easily be imported into Projects, and made available through a GeoTiff Overlay. To then properly interpret the data, the GeoTiff Overlay should have an appropriately configured Legend. Rather than relying on the manual configuration of a Legend in the individual Projects where the data is included, it is possible to add the definition of a Legend to the metadata of GeoTiff, so that the Tygron Platform can automatically configure an appropriate Legend directly when importing the data.

These steps require and assume the presence of GDAL on the system, which is also automatically available with an installation of QGIS.

These steps make use of Powershell on Windows. See the Notes at the bottom for an alternative command for the regular Windows command line.

Editor → Current Situation (Ribbon tab) → Overlays (Ribbon bar) → The Overlay to edit (Left panel) → Legend tab (Right panel)
How to configure a default legend for GeoTIFFs on the Geoshare:
  1. Ensure the full GeoTIFF file is available as a local file on your computer.
  2. Import the GeoTIFF file into a Project, displaying the data in a GeoTiff Overlay.
  3. Configure the Legend of the GeoTiff Overlay until it matches the desired Legend which should be associated with the full GeoTIFF file.
  4. Use "Export Grid Data" on the GeoTiff Overlay.
  5. Find the file downloaded in windows explorer. Right-click it, and open its properties (if "properties" is not directly available, it may be behind the "Show more options" menu item).
  6. Switch to the "details" tab.
  7. Copy the entry found in "Title" (in the "Description" section)
  8. Close the properties of the downloaded file.
  9. Find the full GeoTIFF file which is to be made available on the Geoshare.
  10. Right-click in the folder, and opt to open the windows command-line. This will open Windows' built-in Powershell application.
  11. Enter the following command with the indicated replacements:
    start-process -NoNewWindow -FilePath '%QGIS%\bin\gdal_translate.exe' '%FILE% output.tiff -mo "TIFFTAG_IMAGEDESCRIPTION=[]"'.replace('[]','%LEGEND%'.replace('"','\"'))
    Replace %QGIS% with the installation directory of QGIS
    Replace %FILE% with the name of the file to add the legend to
    Replace %LEGEND% with the copied entry from the file from the earlier steps, the export with the legend configured
    The resuling command will look similar to the following:
    start-process -NoNewWindow -FilePath 'C:\Program Files\QGIS 3.34.11\bin\gdal_translate.exe' 'input.tiff output.tiff -mo "TIFFTAG_IMAGEDESCRIPTION=[]"'.replace('[]','[ { "color" : { "argb" : -16776961 }, "entryName" : "Low", "id" : 1, "value" : 0.5}, { "color" : { "argb" : -3342337 }, "entryName" : "High", "id" : 5, "value" : 1.25} ]'.replace('"','\"'))
  12. Execute the command
  13. A file named "output.tiff" has now been created, which is a copy of the original file but with the legend included in its metadata.
  14. Open the Geoshare and upload the created GeoTIFF file.
  15. Confirm the process was successful by importing the GeoTIFF file from the Geoshare into the Project and displaying it using a GeoTiff Overlay. The Legend should immediately be configured correctly.

Notes

  • The command makes use of the GDAL library, included with QGIS.
    • The command created is composed of:
      • The location of the library.
      • The input file.
      • The output file.
      • A flag indicating a metadata entry to be modified.
      • A KEY=VALUE pair indicating that the TIFFTAG_IMAGEDESCRIPTION should be changed to a json-representation of a Tygron Platform definition of an Overlay Legend.
    • The replacements are to allow the apostrophes to carry over properly to the actual data, rather than be interpreted as symbols for delimiting strings of text in the command itself.
  • The operation can also be performed in the normal command-line environment. The command would look similar to the following:
    "C:\Program Files\QGIS 3.34.11\bin\gdal_translate.exe" input.tiff output.tiff -mo "TIFFTAG_IMAGEDESCRIPTION=[ { \""color\"" : { \""argb\"" : -16776961 }, \""entryName\"" : \""Low\"", \""id\"" : 1, \""value\"" : 0.5}, { \""color\"" : { \""argb\"" : -3342337 }, \""entryName\"" : \""High\"", \""id\"" : 5, \""value\"" : 1.25} ]"
  • The definition of the Legend can also be obtained by using the "copy" option in the legend tab of the right panel of the editor. However, linebreaks will cause issues when pasted directly into a shell environment, and as such will need to be removed from the defintion before using it. This can be done in a simple text editor, such as notepad, but is an extra step to be aware of.
  • The definition of the Legend can also be obtained directly from the API page of the GeoTiff Overlay. On the general tab in the right panel of the editor, open the API page by clicking on the Overlay's ID in the top right. This will open a web page with the Overlay's configuration. The legend definition can be found under "legend".

See also

External links