trento
Not logged in

Back to RasterLite2 Tutorials index



Tutorial: building and testing the Trento sample

In this tutorial we'll use the following input datasources: please download all them right now. They are Open Data released under a free license, and are available absolutely for free. The whole dataset corresponds to a mosaic of seven orthorectified aerial images covering the Town and the Local Council of Trento (Italy). All images were taken during year 2009 and support a rather high resolution (0.5 meters/pixel). Each image is made available as a JPEG image and is supported by a corresponding WorldFile presenting a non-standard .wld file-extension.

Step 1) renaming all WorldFiles

RasterLite2 expects that each JPEG datasource should be eventually supported by a WorldFile sharing the same identical name of the main image and presenting .jgw file-extension. This obviously isn't the actual case, so you'll first rename all WorldFiles so to adjust for the expected extension.

Step 2) creating the Trento Coverage

$ rl2tool CREATE -db trento.sqlite -cov photo -smp UINT8 -pxl RGB \
-cpr JPEG -srid 25832 -res 0.5 -nd 255,255,255

rl2_tool: request is CREATE
===========================================================
              DB path: trento.sqlite
             Coverage: photo
          Sample Type: UINT8
           Pixel Type: RGB
      Number of Bands: 3
        NO-DATA pixel: 255,255,255
          Compression: JPEG (lossy)
  Compression Quality: 80
   Tile size (pixels): 512 x 512
                 Srid: 25832
Pixel base resolution: X=0.5 Y=0.5
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc1
RasterLite2 version: 0.8

Raster Coverage "photo" successfully created

Operation CREATE successfully completed
$

Step 3) populating the Trento Coverage

$ rl2tool IMPORT -db trento.sqlite -cov photo -srid 25832 \
-wf -dir . -ext .jpg

rl2_tool; request is IMPORT
===========================================================
              DB path: trento.sqlite
 Input Directory path: .
       File Extension: .jpg
             Coverage: photo
              Section: from file name
Using the WorldFile
          Forced SRID: 25832
Ignoring Pyramid Levels for now
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc1
RasterLite2 version: 0.8

Importing: ./bondone_2009.jpg
------------------
    Image Size (pixels): 6540 x 6860
                   SRID: 25832
       LowerLeft Corner: X=658501.45 Y=5099307.10
      UpperRight Corner: X=661771.25 Y=5102737.04
       Pixel resolution: X=0.499969419 Y=0.4999912536
Importing: ./centronord_2009.jpg
------------------
    Image Size (pixels): 10660 x 10220
                   SRID: 25832
       LowerLeft Corner: X=660901.46 Y=5102707.02
      UpperRight Corner: X=666231.34 Y=5107816.92
       Pixel resolution: X=0.499988743 Y=0.4999902152999999
Importing: ./centrosud_2009.jpg
------------------
    Image Size (pixels): 10500 x 9200
                   SRID: 25832
       LowerLeft Corner: X=662341.39 Y=5098307.09
      UpperRight Corner: X=667591.29 Y=5102906.98
       Pixel resolution: X=0.4999904761999999 Y=0.4999880434999999
Importing: ./est_2009.jpg
------------------
    Image Size (pixels): 8060 x 7910
                   SRID: 25832
       LowerLeft Corner: X=666081.25 Y=5102846.97
      UpperRight Corner: X=670111.27 Y=5106801.75
       Pixel resolution: X=0.5000024814 Y=0.4999721871
Importing: ./nord_2009.jpg
------------------
    Image Size (pixels): 10602 x 10230
                   SRID: 25832
       LowerLeft Corner: X=660810.60 Y=5107731.93
      UpperRight Corner: X=666111.37 Y=5112846.75
       Pixel resolution: X=0.4999783496999999 Y=0.4999824046999999
Importing: ./ovest_2009.jpg
------------------
    Image Size (pixels): 9230 x 9100
                   SRID: 25832
       LowerLeft Corner: X=656466.25 Y=5102637.04
      UpperRight Corner: X=661081.43 Y=5107186.96
       Pixel resolution: X=0.5000195015999999 Y=0.4999912087999999
Importing: ./sud_2009.jpg
------------------
    Image Size (pixels): 10520 x 9220
                   SRID: 25832
       LowerLeft Corner: X=662451.35 Y=5093856.75
      UpperRight Corner: X=667711.26 Y=5098466.75
       Pixel resolution: X=0.4999914449 Y=0.5

Operation IMPORT successfully completed
$

Step 4) Creating a Monolithic Pyramid

