CosmiQ / solaris

CosmiQ Works Geospatial Machine Learning Analysis Toolkit
https://solaris.readthedocs.io
Apache License 2.0
411 stars 112 forks source link

[MAINT] Update deprecated shapely.ops.cascaded_union to shapely.ops.unary_union #471

Open imharrisonking opened 8 months ago

imharrisonking commented 8 months ago

Maintenance request summary

Calling the solaris.vector.mask.df_to_px_mask function is throwing the below depreciation warning related to shapely.ops.cascaded_union which has been superseded by the more performant shapely.ops.unary_union and deprecated in Shapely 1.8. Proposing that this is updated.

ShapelyDeprecationWarning: The 'cascaded_union()' function is deprecated. Use 'unary_union()' instead. gs[x['gs_idx']].intersection(cascaded_union(gs[x['intersectors']]))

This is called from solaris/utils/geo.py on line 474:

 output_polys = []
  _ = intersect_lists.apply(lambda x: output_polys.append(
      gs[x['gs_idx']].intersection(cascaded_union(gs[x['intersectors']]))
  ), axis=1)
  # we then generate the union of all of these intersections and return it.
  return cascaded_union(output_polys)

Task detail and notes

Straight swap of cascaded_union for unary_union in geo.py and updating of tutorials and tests that use cascaded_union (see below).

Any additional information: Not sure what the plans are in terms of moving to a newer version of Shapely in future releases of solaris, or how actively maintained this project is, but I'm loving the solaris.vector.mask.df_to_px_mask function and I'm happy to fork a branch and make the below proposed changes.

Tutorials in docs: