[gdal-dev] OGR Multiple features to Shapefile

Andrea Battisti battisti at actgate.com
Wed May 7 15:20:19 EDT 2008



> Andrea,
> 
> Yes, the shapefile driver should support all these types in
> when creating.  Your code looks fine.  The only reason I can
> think of for why this might be failing is if you are building
> on Win32 and you have a distinct heap for your application and
> for GDAL in which case there could be a problem with the OGRPoint
> you create in the application being destroyed on the GDAL heap.


Thanks for the quick reply,

I am building the test app on linux, but I saw the same problem on
win32.

Yes, as you suggest, there might be a problem with memory, because if I
create the geometry object without using the "new" operator, then it
works, i.e.:


/* working: */

#include "ogrsf_frmts.h"

int main()
{

	OGRMultiPoint dpoly;

	OGRPoint * point = new OGRPoint();
	point->setX( 42.0 );
	point->setY( 42.0 );

	OGRPoint * point2 = new OGRPoint();
	point2->setX( 4242.0 );
	point2->setY( 4242.0 );

	dpoly.addGeometryDirectly( point );
	dpoly.addGeometryDirectly( point2 );

}


/* segfaulting: */

#include "ogrsf_frmts.h"

int main()
{

	OGRMultiPoint * dpoly = new OGRMultiPoint();

	OGRPoint * point = new OGRPoint();
	point->setX( 42.0 );
	point->setY( 42.0 );

	OGRPoint * point2 = new OGRPoint();
	point2->setX( 4242.0 );
	point2->setY( 4242.0 );

	dpoly->addGeometryDirectly( point );
	dpoly->addGeometryDirectly( point2 );

}


Thanks,

-- 
Andrea Battisti
Applied Coherent Technology Corp.



More information about the gdal-dev mailing list