Skip to content

[WIP] Add geometry clipping function to pygmt helper#16

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/add-geometry-clipping-function
Draft

[WIP] Add geometry clipping function to pygmt helper#16
Copilot wants to merge 1 commit intomainfrom
copilot/add-geometry-clipping-function

Conversation

Copy link
Contributor

Copilot AI commented Feb 9, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Add this geometry clipping function to pygmt helper I wrote. Add a suitable docstring and fit the style of the existing codebase. It should live in the plotting module. Add a very basic unit test to check it doesn't crash.

@contextmanager
def clip(
clipping_geometries: Sequence[shapely.Polygon],
) -> Generator[None, None, None]:
with Session() as s, tempfile.TemporaryDirectory() as tmp_dir_name:
tmp_dir = Path(tmp_dir_name)
paths = [tmp_dir / f"geom_{i}.txt" for i in range(len(clipping_geometries))]
for path, geometry in zip(paths, clipping_geometries):
path.write_text("\n".join(f"{x} {y}" for x, y in geometry.exterior.coords))

    s.call_module("clip", [str(path) for path in paths])
    try:
        yield
    finally:
        s.call_module("clip", ["-C"])

You will need from pygmt.clib import Session


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants