Importare un file CSV di punti in Spatialite tramite script sql

Quesito preso dalla lista spatialite-users:

— creating the VirtualText table
CREATE VIRTUAL TABLE txt_pts USING VirtualText('C:\Users\pigre\Desktop\prov_centroid.csv','UTF-8', 1,'POINT','NONE', ',');
— creating the Spatial Table
CREATE TABLE mypoints (fid INTEGER PRIMARY KEY AUTOINCREMENT);
— adding a POINT geometry to the Spatial Table
SELECT AddGeometryColumn('mypoints', 'geom', 4326, 'POINT', 'XY');
— populating the Spatial Table from the VirtualText
INSERT INTO mypoints (fid, geom)
SELECT NULL, MakePoint(long, lat, 4326)
FROM txt_pts;
— dropping the now useless VirtualText
DROP TABLE txt_pts;

Riferimenti:

Ringraziamenti:

Alessandro Furieri papà di SpatiaLite

Lascia un commento

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.