[gdal-dev] create 25D MultiPolygon how to

legeochen legeochen at gmail.com
Mon Mar 2 20:53:56 EST 2009


Wow:
 Tanks for your suggestion! Yeaph! That maybe where the rub is. I will try
it out soon.
cheers!

2009/3/3 wow <27949218 at qq.com>

>         Hi,
>  Your code looks like that you didn't create any field for the feature. At
> least create one field would ensure success.
> Like this:
>     OGRFieldDefn oField( "Name", OFTString );
>     oField.SetWidth(32);
>     if( pLayer->CreateField( &oField ) != OGRERR_NONE )
>     {
>         printf( "Creating Name field failed.\n" );
>         exit( 1 );
>     }
>
> Xuexia Chen
>  ------------------
> To the world you're little, but to a person, maybe you're the world.
>
>
>
>
> ------------------ Original ------------------
>  *From: * "legeochen"<legeochen at gmail.com>;
> *Date: * Fri, Feb 27, 2009 09:47 PM
> *To: * "Gdal-Dev"<gdal-dev at lists.osgeo.org>;
>  *Subject: * [gdal-dev] create 25D MultiPolygon how to
>
>  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/20090303/863f5563/attachment.html


More information about the gdal-dev mailing list