You probably noticed that during the previous step no immediate Pyramid generation was required.
This was because we are going to create now a different kind of Pyramid; RasterLite2 allows to choose between two alternative strategies:
$ rl2tool PYRAMIDIZE-MONOLITHIC -db trento.sqlite -cov photo -lev 3

rl2_tool; request is PYRAMIDIZE-MONOLITHIC
===========================================================
DB path: trento.sqlite
Coverage: photo
Pyramid Virtual Levels: 3
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc1
RasterLite2 version: 0.8

  ----------
    photo: Monolithic Pyramid Level 1 - Row 1 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 2 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 3 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 4 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 5 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 6 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 7 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 8 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 9 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 1 - Row 10 of 10  successfully built
  ----------
    photo: Monolithic Pyramid Level 2 - Row 1 of 2  successfully built
  ----------
    photo: Monolithic Pyramid Level 2 - Row 2 of 2  successfully built
  ----------
    photo: Monolithic Pyramid Level 3 - Row 1 of 1  successfully built
  ----------
    Monolithic Pyramid levels successfully built for: photo

Operation PYRAMIDIZE-MONOLITHIC successfully completed
$
SELECT RL2_SetCoverageInfos('photo', 'Orthophoto 2009', 'Aerial orthophotos; RGB 0.5m/pixel year 2009');
Please remember: always setting a TITLE and an ABSTRACT for any Coverage being creates always is a strongly recommended good practice.

Step 5) Testing the Trento sample

As you've already done in the previous Planet Earth you can now directly test the Trento Coverage by publishing a standard WMS service.
You simply have to start the wmslite light-weight server, then connecting some WMS viewer (e.g. LibreWMS) to the service being published on localhost aka IP address 127.0.0.1, port 8080.

Trento #1

Trento #2

Trento #3

Step 6) retrieving Coverage- and Section-level statistics

$ rl2tool CATALOG -db trento.sqlite -cov photo

rl2_tool; request is CATALOG
===========================================================
DB path: trento.sqlite
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc1
RasterLite2 version: 0.8

===============================================================================
             Coverage: photo
                Title: *** missing Title ***
             Abstract: *** missing Abstract ***
-------------------------------------------------------------------------------
          Sample Type: UINT8
           Pixel Type: RGB
      Number of Bands: 3
          Compression: JPEG (lossy)
  Compression Quality: 80
   Tile Size (pixels): 512 x 512
Pixel base resolution: X=0.5 Y=0.5
-------------------------------------------------------------------------------
Overall Size (pixels): 27290 x 37980
                 Srid: 25832 (epsg,25832) ETRS89 / UTM zone 32N
      LowerLeftCorner: X=656466.2500097508 Y=5093856.75
     UpperRightCorner: X=670111.2700013245 Y=5112846.750008797
-------------------------------------------------------------------------------
        NO-DATA Pixel: 255, 255, 255
-------------------------------------------------------------------------------
 NO-DATA Pixels Count: 164199958
   Valid Pixels Count: 457867754
  =========== Band #0 Summary ==========
            Min Value: 0
            Max Value: 255
           Mean Value: 123.3914654950782
             Variance: 2005.477819097288
   Standard Deviation: 44.78256155131468
  =========== Band #1 Summary ==========
            Min Value: 0
            Max Value: 255
           Mean Value: 127.438034312851
             Variance: 1605.106033488249
   Standard Deviation: 40.0637745786421
  =========== Band #2 Summary ==========
            Min Value: 0
            Max Value: 255
           Mean Value: 118.3748520233202
             Variance: 1586.230239285422
   Standard Deviation: 39.82750606409372
-------------------------------------------------------------------------------
   ===  Pyramid Level: 0  ==========================
  Physical resolution: X=0.5 Y=0.5
   Virtual resolution: X=1.0 Y=1.0
   Virtual resolution: X=2.0 Y=2.0
   Virtual resolution: X=4.0 Y=4.0
          Tiles Count: 2397
           BLOB Bytes: 424388165
   ===  Pyramid Level: 1  ==========================
  Physical resolution: X=4.0 Y=4.0
   Virtual resolution: X=8.0 Y=8.0
   Virtual resolution: X=16.0 Y=16.0
   Virtual resolution: X=32.0 Y=32.0
          Tiles Count: 43
           BLOB Bytes: 3142420
   ===  Pyramid Level: 2  ==========================
  Physical resolution: X=32.0 Y=32.0
   Virtual resolution: X=64.0 Y=64.0
   Virtual resolution: X=127.9999999999999 Y=127.9999999999999
   Virtual resolution: X=255.9999999999999 Y=255.9999999999999
          Tiles Count: 2
           BLOB Bytes: 64692
   ===  Pyramid Level: 3  ==========================
  Physical resolution: X=255.9999999999999 Y=255.9999999999999
   Virtual resolution: X=511.9999999999999 Y=511.9999999999999
   Virtual resolution: X=1023.999999999999 Y=1023.999999999999
   Virtual resolution: X=2047.999999999999 Y=2047.999999999999
          Tiles Count: 1
           BLOB Bytes: 8154
