From: Justin D. <jde...@op...> - 2013-03-12 16:23:04
|
Hey Chris, If you can keep messages on the public list that is appreciated. As for creating the encoder class taking 3s, are you sure that is every instantiation, and not just the frist? It sounds like the caching of the GML3 schema (which is a huge structure) but generally you only pay that cost the first time around as it is cached lazily. That said as long as the encoder object is not shared among threads it should be reusable. I think :) On Tue, Mar 12, 2013 at 6:40 AM, Christian Gendreau < chr...@gm...> wrote: > Hi Justin, > > Thanks for your answer. > > I wanted to reuse the same instance because I always use the same > configurations. The Encoder is expensive to create (approx 3s on my > machine), and I could have a bunch of different files to encode. The > instance would not be shared among different threads. I think the > Encoder(with new instances) is still my only option for now. > > Thanks > > Chris > > On Mon, Mar 11, 2013 at 11:10 AM, Justin Deoliveira > <jde...@op...> wrote: > > Hey Chris, > > > > I recommend just going straight with the Encoder and GMLConfiguration > > instances, as in your last example. > > > > As for not being able to reuse the encoder instance why in particular is > > this an issue? Sharing of instances of the Encoder and Configuration > should > > be done with care as they are not thread safe. They are designed to be > > instantiated at the time of usage. > > > > -Justin > > > > > > On Fri, Mar 8, 2013 at 7:44 AM, Christian Gendreau > > <chr...@gm...> wrote: > >> > >> Hi there, > >> > >> I would like to encode a DefaultFeatureCollection object into GML3. > >> > >> >From the example > >> > >> ( > http://docs.geotools.org/latest/userguide/library/xml/geometry.html#gml3-encoding > ), > >> I'm getting an empty String (no error, nothing in the debug file) : > >> > >> Note : This was already reported here : > >> http://osgeo-org.1560.n6.nabble.com/Write-GML-td5009329.html but still > >> without solution. > >> > >> SimpleFeatureType TYPE; > >> try { > >> TYPE = DataUtilities.createType("location", > >> "geom:Point,name:String"); > >> > >> ByteArrayOutputStream xml = new ByteArrayOutputStream(); > >> DefaultFeatureCollection featureCollection = new > >> DefaultFeatureCollection(); > >> WKTReader2 wkt = new WKTReader2(); > >> > >> featureCollection.add(SimpleFeatureBuilder.build(TYPE, new > >> Object[] { > >> wkt.read("POINT (1 2)"),"name1" }, null)); > >> featureCollection.add(SimpleFeatureBuilder.build(TYPE, new > >> Object[] { > >> wkt.read("POINT (4 4)"),"name2" }, null)); > >> > >> GML encode = new GML(Version.GML3); > >> encode.setNamespace("geotools", "http://geotools.org"); > >> encode.encode(xml, featureCollection); > >> > >> xml.close(); > >> > >> String gml = xml.toString(); > >> System.out.println(gml); > >> } catch (SchemaException e) { > >> e.printStackTrace(); > >> } catch (ParseException e) { > >> e.printStackTrace(); > >> } catch (IOException e) { > >> e.printStackTrace(); > >> } > >> > >> If I use: > >> GML encode = new GML(Version.GML2); > >> encode.setLegacy(true); > >> It is working. > >> If I look at the code of the GML class > >> > >> ( > http://svn.osgeo.org/geotools/trunk/modules/library/xml/src/main/java/org/geotools/GML.java > ). > >> The encode(OutputStream out, SimpleFeatureCollection collection) > >> function will never use Version.GML3. > >> > >> This below is also working but I can't reuse the Encoder object more > than > >> once: > >> org.geotools.gml3.GMLConfiguration.GMLConfiguration configuration = > >> new org.geotools.gml3.GMLConfiguration.GMLConfiguration(); > >> org.geotools.xml.Encoder encoder = new org.geotools.xml.Encoder( > >> configuration ); > >> > >> So I would like to know the easiest way to generate GML3 XML string > >> from a DefaultFeatureCollection object? > >> > >> I'm using the library gt-xml Version 10-SNAPSHOT. > >> > >> Thanks for the help > >> > >> Chris > >> > >> > >> > ------------------------------------------------------------------------------ > >> Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester > >> Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the > >> endpoint security space. For insight on selecting the right partner to > >> tackle endpoint security challenges, access the full report. > >> http://p.sf.net/sfu/symantec-dev2dev > >> _______________________________________________ > >> GeoTools-GT2-Users mailing list > >> Geo...@li... > >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > > > > > > > > > -- > > Justin Deoliveira > > OpenGeo - http://opengeo.org > > Enterprise support for open source geospatial. > > > > -- > Christian Gendreau ing. jr > Ingénieur logiciel / Software Engineer > Canadensys - www.canadensys.net > > Université de Montréal, Centre sur la biodiversité / Biodiversity Centre > 4101 rue Sherbrooke est > Montreal, QC, H1X 2B2 > Canada > 514-343-6111 ext. 83146 > Email: chr...@um... > -- Justin Deoliveira OpenGeo - http://opengeo.org Enterprise support for open source geospatial. |