Siva,

You can create a new shapefile layer using the poGeometry2 objects. Set
each of them to a feature object and add them to the layer.
Refer to the OGR API Tutorial.
http://www.gdal.org/ogr/ogr_apitut.html

On Fri, Jun 8, 2012 at 11:38 AM, SIVA RAMA KRISHNA
<[email protected]>wrote:

> mywindow::mywindow(QWidget *parent) :    QMainWindow(parent){        view=new 
> QGraphicsView(this);    view->repaint();    scene=new QGraphicsScene();    
> OGRRegisterAll();    scaleFactor=0.01;    //poDS = 
> OGRSFDriverRegistrar::Open( "admin.shp");    //poLayer = 
> poDS->GetLayerByName( "admin");    poDS = OGRSFDriverRegistrar::Open( 
> "india_st.shp");    poLayer = poDS->*GetLayerByName*( "india_st");    
> poDS1=OGRSFDriverRegistrar::Open("india_ds.shx");    
> poLayer1=poDS1->*GetLayerByName*("india_ds");    poLayer->*ResetReading*();   
>  poLayer1->*ResetReading*();    view->setRenderHint(QPainter::Antialiasing);  
>   while(((poFeature=poLayer->*GetNextFeature*())!=NULL) && 
> ((poFeature1=poLayer1->*GetNextFeature*())!=NULL))    {        
> poGeometry=poFeature->GetGeometryRef();        
> poGeometry1=poFeature1->GetGeometryRef();        OGREnvelope * psEnvelope1 = 
> new OGREnvelope();        OGREnvelope * psEnvelope2 = new OGREnvelope();      
>   poGeometry->*getEnvelope*(psEnvelope1);        
> poGeometry1->*getEnvelope*(psEnvelope2);        qDebug() << psEnvelope1->MinX 
> << psEnvelope1->MinY <<  psEnvelope1->MaxX << psEnvelope1->MaxY;        
> qDebug() << psEnvelope2->MinX << psEnvelope2->MinY <<  psEnvelope2->MaxX << 
> psEnvelope2->MaxY;        if (this->Intersects1(poGeometry,poGeometry1)==1)   
>      {            QPainter painter2;            
> poGeometry2=poGeometry->*Intersection*(poGeometry1);            
> if(poGeometry2 !=NULL                    && 
> wkbFlatten(poGeometry2->*getGeometryType*()) == wkbPolygon)            {      
>           qDebug()<<"1yes";                polyShape2 = (OGRPolygon*) 
> poGeometry2;                
> drawPolyShape(painter2,polyShape2,MBR,scaleFactor);            }        }     
>    this->setCentralWidget(view);    }//end of while loop    QString 
> filename3,projString;    filename3="india_st_out.shp";    OGRwkbGeometryType 
> type;    ShapeFileWriter( filename3,type, projString);}//end of main
> OGRBoolean mywindow::Intersects1(OGRGeometry *poGeom,  OGRGeometry 
> *poOtherGeom ) const{   // this is for obtaining a region for interscetion}
> void mywindow::drawPolyShape(QPainter& painter,OGRPolygon* polyShape,const 
> QRectF& MBR, const double& scaleFactor){        // for drawing a shape file
> }
> void mywindow::drawClosedLinearRing(QPainterPath& painter,OGRLinearRing* 
> linearRing,                                    const QRectF& MBR, const 
> double& scaleFactor){              // for drawing a  shape  file
> }
> void mywindow::ShapeFileWriter(QString filename,OGRwkbGeometryType 
> type,QString projString)// program to write to shape file     {        
> QFileInfo info(filename);        QString baseFileName = info.absolutePath(); 
> //+ QDir::separator();        baseFileName += info.baseName();            
> QFile fileshx(baseFileName + ".shx");        QFile fileshp(baseFileName + 
> ".shp");        QFile filedbf(baseFileName + ".dbf");        QFile 
> fileprj(baseFileName + ".prj");        if(fileshp.exists())        {          
>   fileshp.remove();        }        if(fileshx.exists())        {            
> fileshx.remove();        }        if(filedbf.exists())        {            
> filedbf.remove();        }        if(fileprj.exists())        {            
> fileprj.remove();        }        QString fileName = filename;        
> QStringList list;        const char *pszDriverName = "ESRI Shapefile";        
> OGRSFDriver *poDriver;        OGRRegisterAll();        poDriver = 
> OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(                
> pszDriverName );        if( poDriver == NULL )        {            return;    
>     }        poDS = poDriver->*CreateDataSource*(filename.toLatin1().data(), 
> NULL );        if( poDS == NULL )        {            return;        }        
> filename.truncate(fileName.length()-4);        poLayer = 
> poDS->*CreateLayer*(filename.toLatin1().data(), NULL, type, NULL);        if( 
> poLayer == NULL )        {            return;        }        
> if(!projString.isEmpty() && !projString.isNull())        {            
> filename = filename + ".prj";            QFile data(filename);            if 
> (data.*open*(QFile::WriteOnly | QFile::Truncate))            {                
>  QTextStream out(&data);                 out<<projString<<"\n";               
>   list.append(projString);            }            data.*close*();        }
>         int rec;//      
> rec=identifyRecord(psEnvelope3->MinX,psEnvelope3->MinY,psEnvelope3->MaxX );   
>      int x;        x=addRecord(poGeometry2,list);        int y;        
> y=getNumofRecords();        qDebug()<<y;    }int 
> mywindow::addRecord(OGRGeometry* geometry,QStringList list)    {        int 
> fID;        OGRFeature *poFeature;        poFeature = 
> OGRFeature::CreateFeature( poLayer->*GetLayerDefn*() );        
> poFeature->SetField( "ID", (int)poFeature->GetFID());        
> poFeature->SetGeometry( geometry );        for(int i = 0; i < list.size(); 
> i++)        {            qDebug()<<"ADDED";            poFeature->SetField( 
> i, list.at(i).toDouble());        }        if( poLayer->*CreateFeature*( 
> poFeature ) != OGRERR_NONE )        {            return -1;        }        
> fID = (int)poFeature->GetFID();        OGRFeature::DestroyFeature( poFeature 
> );        return fID;   }
>
>
>
> _______________________________________________
> gdal-dev mailing list
> [email protected]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
Best regards,
Chaitanya kumar CH.

+91-9494447584
17.2416N 80.1426E
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to