Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to combine overlapping layers and preserve holes? #586

Open
eric-g-97477 opened this issue May 10, 2023 · 3 comments
Open

Comments

@eric-g-97477
Copy link

poly_a.geo.json.txt
poly_b.geo.json.txt

I have these two geojson files. The polygon defined in poly_b contains a hole and is contained within the polygon defined by poly_a.

What I would like to do is merge these two polygons together, but preserve the hole in poly_b.

Is that possible using mapshaper?

If it is not possible, then this can be considered a feature request for the boolean operations needed to accomplish this.

@mbloch
Copy link
Owner

mbloch commented May 11, 2023

I can give you a sequence of commands to merge the two layers in the way you described, but I'd like you to consider a slightly more complex example first. What if the "A" dataset had two polygons that both partially overlapped the "B" donut-shaped polygon. What should the output look like in that case? I'm attaching a .zip archive, the new file is called "poly_c.geojson"

Archive.zip

@eric-g-97477
Copy link
Author

That, fortunately, is not a case I need to worry about.

@mbloch
Copy link
Owner

mbloch commented May 12, 2023

I see, it sounds like you are using mapshaper to merge two individual polygons. I can give you a series of commands that will merge "A" and "B", and then add the holes in the original "B" shape to the merged shape (see below).

Mapshaper's commands are designed to work on layers of one or more shapes. To create a more user-friendly command for this transformation, I'd have to understand how it would behave when applied to two layers containing multiple shapes.

 	mapshaper -i poly_a.geo.json name=A \
	-i poly_b.geo.json name=B \
	-mosaic calc='n = count()' + name=holes \
	-filter 'n === 0' \
	-target A,B \
	-merge-layers force name=C \
	-dissolve2 \
	-erase holes \
	-o poly_c.geojson

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

No branches or pull requests

2 participants