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

GeometryCollection encoding issue #3167

Closed
atararaksin opened this issue Dec 19, 2019 · 2 comments · Fixed by #3288
Closed

GeometryCollection encoding issue #3167

atararaksin opened this issue Dec 19, 2019 · 2 comments · Fixed by #3288
Labels

Comments

@atararaksin
Copy link
Contributor

The following code

val p = Point(1, 1)
println(GeometryCollection(multiPoints = Seq(MultiPoint(p, p))).toGeoJson)

prints

{
  "type" : "GeometryCollection",
  "geometries" : [
    {"type" : "MultiPoint", "coordinates" : [[1.0, 1.0], [1.0, 1.0]]},
    {"type" : "GeometryCollection", "geometries" : [
      {"type" : "Point", "coordinates" : [1.0, 1.0]},
      {"type" : "Point", "coordinates" : [1.0, 1.0]}
    ]}
  ]
}

The same duplication happens with MultiPolygons and MultiLines when nested into GeometryCollection. It appears that this is because a MultiPoint IS a GeometryCollection, so the Encoder retrieves it two times - first by getAll[MultiPoint], then by getAll[GeometryCollection].

@pomadchin pomadchin added the bug label Dec 19, 2019
@atararaksin
Copy link
Contributor Author

atararaksin commented Dec 20, 2019

Besides serialization, some other operations are also affected by this:

scala> val p = Point(1, 1)
p: org.locationtech.jts.geom.Point = POINT (1 1)

scala> val gc = GeometryCollection(multiPoints = Seq(MultiPoint(p, p)))
gc: org.locationtech.jts.geom.GeometryCollection = GEOMETRYCOLLECTION (MULTIPOINT ((1 1), (1 1)))

scala> gc.reproject(WebMercator, LatLng)
res0: org.locationtech.jts.geom.GeometryCollection = GEOMETRYCOLLECTION (MULTIPOINT ((0.0000089831528412 0.000008983152841), (0.0000089831528412 0.000008983152841)), GEOMETRYCOLLECTION (POINT (0.0000089831528412 0.000008983152841), POINT (0.0000089831528412 0.000008983152841)))

On the other hand, MultiPoint extends GeometryCollection, and from this point of view .getAll[GeometryCollection]() behaves correctly, the caller might expect to get all subclasses of GeometryCollection (though I personally wouldn't).

agrian-joel added a commit to agrian-joel/geotrellis that referenced this issue Sep 4, 2020
…eString should serialize those geometries once. Fixes locationtech#3167

Current behavior encodes them in geometries as both `type: MultX` and `type: GeometryCollection`
agrian-joel added a commit to agrian-joel/geotrellis that referenced this issue Sep 4, 2020
…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 added a commit to agrian-joel/geotrellis that referenced this issue Sep 4, 2020
…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>
@pomadchin
Copy link
Member

@atararaksin I moved your last comment into a separate issue: #3289

agrian-joel added a commit to agrian-joel/geotrellis that referenced this issue Sep 4, 2020
…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>
pomadchin added a commit that referenced this issue Sep 4, 2020
* Encoding a GeometryCollection with a Multipolygon/MultiPoint/MultiLineString should serialize those geometries once. Fixes #3167

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

Signed-off-by: Joel Anna <joel@agrian.com>
Co-authored-by: Grigory Pomadchin <gr.pomadchin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants