Generate a simple VRT file for data transformations
Project description
ogr2vrt simple
Generate a simple VRT file from an OGR-compatible dataset
Generate a VRT file from an OGR-compatible source. The result is to be considered as a "kickoff" VRT file, to refine according to your desires but it will save you some time.
It mostly targets and was tested with spreadsheet data (xls, xslx, ods, csv) but actually should work with most data sources supported by the OGR drivers
Are currently detected:
- the datasource path
- for each layer (depending on the source, there might be one or more layers):
- the layer name
- for each field in this layer
- name
- type if available (defaults to string)
- width (precision) if available
By default, the VRT file will be generated alongside the source file, extension .vrt
Features
- Support file as datasource
- Support plain URL as datasource:
- E.g. https://www.data.gouv.fr/fr/datasets/r/c53cd4d4-4623-4772-9b8c-bc72a9cdf4c2
- Autodetects the file format if provided in the headers
- Supports streaming service (e.g. https://www.data.gouv.fr/fr/datasets/r/d22ba593-90a4-4725-977c-095d1f654d28)
- find path to dataset inside an archive e.g. https://open-data.s3.fr-par.scw.cloud/bdnb_millesime_2022-10-d/millesime_2022-10-d_dep59/open_data_millesime_2022-10-d_dep59_gpkg.zip)
- determine if needs to download the file as a first step or can use vsicurl functions
Does not support (yet):
- non-UTF-8 csv files
Install
-
You will need the GDAL/OGR library. It is not listed in the requirements.txt file, because the installation depends on having the proper libraries already installed on your computer.
The simplest way:
- install gdal, libgdal-dev, python3-dev packages on your computer
- install GDAL package using
pip install GDAL==$(gdal-config --version)
-
Create a virtual env and install the app
python3 -m venv .venv
source .venv/bin/activate
pip install ogr2vrt-simple
Develop
Compatibility
python >=3.10
This code users features (match-case) introduced with python 3.10.
Using poetry
This is now the recommended way
- Install poetry
- Install the dependencies:
poetry install
- Run the script:
# Install the dependencies:
poetry install
#activate the environment
poetry shell
cd ogr2vrt_simple/
python3 cli.py generate-vrt --help
Simply using pip
This should still work.
Create a virtual env and install the requirements
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
You will need the GDAL/OGR library. See above in the install section
Run it
cd ogr2vrt_simple/
# Generate VRT file for a local file (zipped shapefile)
python3 cli.py generate-vrt https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/ogr/data/shp/poly.zip
# Generate VRT file for a remote CSV resource
python3 cli.py generate-vrt --with_vsicurl https://www.data.gouv.fr/fr/datasets/r/c53cd4d4-4623-4772-9b8c-bc72a9cdf4c2
List options:
python3 cli.py generate-vrt --help
Build
Use Poetry to build this script:
# Build
poetry build
# install
poetry install
# test it
ogr2vrt_cli --help
# Publish it to test-pypi
poetry publish -r test-pypi
# ... or to pypi
poetry publish
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ogr2vrt_simple-0.1.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96dc3a8838dfc2ab896be1d7c20e4001cef2c914d58a0b41103ab0975fcbae97 |
|
MD5 | f2b3ac2935d91ca39df045bbcec1ce02 |
|
BLAKE2b-256 | 5beb10fb7d9ea78ab619ad674b44e6dbd2fd7a384e315c7d0e7ba05bd9b3bc76 |