Hi,<div>I try to edit in this way, but it can not work,although it can save geometry,but it cannot save feature.</div><div>My purpose is alter the previous file,and copy a DataSource to create a new file.<br><div><br></div>
<div><br></div><div><div><span style="white-space:pre-wrap">        </span>OGRRegisterAll(); </div><div><span style="white-space:pre-wrap">        </span>OGRDataSource *poDS = OGRSFDriverRegistrar::Open( srcname.c_str(), FALSE );</div>
<div><span style="white-space:pre-wrap">        </span>int layercount=poDS->GetLayerCount();</div><div><br></div><div><span style="white-space:pre-wrap">        </span>for(int num=0;num<layercount;num++)</div>
<div><span style="white-space:pre-wrap">        </span>{</div><div><span style="white-space:pre-wrap">        </span> OGRLayer* poLayer = poDS->GetLayer(num);</div><div><span style="white-space:pre-wrap">        </span> OGRFeature * pFeature;</div>
<div><span style="white-space:pre-wrap">        </span> poLayer->ResetReading();</div><div><br></div><div> while ((pFeature=poLayer->GetNextFeature())!=NULL)</div><div><span style="white-space:pre-wrap">        </span>{</div>
<div><span style="white-space:pre-wrap">        </span> OGRGeometry* pGeometry = pFeature->GetGeometryRef();</div><div><span style="white-space:pre-wrap">        </span> OGRwkbGeometryType geoType = pGeometry->getGeometryType();</div>
<div><span style="white-space:pre-wrap">        </span> if (pGeometry != NULL &&wkbPoint==geoType)</div><div><span style="white-space:pre-wrap">        </span> {</div><div> //change the coordinate value</div>
<div><span style="white-space:pre-wrap">                </span> OGRPoint *poPoint = (OGRPoint *) pGeometry;</div><div><span style="white-space:pre-wrap">                </span> double pointx=poPoint->getX()-X;</div>
<div><span style="white-space:pre-wrap">                </span> double pointy=poPoint->getY()-Y;</div><div><span style="white-space:pre-wrap">                </span> poPoint->setX((pointx*cos(e)-pointy*sin(e))+X);</div>
<div><span style="white-space:pre-wrap">                </span> poPoint->setY((pointx*sin(e)+pointy*cos(e))+Y);</div><div><span style="white-space:pre-wrap">        </span> }</div><div><span style="white-space:pre-wrap">        </span> else if(pGeometry != NULL &&wkbLineString==geoType)</div>
<div><span style="white-space:pre-wrap">        </span> {</div><div><span style="white-space:pre-wrap">                </span> OGRLineString* pLineGeo = (OGRLineString*)pGeometry;</div><div><span style="white-space:pre-wrap">                </span> int linestringsize=pLineGeo->getNumPoints();</div>
<div><span style="white-space:pre-wrap">                </span> for(int i=0;i<linestringsize;i++)</div><div><span style="white-space:pre-wrap">                </span> {</div><div><span style="white-space:pre-wrap">                </span> double pointx=((pLineGeo->getX(i)-X)*cos(e*PI/180.0)-(pLineGeo->getY(i)-Y)*sin(e*PI/180.0))+X;</div>
<div><span style="white-space:pre-wrap">        </span> double pointy=((pLineGeo->getX(i)-X)*sin(e*PI/180.0)+(pLineGeo->getY(i)-Y)*cos(e*PI/180.0))+Y;</div><div><span style="white-space:pre-wrap">        </span> pLineGeo->setPoint(i,pointx,pointy);</div>
<div><span style="white-space:pre-wrap">                </span> }</div><div><span style="white-space:pre-wrap">        </span> }</div><div><span style="white-space:pre-wrap">        </span> else if( pGeometry != NULL &&wkbPolygon==geoType)</div>
<div><span style="white-space:pre-wrap">        </span> {</div><div><span style="white-space:pre-wrap">                </span> OGRPolygon *pPolygon=(OGRPolygon*)pGeometry;</div><div><span style="white-space:pre-wrap">                </span> OGRLinearRing *ogrlring=pPolygon->getExteriorRing();</div>
<div><span style="white-space:pre-wrap">                </span> int lenth=ogrlring->getNumPoints();</div><div><span style="white-space:pre-wrap">                </span> for(int i=0;i<lenth;i++)</div><div>
<span style="white-space:pre-wrap">                </span> {</div><div><span style="white-space:pre-wrap">                        </span> double pointx=((ogrlring->getX(i)-X)*cos(e*PI/180.0)-(ogrlring->getY(i)-Y)*sin(e*PI/180.0))+X;</div>
<div><span style="white-space:pre-wrap">        </span> double pointy=((ogrlring->getX(i)-X)*sin(e*PI/180.0)+(ogrlring->getY(i)-Y)*cos(e*PI/180.0))+Y;</div><div><span style="white-space:pre-wrap">                        </span> ogrlring->setPoint(i,pointx,pointy);</div>
<div><span style="white-space:pre-wrap">                </span> }</div><div><span style="white-space:pre-wrap">                </span></div><div><span style="white-space:pre-wrap">        </span> }</div>
<div><span style="white-space:pre-wrap">        </span> else</div><div><span style="white-space:pre-wrap">        </span> {</div><div><span style="white-space:pre-wrap">        </span> }</div>
<div><span style="white-space:pre-wrap">                </span> poLayer->SetFeature(pFeature); //it can not save feature</div><div><br></div><div><span style="white-space:pre-wrap">        </span> }</div>
<div><span style="white-space:pre-wrap">        </span>}</div><div><span style="white-space:pre-wrap">        </span>OGRSFDriver* poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile");</div>
<div><span style="white-space:pre-wrap">        </span>OGRDataSource* desDS = poDriver->CopyDataSource(poDS,desname.c_str(),0);</div><div><span style="white-space:pre-wrap">        </span>OGRDataSource::DestroyDataSource( desDS );</div>
<div><span style="white-space:pre-wrap">        </span>OGRDataSource::DestroyDataSource( poDS );</div><div> OGRCleanupAll();</div></div><div><br></div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Can you help me?</span><br style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Thank you!</span><br style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Cheers,</span>
</div><div><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Huahu</span></div>
</div>