[gdal-dev] OGR Multiple features to Shapefile

Frank Warmerdam warmerdam at pobox.com
Wed May 7 14:37:32 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.

If that isn't the issue, I'd encourage you to boil this down to
a standalone code sample that should build and run, and submitting
it via a ticket.

Best regards,
Frank

Andrea Battisti wrote:
> 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 the 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,
> 


-- 
---------------------------------------+--------------------------------------
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    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list