===============================================================================

Operation CATALOG successfully completed
$
You can invoke rl2tool CATALOG in order to retrieve fine-grained statistical informations about any Coverage; just omitting to specify any Coverage name will then report all Coverages from a DB-file.

$ rl2tool LIST -db trento.sqlite -cov photo -sec sud_2009

rl2_tool; request is LIST
===========================================================
 DB path: trento.sqlite
Coverage: photo
 Section: sud_2009
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc1
RasterLite2 version: 0.8

===============================================================================
             Coverage: photo
===============================================================================

-------------------------------------------------------------------------------
              Section: (7) sud_2009
-------------------------------------------------------------------------------
        Size (pixels): 10520 x 9220
           Input Path: ./sud_2009.jpg
     LowerLeft corner: X=662451.35 Y=5093856.75
    UpperRight corner: X=667711.26 Y=5098466.75
         Center Point: X=665081.30 Y=5096161.75
-------------------------------------------------------------------------------
 NO-DATA Pixels Count: 48721641
   Valid Pixels Count: 55873815
  =========== Band #0 Summary ==========
            Min Value: 0
            Max Value: 255
           Mean Value: 127.3124062138946
             Variance: 2087.151931900126
   Standard Deviation: 45.68535795963654
  =========== Band #1 Summary ==========
            Min Value: 0
            Max Value: 255
           Mean Value: 132.3306155844202
             Variance: 1633.408543226294
   Standard Deviation: 40.41544931367575
  =========== Band #2 Summary ==========
            Min Value: 0
            Max Value: 255
           Mean Value: 123.6940782547244
             Variance: 1597.50000265527
   Standard Deviation: 39.96873781663952
-------------------------------------------------------------------------------
    ==========  Level: 0  ==========
          Tiles Count: 399
           BLOB Bytes: 54326168
-------------------------------------------------------------------------------

Operation LIST successfully completed
$
And you can invoke rl2tool LIST in order to retrieve fine-grained statistical informations about any Section; just omitting to specify any Section name will then report all Sections from a Coverage.

$ rl2tool MAP -db trento.sqlite -cov photo -outw 480 \
-outh 640 -dst trento.png

rl2_tool; request is MAP
===========================================================
           DB path: trento.sqlite
          Coverage: photo
  Destination Path: trento.png
        Image Size: 512 x 640
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc1
RasterLite2 version: 0.8

Operation MAP successfully completed
$
By invoking rl2tool MAP you can create a PNG image representing the overall Sections layout within a Coverage: trento map
And this image corresponds to the actual output created by the above rl2tool MAP execution.



Step 7) examining Band Histograms

You could eventually invoke rl2tool HISTOGRAM in order to get the visual representation of any band histogram (i.e. the statistical distribution of pixel values for the given band). You are free to examine band histograms both for a Coverage as a whole or for a single Section; just omitting to specify any Section name will then report all Sections from a Coverage.

$ rl2tool HISTOGRAM -db trento.sqlite -cov photo -bnd 0 \
-dst red_histogram.png

rl2_tool; request is HISTOGRAM
===========================================================
    DB path: trento.sqlite
   Coverage: photo
             Histogram from Coverage-level Statistics
 Band Index: 0
Destination: red_histogram.png
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation HISTOGRAM successfully completed

$ rl2tool HISTOGRAM -db trento.sqlite -cov photo -bnd 1 \
-dst green_histogram

rl2_tool; request is HISTOGRAM
===========================================================
    DB path: trento.sqlite
   Coverage: photo
             Histogram from Coverage-level Statistics
 Band Index: 1
Destination: green_histogram.png
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation HISTOGRAM successfully completed

$ rl2tool HISTOGRAM -db trento.sqlite -cov photo -bnd 2 \
-dst blue_histogram

rl2_tool; request is HISTOGRAM
===========================================================
    DB path: trento.sqlite
   Coverage: photo
             Histogram from Coverage-level Statistics
 Band Index: 2
Destination: blue_histogram.png
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation HISTOGRAM successfully completed

$ rl2tool HISTOGRAM -db trento.sqlite -cov photo -bnd 2 \
-sec est_2009 -dst blue_sec_histogram

