HELP. Using GML Parser in the project

2 messages Options
Embed this post
Permalink
Michael Wong

HELP. Using GML Parser in the project

Reply Threaded More More options
Print post
Permalink
Hi, members on geotools-gt-users,

My company wants to use geotools to parse GML files. So, I am responsible for studying whether it's suitable to be the library to support our product.

I tried to parse several different GML files. Some of them success, but some of them fail. They are all well-formed and validated gml files. I am wondering if the GML parser included in 2.5.4 able to parse any GML files if they are validated. When the parsing is failed, I got the following message, and I can only get a HashMap, instead of a FeatureCollection:
Jun 26, 2009 12:11:29 PM org.geotools.xml.impl.ParserHandler startElement
WARNING: Error parsing: http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd
Jun 26, 2009 12:11:29 PM org.geotools.xml.impl.ParserHandler startElement
WARNING: Could not find a schema

================================================================
The java code I am using is:

import java.io.*;
import java.util.*;
import org.geotools.gml3.GMLConfiguration;
import org.opengis.feature.simple.SimpleFeature;
import org.geotools.feature.FeatureCollection;

public class TestGeoTools3 {
        public static void main(String[] argv) throws Exception{
                GMLConfiguration configuration = new GMLConfiguration();
                org.geotools.xml.Parser parser = new org.geotools.xml.Parser(configuration);
                // Part 1: the gml instance document
                InputStream xml = new FileInputStream("sensorML.gml");

                // Part 2: parse the gml
                FeatureCollection fc = (FeatureCollection) parser.parse( xml );
               
                // Part 3: iterate through the collection, to get each feature
                for ( Iterator i = fc.iterator(); i.hasNext(); ) {  
                        SimpleFeature f = (SimpleFeature) i.next();
                        String name = (String) f.getAttribute( "NAME" );
                        System.out.println(name);
                }
        }
}


----------------------------------------------------

My gml file is: sensorML.gml

<?xml version="1.0"?>
<SensorML xmlns="http://www.opengis.net/sensorML/1.0.1"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:swe="http://www.opengis.net/swe/1.0.1" xmlns:gml="http://www.opengis.net/gml"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xsi:schemaLocation="http://www.opengis.net/sensorML/1.0.1 http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd"
   version="1.0.1">
   <member xlink:arcrole="urn:ogc:def:process:OGC:SensorInstance">
      <System gml:id="NSSTC_WX01">
         <!--============================-->
         <!-- Station Discovery Metadata -->
         <!--============================-->
         <gml:description>Davis weather station on roof of NSSTC Building, Huntsville, AL </gml:description>
         <keywords>
            <KeywordList codeSpace="urn:x-nasa:def:gcmd:keywords">
               <keyword>weather</keyword>
               <keyword>insitu</keyword>
               <keyword>station</keyword>
            </KeywordList>
         </keywords>
         <identification>
            <IdentifierList>
               <identifier name="longName">
                  <Term definition="urn:ogc:def:property:OGC:longName">
                     <value>NSSTC Weather Station WX-01</value>
                  </Term>
               </identifier>
               <identifier name="shortName">
                  <Term definition="urn:ogc:def:property:OGC:shortName">
                     <value>NSSTC-WX01</value>
                  </Term>
               </identifier>
            </IdentifierList>
         </identification>
         <classification>
            <ClassifierList>
               <classifier name="intendedApplication">
                  <Term definition="urn:ogc:def:property:OGC:application">
                     <value>weather</value>
                  </Term>
               </classifier>
               <classifier name="sensorType">
                  <Term definition="urn:ogc:def:property:OGC:sensorType">
                     <value>thermometer</value>
                  </Term>
               </classifier>
               <classifier name="sensorType">
                  <Term definition="urn:ogc:def:property:OGC:sensorType">
                     <value>barometer</value>
                  </Term>
               </classifier>
               <classifier name="sensorType">
                  <Term definition="urn:ogc:def:property:OGC:sensorType">
                     <value>anemometer</value>
                  </Term>
               </classifier>
               <classifier name="sensorType">
                  <Term definition="urn:ogc:def:property:OGC:sensorType">
                     <value>rain gauge</value>
                  </Term>
               </classifier>
            </ClassifierList>
         </classification>
         <validTime>
            <gml:TimeInstant>
               <gml:timePosition indeterminatePosition="after">2005-01-01</gml:timePosition>
            </gml:TimeInstant>
         </validTime>
         <contact xlink:arcrole="urn:ogc:def:property:OGC:operator"
            xlink:href="http://vast.uah.edu/SensorML/contacts/paulMeyer.xml"/>
         <components>
            <ComponentList>
               <!--==================================-->
               <!-- Davis Weather Station Monitor II -->
               <!--==================================-->
               <component name="weatherStation"
                  xlink:href="http://vast.uah.edu/downloads/sensorML/v1.0/examples/sensors/DavisWeather/DavisMonitorII-WeatherStation.xml"/>
            </ComponentList>
         </components>
         <positions>
            <PositionList>
               <!--=================================-->
               <!-- Position of Station in EPSG4329 -->
               <!--=================================-->
               <position name="stationPosition">
                  <swe:Position localFrame="#STATION_FRAME"
                     referenceFrame="urn:ogc:def:crs:EPSG:4329">
                     <swe:location>
                        <swe:Vector definition="urn:ogc:def:property:OGC:location">
                           <swe:coordinate name="latitude">
                              <swe:Quantity definition="urn:ogc:def:property:OGC:latitude">
                                 <swe:uom code="deg"/>
                                 <swe:value>34.72450</swe:value>
                              </swe:Quantity>
                           </swe:coordinate>
                           <swe:coordinate name="longitude">
                              <swe:Quantity definition="urn:ogc:def:property:OGC:longitude">
                                 <swe:uom code="deg"/>
                                 <swe:value>-86.94533</swe:value>
                              </swe:Quantity>
                           </swe:coordinate>
                           <swe:coordinate name="altitude">
                              <swe:Quantity definition="urn:ogc:def:property:OGC:altitude">
                                 <swe:uom code="m"/>
                                 <swe:value>20.1169</swe:value>
                              </swe:Quantity>
                           </swe:coordinate>
                        </swe:Vector>
                     </swe:location>
                     <swe:orientation>
                        <swe:Vector definition="urn:ogc:def:property:OGC:orientation">
                           <swe:coordinate name="trueHeading">
                              <swe:Quantity axisID="Z"
                                 definition="urn:ogc:def:property:OGC:angleToNorth">
                                 <swe:uom code="deg"/>
                                 <swe:value>87.0</swe:value>
                              </swe:Quantity>
                           </swe:coordinate>
                           <swe:coordinate name="pitch">
                              <swe:Quantity axisID="X"
                                 definition="urn:ogc:def:property:OGC:pitch">
                                 <swe:uom code="deg"/>
                                 <swe:value>0</swe:value>
                              </swe:Quantity>
                           </swe:coordinate>
                           <swe:coordinate name="roll">
                              <swe:Quantity axisID="Y"
                                 definition="urn:ogc:def:property:OGC:roll">
                                 <swe:uom code="deg"/>
                                 <swe:value>0</swe:value>
                              </swe:Quantity>
                           </swe:coordinate>
                        </swe:Vector>
                     </swe:orientation>
                  </swe:Position>
               </position>
            </PositionList>
         </positions>
      </System>
   </member>
</SensorML>

Justin Deoliveira

Re: HELP. Using GML Parser in the project

Reply Threaded More More options
Print post
Permalink
Hi Michael,

As said in a previous email only part of the GML 3 schema is supported
in geotools, simple features level 0. The reason you are getting a hash
map back is because the parser does not know what type of object to
return (since those elements of the schema are not supported).

So unfortunately you are stuck filing a feature or bug request in the
issue tracker, or implementing it yourself. There is also commercial
support available for such feature requests.

