[Gdal-dev] OGR Multiple features to Shapefile

Even Rouault even.rouault at mines-paris.org
Tue Dec 30 14:41:22 EST 2008


Hi,

I've tested your code snippet under Linux and it works perfectly.

If you are under Windows, I'd suspect you hit a known issue about incompatible 
new/delete procedures of the C runtime from your module with the ones used by 
GDAL's C runtime. See 
http://trac.osgeo.org/gdal/wiki/FAQMiscellaneous#HowshouldIdeallocateresourcesacquaintedfromGDALonWindows

So, you should try :
OGRMultiPoint * dpoly = (OGRMultiPoint *)
		 OGRGeometryFactory::createGeometry(wkbMultiPoint);
OGRPoint * point = (OGRPoint *)
                 OGRGeometryFactory::createGeometry(wkbPoint);
OGRGeometryFactory::destroyGeometry(the_geom);

Best regards,

Even

Le Wednesday 07 May 2008 17:10:42 Andrea Battisti, vous avez écrit :
> Hi all,
>
> are the OGRMulti{ LineString | Point | Polygon } geometries supported by
> the ESRI Shapefile driver (in creation mode?); if so I am probably
> missing something in they way they should be used.
>
> I am asking this because when I try to write such features (i.e. an
> OGRMultiPoint) to a shapefile I get a crash when calling the
> addGeometry() method.
> I was looking for a working example of OGRMulti* features creation, but
> couldn't find one.
>
>
> Example code:
>
>   const char *pszDriverName = "ESRI Shapefile";
>   OGRSFDriver *poDriver;
>
>   OGRRegisterAll();
>
>   poDriver =
> OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName( pszDriverName );
>
> // ...
>
>     OGRDataSource *poDS;
> poDS = poDriver->CreateDataSource( "multi_out.shp", NULL );
>
> // ...
>
>     OGRLayer *poLayer;
>     poLayer = poDS->CreateLayer( "poly_out", NULL, wkbMultiPoint,
> NULL );
>
> // ...
>
> 	OGRFeature *poFeature;
> 	OGRGeometry * the_geom = NULL;
>
> 	poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
>
>
> 	OGRMultiPoint * dpoly = new OGRMultiPoint();
>
>
> 	OGRPoint * point = new OGRPoint();
> 	point->setX( 42.0 );
> 	point->setY( 42.0 );
>
> 	dpoly->addGeometryDirectly( point );
> 	// delete point;
>
>
> 	the_geom = dpoly;
> 	poFeature->SetGeometry( the_geom );
> 	delete the_geom;
>
>
> 	if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
> 	{
> 		printf( "Failed to create feature in shapefile.\n" );
> 		exit( 1 );
> 	}
>
> 	OGRFeature::DestroyFeature( poFeature );
>
> 	OGRDataSource::DestroyDataSource( poDS );
>
>
> Thanks in advance!
> Best Regards,




More information about the gdal-dev mailing list