Skip to main content

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

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

ogr2vrt_simple-0.1.10.tar.gz (11.4 kB view hashes)

Uploaded Source

Built Distribution

ogr2vrt_simple-0.1.10-py3-none-any.whl (12.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page