Fix flake8 issues and add more detail on spatial types

This commit is contained in:
Chris Amico 2022-02-15 12:08:29 -05:00
commit 36518cbfcd
4 changed files with 19 additions and 6 deletions

View file

@ -1988,14 +1988,27 @@ Since `SpatiaLite <https://www.gaia-gis.it/fossil/libspatialite/index>`__ is com
SpatiaLite helpers
==================
`SpatiaLite <https://www.gaia-gis.it/fossil/libspatialite/home>`_ adds geographic capability to SQLite (similar to how PostGIS builds on PostgreSQL).
`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.
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

View file

@ -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)

View file

@ -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

View file

@ -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()