A collection of one or more LineStrings. A MultiLineString has non-zero length and zero area. Parameters ---------- lines : sequence A sequence LineStrings, or a sequence of line-like coordinate sequences or array-likes (see accepted input for LineString). Attr
| 9 | |
| 10 | |
| 11 | class MultiLineString(BaseMultipartGeometry): |
| 12 | """A collection of one or more LineStrings. |
| 13 | |
| 14 | A MultiLineString has non-zero length and zero area. |
| 15 | |
| 16 | Parameters |
| 17 | ---------- |
| 18 | lines : sequence |
| 19 | A sequence LineStrings, or a sequence of line-like coordinate |
| 20 | sequences or array-likes (see accepted input for LineString). |
| 21 | |
| 22 | Attributes |
| 23 | ---------- |
| 24 | geoms : sequence |
| 25 | A sequence of LineStrings |
| 26 | |
| 27 | Examples |
| 28 | -------- |
| 29 | Construct a MultiLineString containing two LineStrings. |
| 30 | |
| 31 | >>> from shapely import MultiLineString |
| 32 | >>> lines = MultiLineString([[[0, 0], [1, 2]], [[4, 4], [5, 6]]]) |
| 33 | |
| 34 | """ |
| 35 | |
| 36 | __slots__ = [] |
| 37 | |
| 38 | def __new__(self, lines=None): |
| 39 | """Create a new MultiLineString geometry.""" |
| 40 | if not lines: |
| 41 | # allow creation of empty multilinestrings, to support unpickling |
| 42 | # TODO better empty constructor |
| 43 | return shapely.from_wkt("MULTILINESTRING EMPTY") |
| 44 | elif isinstance(lines, MultiLineString): |
| 45 | return lines |
| 46 | |
| 47 | lines = getattr(lines, "geoms", lines) |
| 48 | subs = [] |
| 49 | for item in lines: |
| 50 | line = linestring.LineString(item) |
| 51 | if line.is_empty: |
| 52 | raise EmptyPartError( |
| 53 | "Can't create MultiLineString with empty component" |
| 54 | ) |
| 55 | subs.append(line) |
| 56 | |
| 57 | if len(lines) == 0: |
| 58 | return shapely.from_wkt("MULTILINESTRING EMPTY") |
| 59 | |
| 60 | return shapely.multilinestrings(subs) |
| 61 | |
| 62 | @property |
| 63 | def __geo_interface__(self): |
| 64 | """Return a GeoJSON-like mapping interface for this MultiLineString.""" |
| 65 | return { |
| 66 | "type": "MultiLineString", |
| 67 | "coordinates": tuple(tuple(c for c in g.coords) for g in self.geoms), |
| 68 | } |
no outgoing calls
searching dependent graphs…