STARELite is the SQLite STARE extensions. It allows conversions of geospatial objects to their STARE representation as well as to perform geospatial relation tests.
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 -lSTARESELECT load_extension("./STARELite");equivalent to
.load ./STARELite in the sqlite3 shell
From longitude, latitude, and level
SELECT stare_from_lonlat(5, 3.1, 2);
SELECT name, stare_from_lonlat(longitude, latitude, 15) FROM cities; SELECT name, stare_from_point(geometry, 15) FROM cities; ALTER TABLE countries ADD column stare blob;
UPDATE countries
SET stare=stare_from_polygon(geometry, 5); SELECT name, decode_stareblob(stare)
FROM countriesConversion from human readable string
SELECT encode_stareblob('[3666130979403333634, 3666130979403333634]')); SELECT stare_intersects(3666130979403333634, 3666130979403333634);
SELECT name, stare_intersects(2667981979956219503, stare)
FROM countries; 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));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;