<div>Hi All</div>
<div>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:</div>
<div>ESRIShape loader: .dbf file containe different record number that .shp file. </div>
<div> .dbf record skipped.</div>
<div>Actually, only one feature in the dataset had been readed out.</div>
<div>Then, I tried osgviewer with ogr, got warnings like this:</div>
<div>Warning something wrong with a polygon in a multi polygon.</div>
<div>And, the result is not quite as expected!</div>
<div>Here is my code:</div>
<div> const char* pszDriverName = "ESRI Shapefile";<br> OGRSFDriver *poDriver;</div>
<div> OGRRegisterAll();</div>
<div> poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(<br> pszDriverName );<br> if( poDriver == NULL )<br> {<br> printf( "%s driver not available.\n", pszDriverName );<br>
return false;<br> }</div>
<div> OGRDataSource *poDS;</div>
<div> poDS = poDriver->Open(shpfile,TRUE);<br> if(poDS == NULL)<br> poDS = poDriver->CreateDataSource(shpfile,NULL);<br> if(poDS == NULL)<br> {<br> printf("Creation of output file failed.\n");<br> return false;<br>
}</div>
<div> OGRLayer* poLayer = poDS->GetLayerByName (layername);<br> if(poLayer == NULL)<br> {<br> if( !poDS->TestCapability( ODsCCreateLayer ) )<br> {<br> fprintf( stderr, <br> "Layer Roadway not found, and CreateLayer not supported by driver." );<br>
return FALSE;<br> }<br> CPLErrorReset();</div>
<div> poLayer = poDS->CreateLayer(layername,NULL,wkbMultiPolygon25D,NULL);<br> if(poLayer == NULL)<br> {<br> printf( "Layer creation failed.\n" );<br> return false;<br> }<br> }</div>
<div><br> for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw != _roadwayArr.end();itrw++)<br> {<br> OGRFeature *poFeature;<br> <br> OGRMultiPolygon multiPoly;<br> poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());<br>
Roadway::Triangle_list tris = (*itrw)->getTrianglelist();<br> for(Triangle_list::const_iterator ittri = tris.begin();ittri != tris.end();ittri++)<br> {<br> OGRPolygon polygon;<br> OGRLinearRing poRing;</div>
<div> poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z());<br> poRing.addPoint((*ittri).b().x(),(*ittri).b().y(),(*ittri).b().z());<br> poRing.addPoint((*ittri).c().x(),(*ittri).c().y(),(*ittri).c().z());<br>
poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z());<br> <br> polygon.addRing(&poRing);<br> multiPoly.addGeometry(&polygon);<br> <br> }<br> poFeature->SetGeometry(&multiPoly);<br>
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )<br> {<br> printf( "Failed to create feature in shapefile.\n" ); <br> return false;<br> }<br> OGRFeature::DestroyFeature( poFeature );<br>
}<br> OGRDataSource::DestroyDataSource( poDS );</div>
<div>Any help is appreciated!! <br> </div>