Package: ogrtools
Introductionogrtools is a collection of libraries and tools built with the Python
API ofOGR.pyogr librarypyogr gives you OGR commands like ogr2ogr or ogrinfo as Python library,
i.e. without calling an external executable file. Most of the code is
already included in the OGR source distribution as samples for using the
Python API.ogr2ogr.py: ogr2ogr call with stdout/stderr redirectionogrinfo.py: ogrinfo callogrvrt.py: generate a VRT from a datasourceogrds.py: Call OGR SQL commands on a datasourceinterlis libraryExtensions for the OGRInterlis
driver.Automatic detection of used models in transfer filesExtracting enums from IlisMeta modelLoading and converting of Interlis models from model repositoriesogrtransform libraryOGR has many options to transform data when converting from one format
into an other. The ogrtransform library uses a configuration in JSON
format to transform data.Example:{
  "//": "OGR transformation configuration",
  "src_format": "Interlis 2",
  "dst_format": "PostgreSQL",
  "dst_dsco": {},
  "dst_lco": {
    "SCHEMA": "public"
  },
  "layers": {
    "roadsexdm2ben_roads_streetnameposition": {
      "fields": {
        "tid": {
          "src": "TID",
          "type": "String"
        },
        "street": {
          "src": "Street",
          "type": "String"
        },
        "namori": {
          "src": "NamOri",
          "type": "Real"
        }
      },
      "geometry_type": "Point",
      "src_layer": "RoadsExdm2ben.Roads.StreetNamePosition",
      "geom_fields": {
        "nampos": {
          "src": "NamPos",
          "type": "Point"
        }
      }
    },
    "roadsexdm2ben_roads_streetaxis": {
      "fields": {
        "tid": {
          "src": "TID",
          "type": "String"
        },
        "street": {
          "src": "Street",
          "type": "String"
        }
      },
      "geometry_type": "MultiLineString",
      "src_layer": "RoadsExdm2ben.Roads.StreetAxis",
      "geom_fields": {
        "geometry": {
          "src": "Geometry",
          "type": "MultiLineString"
        }
      }
    }
  },
  "enums": {
    "enum0_type": {
      "src_name": "RoadsExdm2ben.Roads.RoadSign.Type",
      "values": [
        {
          "enumtxt": "prohibition",
          "enum": "prohibition",
          "id": 0
        },
        {
          "enumtxt": "indication",
          "enum": "indication",
          "id": 1
        },
        {
          "enumtxt": "danger",
          "enum": "danger",
          "id": 2
        },
        {
          "enumtxt": "velocity",
          "enum": "velocity",
          "id": 3
        }
      ]
    }
  }
}SeeWikifor more
information.ogr command line toolThe ogr command line tool exposes ogrtools functionality for using in a
command shell.ogr --help
usage: ogr [-h]
           {version,formats,info,sql,vrt,genconfig,write-enums,transform} ...

Query and transform OGR compatible vector data

optional arguments:
  -h, --help            show this help message and exit

commands:
  valid commands

  {version,formats,info,sql,vrt,genconfig,write-enums,transform}
    version             Show version information
    formats             List available data formats
    info                Information about data
    sql                 Execute SQL Query
    vrt                 Create VRT from data source
    genconfig           Generate OGR configuration from data source
    write-enums         Write tables with enumeration values
    transform           Transform data source based on OGR configurationogr versionShow version informationusage: ogr version [-h]ogr formatsList available data formatsusage: ogr formats [-h]ogr infoInformation about datausage: ogr info [-h] source [layers [layers ...]]Example:ogr info tests/data/osm/railway.shpINFO: Open of `tests/data/osm/railway.shp'
      using driver `ESRI Shapefile' successful.

Layer name: railway
Geometry: Line String
Feature Count: 73
Extent: (9.478497, 9.628118) - (47.124600, 47.262550)
Layer SRS WKT:
GEOGCS["GCS_WGS_1984",
    DATUM["WGS_1984",
        SPHEROID["WGS_84",6378137,298.257223563]],
    PRIMEM["Greenwich",0],
    UNIT["Degree",0.017453292519943295]]
type: String (255.0)
osm_id: Real (11.0)
lastchange: Date (10.0)
name: String (255.0)
keyvalue: String (80.0)ogr sqlExecute SQL Queryusage: ogr sql [-h] source sql-queryExample:ogr sql tests/data/osm/railway.shp "SELECT type,osm_id,lastchange FROM railway WHERE lastchange < '2008/04/01'"INFO: Open of `tests/data/osm/railway.shp'
      using driver `ESRI Shapefile' successful.

Layer name: railway
Geometry: Line String
Feature Count: 8
Extent: (9.478497, 9.628118) - (47.124600, 47.262550)
Layer SRS WKT:
GEOGCS["GCS_WGS_1984",
    DATUM["WGS_1984",
        SPHEROID["WGS_84",6378137,298.257223563]],
    PRIMEM["Greenwich",0],
    UNIT["Degree",0.017453292519943295]]
