On 11-01-18 11:28 AM, Jorge Martin wrote:
OGRPolygon myPoligon;

tmp = strtok (Line, ":");

szName = string (tmp);


        while (tmp != NULL)
            {

        OGRLinearRing MyRing;// = (OGRLinearRing*)
OGRGeometryFactory::createGeometry(wkbLinearRing);

         tmp = strtok (NULL, ",");

         if(tmp)
         {

                string Coords = string(tmp);

               size_t pos = Coords.find(" ");

               string CoordX = Coords.substr(0,pos);
               string CoordY = Coords.substr(pos);

               x = atof(CoordX.c_str());
                y = atof(CoordY.c_str());

MyRing.addPoint(x,y);


         }

         myPoligon.addRing(&MyRing);

     }

Jorge,

The essence of your problem is that you are creating a new
ring for each point instead of creating one ring for the
polygon and adding all the points to that ring before adding
the ring to the polygon.  A slightly altered form of the core
that works looks like:

        OGRPolygon myPoligon;
        OGRLinearRing MyRing;// = (OGRLinearRing*)

        tmp = strtok (Line, ":");
        szName = string (tmp);
        while (tmp != NULL)
        {
            OGRGeometryFactory::createGeometry(wkbLinearRing);

            tmp = strtok (NULL, ",");

            if(tmp)
            {
                string Coords = string(tmp);

                size_t pos = Coords.find(" ");

                string CoordX = Coords.substr(0,pos);
                string CoordY = Coords.substr(pos);

                x = atof(CoordX.c_str());
                y = atof(CoordY.c_str());

                MyRing.addPoint(x,y);
            }
        }

        myPoligon.addRing(&MyRing);

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmer...@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to