From 36518cbfcd5101e423b649cd0e213df9786ae5e0 Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 15 Feb 2022 12:08:29 -0500 Subject: [PATCH] Fix flake8 issues and add more detail on spatial types --- docs/cli.rst | 17 +++++++++++++++-- sqlite_utils/cli.py | 2 +- tests/test_cli.py | 1 - tests/test_gis.py | 5 +++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/cli.rst b/docs/cli.rst index 1708a30..cadcbf1 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -1988,14 +1988,27 @@ Since `SpatiaLite `__ is com SpatiaLite helpers ================== -`SpatiaLite `_ adds geographic capability to SQLite (similar to how PostGIS builds on PostgreSQL). +`SpatiaLite `_ adds geographic capability to SQLite (similar to how PostGIS builds on PostgreSQL). The `SpatiaLite cookbook `_ is a good resource for learning what's possible with it. -To add a geometry column to an existing table, use the `sqlite-utils add-geometry-column` command:: +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 diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index 0809177..7a827ba 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -2810,7 +2810,7 @@ def create_spatial_index(db_path, table, column_name, load_extension): raise click.ClickException( "You must add a geometry column before creating a spatial index" ) - + db[table].create_spatial_index(column_name) diff --git a/tests/test_cli.py b/tests/test_cli.py index a97c047..1922941 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7,7 +7,6 @@ from unittest import mock import json import os import pytest -from sqlite_utils.utils import sqlite3, find_spatialite import textwrap from .utils import collapse_whitespace diff --git a/tests/test_gis.py b/tests/test_gis.py index 4eccbf2..3b1fbf1 100644 --- a/tests/test_gis.py +++ b/tests/test_gis.py @@ -2,10 +2,9 @@ import json import pytest from click.testing import CliRunner -from sqlite_utils.utils import find_spatialite from sqlite_utils.cli import cli from sqlite_utils.db import Database -from sqlite_utils.utils import sqlite3 +from sqlite_utils.utils import find_spatialite, sqlite3 pytestmark = [ pytest.mark.skipif( @@ -232,4 +231,6 @@ def test_cli_create_spatial_index(tmpdir): cli, ["create-spatial-index", str(db_path), table.name, "geometry"] ) + assert 0 == result.exit_code + assert "idx_locations_geometry" in db.table_names()