-Justin

Michael Wong wrote:

> Hi, members on geotools-gt-users,
>
> My company wants to use geotools to parse GML files. So, I am responsible
> for studying whether it's suitable to be the library to support our product.
>
> I tried to parse several different GML files. Some of them success, but some
> of them fail. They are all well-formed and validated gml files. I am
> wondering if the GML parser included in 2.5.4 able to parse any GML files if
> they are validated. When the parsing is failed, I got the following message,
> and I can only get a HashMap, instead of a FeatureCollection:
> Jun 26, 2009 12:11:29 PM org.geotools.xml.impl.ParserHandler startElement
> WARNING: Error parsing:
> http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd
> Jun 26, 2009 12:11:29 PM org.geotools.xml.impl.ParserHandler startElement
> WARNING: Could not find a schema
>
> ================================================================
> The java code I am using is:
>
> import java.io.*;
> import java.util.*;
> import org.geotools.gml3.GMLConfiguration;
> import org.opengis.feature.simple.SimpleFeature;
> import org.geotools.feature.FeatureCollection;
>
> public class TestGeoTools3 {
> public static void main(String[] argv) throws Exception{
> GMLConfiguration configuration = new GMLConfiguration();
> org.geotools.xml.Parser parser = new
> org.geotools.xml.Parser(configuration);
> // Part 1: the gml instance document
> InputStream xml = new FileInputStream("sensorML.gml");
>
> // Part 2: parse the gml
> FeatureCollection fc = (FeatureCollection) parser.parse( xml );
>
> // Part 3: iterate through the collection, to get each feature
> for ( Iterator i = fc.iterator(); i.hasNext(); ) {  
> SimpleFeature f = (SimpleFeature) i.next();
> String name = (String) f.getAttribute( "NAME" );
> System.out.println(name);
> }
> }
> }
>
>
> ----------------------------------------------------
>
> My gml file is: sensorML.gml
>
> <?xml version="1.0"?>
> <SensorML xmlns="http://www.opengis.net/sensorML/1.0.1"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:swe="http://www.opengis.net/swe/1.0.1"
> xmlns:gml="http://www.opengis.net/gml"
>    xmlns:xlink="http://www.w3.org/1999/xlink"
>    xsi:schemaLocation="http://www.opengis.net/sensorML/1.0.1
> http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd"
>    version="1.0.1">
>    <member xlink:arcrole="urn:ogc:def:process:OGC:SensorInstance">
>       <System gml:id="NSSTC_WX01">
>          <!--============================-->
>          <!-- Station Discovery Metadata -->
>          <!--============================-->
>          <gml:description>Davis weather station on roof of NSSTC Building,
> Huntsville, AL </gml:description>
>          <keywords>
>             <KeywordList codeSpace="urn:x-nasa:def:gcmd:keywords">
>                <keyword>weather</keyword>
>                <keyword>insitu</keyword>
>                <keyword>station</keyword>
>             </KeywordList>
>          </keywords>
>          <identification>
>             <IdentifierList>
>                <identifier name="longName">
>                   <Term definition="urn:ogc:def:property:OGC:longName">
>                      <value>NSSTC Weather Station WX-01</value>
>                   </Term>
>                </identifier>
>                <identifier name="shortName">
>                   <Term definition="urn:ogc:def:property:OGC:shortName">
>                      <value>NSSTC-WX01</value>
>                   </Term>
>                </identifier>
>             </IdentifierList>
>          </identification>
>          <classification>
>             <ClassifierList>
>                <classifier name="intendedApplication">
>                   <Term definition="urn:ogc:def:property:OGC:application">
>                      <value>weather</value>
>                   </Term>
>                </classifier>
>                <classifier name="sensorType">
>                   <Term definition="urn:ogc:def:property:OGC:sensorType">
>                      <value>thermometer</value>
>                   </Term>
>                </classifier>
>                <classifier name="sensorType">
>                   <Term definition="urn:ogc:def:property:OGC:sensorType">
>                      <value>barometer</value>
>                   </Term>
>                </classifier>
>                <classifier name="sensorType">
>                   <Term definition="urn:ogc:def:property:OGC:sensorType">
>                      <value>anemometer</value>
>                   </Term>
>                </classifier>
>                <classifier name="sensorType">
>                   <Term definition="urn:ogc:def:property:OGC:sensorType">
>                      <value>rain gauge</value>
>                   </Term>
>                </classifier>
>             </ClassifierList>
>          </classification>
>          <validTime>
>             <gml:TimeInstant>
>                <gml:timePosition
> indeterminatePosition="after">2005-01-01</gml:timePosition>
>             </gml:TimeInstant>
>          </validTime>
>          <contact xlink:arcrole="urn:ogc:def:property:OGC:operator"
>            
> xlink:href="http://vast.uah.edu/SensorML/contacts/paulMeyer.xml"/>
>          <components>
>             <ComponentList>
>                <!--==================================-->
>                <!-- Davis Weather Station Monitor II -->
>                <!--==================================-->
>                <component name="weatherStation"
>                  
> xlink:href="http://vast.uah.edu/downloads/sensorML/v1.0/examples/sensors/DavisWeather/DavisMonitorII-WeatherStation.xml"/>
>             </ComponentList>
>          </components>
>          <positions>
>             <PositionList>
>                <!--=================================-->
>                <!-- Position of Station in EPSG4329 -->
>                <!--=================================-->
>                <position name="stationPosition">
>                   <swe:Position localFrame="#STATION_FRAME"
>                      referenceFrame="urn:ogc:def:crs:EPSG:4329">
>                      <swe:location>
>                         <swe:Vector
> definition="urn:ogc:def:property:OGC:location">
>                            <swe:coordinate name="latitude">
>                               <swe:Quantity
> definition="urn:ogc:def:property:OGC:latitude">
>                                  <swe:uom code="deg"/>
>                                  <swe:value>34.72450</swe:value>
>                               </swe:Quantity>
>                            </swe:coordinate>
>                            <swe:coordinate name="longitude">
>                               <swe:Quantity
> definition="urn:ogc:def:property:OGC:longitude">
>                                  <swe:uom code="deg"/>
>                                  <swe:value>-86.94533</swe:value>
>                               </swe:Quantity>
>                            </swe:coordinate>
>                            <swe:coordinate name="altitude">
>                               <swe:Quantity
> definition="urn:ogc:def:property:OGC:altitude">
>                                  <swe:uom code="m"/>
>                                  <swe:value>20.1169</swe:value>
>                               </swe:Quantity>
>                            </swe:coordinate>
>                         </swe:Vector>
>                      </swe:location>
>                      <swe:orientation>
>                         <swe:Vector
> definition="urn:ogc:def:property:OGC:orientation">
>                            <swe:coordinate name="trueHeading">
>                               <swe:Quantity axisID="Z"
>                                
> definition="urn:ogc:def:property:OGC:angleToNorth">
>                                  <swe:uom code="deg"/>
>                                  <swe:value>87.0</swe:value>
>                               </swe:Quantity>
>                            </swe:coordinate>
>                            <swe:coordinate name="pitch">
>                               <swe:Quantity axisID="X"
>                                
> definition="urn:ogc:def:property:OGC:pitch">
>                                  <swe:uom code="deg"/>
>                                  <swe:value>0</swe:value>
>                               </swe:Quantity>
>                            </swe:coordinate>
>                            <swe:coordinate name="roll">
>                               <swe:Quantity axisID="Y"
>                                  definition="urn:ogc:def:property:OGC:roll">
>                                  <swe:uom code="deg"/>
>                                  <swe:value>0</swe:value>
>                               </swe:Quantity>
>                            </swe:coordinate>
>                         </swe:Vector>
>                      </swe:orientation>
>                   </swe:Position>
>                </position>
>             </PositionList>
>          </positions>
>       </System>
>    </member>
> </SensorML>
>
>


--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users