SpatiaLite: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(Updated the explanation how to export a grass vector layer to a spatialite database)
Line 1: Line 1:
== Spatialite ==
== Spatialite ==


A {{Wikipedia|SQLite}} database with geospatial extensions, much list [[PostGIS]] is to {{Wikipedia|PostgreSQL}}.
A {{Wikipedia|SQLite}} database with geospatial extensions, much list [[PostGIS]] is to {{Wikipedia|PostgreSQL}}. To export a layer to a Spatialite database with v.out.ogr, use the SQLite [[OGR]] driver and set the SPATIALITE data creation option to "yes".


==== New database ====


=== Export ===
  v.out.ogr in=mymap output=mydbase.sqlite format=SQLite \
    type=area dsco='SPATIALITE=yes' output_layer="mymap"


* ''fixme!'' this page is heavily under construction.
==== Existing spatialite database ====
Note that you need to use --overwrite, otherwise v.out.ogr will complain that the output already exists. Using --overwrite should maintain the existing tables in the spatialite database. However, it is strongly suggested to run this on a copy of the database, or make sure you have a recent backup.


Use the SQLite [[OGR]] driver and set the SPATIALITE data creation option to "yes".
  v.out.ogr -u in=mymap output=mydbase.sqlite format=SQLite \
 
     type=area dsco='SPATIALITE=yes' output_layer="mymap" --overwrite
v.out.ogr in=usgsgages dsn=usgsgages.sqlite \
     format=SQLite type=point dsco='SPATIALITE=yes'  
 
fixme: I'm getting this error:
ERROR 1: sqlite3_step() failed:
  usgsgages.GEOMETRY violates Geometry constraint [geom-type or SRID not allowed] (19)


==== Using QGIS (1) ====
An alternate way is to load the layer in QGIS's GRASS toolbox, then right click on the layer name and select "Save As...".


An alternate way is to load the layer in QGIS's GRASS toolbox, then right click on the layer name and select "Save As...".
==== Using QGIS (2) ====
Open the layer in QGIS using the browser panel. Next, open the spatialite database in the QGIS DB manager and use the 'import layer' option to import the grass vector layer you just opened in QGIS into the spatialite database.

Revision as of 14:31, 1 February 2017

Spatialite

A SQLite database with geospatial extensions, much list PostGIS is to PostgreSQL. To export a layer to a Spatialite database with v.out.ogr, use the SQLite OGR driver and set the SPATIALITE data creation option to "yes".

New database

 v.out.ogr in=mymap output=mydbase.sqlite format=SQLite \
   type=area dsco='SPATIALITE=yes' output_layer="mymap"

Existing spatialite database

Note that you need to use --overwrite, otherwise v.out.ogr will complain that the output already exists. Using --overwrite should maintain the existing tables in the spatialite database. However, it is strongly suggested to run this on a copy of the database, or make sure you have a recent backup.

 v.out.ogr -u in=mymap output=mydbase.sqlite format=SQLite \
   type=area dsco='SPATIALITE=yes' output_layer="mymap" --overwrite

Using QGIS (1)

An alternate way is to load the layer in QGIS's GRASS toolbox, then right click on the layer name and select "Save As...".

Using QGIS (2)

Open the layer in QGIS using the browser panel. Next, open the spatialite database in the QGIS DB manager and use the 'import layer' option to import the grass vector layer you just opened in QGIS into the spatialite database.