[gdal-dev] to find area of shapeFile

Eli Adam eadam at co.lincoln.or.us
Thu Jun 14 09:35:35 PDT 2012


Siva,

I'm not sure how to help you with the below code.  Perhaps if you
explain the error someone else on the list might be able to help.

My suggestion was how to get the area using the command line tool ogr2ogr.

Regards, Eli

On Thu, Jun 14, 2012 at 1:16 AM, SIVA RAMA KRISHNA
<s.r.kriishna at gmail.com> wrote:
>  Eli Adam,
>
>        i  am Trying To Find Area of A Polygon
>        with the Following Code
>
> int main()
>     {
>     OGRRegisterAll();
>     OGRLayer *poLayer;
>     OGRFeature *poFeature;
>     OGRDataSource       *poDS;
>     poDS = OGRSFDriverRegistrar::Open( "first.shp");
>     poLayer = poDS->GetLayerByName( "first");
>     int nCount=poDS->GetLayerCount();
>     printf("%d",nCount);
>     poLayer->ResetReading();
>     OGRGeometry *poGeometry;
>     OGRGeometryCollection *PoGC;
>     while((poFeature=poLayer->GetNextFeature())!=NULL)
>     {
>         int nCnt=poFeature->GetFieldCount();
>         printf("\n %d",nCnt);
>         qDebug()<<"entered";
>         poGeometry=poFeature->GetGeometryRef();
>          if(poGeometry !=NULL
>              && wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon)
>        {
>              PoGC->addGeometry(poGeometry);
>              double area = PoGC->get_Area() ;
>             qDebug() << area ;
>          }
>     }
>     return 0;
> }
>
> i am getting Error
> With Regards
> siva
>


More information about the gdal-dev mailing list