[fdo-users] RE: Right way of creating a GML file?

Elavazhagan. M elavazhagan.mouniandy at kcubeconsulting.com
Fri Nov 26 09:01:39 EST 2010


Okay, I somehow have got it to work. Here is a solution (still not sure if
this the correct approach, but it works!!!)

 

//Create an XSD file before writing the GML file - this will be used to set
XmlFeatureFlags

            String xsdFilePath = gmlFilePath + ".xsd";

            XmlWriter xsdXmlWriter = new XmlWriter(xsdFilePath);

            XmlSpatialContextWriter spatialContextWriter = new
XmlSpatialContextWriter(xsdXmlWriter);

            XmlSpatialContextSerializer.XmlSerialize(connection,
spatialContextWriter);

            featureClass.FeatureSchema.WriteXml(xsdXmlWriter);

            xsdXmlWriter.Close();

            xsdXmlWriter.Dispose();

 

//Prepare to write GML file

            XmlFeatureFlags xmlFeatureFlags = new
XmlFeatureFlags(xsdFilePath);

            XmlWriter gmlXmlWriter = new XmlWriter(gmlFilePath);

            XmlFeatureWriter xmlFeatureWriter = new
XmlFeatureWriter(gmlXmlWriter);

 

//Select & write the features into GML file

            ISelect select =
(ISelect)connection.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType
_Select);

            select.SetFeatureClassName(featureClass.Name);

            IFeatureReader  featureReader = select.Execute();

            XmlFeatureSerializer.XmlSerialize(featureReader,
xmlFeatureWriter, xmlFeatureFlags);

 

Now, the GML is written in the correct format and QGIS is able to open it
too.

 

Regards,

Ela.

From: Elavazhagan. M [mailto:elavazhagan.mouniandy at kcubeconsulting.com] 
Sent: Friday, November 26, 2010 4:23 PM
To: 'FDO Users Mail List'
Subject: Right way of creating a GML file?

 

Hi,

 

Can somebody please tell me whether the following approach (in C#) is the
right way to generate a GML file?

 

               //Select features

ISelect select =
(ISelect)connection.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType
_Select);

               select.SetFeatureClassName(featureClassName); 

               IFeatureReader featureReader = select.Execute();

 

               //Write features

XmlWriter xmlWriter = new XmlWriter(gmlFilePath);

               XmlFeatureWriter xmlFeatureWriter = new
XmlFeatureWriter(xmlWriter);

               XmlFeatureSerializer.XmlSerialize(featureReader,
xmlFeatureWriter);

 

This creates a GML file in the following format: 

 

<?xml version="1.0" encoding="UTF-8" ?>

<fdo:DataStore xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:gml="http://www.opengis.net/gml"
xmlns:fdo="http://fdo.osgeo.org/schemas"
xmlns:fds="http://fdo.osgeo.org/schemas/fds">

    <building>

        <gid>10</gid>

        <AREA>2365</AREA>

        <PERIMETER>3400</PERIMETER>

        <the_geom>

            <gml:Polygon srsName="EPSG:4326">

                <gml:outerBoundaryIs>

                    <gml:LinearRing>

                        <gml:coordinates>1550000.000000,6425000.000000
1525000.000000,6425000.000000 1525000.000000,6450000.000000
1550000.000000,6450000.000000
1550000.000000,6425000.000000</gml:coordinates>

                    </gml:LinearRing>

                </gml:outerBoundaryIs>

            </gml:Polygon>

        </the_geom>

    </building>

</fdo:DataStore>

 

But I am unable to open the GML in QGIS as it says, "building.gml is not a
valid or recognized data source".

 

Thanks,

Ela.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/fdo-users/attachments/20101126/39280a5d/attachment-0001.html


More information about the fdo-users mailing list