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

Fix Encoder[GeometryCollection] #3288

Merged

Conversation

agrian-joel
Copy link
Contributor

@agrian-joel agrian-joel commented Sep 4, 2020

Overview

Encoding a GeometryCollection with a Multipolygon/MultiPoint/MultiLineString should serialize those geometries once

Current behavior encodes them in geometries as both type: MultiX and type: GeometryCollection

Checklist

  • ./CHANGELOG.md updated, if necessary. Link to the issue if closed, otherwise the PR.
  • Unit tests added for bug-fix or new feature

Closes #3167

@agrian-joel agrian-joel force-pushed the geometryCollectionEncoder branch from 41a178d to 95ad474 Compare September 4, 2020 20:53
@pomadchin pomadchin self-requested a review September 4, 2020 20:57
@pomadchin
Copy link
Member

Hi @agrian-joel thanks a lot for your first contribution! I'll review it a bit later.

Copy link
Member

@pomadchin pomadchin left a comment

Choose a reason for hiding this comment

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

In general LGTM! But I left a minor question in comments.

Thanks again!

Comment on lines 180 to 188
obj.geometries.map({
case geom: Point => geom.asJson
case geom: LineString => geom.asJson
case geom: Polygon => geom.asJson
case geom: MultiPolygon => geom.asJson
case geom: MultiPoint => geom.asJson
case geom: MultiLineString => geom.asJson
case geom: GeometryCollection => geom.asJson
case geom => throw new Exception(s"Unknown Geometry type ${geom.getClass.getName}: $geom")
}).asJson
Copy link
Member

@pomadchin pomadchin Sep 4, 2020

Choose a reason for hiding this comment

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

Hm, I don't think it would make a lot of sense to throw here, the all types supported are listed here.

How about the following?

obj.geometries.collect {
  case geom: Point => geom.asJson
  case geom: LineString => geom.asJson
  case geom: Polygon => geom.asJson
  case geom: MultiPolygon => geom.asJson
  case geom: MultiPoint => geom.asJson
  case geom: MultiLineString => geom.asJson
  case geom: GeometryCollection => geom.asJson
}.asJson

@agrian-joel agrian-joel force-pushed the geometryCollectionEncoder branch from 95ad474 to 5d0d210 Compare September 4, 2020 21:24
obj.getAll[GeometryCollection].map(_.asJson)
).flatten.asJson
"geometries" ->
obj.geometries.map({
Copy link
Member

@pomadchin pomadchin Sep 4, 2020

Choose a reason for hiding this comment

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

In order not to throw in case of the type mismatch, it is possible to use the collect function instead of map here (see #3288 (comment))

…eString should serialize those geometries once. Fixes locationtech#3167

Current behavior encodes them in geometries as both `type: MultX` and `type: GeometryCollection`

Signed-off-by: Joel Anna <joel@agrian.com>
@agrian-joel agrian-joel force-pushed the geometryCollectionEncoder branch from 5d0d210 to 5aff455 Compare September 4, 2020 21:31
Copy link
Member

@pomadchin pomadchin left a comment

Choose a reason for hiding this comment

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

Thanks!

@pomadchin pomadchin merged commit 50aa57c into locationtech:master Sep 4, 2020
@agrian-joel agrian-joel deleted the geometryCollectionEncoder branch September 4, 2020 22:47
@echeipesh echeipesh added this to the GT Sprint 9/4 - 9/17/2020 milestone Sep 17, 2020
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.

GeometryCollection encoding issue
3 participants