I am parsing a .GML file (sample below) and each single coordinate is being treated as it’s own coordinate, instead of matching with the next coordinate as a pair.
In this example, instead of 5 lat/lon coordinates, I wind up with 10 (each with ###, 0 format).
I’ve tried modifying the file with commas between pairs… same result.
Original XML
<?xml version="1.0" encoding="utf-8"?>
<gml:FeatureCollection
xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:DigSitegml="http://www.irth.com/digsitegml" xsi:schemaLocation="http://www.irth.com/onecallgml http://www.irth.com/irthnet/digsitegml.xsd">
<gml:featureMember>
<DigSitegml:DigSiteReferral gml:id="digsite">
<DigSitegml:LocationDetails>
<surfaceProperty
xmlns="http://www.opengis.net/gml">
<Polygon srsName="EPSG:4326">
<outerBoundaryIs>
<LinearRing>
<coordinates>-93.568071 41.371658 -93.566828 41.371658 -93.566828 41.371883 -93.568071 41.371883 -93.568071 41.371658 </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</surfaceProperty>
</DigSitegml:LocationDetails>
</DigSitegml:DigSiteReferral>
</gml:featureMember>
</gml:FeatureCollection>
Alternative XML
Separated each pair of coordinates with a comma.
Only the element included for brevity
<coordinates>-93.568071 41.371658, -93.566828 41.371658, -93.566828 41.371883, -93.568071 41.371883, -93.568071 41.371658</coordinates>
The result of both is a set of 10 points as this:
IPoint |
IPoint.X |
IPoint.Y |
POINT (-93.568071 0) |
-93.568071 |
0 |
POINT (41.371658 0) |
41.371658 |
0 |
POINT (-93.566828 0) |
-93.566828 |
0 |
POINT (41.371658 0) |
41.371658 |
0 |
POINT (-93.566828 0) |
-93.566828 |
0 |
POINT (41.371883 0) |
41.371883 |
0 |
POINT (-93.568071 0) |
-93.568071 |
0 |
POINT (41.371883 0) |
41.371883 |
0 |
POINT (-93.568071 0) |
-93.568071 |
0 |
POINT (41.371658 0) |
41.371658 |
0 |
This is how I get my layer:
public VectorLayer GetGisLayerFromGmlData(Stream gml)
{
return Drivers.Gml.OpenLayer(AbstractPath.FromStream(gml), new GmlOptions() { RestoreSchema = true });
}
Thoughts on how I can achieve GML processing and treating each PAIR of numbers as a coordinate pair?
@c2itconsult
To properly parse the GML coordinate pairs from your provided XML, you need to ensure that the coordinates are treated as pairs rather than individual points. The issue you’re encountering, where each coordinate is being treated separately, can often be resolved by ensuring that the GML options are correctly set when reading the file.
Here are some steps and code snippets that may help you achieve the desired result:
-
Ensure Proper GML Options: When opening the GML file, you should specify the GmlOptions
to ensure that the schema is restored correctly. This can help in interpreting the coordinates as pairs.
-
Example Code: Below is an example of how to read the GML file with the appropriate options:
using Aspose.Gis;
using Aspose.Gis.Formats.Gml;
public VectorLayer GetGisLayerFromGmlData(Stream gml)
{
var options = new GmlOptions()
{
RestoreSchema = true // This helps in restoring the schema from the GML data
};
return VectorLayer.Open(gml, Drivers.Gml, options);
}
-
Coordinate Format: Ensure that your coordinates are formatted correctly. The original format you provided is valid, but if you are modifying it, make sure to keep the pairs intact. For example, the coordinates should be in the format -93.568071 41.371658
without any additional commas or separators between pairs.
-
Testing with Different Formats: If you continue to face issues, try testing with both the original and modified formats of the coordinates to see if there is any difference in how they are parsed.
-
Refer to Documentation: For more detailed information on handling GML files and coordinate parsing, you can refer to the official documentation on reading GML files with Aspose.GIS.
By following these steps, you should be able to parse the GML file correctly and treat each pair of coordinates as a single point. If you encounter further issues, consider checking the structure of your GML file and ensuring that it adheres to the expected schema.
Sources:
[1]: Read GML Geography Markup Language files in C# … - Aspose Documentation
Not bad feedback AI, and it’s what we’ve done already. Other GML we have seen has no commas either, but the Aspose driver doesn’t seem to like it either way. I wonder if it’s something from the schema that may need changed and pulled in, but not sure. Help me some more. 
Tried this per documentation as well:
GmlOptions options = new GmlOptions
{
// In this example we specify custom schemaLocation, since there is no 'schemaLocation' in GML file.
SchemaLocation = "http://www.aspose.com schema.xsd",
LoadSchemasFromInternet = false,
};
Got this working!
For what it’s worth, I had to put commas between lat/lon, and spaces between the coordinate pairs.
<?xml version="1.0" encoding="utf-8"?>
<gml:FeatureCollection
xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:DigSitegml="http://www.irth.com/digsitegml" xsi:schemaLocation="http://www.irth.com/onecallgml http://www.irth.com/irthnet/digsitegml.xsd">
<gml:featureMember>
<DigSitegml:DigSiteReferral gml:id="digsite">
<DigSitegml:LocationDetails>
<surfaceProperty
xmlns="http://www.opengis.net/gml">
<Polygon srsName="EPSG:4326">
<outerBoundaryIs>
<LinearRing>
<coordinates>-93.568071,41.371658 -93.566828,41.371658 -93.566828,41.371883 -93.568071,41.371883 -93.568071,41.371658</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</surfaceProperty>
</DigSitegml:LocationDetails>
</DigSitegml:DigSiteReferral>
</gml:featureMember>
</gml:FeatureCollection>
@c2itconsult If you need further assistance, please don’t hesitate to reach out.
We would be pleased if you describe your experience of using Aspose.GIS for the GML format and tell us about the cases in which you plan to use it. The team currently works on expanding of GML format support.
If you are concerned that your business case may be used by competitors, you can use forum direct messages or make the topic private.
Your feedback is very valuable to us and can make Aspose.GIS better.
Thank you
@c2itconsult
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): GISNET-1797 "Support of coordinates in GML format that are delimitered by whitespaces"
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.