使用ogr的python api构建的库和工具的集合。

ogrtools的Python项目详细描述


简介

ogrtools是用python构建的库和工具的集合。 OGR的api。

pyogr库

pyogr将ogr命令(如ogr2ogr或ogrinfo)作为python库提供给您, 即不调用外部可执行文件。大部分代码是 已经作为使用 python api。

  • ogr2ogr.py:使用stdout/stderr重定向的ogr2ogr调用
  • ogrinfo.py:ogrinfo调用
  • ogrvrt.py:从数据源生成VRT
  • py:对数据源调用ogr sql命令

Interlis库

ogrInterlis driver的扩展。

  • 自动检测传输文件中使用的模型
  • 从ILISmeta模型提取枚举
  • 从模型库加载和转换interlis模型

ogrtransform库

从一种格式转换数据时,ogr有许多选项 变成另一个。ogrtransform库使用json中的配置 转换数据的格式。

示例:

{
  "//": "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
        }
      ]
    }
  }
}

有关详细信息,请参见Wiki 信息。

ogr命令行工具

ogr命令行工具公开ogrtools功能,以便在 命令外壳。

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 configuration

ogr版本

显示版本信息

usage: ogr version [-h]

ogr格式

列出可用的数据格式

usage: ogr formats [-h]

ogr信息

有关数据的信息

usage: ogr info [-h] source [layers [layers ...]]

示例:

ogr info tests/data/osm/railway.shp
INFO: 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 sql

执行SQL查询

usage: ogr sql [-h] source sql-query

示例:

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 vrt

从数据源创建VRT

usage: ogr vrt [-h] source [layers [layers ...]]

示例:

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 genconfig

从数据源生成转换规范

usage: ogr genconfig [-h] [--format FORMAT] [--model MODEL]
                   source [layers [layers ...]]

示例:

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枚举

使用枚举值编写表

usage: 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 configuration

示例:

ogr write-enums --config=roads.cfg "PG:dbname=ogrili"

ogr变换

基于转换配置转换数据源

usage: 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 configuration

示例:

ogr transform --config=roads.cfg "PG:dbname=ogrili" RoadsExdm2ien.xml

从Interlis到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.imd

返回Interlis:

ogr transform --reverse --config tests/data/ili/RoadsExdm2ien.cfg /tmp/roads23_from_gml.xtf,tests/data/ili/RoadsExdm2ien.imd tests/data/ili/RoadsExdm2ien.gml

ogr处理qgis插件

提供了作为qgis sextante插件的ogr功能。它是为 qgis 1.8,现在被纳入qgis的核心处理算法中。 2.0条。

interlis qgis插件

用于使用ogr/ogrtools导入和导出interlis数据的gui。 包括易于安装的python库。目前测试 Qgis 2.0版。

开发

git clone https://github.com/sourcepole/ogrtools.git

运行测试:

apt-get install python-nose
nosetests

用于从源树运行ogr命令:

alias ogr="PYTHONPATH=$(pwd) $(pwd)/ogr_cli/ogr.py"

许可证

Ogrtools版权所有©2012-2015 SourcePole AG。它是自由软件, 并可根据license.txt中指定的条款重新分发。 文件。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Hystrixjavanica在类级别动态设置属性   按id在firestore文档上进行java循环   java线程的多线程死锁   java无法将行插入MySQL数据库   java在使用TestNG框架从ALM运行LeanFT脚本时没有抛出这样的方法错误,对此有任何输入吗?   在内核上编写基本的java shell或GUI   java访问级别感知的依赖项注入到继承字段中   java Twilio通过ivr呼叫回复传入短信   javaant<jar>任务:使用excludes参数   ApacheFelix中的java禁用缓存   安卓通过Java动态设置表布局   java如何确定算术表达式中第一个冗余括号的索引?   JSP中基于数据库选择值的java变更表   在从JavaSOAP接收的Windows调用(C++)中使用Unicode文本   java在mySql中是否可以将用户确定的路径作为连接URL