type: String (255.0)
osm_id: Real (11.0)
lastchange: Date (10.0)
OGRFeature(railway):6
  type (String) = rail
  osm_id (Real) = 9675696
  lastchange (Date) = 2007/10/17
  LINESTRING (9.6174755 47.227974,9.6170635 47.22802)

OGRFeature(railway):8
  type (String) = rail
  osm_id (Real) = 9675711
  lastchange (Date) = 2007/10/17
  LINESTRING (9.617415 47.22794,9.617038 47.227985)
...ogr vrtCreate VRT from data sourceusage: ogr vrt [-h] source [layers [layers ...]]Example:ogr vrt tests/data/osm/railway.shp<OGRVRTDataSource>
  <OGRVRTLayer name="railway">
    <SrcDataSource relativeToVRT="0" shared="1">tests/data/osm/railway.shp</SrcDataSource>
    <SrcLayer>railway</SrcLayer>
    <GeometryType>wkbLineString</GeometryType>
    <LayerSRS>GEOGCS[&quot;GCS_WGS_1984&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS_84&quot;,6378137,298.257223563]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;Degree&quot;,0.017453292519943295]]</LayerSRS>
    <Field name="type" type="String" src="type" width="255"/>
    <Field name="osm_id" type="Real" src="osm_id" width="11"/>
    <Field name="lastchange" type="Date" src="lastchange" width="10"/>
    <Field name="name" type="String" src="name" width="255"/>
    <Field name="keyvalue" type="String" src="keyvalue" width="80"/>
  </OGRVRTLayer>
</OGRVRTDataSource>ogr genconfigGenerate transormation specification from data sourceusage: ogr genconfig [-h] [--format FORMAT] [--model MODEL]
                   source [layers [layers ...]]Example:ogr genconfig --format=PostgreSQL tests/data/osm/railway.shp{
  "comment": "// OGR transformation specification",
  "layers": {
    "railway": {
      "fields": {
        "keyvalue": {
          "src": "keyvalue",
          "type": "String",
          "width": 80
        },
        "lastchange": {
          "src": "lastchange",
          "type": "Date",
          "width": 10
        },
        "type": {
          "src": "type",
          "type": "String",
          "width": 255
        },
        "name": {
          "src": "name",
          "type": "String",
          "width": 255
        },
        "osm_id": {
          "src": "osm_id",
          "type": "Real",
          "width": 11
        }
      },
      "geometry_type": "LineString",
      "src_layer": "railway"
    }
  }
}ogr write-enumsWrite tables with enumeration valuesusage: ogr write-enums [-h] [--debug] [--format FORMAT] [--config CONFIG]
                       [dest]

positional arguments:
  dest             output datasource

optional arguments:
  -h, --help       show this help message and exit
  --debug          Display debugging information
  --format FORMAT  Destination format
  --config CONFIG  OGR configurationExample:ogr write-enums --config=roads.cfg "PG:dbname=ogrili"ogr transformTransform data source based on transformation configurationusage: ogr transform [-h] [--debug] [--reverse] [--format FORMAT]
                     [--config CONFIG]
                     [dest] source [layers [layers ...]]

positional arguments:
  dest             output datasource
  source           input datasource
  layers           layer names

optional arguments:
  -h, --help       show this help message and exit
  --debug          Display debugging information
  --reverse        Reverse transformation
  --format FORMAT  Destination format
  --config CONFIG  OGR configurationExample:ogr transform --config=roads.cfg "PG:dbname=ogrili" RoadsExdm2ien.xmlFrom Interlis to GML:ogr transform --format GML --config tests/data/ili/RoadsExdm2ien.cfg tests/data/ili/RoadsExdm2ien.gml tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imdBack to Interlis:ogr transform --reverse --config tests/data/ili/RoadsExdm2ien.cfg /tmp/roads23_from_gml.xtf,tests/data/ili/RoadsExdm2ien.imd tests/data/ili/RoadsExdm2ien.gmlogrprocessing QGIS pluginProvides OGR functionality as QGIS SEXTANTE plugin. It was published for
QGIS 1.8 and is now included in the core processing algorithms of QGIS
2.0.Interlis QGIS pluginGUI for importing and exporting Interlis data with OGR/ogrtools.
Includes Python libraries for easy installation. Currently tested with
QGIS 2.0.Developmentgit clone https://github.com/sourcepole/ogrtools.gitRunning tests:apt-get install python-nosenosetestsFor running ogr commands from source tree:alias ogr="PYTHONPATH=$(pwd) $(pwd)/ogr_cli/ogr.py"Licenseogrtools is Copyright © 2012-2015 Sourcepole AG. It is free software,
and may be redistributed under the terms specified in the LICENSE.txt
file.