<div>Wow:</div>
<div>I have tried your suggestion. but it won't work. It seems the shp file create by ogr is a little different from which generated with shplib. <br>reading shp file ceated by ogr with shplib gives me warning like the dbf. containe different record than shp. Actually, only the first geometry can be read out. <br>
</div>
<div class="gmail_quote">2009/3/3 legeochen <span dir="ltr"><<a href="mailto:legeochen@gmail.com">legeochen@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Wow:</div>
<div> Tanks for your suggestion! Yeaph! That maybe where the rub is. I will try it out soon.</div>
<div>cheers!<br><br></div>
<div class="gmail_quote">2009/3/3 wow <span dir="ltr"><<a href="mailto:27949218@qq.com" target="_blank">27949218@qq.com</a>></span>
<div>
<div></div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<table style="TABLE-LAYOUT: fixed; FONT-SIZE: 1px; WIDTH: 100%" cellspacing="0" cellpadding="0" width="100%" align="center" bgcolor="#dafefc" border="0">
<tbody>
<tr>
<td valign="top" nowrap width="188" height="118"></td>
<td style="WIDTH: 99%" valign="top" nowrap height="118"> </td>
<td valign="top" nowrap width="1%"> </td></tr></tbody></table>
<table style="TABLE-LAYOUT: fixed; FONT-SIZE: 1px; WIDTH: 100%" height="344" cellspacing="0" cellpadding="0" align="center" bgcolor="#dafefc" border="0">
<tbody>
<tr>
<td valign="top" width="40"></td>
<td style="FONT-SIZE: 12px; COLOR: #003399; LINE-HEIGHT: 30px" valign="top" align="left">
<div>Hi,</div>
<div> Your code looks like that you didn't create any field for the feature. At least create one field would ensure success.</div>
<div>Like this:</div>
<div> OGRFieldDefn oField( "Name", OFTString );<br> oField.SetWidth(32);<br> if( pLayer->CreateField( &oField ) != OGRERR_NONE )<br> {<br> printf( "Creating Name field failed.\n" );<br>
exit( 1 );<br> }</div>
<div> </div>
<div>Xuexia Chen</div>
<div>
<div style="FONT-SIZE: 12px; COLOR: #909090; FONT-FAMILY: Arial Narrow">------------------</div>
<div>To the world you're little, but to a person, maybe you're the world.</div>
<div> </div></div>
<div></div>
<div></div>
<div> </div>
<div>
<div> </div>
<div> </div>
<div style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12px; PADDING-BOTTOM: 2px; PADDING-TOP: 2px; FONT-FAMILY: Arial Narrow">------------------ Original ------------------</div>
<div style="FONT-SIZE: 12px">
<div><b>From: </b> "legeochen"<<a href="mailto:legeochen@gmail.com" target="_blank">legeochen@gmail.com</a>>;</div>
<div><b>Date: </b> Fri, Feb 27, 2009 09:47 PM</div>
<div><b>To: </b> "Gdal-Dev"<<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>>; </div>
<div></div>
<div><b>Subject: </b> [gdal-dev] create 25D MultiPolygon how to</div></div>
<div> </div>
<div style="FONT-WEIGHT: normal">
<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></div></div></td>
<td valign="top" width="40"></td></tr></tbody></table>
<table style="TABLE-LAYOUT: fixed; FONT-SIZE: 1px; WIDTH: 100%" cellspacing="0" cellpadding="0" width="100%" align="center" bgcolor="#dafefc" border="0">
<tbody>
<tr>
<td style="WIDTH: 99%" nowrap> </td>
<td width="179" height="34"></td></tr></tbody></table>
<table style="FONT-SIZE: 0px; HEIGHT: 0px" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td></td></tr></tbody></table></blockquote></div></div></div><br></blockquote></div><br>