Closed kaczmarj closed 3 years ago
here's one way we can tackle this problem... we get the exterior of the unioned tumor multipolygon. we convert the exterior of the biomarker-positive multipolygon to a multilinestring, and we keep all of the lines that are contained in the tumor exterior. we do the same with biomarker-negative.
import shapely.geometry
def get_exterior_of_multigeom(multigeom):
return shapely.geometry.MultiLineString([g.exterior for g in multigeom.geoms])
def exterior_to_multilinestring(exterior):
lines = []
for t in exterior:
lines.extend(zip(t.coords[:-1], t.coords[1:]))
lines = shapely.geometry.MultiLineString(lines)
return lines
def get_exterior(multigeom, big_geom):
exterior = get_exterior_of_multigeom(multigeom)
lines = exterior_to_multilinestring(exterior)
big_geom_ext = get_exterior_of_multigeom(big_geom)
big_geom_ext = big_geom_ext.buffer(1)
# big_geom_lines = exterior_to_multilinestring(big_geom_ext)
lines = shapely.geometry.MultiLineString(
[g for g in lines if big_geom_ext.contains(g)])
return lines
mpos_edges = get_exterior(mpos_geoms, tumor_geoms)
mneg_edges = get_exterior(mneg_geoms, tumor_geoms)
we should only be considering distances from the edge of the tumor.