[Gdal-dev] OGR, SHP, and multi-polygons

Chapman, Martin MChapman at sanz.com
Thu Feb 5 18:15:00 EST 2004


The ShapeLib is correct.  Holes are defined by the winding of the points
(clockwise versus counter clockwise)  here is the description from
esri's white paper:

"A polygon consists of one or more rings. A ring is a connected sequence
of four or more
points that form a closed, non-self-intersecting loop. A polygon may
contain multiple
outer rings. The order of vertices or orientation for a ring indicates
which side of the ring
is the interior of the polygon. The neighborhood to the right of an
observer walking along
the ring in vertex order is the neighborhood inside the polygon.
Vertices of rings defining
holes in polygons are in a counterclockwise direction. Vertices for a
single, ringed
polygon are, therefore, always in clockwise order. The rings of a
polygon are referred to
as its parts.
Because this specification does not forbid consecutive points with
identical coordinates,
shapefile readers must handle such cases. On the other hand, the
degenerate, zero length
or zero area parts that might result are not allowed."

So, the lib doesn't distinguish between holes and shapes, there all just
points to the ShapeLib library.  It's up to the rendering engine to show
holes correctly based upon the winding pattern.  OpenGL handles this
nicely with a tesselation object.  You set the winding property like
this for esri shape files, where holes are wound counter clockwise:

gluTessProperty(pTesselator, GLU_TESS_WINDING_RULE,
GLU_TESS_WINDING_POSITIVE);

Then opengl will handle the holes for you and there is no need to
distinguish between them in your code.  Basically, "parts is parts".
HA, that was bad, does anyone remember that commercial?

Martin Chapman


-----Original Message-----
From: Frank Warmerdam [mailto:warmerdam at pobox.com] 
Sent: Thursday, February 05, 2004 7:04 AM
To: gdal-dev at remotesensing.org
Subject: Re: [Gdal-dev] OGR, SHP, and multi-polygons


Ben Discoe wrote:
> I've got code which is using Shapelib to read SHP files.  It is not 
> handling some polygons correctly, so i am trying to change to using 
> OGR instead, in the hopes that will solve the issue.
> 
> The issue is that some SHP files, including some that are example 
> files that ship  with ESRI software, like 'CNTRY92.SHP', are of type 
> 'Polygon' but actually contain MultiPolygons.  E.g. the USA is 
> represented as a single polygon (!) including Alaska and Hawai'i.
> 
> When i use Shapelib, it gives me a number of 'parts' (nParts) per 
> polygon. The information apparently lacking is which 'part' is the 
> exterior, and which which 'parts' are wholes.
> 
> Switching to OGR, the problem remains.  There is only one 
> ExternalRing, which is _definitely_ not right; in the above example 
> data, if we use only the ExternalRing, then we get a small island off 
> the coast of Alaska, and the rest of USA is not loaded.
> 
> I'm left wondering - is there any way to successfully load SHP files 
> like this with either Shapelib or OGR?

Ben,

What version of OGR are you using.  Patches were introduced in the fall
some time to try and classify rings properly and form correct
multi-polygons when
reading from Shapefiles.   This did not exist in GDAL 1.1.9 so you will
need
a nightly snapshot.

This code is likely not bullet proof, so if you are still running into
problems I would appreciate your providing the dataset in question.

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 remotesensing.org
http://remotesensing.org/mailman/listinfo/gdal-dev



More information about the Gdal-dev mailing list