用于将地理空间数据读写为多种矢量格式的gdal包装器

geometryIO的Python项目详细描述


这是一个gdal包装器,用于将地理空间数据读写为各种矢量格式。有关支持的矢量格式和驱动程序名称的列表,请参见http://www.gdal.org/ogr/ogr_formats.html

安装

下面是在virtualenv中安装geometryIO的说明

# Prepare isolated environment
ENV=$HOME/Projects/env
virtualenv $ENV
mkdir $ENV/opt

# Activate isolated environment
source $ENV/bin/activate

# Install GDAL
sudo yum -y install swig
GDAL_VERSION=1.9.0
GDAL_FILENAME=gdal-$GDAL_VERSION
cd $ENV/opt
wget http://download.osgeo.org/gdal/$GDAL_FILENAME.tar.gz
tar xzvf $GDAL_FILENAME.tar.gz
cd $GDAL_FILENAME
./configure --prefix=$ENV --with-python
make install

# Install package
export LD_LIBRARY_PATH=$ENV/lib:$LD_LIBRARY_PATH
easy_install -U geometryIO

用法

准备环境

ENV=$HOME/Projects/env
source $ENV/bin/activate
export LD_LIBRARY_PATH=$ENV/lib:$LD_LIBRARY_PATH
ipython

运行代码

import geometryIO
import datetime
import itertools
from osgeo import ogr
from shapely import geometry

geometryIO.save(
    # Save to a compressed shapefile
    targetPath='polygons.shp.zip',
    # Declare that source coordinates are in longitude and latitude
    sourceProj4=geometryIO.proj4LL,
    # Specify geometries using shapely
    shapelyGeometries=[
        geometry.Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]),
        geometry.Polygon([(10, 0), (10, 10), (20, 10), (20, 0), (10, 0)]),
    ],
    # Specify attributes for each geometry
    fieldPacks=[
        ('xxx', 11111, 44444.44, datetime.datetime(1980, 1, 1)),
        ('yyy', 22222, 88888.88, datetime.datetime(1990, 1, 1)),
    ],
    # Define attributes
    fieldDefinitions=[
        ('Name', ogr.OFTString),
        ('Population', ogr.OFTInteger),
        ('GDP', ogr.OFTReal),
        ('Date', ogr.OFTDate),
    ],
    # Specify desired vector format
    driverName='ESRI Shapefile',
    # Transform coordinates to spherical mercator
    targetProj4=geometryIO.proj4SM)

proj4, shapelyGeometries, fieldPacks, fieldDefinitions = geometryIO.load(
    # Load from a compressed shapefile
    sourcePath='polygons.shp.zip',
    # Transform coordinates to longitude and latitude
    targetProj4=geometryIO.proj4LL)
for shapelyGeometry, fPack in itertools.izip(shapelyGeometries, fieldPacks):
    print
    for fValue, (fName, fType) in itertools.izip(fPack, fieldDefinitions):
        print '%s = %s' % (fName, fValue)
    print shapelyGeometry

geometryIO.save_points(
    # Save to a compressed shapefile
    targetPath='points.shp.tar.gz',
    # Declare that source coordinates are in longitude and latitude
    sourceProj4=geometryIO.proj4LL,
    # Specify coordinates
    coordinateTuples=[
        (0, +1),
        (+1, 0),
        (0, -1),
        (-1, 0),
    ])
print geometryIO.load_points('points.shp.tar.gz')[1]

0.9.7

  • 修复python 3兼容性

0.9.5

  • 加载包含多种格式的存档文件时按优先顺序排列的形状文件

0.9.4

  • 改进了对空日期时间字段的处理

0.9.3

  • 添加了对datetime属性的支持
  • 将feature.setfield()替换为feature.setfield2()

0.9.2

  • 从Geometry商店移植代码

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

推荐PyPI第三方库


热门话题
java为什么数据库中具有“读取”角色的用户不能列出集合?   在Java中使用带有反应式包装器的非阻塞IO逐行读取文件   java当`!`时,什么可以简化表达式应用于`&`或`||`   java Jasperreports报告了四组多个动态图像   java我想将单个字符串的ascii值存储在一行中,如何使用getbyte函数实现这一点   javascript如何在java中写入文件时响应帖子?   新用户注册后java登录失败| Weblogic安全   java中的多线程和同步   java在FOR循环中使用ParseObject   Java货币数字格式   java模拟单例类   java编写大量数据时,部分数据会丢失/当所有数据都存在时,写入过程非常缓慢   java如何处理复合对象的所有子对象?   java如何获得相交集的大小?   我需要在java中的不同源代码中对broadcost Httprequest进行测试   java我想在MainActivity中添加SpreadsheetWebService,而不需要从其他类调用它   安卓 Java是否有NFC API用于标准机器?