mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-15 04:54:23 +02:00
Add SpatiaLite helpers to CLI (#407)
* Add SpatiaLite CLI helpers * Add docs for spaitalite helpers * Fix flake8 issues and add more detail on spatial types * Run cog and add some help text. * Use SpatiaLite when calculating coverage, refs #407 Co-authored-by: Simon Willison <swillison@gmail.com>
This commit is contained in:
parent
e7f040106b
commit
a692c56659
6 changed files with 370 additions and 35 deletions
39
docs/cli.rst
39
docs/cli.rst
|
|
@ -724,6 +724,14 @@ To enable :ref:`cli_wal` on the newly created database add the ``--enable-wal``
|
|||
|
||||
$ sqlite-utils create-database empty.db --enable-wal
|
||||
|
||||
To enable SpatiaLite metadata on a newly created database, add the ``--init-spatialite`` flag::
|
||||
|
||||
$ sqlite-utils create-database empty.db --init-spatialite
|
||||
|
||||
That will look for SpatiaLite in a set of predictable locations. To load it from somewhere else, use the ``--load-extension`` option::
|
||||
|
||||
$ sqlite-utils create-database empty.db --init-spatialite --load-extension /path/to/spatialite.so
|
||||
|
||||
.. _cli_inserting_data:
|
||||
|
||||
Inserting JSON data
|
||||
|
|
@ -1975,3 +1983,34 @@ Since `SpatiaLite <https://www.gaia-gis.it/fossil/libspatialite/index>`__ is com
|
|||
|
||||
$ sqlite-utils memory "select spatialite_version()" --load-extension=spatialite
|
||||
[{"spatialite_version()": "4.3.0a"}]
|
||||
|
||||
|
||||
SpatiaLite helpers
|
||||
==================
|
||||
|
||||
`SpatiaLite <https://www.gaia-gis.it/fossil/libspatialite/home>`_ adds geographic capability to SQLite (similar to how PostGIS builds on PostgreSQL). The `SpatiaLite cookbook <http://www.gaia-gis.it/gaia-sins/spatialite-cookbook-5/index.html>`_ is a good resource for learning what's possible with it.
|
||||
|
||||
You can convert an existing table to a geographic table by adding a geometry column, use the `sqlite-utils add-geometry-column` command::
|
||||
|
||||
$ sqlite-utils add-geometry-column spatial.db locations geometry --type POLYGON --srid 4326
|
||||
|
||||
The table (``locations`` in the example above) must already exist before adding a geometry column. Use ``sqlite-utils create-table`` first, then ``add-geometry-column``.
|
||||
|
||||
Use the ``--type`` option to specify a geometry type. By default, ``add-geometry-column`` uses a generic ``GEOMETRY``, which will work with any type, though it may not be supported by some desktop GIS applications.
|
||||
|
||||
Eight (case-insensitive) types are allowed:
|
||||
|
||||
* POINT
|
||||
* LINESTRING
|
||||
* POLYGON
|
||||
* MULTIPOINT
|
||||
* MULTILINESTRING
|
||||
* MULTIPOLYGON
|
||||
* GEOMETRYCOLLECTION
|
||||
* GEOMETRY
|
||||
|
||||
Once you have a geometry column, you can speed up bounding box queries by adding a spatial index::
|
||||
|
||||
$ sqlite-utils create-spatial-index spatial.db locations geometry
|
||||
|
||||
See the `SpatiaLite Cookbook <http://www.gaia-gis.it/gaia-sins/spatialite-cookbook-5/cookbook_topics.03.html#topic_Wonderful_RTree_Spatial_Index>`_ for examples of how to use a spatial index.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue