Skip to main content

shapefile-to-sqlite

PyPI Changelog Tests License

Load shapefiles into a SQLite (optionally SpatiaLite) database.

Project background: Things I learned about shapefiles building shapefile-to-sqlite

How to install

$ pip install shapefile-to-sqlite

How to use

You can run this tool against a shapefile file like so:

$ shapefile-to-sqlite my.db features.shp

This will load the geometries as GeoJSON in a text column.

Using with SpatiaLite

If you have SpatiaLite available you can load them as SpatiaLite geometries like this:

$ shapefile-to-sqlite my.db features.shp --spatialite

The data will be loaded into a table called features - based on the name of the shapefile. You can specify an alternative table name using --table:

$ shapefile-to-sqlite my.db features.shp --table=places --spatialite

The tool will search for the SpatiaLite module in the following locations:

  • /usr/lib/x86_64-linux-gnu/mod_spatialite.so
  • /usr/local/lib/mod_spatialite.dylib

If you have installed the module in another location, you can use the --spatialite_mod=xxx option to specify where:

$ shapefile-to-sqlite my.db features.shp \
    --spatialite_mod=/usr/lib/mod_spatialite.dylib

You can use the --spatial-index option to create a spatial index on the geometry column:

$ shapefile-to-sqlite my.db features.shp --spatial-index

You can omit --spatialite if you use either --spatialite-mod or --spatial-index.

Projections

By default, this tool will attempt to convert geometries in the shapefile to the WGS 84 projection, for best conformance with the GeoJSON specification.

If you want it to leave the data in whatever projection was used by the shapefile, use the --crs=keep option.

You can convert the data to another output projection by passing it to the --crs option. For example, to convert to EPSG:2227 (California zone 3) use --crs=espg:2227.

The full list of formats accepted by the --crs option is documented here.

Extracting columns

If your data contains columns with a small number of heavily duplicated values - the names of specific agencies responsible for parcels of land for example - you can extract those columns into separate lookup tables referenced by foreign keys using the -c option:

$ shapefile-to-sqlite my.db features.shp -c agency

This will create a agency table with id and name columns, and will create the agency column in your main table as an integer foreign key reference to that table.

The -c option can be used multiple times.

CPAD_2020a_Units is an example of a table created using the -c option.

Metadata

Release files for shapefile-to-sqlite 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shapefile-to-sqlite 0.4.2
File Size Uploaded
shapefile-to-sqlite-0.4.2.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shapefile-to-sqlite 0.4.2
File Interpreter ABI Platform
shapefile_to_sqlite-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.4 kB

Release files / shapefile-to-sqlite-0.4.2.tar.gz

Download URL shapefile-to-sqlite-0.4.2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
68bccd2fbdd5a9edacf2398e1c72d5261b965ba4e835c7580601990b26711a21
BLAKE2b-256 checksum
How to use checksums
8955fe8b70938e8b20a2864d0439760b840a71296abdc78e2f7c650b81f27941
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / shapefile_to_sqlite-0.4.2-py3-none-any.whl

Download URL shapefile_to_sqlite-0.4.2-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c57d3654746cad7c83ce7f649eedd00bfc5751e7a0b0c90a3b48b37ad4af5d5
BLAKE2b-256 checksum
How to use checksums
ae4becda285141fe5ae43aeebc6902a7460fc07bf93510cd536a146f0d6e5417
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page