{"id":13586019,"url":"https://github.com/simonw/geojson-to-sqlite","last_synced_at":"2025-04-15T01:43:41.210Z","repository":{"id":42085952,"uuid":"237321267","full_name":"simonw/geojson-to-sqlite","owner":"simonw","description":"CLI tool for converting GeoJSON files to SQLite (with SpatiaLite)","archived":false,"fork":false,"pushed_at":"2022-04-13T23:39:25.000Z","size":117,"stargazers_count":56,"open_issues_count":4,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-18T07:53:54.164Z","etag":null,"topics":["datasette-io","datasette-tool","geojson","gis","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-30T22:51:05.000Z","updated_at":"2024-08-31T15:36:51.000Z","dependencies_parsed_at":"2022-09-26T18:52:01.994Z","dependency_job_id":null,"html_url":"https://github.com/simonw/geojson-to-sqlite","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgeojson-to-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgeojson-to-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgeojson-to-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgeojson-to-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/geojson-to-sqlite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991525,"owners_count":21194893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datasette-io","datasette-tool","geojson","gis","sqlite"],"created_at":"2024-08-01T15:05:16.626Z","updated_at":"2025-04-15T01:43:41.188Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# geojson-to-sqlite\n\n[![PyPI](https://img.shields.io/pypi/v/geojson-to-sqlite.svg)](https://pypi.org/project/geojson-to-sqlite/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/geojson-to-sqlite?include_prereleases\u0026label=changelog)](https://github.com/simonw/geojson-to-sqlite/releases)\n[![Tests](https://github.com/simonw/geojson-to-sqlite/workflows/Test/badge.svg)](https://github.com/simonw/geojson-to-sqlite/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/geojson-to-sqlite/blob/main/LICENSE)\n\nCLI tool for converting GeoJSON to SQLite (optionally with SpatiaLite)\n\n[RFC 7946: The GeoJSON Format](https://tools.ietf.org/html/rfc7946)\n\n## How to install\n\n    $ pip install geojson-to-sqlite\n\n## How to use\n\nYou can run this tool against a GeoJSON file like so:\n\n    $ geojson-to-sqlite my.db features features.geojson\n\nThis will load all of the features from the `features.geojson` file into a table called `features`.\n\nEach row will have a `geometry` column containing the feature geometry, and columns for each of the keys found in any `properties` attached to those features. (To bundle all properties into a single JSON object, use the `--properties` flag.)\n\nThe table will be created the first time you run the command.\n\nOn subsequent runs you can use the `--alter` option to add any new columns that are missing from the table.\n\nYou can pass more than one GeoJSON file, in which case the contents of all of the files will be inserted into the same table.\n\nIf your features have an `\"id\"` property it will be used as the primary key for the table. You can also use `--pk=PROPERTY` with the name of a different property to use that as the primary key instead. If you don't want to use the `\"id\"` as the primary key (maybe it contains duplicate values) you can use `--pk ''` to specify no primary key.\n\nSpecifying a primary key also will allow you to upsert data into the rows instead of insert data into new rows.\n\nIf no primary key is specified, a SQLite `rowid` column will be used.\n\nYou can use `-` as the filename to import from standard input. For example:\n\n    $ curl https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_040_00_20m.json \\\n        | geojson-to-sqlite my.db states - --pk GEO_ID\n\n## Using with SpatiaLite\n\nBy default, the `geometry` column will contain JSON.\n\nIf you have installed the [SpatiaLite](https://www.gaia-gis.it/fossil/libspatialite/index) module for SQLite you can instead import the geometry into a geospatially indexed column.\n\nYou can do this using the `--spatialite` option, like so:\n\n    $ geojson-to-sqlite my.db features features.geojson --spatialite\n\nThe tool will search for the SpatiaLite module in the following locations:\n\n- `/usr/lib/x86_64-linux-gnu/mod_spatialite.so`\n- `/usr/local/lib/mod_spatialite.dylib`\n\nIf you have installed the module in another location, you can use the `--spatialite_mod=xxx` option to specify where:\n\n    $ geojson-to-sqlite my.db features features.geojson \\\n        --spatialite_mod=/usr/lib/mod_spatialite.dylib\n\nYou can create a SpatiaLite spatial index on the `geometry` column using the `--spatial-index` option:\n\n    $ geojson-to-sqlite my.db features features.geojson --spatial-index\n\nUsing this option implies `--spatialite` so you do not need to add that.\n\n## Streaming large datasets\n\nFor large datasets, consider using newline-delimited JSON to stream features into the database without loading the entire feature collection into memory.\n\nFor example, to load a day of earthquake reports from USGS:\n\n    $ geojson-to-sqlite quakes.db quakes tests/quakes.ndjson \\\n      --nl --pk=id --spatialite\n\nWhen using newline-delimited JSON, tables will also be created from the first feature, instead of guessing types based on the first 100 features.\n\nIf you want to use a larger subset of your data to guess column types (for example, if some fields are inconsistent) you can use [fiona](https://fiona.readthedocs.io/en/latest/cli.html) to collect features into a single collection.\n\n    $ head tests/quakes.ndjson | fio collect | \\\n      geojson-to-sqlite quakes.db quakes - --spatialite\n\nThis will take the first 10 lines from `tests/quakes.ndjson`, pass them to `fio collect`, which turns them into a single feature collection, and pass that, in turn, to `geojson-to-sqlite`.\n\n## Using this with Datasette\n\nDatabases created using this tool can be explored and published using [Datasette](https://datasette.readthedocs.io/).\n\nThe Datasette documentation includes a section on [how to use it to browse SpatiaLite databases](https://datasette.readthedocs.io/en/stable/spatialite.html).\n\nThe [datasette-leaflet-geojson](https://datasette.io/plugins/datasette-leaflet-geojson) plugin can be used to visualize columns containing GeoJSON geometries on a [Leaflet](https://leafletjs.com/) map.\n\nIf you are using SpatiaLite you will need to output the geometry as GeoJSON in order for that plugin to work. You can do that using the SpaitaLite `AsGeoJSON()` function - something like this:\n\n```sql\nselect rowid, AsGeoJSON(geometry) from mytable limit 10\n```\n\nThe [datasette-geojson-map](https://datasette.io/plugins/datasette-geojson-map) is an alternative plugin which will automatically render SpatiaLite geometries as a Leaflet map on the corresponding table page, without needing you to call `AsGeoJSON(geometry)`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fgeojson-to-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fgeojson-to-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fgeojson-to-sqlite/lists"}