[Gdal-dev] OGR question

Frank Warmerdam warmerdam at pobox.com
Thu Feb 26 15:32:32 EST 2004


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




More information about the Gdal-dev mailing list