upxo.geoEntities.polygon2d_from_shapely module
Shapely multi-polygon grain structure -> topologically-linked
{gid: Polygon2d | NestedPolygon2d}.
Builds genuine UPXO objects (Point2d/Sline2d/MSline2d/ring2d)
from a Shapely-sourced multi-grain structure – e.g. GrainManifold2D
(Technique B)’s self.cells – with the same cross-grain shared-segment
object identity Technique A already achieves for pixel-derived grains, so
that Polygon2d.edit_segment/subdivide_segment on one grain’s shared
wall is visible in its neighbour with no extra step.
Junction detection and ring assembly (the parts of Technique A’s pipeline
that are already polygon/coordinate-generic) are reused via
upxo.pxtal._gb_topology. Wall canonicalization here follows a simpler
“build once, reuse by reference” strategy instead of Technique A’s
build-both-then-dedup-by-property approach – see this module’s design
notes / project plan for the reasoning.
- upxo.geoEntities.polygon2d_from_shapely.polygon_collection_from_shapely(cells, gid_key=None, tol=1e-06, verbose=False)[source]
Convert a Shapely-sourced multi-grain structure into a topologically linked UPXO collection.
- Parameters:
cells (dict) –
{gid: shapely.Polygon | MultiPolygon | GeometryCollection}, e.g.GrainManifold2D.cellsdirectly.gid_key (callable or None, optional) – Applied to cells’ keys before use as the output dict’s keys.
None(default): use as-is.tol (float, optional) – Coordinate-match tolerance for wall canonicalization and junction- point insertion. Default
1e-6matchesGrainManifold2D’s ownshapely.set_precisiongrid; loosen for other Shapely sources.verbose (bool, optional) – Print phase progress.
- Returns:
{gid: Polygon2d | NestedPolygon2d}. AMultiPolygon-valued cell contributes its largest-area part as the dict value; smaller disjoint parts are appended to.props['extra_parts'](list ofPolygon2d/NestedPolygon2d, still wall-linked to neighbours through the same tolerance-keyed lookup) – nothing is silently dropped.- Return type: