[Gdal-dev] OGR question

Clay, Bruce bclay at ball.com
Thu Feb 26 15:59:27 EST 2004


Frank:
  thanks for the reply.  

I am using the following

        while( (feature = OGR_L_GetNextFeature( layer )) != NULL )
        {
			OGRGeometryH geom_handl =
OGR_F_GetGeometryRef(feature);
			OGRwkbGeometryType type =
OGR_G_GetGeometryType(geom_handl);
 more stuff
	}

The type is wkbPolygon.  When I look in the ogrpolygon.cpp file I don't
find getNumPoints, getX or getY;

I started this task by copying OGRDump and modifying that.

Am I in the wrong ballpark?

Bruce
bclay at ball.com

-----Original Message-----
From: Frank Warmerdam [mailto:warmerdam at pobox.com] 
Sent: Thursday, February 26, 2004 3:33 PM
To: gdal-dev at remotesensing.org
Subject: Re: [Gdal-dev] OGR question


Clay, Bruce wrote:
> I see from going through the OGR code that I can get the data from a 
> shape file using OGR_G_ExportToWkb(). I can get the size of the 
> required data buffer by calling OGR_G_WkbSize();
> 
> What I don't see is how to find the number of points in the chunk or 
> where it starts in the buffer. From the code I see something like 9 
> bytes + (number of points * number of bytes per point based on data 
> dimension (2D or 3D))  but I don't see an actual accessor to the 
> number of points or where to start in the data buffer considering the 
> 9  bytes what ever they contain.
> 
> Any clues to where I am going wrong would be greatly appreciated.

Bruce,

The ExportToWkb() isn't intended to be the "normal" way to get at the
geometry information.  It is producing a well defined binary format used
in some OGC specifications.  If you just want to get the points, you
should read the features with GetNextFeature(), pull out the geometry
with
GetGeometryRef() on the feature.  And then cast the geometry to the
appropriate type.  If the geometry GetGeometryType() returns
wkbLineString for instance, you could cast it to OGRLineString, and then
use line string methods like getNumPoints(), and getX(i), getY(i) and so
forth.

Does that make sense?

Note that the WKB representation isn't necessarily in local machine byte
order and the floating point coordinates are generally not word aligned
which would be necessary if you wanted to access them directly (at least
on some platforms).

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

_______________________________________________
Gdal-dev mailing list
Gdal-dev at remotesensing.org
http://remotesensing.org/mailman/listinfo/gdal-dev



More information about the Gdal-dev mailing list