[gdal-dev] How to edit a .dxf file?

huahu huahu0213 at gmail.com
Fri Mar 2 12:26:52 EST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120303/f91a6996/attachment.html


More information about the gdal-dev mailing list