[gdal-dev] create 25D MultiPolygon how to

legeochen legeochen at gmail.com
Fri Feb 27 08:47:06 EST 2009


Hi All
I try to create some multipolygons with OGR. After creating them, but when I
want view them in arcscene, it just make arcscene crash! Then I tried
osgviewer with ESRI Shapefile, I was warned:
ESRIShape loader: .dbf file containe different record number that .shp file.

                             .dbf record skipped.
Actually, only one feature in the dataset had been readed out.
Then, I tried osgviewer with ogr, got warnings like this:
Warning something wrong with a polygon in a multi polygon.
And, the result is not quite as expected!
Here is my code:
 const char* pszDriverName = "ESRI Shapefile";
 OGRSFDriver *poDriver;
 OGRRegisterAll();
    poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
                pszDriverName );
    if( poDriver == NULL )
    {
        printf( "%s driver not available.\n", pszDriverName );
        return false;
    }
 OGRDataSource *poDS;
 poDS = poDriver->Open(shpfile,TRUE);
 if(poDS == NULL)
  poDS = poDriver->CreateDataSource(shpfile,NULL);
 if(poDS == NULL)
 {
  printf("Creation of output file failed.\n");
  return false;
 }
 OGRLayer* poLayer = poDS->GetLayerByName (layername);
 if(poLayer == NULL)
 {
  if( !poDS->TestCapability( ODsCCreateLayer ) )
        {
            fprintf( stderr,
              "Layer Roadway not found, and CreateLayer not supported by
driver." );
            return FALSE;
        }
  CPLErrorReset();
  poLayer = poDS->CreateLayer(layername,NULL,wkbMultiPolygon25D,NULL);
  if(poLayer == NULL)
  {
   printf( "Layer creation failed.\n" );
   return false;
  }
 }

 for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw !=
_roadwayArr.end();itrw++)
 {
  OGRFeature *poFeature;

  OGRMultiPolygon multiPoly;
  poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());
  Roadway::Triangle_list tris = (*itrw)->getTrianglelist();
  for(Triangle_list::const_iterator ittri = tris.begin();ittri !=
tris.end();ittri++)
  {
   OGRPolygon polygon;
   OGRLinearRing poRing;
   poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z());
   poRing.addPoint((*ittri).b().x(),(*ittri).b().y(),(*ittri).b().z());
   poRing.addPoint((*ittri).c().x(),(*ittri).c().y(),(*ittri).c().z());
   poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z());

   polygon.addRing(&poRing);
   multiPoly.addGeometry(&polygon);

  }
  poFeature->SetGeometry(&multiPoly);
  if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
  {
   printf( "Failed to create feature in shapefile.\n" );
   return false;
  }
  OGRFeature::DestroyFeature( poFeature );
 }
 OGRDataSource::DestroyDataSource( poDS );
Any help is appreciated!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090227/8b02e654/attachment-0001.html


More information about the gdal-dev mailing list