locked
Problem converting to SqlGeometry from gml RRS feed

  • Question

  • Hi !

    I have an xml string from a WFS service and I want to parse it to a SqlGeometry object.
    I get Error System.FormatException] = {"24130: The given XML instance contains attributes. Attributes in Geography Markup Language (GML) input are not permitted."}

    But I cannot figure where the problem is.

    This is the string:

    <gml:Polygon srsName="EPSG:4326" xmlns:gml="http://www.opengis.net/gml">
      <gml:outerBoundaryIs>
        <gml:LinearRing>
          <gml:coordinates>60.459099,16.926436 60.460080,16.933631 60.460272,16.935328 60.460563,16.936937 60.474139,16.929063 60.474348,16.930889 60.476611,16.929621 60.479701,16.929346 60.479487,16.922792 60.476801,16.923118 60.475752,16.921900 60.472010,16.923844 60.470093,16.920215 60.459099,16.926436 </gml:coordinates>
        </gml:LinearRing>
      </gml:outerBoundaryIs>
    </gml:Polygon>

    And this is how I do it :

    string gml = “<gml:Polygon srsName …. </gml:Polygon>

    XmlReader xmlReader = XmlReader.Create(new System.IO.StringReader(gml));

    SqlXml newXml = new SqlXml(xmlReader);

     

    SqlGeometry geometry = SqlGeometry.GeomFromGml(newXml, 4326);

    Any help would be appreciated

    Monday, June 21, 2010 10:26 PM

Answers

  • Altough it's not specified (http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.types.sqlgeometry.geomfromgml.aspx), it seems that sqlgeometry supports only gml version 3

     

    outerBoundaryIs, for example, is version 2

    http://schemas.liquid-technologies.com/LibraryDocs/OpenGis/sps/1.0.0/default.html?url=http://schemas.liquid-technologies.com/LibraryDocs/OpenGis/sps/1.0.0/outerBoundaryIs.html

     

    So, for this gml to work:

    1) Remove srsName attribute to avoid the error 24130

    2) Replace 'outerBoundaryIs' by 'exterior'

    3) Replace 'coordinates' by 'posList'

    4) Replace commas in coordinates by white blanks

     

    Here is the resulting gml:

     

    <gml:Polygon xmlns:gml="http://www.opengis.net/gml">
     <gml:exterior>
      <gml:LinearRing>
       <gml:posList>60.459099 16.926436 60.460080 16.933631 60.460272 16.935328 60.460563 16.936937 60.474139 16.929063 60.474348 16.930889 60.476611 16.929621 60.479701 16.929346 60.479487 16.922792 60.476801 16.923118 60.475752 16.921900 60.472010 16.923844 60.470093 16.920215 60.459099 16.926436</gml:posList>
      </gml:LinearRing>
     </gml:exterior>
    </gml:Polygon>
     

     

     

     

    • Marked as answer by Montanazo Tuesday, June 22, 2010 9:14 AM
    Tuesday, June 22, 2010 6:28 AM
  • SQL Server 2008 actually supports a modified subset of the GML 3.1.1 standard. For reference, you can view Microsoft's implementation of the GML schema here:

    http://schemas.microsoft.com/sqlserver/profiles/gml/SpatialGML.xsd

     

    vIndEx's instructions should make this particular example work - if you want to see the format expected by the GeomFromGml() method for other geometry types, you can always use .AsGml() to create the GML of an existing object.

    Of course, these changes are easy to make assuming that you're in control of the WFS service you mention, less so if you're not :(


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked as answer by Montanazo Tuesday, June 22, 2010 9:14 AM
    Tuesday, June 22, 2010 6:46 AM
    Answerer

All replies

  • Altough it's not specified (http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.types.sqlgeometry.geomfromgml.aspx), it seems that sqlgeometry supports only gml version 3

     

    outerBoundaryIs, for example, is version 2

    http://schemas.liquid-technologies.com/LibraryDocs/OpenGis/sps/1.0.0/default.html?url=http://schemas.liquid-technologies.com/LibraryDocs/OpenGis/sps/1.0.0/outerBoundaryIs.html

     

    So, for this gml to work:

    1) Remove srsName attribute to avoid the error 24130

    2) Replace 'outerBoundaryIs' by 'exterior'

    3) Replace 'coordinates' by 'posList'

    4) Replace commas in coordinates by white blanks

     

    Here is the resulting gml:

     

    <gml:Polygon xmlns:gml="http://www.opengis.net/gml">
     <gml:exterior>
      <gml:LinearRing>
       <gml:posList>60.459099 16.926436 60.460080 16.933631 60.460272 16.935328 60.460563 16.936937 60.474139 16.929063 60.474348 16.930889 60.476611 16.929621 60.479701 16.929346 60.479487 16.922792 60.476801 16.923118 60.475752 16.921900 60.472010 16.923844 60.470093 16.920215 60.459099 16.926436</gml:posList>
      </gml:LinearRing>
     </gml:exterior>
    </gml:Polygon>
     

     

     

     

    • Marked as answer by Montanazo Tuesday, June 22, 2010 9:14 AM
    Tuesday, June 22, 2010 6:28 AM
  • SQL Server 2008 actually supports a modified subset of the GML 3.1.1 standard. For reference, you can view Microsoft's implementation of the GML schema here:

    http://schemas.microsoft.com/sqlserver/profiles/gml/SpatialGML.xsd

     

    vIndEx's instructions should make this particular example work - if you want to see the format expected by the GeomFromGml() method for other geometry types, you can always use .AsGml() to create the GML of an existing object.

    Of course, these changes are easy to make assuming that you're in control of the WFS service you mention, less so if you're not :(


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked as answer by Montanazo Tuesday, June 22, 2010 9:14 AM
    Tuesday, June 22, 2010 6:46 AM
    Answerer
  • Thank you very much for your time vIndEx  and tanoshimi

    I used vIndEx tips  and it worked. 

    Tuesday, June 22, 2010 9:14 AM