[gdal-dev] shapefile polygon/multipolygon ordering
Even Rouault
even.rouault at spatialys.com
Sat Nov 15 02:06:57 PST 2014
Le vendredi 14 novembre 2014 17:26:07, vous avez écrit :
> I used GDAL to create a new shapefile of polygons.
>
> The polygons (multi-polygons) were land areas. Some of the land areas had
> holes defined which were lakes within the land area. Within the lakes there
> were some islands of land...so I had a polygon with a hole with more
> polygons.
In OpenGIS specs, an island inside a lake inside a land area is described as a
multipolygon :
- first polygon:
- outer ring: land area
- inner ring: lake outline
- second polygon:
- outer ring: island
(The order of both polygons might be random)
>
> When I created the shapefile and saved it, it re-ordered the polygons so
> that all the land polygons preceded all the hole polygons (within a single
> multi-polygon). Although it worked ok for the computations I was doing, it
> drew the polygons in the wrong order so that it drew the main land polygon,
> then the islands, then the lakes which then obscured the islands.
>
> I don't really know what the shapefile specification says about this but it
> seems as though whoever did the shapefile writer for GDAL actually had to
> expend extra effort to rearrange the polygons in this manner.
>
> Two questions:
> 1. Is it within the shapefile specification to have polygons that have
> holes that have polygons?
The OpenGIS specification states that a polygon must first list its outer ring
and then its inner rings (holes)
The Shapefile specification doesn't say much about this, but outer and inner
rings are distinguished by their winding order (counterclockwise vc
clockwise).
When writing a shapefile, GDAL does OpenGIS --> Shapefile convention conversion.
AFAICS in the code, it will write the rings in the order they were specified in
the OpenGIS geometry, just fixing the winding order if needed.
When reading a shapefile, the opposite conversion is done, and it tries to
preserve the order in which outer rings appeared in the shapefile (but in the
shapefile holes can potentially appear before land area), inserting their inner
rings in-between.
> 2. Does GDAL provide any options to coerce it to not re-order the polygons?
It should limit the re-ordering to what is strictly needed to form a valid
OpenGIS geometry.
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list