JuliaGeo / GeoJSON.jl

Utilities for working with GeoJSON data in Julia
https://juliageo.org/GeoJSON.jl/stable/
MIT License
68 stars 10 forks source link

MultiLineString is converted to Geometry when writing #67

Closed ErickChacon closed 1 year ago

ErickChacon commented 1 year ago

A MultiLineString is currently being saved as a Polygon. This creates problems when interfacing with other geometry packages because MultiLineStrings are saved as invalid Polygons. So we obtain errors when trying to load this invalid Polygons. This is happening in our GeoTables.jl when intarfecing with GeoJSON.jl (JuliaEarth/GeoTables.jl#24).

Let's consider the following geometry:

d = """{
    "type": "Feature",
    "id": "1",
    "bbox": [-180.0, -90.0, 180.0, 90.0],
    "geometry": {"type": "MultiLineString", "coordinates": [[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]]},
    "properties": {"title": "Dict 1"}
}"""
featu = GJS.read(d)

Given that featu is a GeoJSONT, writing to a file works well because it does not to use the _lower function.

GJS.write("nolower.json", featu)
# {"type":"Feature","id":"1","bbox":[-180.0,-90.0,180.0,90.0],"geometry":{"type":"MultiLineString","coordinates":[[[3.75,9.25],[-130.95,1.52]],[[23.15,-34.25],[-1.35,-4.65],[3.45,77.95]]]},"properties":{"title":"Dict 1"}}

However, if we use the _lower function, the MultiLineString is saved as a Polygon.

featul = GJS._lower(featu)
JSON3.write("lower.json", featul)
# {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[3.75,9.25],[-130.95,1.52]],[[23.15,-34.25],[-1.35,-4.65],[3.45,77.95]]]},"properties":{"title":"Dict 1"},"bbox":[-180.0,-90.0,180.0,90.0]}

The outputs are different when the geometry type should actually be MultiLineString.

juliohm commented 1 year ago

Fixed on master.