[gdal-dev] Create a shape file with polygons
Jorge Martin
jormarfe at gmail.com
Wed Jan 19 03:15:54 EST 2011
Hello Frank,
I have made your change and it works, I can open the .shp with my GIS. Many
thanks for your help.
Best Regards,
Jorge
2011/1/18 Frank Warmerdam <warmerdam at pobox.com>
> 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,
> warmerdam at 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 at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110119/22297d9a/attachment.html
More information about the gdal-dev
mailing list