-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I have found out the problems.
The altitude is available in
track.getDefaultGeometry().getPointN(0).getCoordinate().z
where track is a SimpleFeature
I have made a small patch on the KML parser to get the TimeStamp and to
set it as an attribute of the SimpleFeature. The patch is attached to
this mail.
Thanks
Fabien Carrion wrote:
> Hi the list,
>
>
> I have been trying to read a kml file and display all the points with
> their datetime and altitude.
>
> So I have used this piece of code
>
> File file = new File(filename);
> //create the parser
> Configuration configuration = new KMLConfiguration();
> Parser parser = new Parser( configuration );
> //the xml instance document above
> InputStream xml = new FileInputStream(file);
> //parse
> SimpleFeatureImpl fc = (SimpleFeatureImpl) parser.parse( xml );
> recursiveDisplay(fc);
>
>
> Recursive Display is:
>
> private void recursiveDisplay(SimpleFeature fc) {
> for (Object item : fc.getAttributes()) {
> if (item != null) {
> if (item instanceof Iterable) {
> Iterator i = ((Iterable) item).iterator();
> while (i.hasNext()) {
> Object child = i.next();
> if (child instanceof SimpleFeature) {
> recursiveDisplay((SimpleFeature) child);
> } else {
> logger.info("" + child.getClass() + " " +
> child);
> }
> }
> } else {
> logger.info("" + item.getClass() + " " + item);
> }
> }
> }
> }
>
> And it never appears the altitude and the datetime with this function.
>
> I would like to know if it is possible to get this information in the
> SimpleFeature object, because the information exists in the kml file.
>
> Thanks for your help.
>
- --
Fabien Carrion
() Campagne du ruban ASCII -- Contre les mails en html
/\ contre les pieces-jointes Microsoft
Web: http://fabien.carrion.free.fr/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAktPvtEACgkQTe/bvZWuSM/SYgCdHII6/QRb52+nH5yDum/PtkIf
zG4AnijlzxjlAVarBjEUkAZPJnGBO6uu
=r8mS
-----END PGP SIGNATURE-----
Index: modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/KML.java
===================================================================
--- modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/KML.java (revision 34791)
+++ modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/KML.java (working copy)
@@ -304,6 +304,10 @@
"coordinates");
/** @generated */
+ public static final QName when = new QName("http://earth.google.com/kml/2.1",
+ "when");
+
+ /** @generated */
public static final QName Document = new QName("http://earth.google.com/kml/2.1", "Document");
/** @generated */
Index: modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/KMLConfiguration.java
===================================================================
--- modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/KMLConfiguration.java (revision 34791)
+++ modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/KMLConfiguration.java (working copy)
@@ -49,6 +49,7 @@
import org.geotools.kml.bindings.RegionTypeBinding;
import org.geotools.kml.bindings.StyleMap;
import org.geotools.kml.bindings.StyleTypeBinding;
+import org.geotools.kml.bindings.TimeStampTypeBinding;
import org.geotools.styling.StyleBuilder;
import org.geotools.styling.StyleFactory;
import org.geotools.xml.Configuration;
@@ -174,7 +175,7 @@
//container.registerComponentImplementation(KML.TimePrimitiveType,
// TimePrimitiveTypeBinding.class);
//container.registerComponentImplementation(KML.TimeSpanType, TimeSpanTypeBinding.class);
- //container.registerComponentImplementation(KML.TimeStampType, TimeStampTypeBinding.class);
+ container.registerComponentImplementation(KML.TimeStampType, TimeStampTypeBinding.class);
//container.registerComponentImplementation(KML.unitsEnum, UnitsEnumBinding.class);
//container.registerComponentImplementation(KML.UpdateType, UpdateTypeBinding.class);
//container.registerComponentImplementation(KML.vec2Type, Vec2TypeBinding.class);
Index: modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/TimeStampTypeBinding.java
===================================================================
--- modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/TimeStampTypeBinding.java (revision 0)
+++ modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/TimeStampTypeBinding.java (revision 0)
@@ -0,0 +1,88 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.kml.bindings;
+
+import java.util.Date;
+import javax.xml.namespace.QName;
+import org.geotools.kml.KML;
+import org.geotools.xml.AbstractComplexBinding;
+import org.geotools.xml.ElementInstance;
+import org.geotools.xml.Node;
+
+
+/**
+ * Binding object for the type http://earth.google.com/kml/2.1:TimeStampType.
+ *
+ * <p>
+ * <pre>
+ * <code>
+ * <simpleType name="TimeStampType">
+ * </simpleType>
+ *
+ * </code>
+ * </pre>
+ * </p>
+ *
+ * @generated
+ *
+ * @source $URL: http://svn.osgeo.org/geotools/trunk/modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/TimeStampType.java $
+ */
+public class TimeStampTypeBinding extends AbstractComplexBinding {
+
+ /**
+ * @generated
+ */
+ public QName getTarget() {
+ return KML.TimeStampType;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @generated modifiable
+ */
+ public Class getType() {
+ return Date.class;
+ }
+
+ public int getExecutionMode() {
+ return OVERRIDE;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @generated modifiable
+ */
+ public Object parse(ElementInstance instance, Node node, Object value)
+ throws Exception {
+ Date d = (Date) node.getChildValue(KML.when.getLocalPart());
+ return d;
+ }
+
+
+ public Object getProperty(Object object, QName name) throws Exception {
+ if ( KML.when.equals( name ) ) {
+ Date d = (Date) object;
+ return d;
+ }
+
+ return null;
+ }
+}
Index: modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/DateTimeTypeBinding.java
===================================================================
--- modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/DateTimeTypeBinding.java (revision 34791)
+++ modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/DateTimeTypeBinding.java (working copy)
@@ -16,7 +16,10 @@
*/
package org.geotools.kml.bindings;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import javax.xml.namespace.QName;
+
import org.geotools.kml.KML;
import org.geotools.xml.AbstractSimpleBinding;
import org.geotools.xml.InstanceComponent;
@@ -55,8 +58,12 @@
* @generated modifiable
*/
public Class getType() {
- return null;
+ return Date.class;
}
+
+ public int getExecutionMode() {
+ return OVERRIDE;
+ }
/**
* <!-- begin-user-doc -->
@@ -66,7 +73,19 @@
*/
public Object parse(InstanceComponent instance, Object value)
throws Exception {
- //TODO: implement
- return null;
+ if (value == null) {
+ return null;
+ }
+
+ String dateString = (String) value;
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ return df.parse(dateString);
}
+
+ public String encode(Object object, String value) throws Exception {
+ Date d = (Date) object;
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ return df.format(d);
+ }
}
Index: modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/PlacemarkTypeBinding.java
===================================================================
--- modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/PlacemarkTypeBinding.java (revision 34791)
+++ modules/extension/xsd/xsd-kml/src/main/java/org/geotools/kml/bindings/PlacemarkTypeBinding.java (working copy)
@@ -16,6 +16,7 @@
*/
package org.geotools.kml.bindings;
+import java.util.Date;
import javax.xml.namespace.QName;
import com.vividsolutions.jts.geom.Geometry;
import org.opengis.feature.simple.SimpleFeature;
@@ -66,6 +67,9 @@
//<element minOccurs="0" ref="kml:Geometry"/>
tb.add("Geometry", Geometry.class);
+ //<element minOccurs="0" ref="kml:TimeStamp"/>
+ tb.add("TimeStamp", Date.class);
+
featureType = tb.buildFeatureType();
}
@@ -106,6 +110,9 @@
//<element minOccurs="0" ref="kml:Geometry"/>
b.set("Geometry", node.getChildValue(Geometry.class));
+ //<element minOccurs="0" ref="kml:TimeStamp"/>
+ b.set("TimeStamp", node.getChildValue(KML.TimeStamp.getLocalPart()));
+
return b.buildFeature(feature.getID());
}
@@ -114,6 +121,9 @@
if ( KML.Geometry.equals( name ) ) {
return feature.getDefaultGeometry();
}
+ if ( KML.TimeStamp.equals( name ) ) {
+ return feature.getAttribute("TimeStamp");
+ }
return null;
}
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users