Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STARELite

STARELite is the SQLite STARE extensions. It allows conversions of geospatial objects to their STARE representation as well as to perform geospatial relation tests.

Example 1

Build

STARELite depends on libsqlite, libspatialite and libSTARE

c++ -g -fPIC -L/usr/local/lib/ 
    -L/usr/lib/x86_64-linux-gnu/ 
    -I/usr/local/include 
    -I/usr/include/spatialite/ 
    -std=c++11 
    -shared 
    STARELite.cpp -o STARELite.so 
    -lspatialite -lSTARE

Load extension

SELECT load_extension("./STARELite");

equivalent to

.load ./STARELite 

in the sqlite3 shell

Useage

STARE conversions

From longitude, latitude, and level

    SELECT stare_from_lonlat(5, 3.1, 2);
    SELECT name, stare_from_lonlat(longitude, latitude, 15) FROM cities;

From spatialite WKB blob (point):

    SELECT name, stare_from_point(geometry, 15) FROM cities;

From spatilite WKB blob (polygon)

    ALTER TABLE countries ADD column stare blob;
    UPDATE countries 
    SET stare=stare_from_polygon(geometry, 5);

Conversion between human readable strings and STAREBlobs

    SELECT name, decode_stareblob(stare) 
    FROM countries

Conversion from human readable string

    SELECT encode_stareblob('[3666130979403333634, 3666130979403333634]'));

Stare intersects

    SELECT stare_intersects(3666130979403333634, 3666130979403333634);

    SELECT name, stare_intersects(2667981979956219503, stare) 
    FROM countries;

STARE join

    SELECT countries.name, countries.name 
    FROM countries, cities
    WHERE stare_intersects(countries.stare, stare_from_point(cities.geom, 15));

or

    SELECT countries.name, cities.name 
    FROM cities
    LEFT JOIN countries
    ON stare_intersects(countries.stare, stare_from_point(cities.geom, 15));

Loading Data From DataFrame

A STAREDataFrame stores collections of SIDs representing a cover as 1D numpy arrays. To inject those into SQLite, we have to serialize the arrays and then encode them to STARE blobs using encode_starebolob(). For now, we serialize the arrays to strings. E.g.:

sdf['sids_serialized'] = sdf.apply(lambda row : str(list(row['sids'])), axis = 1)

Then we can do:

sdf.to_file('data.gpkg', driver='GPKG')

Finally, we can bootstrap the STAREBlobs with:

SELECT load_extension("./STARELite");
SELECT encode_stareblob(sids_serialized) FROM featuredb;

About

STARE SQLite Run-Time Loadable Extensions

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages