[Gdal-dev] OGR Multiple features to Shapefile

Andrea Battisti battisti at actgate.com
Mon Dec 29 08:24:28 EST 2008


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,

-- 
Andrea Battisti
Applied Coherent Technology Corp.



More information about the gdal-dev mailing list