OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.84k stars 2.53k forks source link

GML driver doesn't handle standalone geometries #2386

Closed Adraesh closed 4 years ago

Adraesh commented 4 years ago

Hi all,

GDAL 2.4.4, released 2020/01/08

I am trying to convert the simple bellow xml into Geojson using the following command:

ogr2ogr -f "GeoJSON" test.geojson gml.xml

Xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:Surface xmlns:ns1="http://www.opengis.net/gml/3.2" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:ns3="http://www.aixm.aero/schema/5.1" xmlns:ns4="http://www.isotc211.org/2005/gco" xmlns:ns5="http://www.isotc211.org/2005/gmd" xmlns:ns6="http://www.isotc211.org/2005/gts" xmlns:ns7="http://www.aixm.aero/schema/5.1/message" srsName="urn:ogc:def:crs:EPSG::4326" ns1:id="Ase_Proj_1561541">
    <ns1:patches>
        <ns1:PolygonPatch>
            <ns1:exterior>
                <ns1:Ring>
                    <ns1:curveMember>
                        <ns1:Curve ns1:id="Ase_Curv_1561541">
                            <ns1:segments>
<ns1:ArcByCenterPoint interpolation="circularArcCenterPointWithRadius" numArc="1">
    <ns1:posList srsName="urn:ogc:def:crs:EPSG::4326">46.5875 0.3066666666666666</ns1:posList>
    <ns1:radius uom="[nmi_i]">9.5</ns1:radius>
    <ns1:startAngle uom="deg">6.295729688631284</ns1:startAngle>
    <ns1:endAngle uom="deg">67.38797951888118</ns1:endAngle>
</ns1:ArcByCenterPoint>
<ns1:GeodesicString interpolation="geodesic">
    <ns1:posList srsName="urn:ogc:def:crs:EPSG::4326">46.64833333333333 0.5194444444444445 46.43861111111111 0.33805555555555555 46.42305555555555 0.28944444444444445</ns1:posList>
</ns1:GeodesicString>
<ns1:ArcByCenterPoint interpolation="circularArcCenterPointWithRadius" numArc="1">
    <ns1:posList srsName="urn:ogc:def:crs:EPSG::4326">46.581388888888895 0.2980555555555556</ns1:posList>
    <ns1:radius uom="[nmi_i]">9.5</ns1:radius>
    <ns1:startAngle uom="deg">-177.84615335400528</ns1:startAngle>
    <ns1:endAngle uom="deg">-120.68835384474265</ns1:endAngle>
</ns1:ArcByCenterPoint>
<ns1:GeodesicString interpolation="geodesic">
    <ns1:posList srsName="urn:ogc:def:crs:EPSG::4326">46.500277777777775 0.10055555555555556 46.54083333333333 0.10555555555555556 46.575 0.225 46.59444444444445 0.25833333333333336 46.65833333333333 0.2833333333333333 46.69555555555555 0.25555555555555554 46.745 0.33194444444444443</ns1:posList>
</ns1:GeodesicString>
                            </ns1:segments>
                        </ns1:Curve>
                    </ns1:curveMember>
                </ns1:Ring>
            </ns1:exterior>
        </ns1:PolygonPatch>
    </ns1:patches>
</ns3:Surface>

The result is the following:

{
"type": "FeatureCollection",
"name": "Curve",
"features": [
{ "type": "Feature", "properties": { "posList": [ "46.5875 0.3066666666666666", "46.581388888888895 0.2980555555555556" ], "radius": [ 9.5, 9.5 ], "radius_uom": [ "[nmi_i]", "[nmi_i]" ], "startAngle": [ 6.2957296886312841, -177.84615335400528 ], "startAngle_uom": [ "deg", "deg" ], "endAngle": [ 67.387979518881181, -120.68835384474265 ], "endAngle_uom": [ "deg", "deg" ], "segments|GeodesicString|posList": [ "46.64833333333333 0.5194444444444445 46.43861111111111 0.33805555555555555 46.42305555555555 0.28944444444444445", "46.500277777777775 0.10055555555555556 46.54083333333333 0.10555555555555556 46.575 0.225 46.59444444444445 0.25833333333333336 46.65833333333333 0.2833333333333333 46.69555555555555 0.25555555555555554 46.745 0.33194444444444443" ] }, "geometry": null }
]
}

I am wondering why the geometry is null? I wish to have everything resolved/merged into the geometry field to at the end have 1 final geometry.

Thank you in advance.

rouault commented 4 years ago

There are 2 different issues:

NasH5169 commented 4 years ago

Hi all,

@rouault

the GML driver doesn't accept currently single geometries, but only FeatureCollection of features. This part isn't addressed

I don't really understand this sentence. You mean that GML driver is waiting for more than one polygon in the GML? Because @Adraesh sample is one feature with N vertices.

Nice fix by the way. Bien joué.

jratike80 commented 4 years ago

It means that feature(s) must be wrapped inside FeatureCollection


<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ogr.maptools.org/ foo.xsd"
     xmlns:ogr="http://ogr.maptools.org/"
     xmlns:gml="http://www.opengis.net/gml">
  <gml:boundedBy>
    <gml:Box>
      <gml:coord><gml:X>751.339745962156</gml:X><gml:Y>410</gml:Y></gml:coord>
      <gml:coord><gml:X>768.660254037844</gml:X><gml:Y>430</gml:Y></gml:coord>
    </gml:Box>
  </gml:boundedBy>

  <gml:featureMember>
    <ogr:foo fid="foo.0">
      <ogr:geometryProperty><gml:LineString><gml:coordinates>760,430 768.660254037844,425.0 768.660254037844,415.0 760,410 751.339745962156,415.0 751.339745962156,425.0 760,430</gml:coordinates></gml:LineString></ogr:geometryProperty>
      <ogr:R_G_B xsi:nil="true"/>
    </ogr:foo>
  </gml:featureMember>
</ogr:FeatureCollection>