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