Usage๏ƒ

On the console๏ƒ

Geometry-to-spatialite installs two commands: shapefile-to-spatialite and geojson-to-spatialite. Both provide the same arguments.

Basic usage

shapefile-to-spatialite myfile.shp mydatabase.db

This will create a new SQLite database called mydatabase.db containing a single table, myfile

You can provide multiple files:

shapefile-to-spatialite one.shp two.shp bundle.db

The bundle.db database will contain two tables, one and two.

This means you can use wildcards:

shapefile-to-spatialite ~/Downloads/*.shp mydownloads.db

If you pass a path to one or more directories, the script will recursively search those directories for files and create tables for each one:

shapefile-to-spatialite ~/path/to/directory all-my-shapefiles.db

For more help on usage and arguments, run

shapefile-to-spatialite --help

or

geojson-to-spatialite --help

As a library๏ƒ

Basic usage๏ƒ

from geometry_to_spatialite import (
    geojson_to_spatialite,
    shp_to_spatialite,
    DataImportError
)


try:
    # Import myfile.geojson into mydatabase.db using the default settings
    geojson_to_spatialite('mydatabase.db', 'myfile.geojson')
except DataImportError:
    raise

API Reference๏ƒ

geometry_to_spatialite.geojson_to_spatialite(sqlite_db, geojson_file, table_name=None, spatialite_extension=None, srid=4326, pk=None, write_mode=None, geom_type='GEOMETRY')๏ƒ

Load a GeoJSON file into a SpatiaLite database

Parameters:
  • sqlite_db (str) โ€“ Name of the SQLite database file

  • geojson_file (str) โ€“ Path to a GeoJSON file to import

  • table_name (str, optional) โ€“ Custom table name. Default: None (use the GeoJSON file name)

  • spatialite_extension (str, optional) โ€“ Path to mod_spatialite extension. In most cases the spatialite extension can be automatically detected and loaded. If not you can manully pass a path to the .so .dylib or .dll file. Default: None (attempt to load automatically)

  • srid (int, optional) โ€“ Spatial Reference ID (SRID). Default: 4326

  • pk (Union[str, list, tuple], optional) โ€“ Field (str) or fields (list/tuple) to use as a primary key. Default: None (no primary key)

  • write_mode (str, optional) โ€“ By default we assume the target table does not already exist. Pass โ€˜replaceโ€™ or โ€˜appendโ€™ to overwrite or append to an existing table. Default: None (assume the table doesnโ€™t already exist)

  • geom_type (str, optional) โ€“ Data type to use for the geometry column. Default: "GEOMETRY"

Returns:

None

Raises:

DataImportError โ€“

geometry_to_spatialite.shp_to_spatialite(sqlite_db, shp_file, table_name=None, spatialite_extension=None, srid=4326, pk=None, write_mode=None, geom_type='GEOMETRY')๏ƒ

Load a SHP file into a SpatiaLite database

Parameters:
  • sqlite_db (str) โ€“ Name of the SQLite database file

  • shp_file (str) โ€“ Path to a SHP file to import

  • table_name (str, optional) โ€“ Custom table name. Default: None (use the SHP file name)

  • spatialite_extension (str, optional) โ€“ Path to mod_spatialite extension. In most cases the spatialite extension can be automatically detected and loaded. If not you can manully pass a path to the .so .dylib or .dll file. Default: None (attempt to load automatically)

  • srid (int, optional) โ€“ Spatial Reference ID (SRID). Default: 4326

  • pk (Union[str, list, tuple], optional) โ€“ Field (str) or fields (list/tuple) to use as a primary key. Default: None (no primary key)

  • write_mode (str, optional) โ€“ By default we assume the target table does not already exist. Pass โ€˜replaceโ€™ or โ€˜appendโ€™ to overwrite or append to an existing table. Default: None (assume the table doesnโ€™t already exist)

  • geom_type (str, optional) โ€“ Data type to use for the geometry column. Default: "GEOMETRY"

Returns:

None

Raises:

DataImportError โ€“

exception geometry_to_spatialite.DataImportError๏ƒ