Not logged in

Back to RasterLite2 doc index

rl2sniff - an useful sniffer tool supporting RasterLite2

Sometimes handling a relevant number of raster images (may be of different origin and presenting different technical characteristics) isn't an easy task, most notably when your images are dispersed into many different folders.
The rl2sniff CLI tool is exactly intended to offer a significant help in organizing and planning any preliminary activity required in order to create and populate your RasterLite2's Coverages.
$ rl2sniff --help

usage: rl2sniff ARGLIST
-h or --help                    print this help message
-src or --src-path    pathname  single Image/Raster path
-dir or --dir-path    pathname  directory path
-ext or --file-ext    extension file extension (e.g. .tif)
-wf or --worldfile              requires a Worldfile
-md5 or --md5-checksum          enabling MD5 checksums
rl2sniff will examine files containing a raster image, and will then create a report showing the more relevant characteristics for each one; the supported arguments are the followings:

the output report

the report created by rl2sniff simply corresponds to a TXT/TAB being printed on the stdout file.
The report's columns are as follows:

a practical how-to guide

I've casually found in my personal archive an old DVD containing about 700 topographic maps stored as GeoTIFF images; so I've duly decided to use this target as my first rl2sniff testbed.
$ rl2sniff -dir E:/CTR_Toscana -md5 >ctrt.txt
     SQLite version: 3.8.5
 SpatiaLite version: 4.2.0
RasterLite2 version: 1.0.0-rc1
After executing the above command a full report is now stored into the ctrt.txt file.

rl2sniff step #1
Then I started spatialite_gui and I've imported the report into a DB Table using the Load CSV/TXT widget.

SELECT AddGeometryColumn('ctrt', 'geom', 3003, 'POLYGON', 'XY');
UPDATE ctrt SET geom = BuildMBR(min_x, min_y, max_x, max_y, 3003);
Just a couple of trivial SQL statements, and I had a full Geometry Table exactly corresponding to the input report. Exporting this Table as e.g. a Shapefile wasn't at all difficult.

rl2sniff step #2
This figure represents to the overall layout of my 700+ GeoTIFFs.

Taking full profit from Spatial SQL support

SELECT image_path
FROM ctrt
WHERE ST_Intersects(geom, ST_Envelope(ST_Buffer(
    MakePoint(LongitudeFromDMS('43°28′24″N 11°52′12″E'), 
      LatitudeFromDMS('43°28′24″N 11°52′12″E'), 4326), 
5000.0))) = 1;
Just a quick explanation about the above query: At this point I've simply made a cut & paste and I've saved all pathnames returned by the SQL query into a file named ctrt_list.txt.
$ rl2tool CREATE -db ctrt.sqlite -cov ctrt -smp 1-BIT -pxl MONOCHROME \
  -cpr FAX4 -srid 3003 -res 0.5 -strict

rl2tool: request is CREATE
              DB path: ctrt.sqlite
             Coverage: ctrt
          Sample Type: 1-BIT
           Pixel Type: MONOCHROME
      Number of Bands: 1
          Compression: CCITT FAX4, lossless
   Tile size (pixels): 512 x 512
                 Srid: 3003
Pixel base resolution: X=0.5 Y=0.5
======= Coverage Policies =======
Strict Resolution chek: Enabled
Mixed Resolutions mode: Disabled
 Section's Input Paths: Disabled
Section's MD5 Checksum: Enabled
 Section's XML Summary: Enabled

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

Raster Coverage "ctrt" successfully created
Operation CREATE successfully completed
Then I've created a DB-file containing a Coverage of the appropriate type.
$ rl2tool IMPORT -db ctrt.sqlite -cov ctrt -lst ctrt_list.txt -srid 3003

rl2tool; request is IMPORT
              DB path: ctrt.sqlite
   List of paths from: ctrt_list.txt
             Coverage: ctrt
          Forced SRID: 3003
Ignoring Pyramid Levels for now

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

Importing: E:\CTR_Toscana\288060.TIF
    Image Size (pixels): 13835 x 11562
                   SRID: 3003
       LowerLeft Corner: X=1722103.99 Y=4819918.90
      UpperRight Corner: X=1729021.49 Y=4825699.90
       Pixel resolution: X=0.5 Y=0.5
>> Image successfully imported in: 0 mins 40 secs

<------------ snip ---------->

Importing: E:\CTR_Toscana\288160.TIF
    Image Size (pixels): 13887 x 11584
                   SRID: 3003
       LowerLeft Corner: X=1735956.42 Y=4809273.99
      UpperRight Corner: X=1742899.92 Y=4815065.99
       Pixel resolution: X=0.5 Y=0.5
>> Image successfully imported in: 0 mins 43 secs
>> Total time: 6 mins 25 secs

Operation IMPORT successfully completed
And finally I've imported all selected GeoTIFFs into the Coverage by invoking rl2tool and passing the list of files to be imported via the -lst ctrt_list.txt argument.
$ rl2tool PYRAMIDIZE-MONOLITHIC -db ctrt.sqlite -cov ctrt
Just a final touch is now required, i.e. building a Monolithic Pyramid.

rl2sniff step #3
And here is the RasterLite2 Coverage as visualized by wmslite and LibreWMS.

Conclusion: using in a smart way rl2sniff, spatialite_gui and rl2tool made really simple a task that at first glance appeared as an intimidating looking for a needle in a haystack problem.

Back to RasterLite2 doc index