question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MultiPolygon constructor behavior

See original GitHub issue

Expected behavior and actual behavior.

The MultiPolygon constructor seems to behave oddly when provided a sequence containing other MP objects.

See behavior example on nbviewer.

Steps to reproduce the problem.

see nbviewer link

Operating system

Windows 10

Shapely version and provenance

1.6.4 from Chris Gohlke’s whl file page

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
miker985commented, Jun 14, 2018

@sgillies would you be amenable to raising an error instead of silently truncating the multipolygon instance passed to MultiPolygon to its first component polygon?

0reactions
Ricyteachcommented, May 30, 2018

I agree this makes the most sense.

But it does pose a problem: what is the best way to take a sequence of geometry objects, any of which could be multi or single, and combining them? Not into a union but as a “bag of” single geometries? Note that GeometryCollection doesn’t work the way that I mean:

>>> c=geo.GeometryCollection([geo.Polygon([(1,0),(2,0),(2,2),(1,2)]),geo.MultiPolygon([geo.Polygon([(0,0),(0,1),(1,1)]), geo.Polygon([(0,0),(1,0),(1,1)])])])
>>> c[0]
<shapely.geometry.polygon.Polygon object at 0x000001DB0347D940>
>>> c[1]
<shapely.geometry.multipolygon.MultiPolygon object at 0x000001DB0348C4E0>

The collection keeps the multi and single parts separate. The only way to do this I can see is:

x = []
for g in multis_and_singles:
    try:
        x.extend([*g])
    except TypeError:
        x.append(g)

mp = MultiPolygon(x)
Read more comments on GitHub >

github_iconTop Results From Across the Web

MultiPolygon constructor behavior #588 - shapely ... - GitHub
The MultiPolygon constructor seems to behave oddly when provided a sequence containing other MP objects. See behavior example on nbviewer. Steps ...
Read more >
The Shapely User Manual — Shapely 2.0.0 documentation
The Polygon constructor takes two positional parameters. The first is an ordered sequence of (x, y[, z]) point tuples and is treated exactly...
Read more >
L.MultiPolygon is not a constructor (Leaflet 1.2.0) - Drupal
After upgrading Leaflet library to 1.2.0, I get the error: "L.MultiPolygon is not a constructor", when trying to add MultiPolygons to the ...
Read more >
Chapter 17 Advanced Topics - Green Tea Press
The constructor for DrawablePolygon uses super to invoke the constructor for Polygon , which initializes the attributes npoints , xpoints , and ypoints...
Read more >
6.096 Introduction to C++, Assignment 03
Implement a constructor that creates a Polygon from two arguments: an array of Points and the length of that array. Use member initializer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found