[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fdo-users
Subject:    [fdo-users] RE: Right way of creating a GML file?
From:       "Elavazhagan. M" <elavazhagan.mouniandy () kcubeconsulting ! com>
Date:       2010-11-26 14:13:39
Message-ID: 003c01cb8d72$729f45e0$57ddd1a0$ () mouniandy () kcubeconsulting ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@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.


[Attachment #5 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=WordSection1>

<p class=MsoNormal><span style='color:#1F497D'>Okay, I somehow have got it to
work. Here is a solution (still not sure if this the correct approach, but it
works!!!)<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>//Create an XSD file before
writing the GML file &#8211; this will be used to set \
XmlFeatureFlags<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
String xsdFilePath = gmlFilePath + &quot;.xsd&quot;;<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
XmlWriter xsdXmlWriter = new XmlWriter(xsdFilePath);<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 XmlSpatialContextWriter spatialContextWriter = new
XmlSpatialContextWriter(xsdXmlWriter);<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 XmlSpatialContextSerializer.XmlSerialize(connection, \
spatialContextWriter);<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 featureClass.FeatureSchema.WriteXml(xsdXmlWriter);<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 xsdXmlWriter.Close();<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 xsdXmlWriter.Dispose();<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>//Prepare to write GML \
file<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;XmlFeatureFlags xmlFeatureFlags = new \
XmlFeatureFlags(xsdFilePath);<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
XmlWriter gmlXmlWriter = new XmlWriter(gmlFilePath);<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
XmlFeatureWriter xmlFeatureWriter = new \
XmlFeatureWriter(gmlXmlWriter);<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>//Select &amp; write the
features into GML file<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
ISelect select = (ISelect)connection.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select);<o:p></o:p></span></p>


<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 select.SetFeatureClassName(featureClass.Name);<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&nbsp;IFeatureReader &nbsp;featureReader = select.Execute();<o:p></o:p></span></p>

<p class=MsoNormal><span \
style='color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
XmlFeatureSerializer.XmlSerialize(featureReader, xmlFeatureWriter, \
xmlFeatureFlags);<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>Now, the GML is written in the correct
format and QGIS is able to open it too.<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>Regards,<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>Ela.<o:p></o:p></span></p>

<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Elavazhagan. M \
[mailto:elavazhagan.mouniandy@kcubeconsulting.com] <br> <b>Sent:</b> Friday, November \
26, 2010 4:23 PM<br> <b>To:</b> 'FDO Users Mail List'<br>
<b>Subject:</b> Right way of creating a GML file?<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Hi,<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Can somebody please tell me whether the following approach
(in C#) is the right way to generate a GML file?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 //Select features<o:p></o:p></p>

<p class=MsoNormal style='text-indent:.5in'>ISelect select = \
(ISelect)connection.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select);<o:p></o:p></p>


<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; select.SetFeatureClassName(featureClassName); <o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 IFeatureReader featureReader = select.Execute();<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 //Write features<o:p></o:p></p>

<p class=MsoNormal style='text-indent:.5in'>XmlWriter xmlWriter = new
XmlWriter(gmlFilePath);<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 XmlFeatureWriter xmlFeatureWriter = new XmlFeatureWriter(xmlWriter);<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 XmlFeatureSerializer.XmlSerialize(featureReader, xmlFeatureWriter);<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>This creates a GML file in the following format: <o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;
?&gt;<o:p></o:p></p>

<p class=MsoNormal>&lt;fdo:DataStore
xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;
xmlns:gml=&quot;http://www.opengis.net/gml&quot; \
xmlns:fdo=&quot;http://fdo.osgeo.org/schemas&quot; \
xmlns:fds=&quot;http://fdo.osgeo.org/schemas/fds&quot;&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; &lt;building&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;gid&gt;10&lt;/gid&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;AREA&gt;2365&lt;/AREA&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;PERIMETER&gt;3400&lt;/PERIMETER&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&lt;the_geom&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;gml:Polygon srsName=&quot;EPSG:4326&quot;&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &lt;gml:outerBoundaryIs&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &lt;gml:LinearRing&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &lt;gml:coordinates&gt;1550000.000000,6425000.000000
1525000.000000,6425000.000000 1525000.000000,6450000.000000 \
1550000.000000,6450000.000000 \
1550000.000000,6425000.000000&lt;/gml:coordinates&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &lt;/gml:LinearRing&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &lt;/gml:outerBoundaryIs&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/gml:Polygon&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&lt;/the_geom&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; &lt;/building&gt;<o:p></o:p></p>

<p class=MsoNormal>&lt;/fdo:DataStore&gt;<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>But I am unable to open the GML in QGIS as it says,
&#8220;building.gml is not a valid or recognized data source&#8221;.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Thanks,<o:p></o:p></p>

<p class=MsoNormal>Ela.<o:p></o:p></p>

</div>

</div>

</body>

</html>



_______________________________________________
fdo-users mailing list
fdo-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fdo-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic