<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-9" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Courier New, Courier, monospace">Dear all,<br>
<br>
since couple of days I am learning how to use OGR library adn gat some
problems about Polygons and MultiPolygons. I have searched the list's
archive and found some replies to similar questions  (
<a class="moz-txt-link-freetext"
 href="http://lists.maptools.org/pipermail/gdal-dev/2004-February/002095.html">http://lists.maptools.org/pipermail/gdal-dev/2004-February/002095.html</a>,
<a class="moz-txt-link-freetext"
 href="http://lists.maptools.org/pipermail/gdal-dev/2004-May/002713.html">http://lists.maptools.org/pipermail/gdal-dev/2004-May/002713.html</a>)
which did not solve my problem yet. So, I have added my experiment
source code in C and I will be very glad if somebody help me about my
mistakes with in the code. <br>
<br>
Thanks in advances<br>
<br>
Regards,<br>
<br>
Aykut KOCAK<br>
<br>
<br>
------------------------------------<br>
<br>
<br>
#include &lt;stdio.h&gt;<br>
#include &lt;stdlib.h&gt;<br>
<br>
#include &lt;ogr_api.h&gt;<br>
<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
        OGRDataSourceH    *hDS;<br>
        OGRSFDriverH        *pahDriver;<br>
        OGRLayerH *hLY;<br>
        OGRFeatureH *hFT;<br>
        OGRwkbGeometryType *hGT;<br>
        OGRGeometryH *hG;<br>
        OGRFieldDefnH *hFD;<br>
        OGRFieldType hFldTyp;<br>
        char fname[255];<br>
<br>
        OGRRegisterAll();<br>
<br>
        if (argc &gt; 1 ) {<br>
                strcpy( fname, argv[1] );<br>
        } else {<br>
                strcpy( fname,
"/usr/local/share/clown/map/tr/turkiye.shp" );<br>
        }<br>
        hDS = OGROpen( fname, 0, NULL );<br>
        if( hDS == NULL ) {<br>
                fprintf(stderr,"Error %d\n",__LINE__);<br>
                return -1;<br>
        }<br>
        fprintf( stdout, "NAME        : %s \n",OGR_DS_GetName(hDS));<br>
        fprintf( stdout, "LAYER COUNT : %d
\n",OGR_DS_GetLayerCount(hDS));<br>
        hLY=OGR_DS_GetLayer(hDS,0);<br>
        if( hLY == NULL ) {<br>
                fprintf(stderr,"Error %d\n",__LINE__);<br>
                return -1;<br>
        }<br>
<br>
        OGR_L_ResetReading (hLY ) ;<br>
<br>
        while( ( ( hFT=OGR_L_GetNextFeature(hLY) ) != NULL )) {<br>
                int iField;<br>
                int iTotalField;<br>
                iTotalField = OGR_F_GetFieldCount(hFT);<br>
                for (iField=0;iField&lt; iTotalField;iField++) {<br>
                        hFD=OGR_F_GetFieldDefnRef(hFT,iField);<br>
                        if (hFD == NULL) {<br>
                                fprintf(stderr,"Error %d\n",__LINE__);<br>
                                return -1;<br>
                        }<br>
                        hFldTyp=OGR_Fld_GetType( hFD );<br>
                        switch (hFldTyp) {<br>
                        case OFTInteger:<br>
                                fprintf(
stdout,"%d\n",OGR_F_GetFieldAsInteger( hFT, iField));<br>
                                break;<br>
                        case OFTReal:<br>
                                fprintf(
stdout,"%f\n",OGR_F_GetFieldAsDouble( hFT, iField));<br>
                                break;<br>
                        case OFTString:<br>
                                fprintf(
stdout,"%s\n",OGR_F_GetFieldAsString( hFT, iField));<br>
                                break;<br>
                        }<br>
                }<br>
<br>
                /*   OGRGeometryH OGR_F_GetGeometryRef (OGRFeatureH) */<br>
                OGRGeometryH *hG;<br>
                hG=OGR_F_GetGeometryRef( hFT );<br>
                if ( hG == NULL ) {<br>
                        fprintf(stderr,"Error %d\n",__LINE__);<br>
                        return -1;<br>
                }<br>
                /* OGRwkbGeometryType OGR_G_GetGeometryType
(OGRGeometryH) */<br>
                OGRwkbGeometryType hWGT;<br>
                hWGT = OGR_G_GetGeometryType(hG );<br>
                /*<br>
                wkbUnknown = 0,           <br>
                wkbPoint = 1,             <br>
                wkbLineString = 2,<br>
                wkbPolygon = 3,<br>
                wkbMultiPoint = 4,<br>
                wkbMultiLineString = 5,<br>
                wkbMultiPolygon = 6,<br>
                wkbGeometryCollection = 7,<br>
                wkbNone = 100,              <br>
                wkbLinearRing = 101,        <br>
                wkbPoint25D = 0x80000001, <br>
                wkbLineString25D = 0x80000002,<br>
                wkbPolygon25D = 0x80000003,<br>
                wkbMultiPoint25D = 0x80000004,<br>
                wkbMultiLineString25D = 0x80000005,<br>
                wkbMultiPolygon25D = 0x80000006,<br>
                wkbGeometryCollection25D = 0x80000007<br>
                */<br>
                switch( hWGT ) {<br>
                case wkbPoint:<br>
                        fprintf( stdout, "Geometry Type is POINT\n" );<br>
                        break;<br>
                case wkbLineString:<br>
                        fprintf( stdout, "Geometry Type is
LINESTRING\n" );<br>
                        break;<br>
                case wkbPolygon:<br>
                        fprintf( stdout, "Geometry Type is POLYGON\n" );<br>
                        break;<br>
                case wkbMultiPolygon:<br>
                        fprintf( stdout, "Geometry Type is
MULTIPOLYGON\n" );<br>
                        break;<br>
                default:<br>
                        fprintf( stdout, "Geometry Type is %d\n",hWGT);<br>
                }<br>
<br>
                OGRGeometryH *hG2;<br>
                OGRGeometryH *hRing;<br>
<br>
                int iPoint;<br>
                int iTotalPoint;<br>
                int iGeometryCount;<br>
                int iGeometry;<br>
                double x,y;<br>
                fprintf( stdout, "%s\n",OGR_G_GetGeometryName (hG) );<br>
                iGeometryCount = OGR_G_GetGeometryCount (hG);<br>
                if (iTotalPoint &gt; 0) {<br>
                        fprintf( stdout, "Total Geometry Count %d\n\n",
iGeometryCount );<br>
                }<br>
                for (
iGeometry=1;iGeometry&lt;iGeometryCount;iGeometry++) {<br>
                /*
<a class="moz-txt-link-freetext"
 href="http://lists.maptools.org/pipermail/gdal-dev/2004-February/002095.html">http://lists.maptools.org/pipermail/gdal-dev/2004-February/002095.html</a><br>
                 *
<a class="moz-txt-link-freetext"
 href="http://lists.maptools.org/pipermail/gdal-dev/2004-May/002713.html">http://lists.maptools.org/pipermail/gdal-dev/2004-May/002713.html</a><br>
                 */<br>
                        char *buffer=( char *)NULL;<br>
                        double *test;<br>
                        int buf_len;<br>
                        hG2 = OGR_G_GetGeometryRef (hG,iGeometry );<br>
                                               iTotalPoint =
OGR_G_GetPointCount( hG2);<br>
                        fprintf( stdout, "Total Point Count in ring(%d)
is %d\n\n", iGeometry, iTotalPoint );<br>
                        OGREnvelope hEnvelope;<br>
                        OGR_G_GetEnvelope (hG2, &amp;hEnvelope);<br>
                        fprintf( stdout," MinX = %f, MinY=%f,  MaxX=%f,
MaxY=%f\n", hEnvelope.MinX, hEnvelope.MinY, hEnvelope.MaxX,
hEnvelope.MaxY );<br>
                        <br>
                        for ( iPoint=0;iPoint&lt;iTotalPoint;iPoint++) {<br>
                                x=OGR_G_GetX(hG2, iPoint);<br>
                                y=OGR_G_GetY(hG2, iPoint);<br>
                                fprintf( stdout, "\t%9.6f\t%9.6f\n", x,
y );<br>
                        }<br>
                        /* OGR_G_DumpReadable( hG2, stdout, " KC :"); */<br>
                        <br>
                }<br>
                OGR_F_Destroy(hFT);<br>
        }<br>
<br>
        free(hDS);<br>
        return EXIT_SUCCESS;<br>
}<br>
<br>
------------------------------------</font>
</body>
</html>