Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append support for MultiPolygons in shapefiles #18

Closed
olt opened this issue Apr 25, 2012 · 4 comments
Closed

Append support for MultiPolygons in shapefiles #18

olt opened this issue Apr 25, 2012 · 4 comments

Comments

@olt
Copy link
Member

olt commented Apr 25, 2012

Shapefiles have no type MultiPolygon, but they support them anyway (all rings are stored in one polygon). See: http://www.gdal.org/ogr/drv_shapefile.html

Fiona/OGR handles everything right when I create a new Shapefile with geometry type MultiPolygon, but when I open it for appending the type changes to Polygon. Fiona will then refuse to write additional MultiPolygons (see WritingSession.writerecs).

How should we handle that? Ignore the Multi prefix when checking the geometry type for 'ESRI Shapefile' drivers?

@olt
Copy link
Member Author

olt commented Apr 25, 2012

Here is a possible, a bit hackish:
olt/Fiona@sgillies:master...olt:shapefile-multipolygons

I also improved the error output if the property schema differs.

@tylere
Copy link

tylere commented Jun 19, 2012

I feel that this is an important issue. It is quite common to have shapefiles that contain multipolygons.

Here is a convoluted workaround for processing Shapefiles that contain MultiPolygon geometries.:

  1. Read a multipolygon shapefile with Fiona
  2. Iterate through the features
    * If it is a polygons geometry, use Shapely to convert the feature to a MultiPolygon
    * Process the MultiPolygon
    * Write the MultiPolygon to a GeoJSON output
  3. Using ogr2ogr, convert the GeoJSON file back to a Shapefile

@sgillies
Copy link
Member

sgillies commented Feb 3, 2013

(Info copied from #26)

See http://www.gdal.org/ogr/drv_shapefile.html:

Note that when reading a Shapefile of type SHPT_ARC, the corresponding layer will be reported as of type
wkbLineString, but depending on the number of parts of each geometry, the actual type of the geometry for each
feature can be either OGRLineString or OGRMultiLineString. The same applies for SHPT_POLYGON shapefiles,
reported as layers of type wkbPolygon, but depending on the number of parts of each geometry, the actual type
can be either OGRPolygon or OGRMultiPolygon.

When reading from a "polygon" type shapefile, you might get polygons or multi-polygon features. TBD: whether to coerce geometries or just relax the single-type constraint in Fiona for just the Shapefile format.

sgillies added a commit that referenced this issue Feb 3, 2013
Use some of the code provided by olt in #18, add several tests, see the
LineWritingTest in test_collection.py.
@sgillies
Copy link
Member

sgillies commented Feb 3, 2013

Good grief, how did I overlook this issue!? @olt, @tylere, thanks. I've got a fix in commit 4632128.

Sometime I think it would be nice to do away with the distinctions between polygons/multipolygons and linestrings/multilinestrings for all data sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants