yocontra / node-gdal-next

Node.js bindings for GDAL (Geospatial Data Abstraction Library) [Fork]
https://contra.io/node-gdal-next/
Apache License 2.0
75 stars 36 forks source link

Geometry supported by `ogr2ogr` not supported by `gdal-next` #13

Open ekulno opened 3 years ago

ekulno commented 3 years ago

I have a GML file which I want to convert to another format. I am able to do this with the ogr2ogr tool, but with gdal-next I get an error when I try to do the same thing.

With ogr2ogr:

$ ogr2ogr -f GeoJSON test.json test.gml && cat test.json
{
"type": "FeatureCollection",
"name": "_",
"features": [
{ "type": "Feature", "properties": { "gml_id": "" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 1.0, 2.0 ] ] ] } }
]
}

With gdal-next:

const gdal = require("gdal-next");
const dataset = gdal.open('test.gml', 'r', "GML");
const feature = dataset.layers.get(0).features.get(0);
const geometry = feature.getGeometry();

I get the following error for the getGeometry call:

Error: Tried to create unsupported geometry type

test.gml has the following content.

<CityModel>
    <cityObjectMember>
        <_ gml:id="">
            <gml:Polygon
                xmlns:gml="http://www.opengis.net/gml">
                <gml:exterior>
                    <gml:Ring>
                        <gml:curveMember>
                            <gml:Curve>
                                <gml:segments>
                                    <gml:LineStringSegment>
                                        <gml:posList srsDimension="2">1 2 3 4</gml:posList>
                                    </gml:LineStringSegment>
                                    <gml:Arc>
                                        <gml:posList srsDimension="2">3 4 5 6 7 8</gml:posList>
                                    </gml:Arc>
                                    <gml:LineStringSegment>
                                        <gml:posList srsDimension="2">7 8 1 2</gml:posList>
                                    </gml:LineStringSegment>
                                </gml:segments>
                            </gml:Curve>
                        </gml:curveMember>
                    </gml:Ring>
                </gml:exterior>
            </gml:Polygon>
        </_>
    </cityObjectMember>
</CityModel>
yocontra commented 3 years ago

Hmm, that is odd since we support GML in our list of bundled drivers: https://github.com/contra/node-gdal-next/blob/master/deps/libgdal/gyp-formats/ogr_gml.gyp

I can look into it - I just read through the driver docs and saw this:

The reading part of the driver only works if OGR is built with Xerces linked in. When Xerces is unavailable, read support also works if OGR is built with Expat linked in. XML validation is disabled by default. GML writing is always supported, even without Xerces or Expat.

Issue may be that we aren't linking it with libexpat correctly.

mmomtchev commented 3 years ago

@Ysgorg, I just tried to load your geometry with the latest version of node-gdal-next and it works fine for me - I get the feature geometry. I just had to modify the code to load a JSON (the gdal.open call), but since you report a geometry error and not a dataset opening error, I guess it was correct on your side. Can you try again and report your findings?

ekulno commented 3 years ago

When I submitted this ticket I was using version 2.1.0 of the gdal-next package. I now upgraded to 2.4.0 and reran the example code given in the ticket description. I got the same result.

@mmomtchev , I'm not sure what you mean by modifying the code to load JSON. In my use-case I have a large amount of input data and manually rewriting it to JSON is not an option.

mmomtchev commented 3 years ago

@Ysgorg, I am sorry, in fact I tried loading the JSON. This is a duplicate of #8, add support for curve geometries. ogr2ogr silently eliminates the curve geometry, that's why it creates the impression that it works.