Skip to content

Don't inject empty interior rings when converting to geo Polygons #99

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

Merged
merged 2 commits into from
Jul 8, 2018

Conversation

worace
Copy link
Contributor

@worace worace commented Jul 8, 2018

I ran into what I think may be a small bug when using this library in a CLI tool I am working on.

It seems that when converting an exterior-only GeoJson polygon to a geo_types polygon, the library is injecting an empty interior ring rather than simply leaving the interiors field of the geo_types polygon empty.

This results in some surprising behavior if you do any round-trip conversions from geo_types -> GeoJson -> geo_types, since a polygon like this:

{"type":"Polygon",
 "coordinates":[[[30.0, 10.0],[10.0, 30.0],[40.0, 40.0],[30.0, 10.0]]]}

becomes:

{"type":"Polygon",
 "coordinates":[[[30.0, 10.0],[10.0, 30.0],[40.0, 40.0],[30.0, 10.0]], []]}

I've added a test case here which demonstrates the issue and included what I think is a reasonable approach to fixing it. Hope this is helpful!

I also fixed up a few test-name typos I noticed when I was reading these tests -- hope that is Ok.

worace added 2 commits July 7, 2018 18:50
Currently, when converting a GeoJson Polygon with no interior rings
to a geo Polygon, we are injecting a single interior ring consisting
of an empty linestring, rather than simply leaving the list of
interior rings empty.

This results in some strange behavior if you do any geojson -> geo_types
-> geojson round-tripping because your polygons end up with an
additional empty ring included.

e.g this:
{"coordinates":[[[30.0, 10.0],[10.0, 30.0],[40.0, 40.0],[30.0, 10.0]]],
 "type":"Polygon"}

becomes:
{"coordinates":
[[[30.0, 10.0],[10.0, 30.0],[40.0, 40.0],[30.0, 10.0]],[]],
"type":"Polygon"}

This change should fix this behavior.
Copy link
Member

@frewsxcv frewsxcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, good catch! I'll cut a release after this merges

@frewsxcv
Copy link
Member

frewsxcv commented Jul 8, 2018

bors r+

bors bot added a commit that referenced this pull request Jul 8, 2018
99:  Don't inject empty interior rings when converting to geo Polygons  r=frewsxcv a=worace

I ran into what I think may be a small bug when using this library in a CLI tool I am working on.

It seems that when converting an exterior-only GeoJson polygon to a geo_types polygon, the library is injecting an empty interior ring rather than simply leaving the interiors field of the geo_types polygon empty.

This results in some surprising behavior if you do any round-trip conversions from geo_types -> GeoJson -> geo_types, since a polygon like this:

```json
{"type":"Polygon",
 "coordinates":[[[30.0, 10.0],[10.0, 30.0],[40.0, 40.0],[30.0, 10.0]]]}
```

becomes:

```json
{"type":"Polygon",
 "coordinates":[[[30.0, 10.0],[10.0, 30.0],[40.0, 40.0],[30.0, 10.0]], []]}
```

I've added a test case here which demonstrates the issue and included what I think is a reasonable approach to fixing it. Hope this is helpful!

I also fixed up a few test-name typos I noticed when I was reading these tests -- hope that is Ok.

Co-authored-by: Horace Williams <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jul 8, 2018

Build succeeded

@bors bors bot merged commit 1305463 into georust:master Jul 8, 2018
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