Created
July 2, 2023 21:26
-
-
Save DavidKloucek/e39f9a87065f321508c00dd72abe2fcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html | |
# http://www.gaia-gis.it/gaia-sins/spatialite-cookbook/index.html | |
# $em->getConnection()->getNativeConnection()->loadExtension('mod_spatialite.dylib'); | |
CREATE TABLE IF NOT EXISTS city ( | |
id integer primary key AUTOINCREMENT unique not null, | |
name text not null | |
); | |
SELECT InitSpatialMetaData(); | |
select AddGeometryColumn('city', 'loc', 4326, 'POINT', 'XY'); | |
select CreateSpatialIndex('city', 'loc'); | |
INSERT INTO | |
city (id, name, loc) | |
VALUES | |
( | |
1, | |
'Louny', | |
MakePoint(50.354397837796604, 13.803626590794615, 4326) | |
), | |
( | |
2, | |
'Kraków', | |
MakePoint(50.03409465411076, 19.937277968461192, 4326) | |
); | |
select | |
name, | |
x(loc) x, | |
y(loc) y, | |
round( | |
distance( | |
loc, | |
MakePoint(50.0519528233593, 14.43861700065289, 4326), | |
true | |
) / 1000 | |
) as 'km from Prague' | |
from | |
city; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment