Geometry

Basically this module helps to speed up and to simplify the interaction with the ogr-API. Extremely convient if you want to save geomtries and their attributes to a GIS format.

class ogr_utils.geometry.Geometry(vertex_arrays, fields=None, attr=None, driver='ESRI Shapefile', ordered=True)

Geometry class

__init__(vertex_arrays, fields=None, attr=None, driver='ESRI Shapefile', ordered=True)

fields is a tuple or list of field name and field type. Type can be

  • str
  • int
  • float
  • date
  • time

vertex_array is a tuple/list of tuples/lists with all coordinates making the line attr is tuple/list of tuples/lists. They are ordered by default, which means their realtionship to each other is best described by the index they share. Example:

attr = [[0,1,2,...],['heute','morgen','gestern',...]]

by setting the ordered argument to False it is also possible to pass the attributes unordered, which means their relationship is best described by the fact that they belong to the same row. Example:

attr = [(0,'heute'),(1,'morgen'),(2,'gestern'),...]
make_lines(shape)

shape is filename of type .shp

make_points(shape)

shape is filename of type .shp

make_polygons(shape)

shape is filename of type .shp

Example

Save a set of geo objects to a shapefile (or any other file format supported by ogr):

from ogr_utils.geometry import Geometry
g = Geometry( [(xy),], [(fieldname_1, type),(fieldname_2, type),], [(value_field_1,...),(value_field_2,...)] )
f = '/home/.../outfile.shp'
g.make_points(f)

Table Of Contents

Previous topic

Intro

Next topic

Research

This Page