[Gdal-dev] Accessing polygon data through the scripting interface

Frank Warmerdam fwarmerdam at gmail.com
Mon Sep 5 16:57:37 EDT 2005


On 9/5/05, Ari Jolma <ari.jolma at tkk.fi> wrote:
> Hello,
> 
> I saw some discussion on this subject earlier on this list
> (http://lists.maptools.org/pipermail/gdal-dev/2005-February/005109.html)
> but I think it's still impossible(?) to access the polygon data (rings
> and then vertices) through the scripting interface.
> 
> I see that the OO interface for scripting languages is done using the C
> (not C++) api (ogr_api.h etc). The interface is rewritten into C++ in
> ogr.i but without subclasses of OGRGeometry like OGRPolygon. Some of the
> subclass methods are written into the C API but not all. Shouldn't also
> the OGRPolygon methods Get*Ring be wrapped into OGRGeometry? In fact I
> tried this and with these in place one is able to do things like this
> (in Perl but the small changes I had to make were not Perl specific):
> 
> $geom = $feature->GetGeometryRef();
> $ring = $geom->GetExteriorRing(); # assuming geom is polygon...
> $ring->GetX(10);
> 
> Methods GetPoint(int) and GetPoints would be useful also.
> 
> These may be implemented in ogr_api.cpp (then they are available in the
> C interface) or in ogr.i. GetPoint(int) is in ogr_api.cpp but not in ogr.i.

Ari,

Access to the various kinds of geometry is available through the
ogr.Geometry class in Python.  The "trick" is that the explicit
geometry classes are not directly modelled.  Instead a geometry
is a container of sub-geometries and/or a list of points.  So a
simple OGRPolygon object would translate as an ogr.Geometry
with a bunch of sub-geometries (the rings), and each ring would
have a bunch of points. 

In python sub-geometries are grabbed with the GetGeometryRef(int)
method, and the points with GetX(int), GetY(int) and GetZ(int).  Use
GetPointCount() and GetGeometryCount() to find how many of each
are available (they are actually always mutually exclusive). 

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list