Skip to content

Fix Encoder[GeometryCollection] - #3288

Merged
pomadchin merged 2 commits into
locationtech:masterfrom
agrian-joel:geometryCollectionEncoder
Sep 4, 2020
Merged

pomadchin merged 2 commits into
locationtech:masterfrom
agrian-joel:geometryCollectionEncoder

Conversation

@agrian-joel

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@pomadchin pomadchin left a comment

Copy link
Copy Markdown
Member

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

@pomadchin pomadchin Sep 4, 2020 •

Copy link
Copy Markdown
Member

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({

@pomadchin pomadchin Sep 4, 2020 •

Copy link
Copy Markdown
Member

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 <[email protected]>
@agrian-joel
agrian-joel force-pushed the geometryCollectionEncoder branch from 5d0d210 to 5aff455 Compare September 4, 2020 21:31

@pomadchin pomadchin left a comment

Copy link
Copy Markdown
Member

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