[gdal-dev] Create a shape file with polygons
Frank Warmerdam
warmerdam at pobox.com
Tue Jan 18 12:10:59 EST 2011
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
More information about the gdal-dev
mailing list