[Gdal-dev] importFromWkt() problem
Petteri Packalen
packalen at cs.joensuu.fi
Sat Sep 2 10:16:59 EDT 2006
Frank, list,
Once again, I struggled with the weird problem until I understood to look
at the documentation... The problem was that, within importFromWkt(), the
pointer was updated to pointer after the consumed text. However, I don't
still understand why the first *corrected* solution does not work
properly. I want to reset the geometry of an existing feature based on WKT
representation. Below are two examples in which only the latter one works
properly. An example 1 crashes due to illegal memory access. geo_trans is
a buffer which stores WKT.
EXAMPLE 1
=========
OGRPolygon * poPoly = new OGRPolygon();
poPoly->importFromWkt( &geo_trans );
poDstFeature->SetGeometryDirectly( poPoly );
...
OGRFeature::DestroyFeature( poFeature );
EXAMPLE 2
=========
char* pszWkt = (char*) geo_trans;
OGRSpatialReference *ref = new OGRSpatialReference( NULL );
OGRGeometry *new_geom;
OGRErr err = OGRGeometryFactory::createFromWkt(&pszWkt, ref, &new_geom);
poDstFeature->SetGeometryDirectly( new_geom );
...
OGRFeature::DestroyFeature( poFeature );
In the comment within the ogrgeometryfactory.cpp it states that
"createFromWkt() now updates pointer to text to indicate how much text was
consumed". I understand that this can be useful in many occasions although
I don't understand why it is implemented this way. Anyway, why the first
solution does not work? In addition, in an example 1 the problem occurres
only after very many (>million) calls to importFromWkt(). Something is
happening in the background (related to reference counting etc.?) I don't
understand.
Best regards,
Petteri
=========================================================================
Petteri Packalén
University of Joensuu
Faculty of Forestry
P.O. Box 111
80101 Joensuu
Finland
e-mail: packalen at cs.joensuu.fi
=========================================================================
More information about the Gdal-dev
mailing list