rl2_tool; request is HISTOGRAM
===========================================================
    DB path: trento.sqlite
   Coverage: photo
    Section: est_2009
             Histogram from Section-level Statistics
 Band Index: 2
Destination: blue_sec_histogram
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation HISTOGRAM successfully completed
The following images correspond to the actual output created by the above rl2tool HISTOGRAM executions.

red band histogram
Red Band (index = 0) histogram, whole Coverage

green band histogram
Green Band (index = 1) histogram, whole Coverage

blue band histogram
Blue Band (index = 2) histogram, whole Coverage

blue sec_band histogram
Blue Band (index = 2) histogram, est_2009 Section alone



Step 8) exporting a selected sub-portion from a Coverage as an image file

You could eventually invoke rl2tool EXPORT in order to create on the local file-system an image file corresponding to a spatially selected portion of the Coverage. And in doing this you are absolutely free to choose anyone of the multiple resolutions available from the Pyramid supporting the Coverage.

$ rl2tool EXPORT -db trento.sqlite -cov photo -outw 640 \
-outh 480 -res 0.5 -cx 664750 -cy 5104750 -dst trento-sub-05.jpg

rl2_tool; request is EXPORT
===========================================================
           DB path: trento.sqlite
          Coverage: photo
        Pixel size: X=0.5 Y=0.5
        Image Size: 640 x 480
      Output image: trento-sub-05.jpg
 Lower-Left Corner: 664590.00 5104630.00
Upper-Right Corner: 664910.00 5104870.00
            Center: 664750.00 5104750.00
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation EXPORT successfully completed

$ rl2tool EXPORT -db trento.sqlite -cov photo -outw 640 \
-outh 480 -res 1 -cx 664750 -cy 5104750 -dst trento-sub-1.jpg

rl2_tool; request is EXPORT
===========================================================
           DB path: trento.sqlite
          Coverage: photo
        Pixel size: X=1.0 Y=1.0
        Image Size: 640 x 480
      Output image: trento-sub-1.jpg
 Lower-Left Corner: 664430.00 5104510.00
Upper-Right Corner: 665070.00 5104990.00
            Center: 664750.00 5104750.00
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation EXPORT successfully completed

$ rl2tool EXPORT -db trento.sqlite -cov photo -outw 640 \
-outh 480 -res 2 -cx 664750 -cy 5104750 -dst trento-sub-2.jpg

rl2_tool; request is EXPORT
===========================================================
           DB path: trento.sqlite
          Coverage: photo
        Pixel size: X=2.0 Y=2.0
        Image Size: 640 x 480
      Output image: trento-sub-2.jpg
 Lower-Left Corner: 664110.00 5104270.00
Upper-Right Corner: 665390.00 5105230.00
            Center: 664750.00 5104750.00
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation EXPORT successfully completed

$ rl2tool EXPORT -db trento.sqlite -cov photo -outw 640 \
-outh 480 -res 4 -cx 664750 -cy 5104750 -dst trento-sub-4.jpg

rl2_tool; request is EXPORT
===========================================================
           DB path: trento.sqlite
          Coverage: photo
        Pixel size: X=4.0 Y=4.0
        Image Size: 640 x 480
      Output image: trento-sub-4.jpg
 Lower-Left Corner: 663470.00 5103790.00
Upper-Right Corner: 666030.00 5105710.00
            Center: 664750.00 5104750.00
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation EXPORT successfully completed

$ rl2tool EXPORT -db trento.sqlite -cov photo -outw 640 \
-outh 480 -res 8 -cx 664750 -cy 5104750 -dst trento-sub-8.jpg

rl2_tool; request is EXPORT
===========================================================
           DB path: trento.sqlite
          Coverage: photo
        Pixel size: X=8.0 Y=8.0
        Image Size: 640 x 480
      Output image: trento-sub-8.jpg
 Lower-Left Corner: 662190.00 5102830.00
Upper-Right Corner: 667310.00 5106670.00
            Center: 664750.00 5104750.00
===========================================================

     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0-rc2
RasterLite2 version: 0.9

Operation EXPORT successfully completed
$
The following images correspond to the actual output created by the above rl2tool EXPORT executions.

Resolution: 0.5 m / pixel
(original resolution)
trento res=0.5
Resolution: 1.0 m / pixel
(rescaled 1:2)
trento res=1.0
Resolution: 2.0 m / pixel
(rescaled 1:4)
trento res=2.0
Resolution: 4.0 m / pixel
(rescaled 1:8)
trento res=4.0
Resolution: 8.0 m / pixel
(rescaled 1:16)
trento res=8.0



Back to RasterLite2 Tutorials index