Hi Oliver,
You might want to try turning up logging for the org.geotools.xml package.
Also you may want to try the more direct gml3 encoding route:
Also, if you just want to encode some features you can try wrapping them up
in a wfs feature collection, and directly calling the encoder. It is the
easiest way to get a feature collection. Here is an example:
http://svn.osgeo.org/geotools/trunk/modules/extension/xsd/xsd-wfs/src/test/java/org/geotools/wfs/WFSFeatureCollectionEncodingTest.java
-Justin
On Sat, Sep 10, 2011 at 9:46 AM, Oliver Pabst <[email protected]
> wrote:
> Hi,
>
> i twiddled a little with the examples from the Geotools homepage to encode
> a feature collection to GML. Using the example code for GML2 encoding worked
> fine, using GML3 does not work for me, there is neither output from the GML3
> encoder nor any hint whats wrong. The source code is at the end of the mail.
> It would be nice, if someone could take a look on the code and give me a
> hint, why the encoding to GML3 does not work.
>
> Thanks in advance,
> Oliver
>
>
> import java.io.ByteArrayOutputStream;
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.net.URL;
>
> import org.geotools.geometry.jts.WKTReader2;
> import org.geotools.data.simple.SimpleFeatureCollection;
> import org.geotools.data.DataUtilities;
> import org.geotools.feature.FeatureCollections;
> import org.geotools.feature.SchemaException;
> import org.geotools.GML;
> import org.geotools.GML.Version;
> import org.geotools.feature.simple.SimpleFeatureBuilder;
> import org.opengis.feature.simple.SimpleFeatureType;
>
> import com.vividsolutions.jts.io.ParseException;
>
> public class GMLExample {
> public static void main(String [] args) {
> encodeGML2();
> encodeGML3();
> }
>
>
> public static void encodeGML2() {
> try {
> File locationFile = new File("location.xsd");
>
>
> locationFile = locationFile.getCanonicalFile();
> locationFile.createNewFile();
>
>
> URL locationURL = locationFile.toURI().toURL();
> URL baseURL = locationFile.getParentFile().toURI().toURL();
>
>
> FileOutputStream xsd = null;
>
>
> xsd = new FileOutputStream(locationFile);
>
>
> SimpleFeatureType TYPE = DataUtilities.createType("location",
> "geom:Point,name:String");
>
>
> GML encode = new GML(Version.GML2);
> encode.setBaseURL(baseURL);
> encode.setNamespace("location", locationURL.toExternalForm());
> encode.encode(xsd, TYPE);
>
>
> xsd.close();
>
>
> SimpleFeatureCollection collection = FeatureCollections.newCollection();
> WKTReader2 wkt = new WKTReader2();
>
>
> collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT
> (1 2)"),"name1" }, null));
> collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT
> (4 4)"),"name2" }, null));
>
>
> ByteArrayOutputStream xml = new ByteArrayOutputStream();
>
> GML encode2 = new GML(Version.WFS1_0);
> encode2.setBaseURL(baseURL);
> encode2.setNamespace("location", "location.xsd");
> encode2.encode(xml, collection);
>
>
> xml.close();
>
>
> System.out.println("GML2");
> System.out.println(xml.toString());
> } catch (IOException ioe) {
> // TODO Auto-generated catch block
> ioe.printStackTrace();
> } catch (SchemaException se) {
> // TODO Auto-generated catch block
> se.printStackTrace();
> } catch (ParseException pe) {
> // TODO Auto-generated catch block
> pe.printStackTrace();
> }
> }
>
>
> public static void encodeGML3() {
> try {
> File locationFile = new File("location.xsd");
>
>
> locationFile = locationFile.getCanonicalFile();
> locationFile.createNewFile();
>
>
> URL locationURL = locationFile.toURI().toURL();
> URL baseURL = locationFile.getParentFile().toURI().toURL();
>
>
> FileOutputStream xsd = null;
>
>
> xsd = new FileOutputStream(locationFile);
>
>
> SimpleFeatureType TYPE = null;
>
>
> TYPE = DataUtilities.createType("location", "geom:Point,name:String");
>
>
> GML encode = new GML(Version.GML3);
> encode.setBaseURL(baseURL);
> encode.setNamespace("location", locationURL.toExternalForm());
> encode.encode(xsd, TYPE);
>
>
> xsd.close();
>
>
> SimpleFeatureCollection collection = FeatureCollections.newCollection();
> WKTReader2 wkt = new WKTReader2();
>
>
> collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT
> (1 2)"),"name1" }, null));
> collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT
> (4 4)"),"name2" }, null));
>
>
> ByteArrayOutputStream xml = new ByteArrayOutputStream();
>
> GML encode2 = new GML(Version.GML3);
> encode2.setBaseURL(baseURL);
> encode2.setNamespace("location", "location.xsd");
> encode2.encode(xml, collection);
>
>
> xml.close();
> System.out.println("GML3");
> System.out.println(xml.toString());
> } catch (IOException ioe) {
> // TODO Auto-generated catch block
> ioe.printStackTrace();
> } catch (ParseException pe) {
> // TODO Auto-generated catch block
> pe.printStackTrace();
> } catch (SchemaException se) {
> // TODO Auto-generated catch block
> se.printStackTrace();
> }
> }
> }
>
>
>
> ------------------------------------------------------------------------------
> Malware Security Report: Protecting Your Business, Customers, and the
> Bottom Line. Protect your business and customers by understanding the
> threat from malware and how it can impact your online business.
> http://www.accelacomm.com/jaw/sfnl/114/51427462/
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops? How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users