<div dir="ltr">Hello Guilhem,<div><br></div><div>Thank you so much for your code, this is what i was looking for and it opens good perspectives for my software !</div><div><br></div><div>I wasn't aware of FeatureStoreUtilities and of JAXPStreamFeatureWriter. </div>
<div><br></div><div>Thank you again</div><div><br></div><div>François</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-16 11:26 GMT+02:00 Guilhem <span dir="ltr"><<a href="mailto:guilhem.legal@geomatys.fr" target="_blank">guilhem.legal@geomatys.fr</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>hi François,<br>
<br>
To write feature collection, you can't use MarshallerPool (JAXB)
because its dynamical.<br>
You must use JAXP feature writer.<br>
here is a piece of code doing what you are trying to do: <br><div class="">
<br>
final GeometryFactory gf = new GeometryFactory();<br>
<br></div><div class="">
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();<br>
ftb.setName("station:stationType");<br>
ftb.add("name", String.class);<br></div>
CoordinateReferenceSystem wgs84 = CRS.forCode("CRS:84");<div class=""><br>
ftb.add("the_geom", PointType.class, wgs84);<br>
ftb.setDefaultGeometry("the_geom");<br>
final SimpleFeatureType sft =
ftb.buildSimpleFeatureType();<br>
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(sft);<br>
sfb.set("name", "Toulouse");<br>
sfb.set("the_geom", gf.createPoint(new Coordinate(1.4526,
43.5957)));<br>
final Feature feat = sfb.buildFeature("id-0");<br>
<br></div>
FeatureCollection collection =
FeatureStoreUtilities.collection(sft, Arrays.asList(feat));<br>
<br>
final JAXPStreamFeatureWriter writer = new
JAXPStreamFeatureWriter("3.2.1", "1.1.0", new HashMap<String,
String>());<br>
writer.setOutput(System.out);<br>
writer.writeFeatureCollection(collection, false, 1);<br>
<br>
<br>
Guilhem Legal<br>
<br>
Le 15/04/2014 22:50, Francois Andre a écrit :<br>
</div>
<blockquote type="cite"><div><div class="h5">
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi
everybody,</span>
<div style="font-family:arial,sans-serif;font-size:13px"><br>
</div>
<div style="font-family:arial,sans-serif;font-size:13px">I'd
like to generate a WFS GetFeature response with geotoolkit.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br>
</div>
<div style="font-family:arial,sans-serif;font-size:13px">I've
found here and there some clues but I just don't really know
how to link everything together</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br>
</div>
<div style="font-family:arial,sans-serif;font-size:13px">Here is
the XML i'd like to generate:</div>
<div style="font-family:arial,sans-serif;font-size:13px">
<br>
</div>
<div style="font-family:arial,sans-serif;font-size:13px">
<div><?xml version="1.0" encoding="UTF-8"?></div>
<div><wfs:FeatureCollection numberOfFeatures="1"
timeStamp="2014-04-15T15:22:49.133+02:00" </div>
<div> xsi:schemaLocation="<a href="http://www.resif.fr/station" target="_blank">http://www.resif.fr/station</a> <a href="http://localhost/wfs/schema.xsd" target="_blank">http://localhost/wfs/schema.xsd</a> <a href="http://www.opengis.net/wfs" target="_blank">http://www.opengis.net/wfs</a> <a href="http://ogo.heig-vd.ch/geoserver/schemas/wfs/1.1.0/wfs.xsd" target="_blank">http://ogo.heig-vd.ch:80/geoserver/schemas/wfs/1.1.0/wfs.xsd</a>" </div>
<div> xmlns:station="<a href="http://www.resif.fr/station" target="_blank">http://www.resif.fr/station</a>" </div>
<div> xmlns:ogc="<a href="http://www.opengis.net/ogc" target="_blank">http://www.opengis.net/ogc</a>" </div>
<div> xmlns:wfs="<a href="http://www.opengis.net/wfs" target="_blank">http://www.opengis.net/wfs</a>" </div>
<div> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>" </div>
<div> xmlns:gml="<a href="http://www.opengis.net/gml" target="_blank">http://www.opengis.net/gml</a>"
></div>
<div><br>
</div>
<div> <gml:featureMembers></div>
<div> <station:station gml:id="cities.248"></div>
<div>
<station:station_name>Toulouse</station:station_name></div>
<div> <station:the_geom></div>
<div> <gml:Point srsDimension="2" srsName="<a href="http://www.opengis.net/gml/srs/epsg.xml#4326" target="_blank">http://www.opengis.net/gml/srs/epsg.xml#4326</a>"></div>
<div> <gml:pos><a href="tel:1.4434%2043.6045" value="+14434436045" target="_blank">1.4434 43.6045</a></gml:pos></div>
<div> </gml:Point></div>
<div> </station:the_geom></div>
<div> </station:station></div>
<div> </gml:featureMembers></div>
<div> </div>
<div> </wfs:FeatureCollection></div>
<div><br>
</div>
<div>Here is my unworking coding attempt :</div>
<div><br>
</div>
<div>
<div>@Test</div>
<div><span style="white-space:pre-wrap"> </span>public void
GetFeatureTest() throws Exception</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>final
GeometryFactory gf = new GeometryFactory(); </div>
<div><span style="white-space:pre-wrap"> </span>GregorianCalendar
c = new GregorianCalendar();</div>
<div><span style="white-space:pre-wrap"> </span>XMLGregorianCalendar
timeStamp =
DatatypeFactory.newInstance().newXMLGregorianCalendar(c);</div>
<div><span style="white-space:pre-wrap"> </span>String
version = "1.1.0";</div>
<div><span style="white-space:pre-wrap"> </span>FeatureCollectionType
response = (FeatureCollectionType)
WFSXmlFactory.buildFeatureCollection(version, "id", 2,
timeStamp);</div>
<div><span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>final
FeatureTypeBuilder ftb = new FeatureTypeBuilder();</div>
<div><span style="white-space:pre-wrap"> </span>ftb.setName("station:stationType");</div>
<div><span style="white-space:pre-wrap"> </span>ftb.add("name",
String.class);</div>
<div><span style="white-space:pre-wrap"> </span>DefaultGeographicCRS
wgs84 = DefaultGeographicCRS.WGS84;</div>
<div><span style="white-space:pre-wrap"> </span>ftb.add("the_geom",
PointType.class, wgs84);</div>
<div><span style="white-space:pre-wrap"> </span>ftb.setDefaultGeometry("the_geom");</div>
<div><span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>final
SimpleFeatureType sft = ftb.buildSimpleFeatureType();</div>
<div><span style="white-space:pre-wrap"> </span>SimpleFeatureBuilder
sfb = new SimpleFeatureBuilder(sft);</div>
<div><span style="white-space:pre-wrap"> </span>sfb.set("name",
"Toulouse");</div>
<div><span style="white-space:pre-wrap"> </span>sfb.set("the_geom",
gf.createPoint(new Coordinate(1.4526, 43.5957)));</div>
<div><span style="white-space:pre-wrap"> </span>final
Feature feat = sfb.buildFeature("id-0");</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>Marshaller
marshaller =
WFSMarshallerPool.getInstance().acquireMarshaller();</div>
<div><span style="white-space:pre-wrap"> </span>final
StringWriter sw = new StringWriter();</div>
<div><span style="white-space:pre-wrap"> </span>marshaller.marshal(response,
sw);</div>
<div><span style="white-space:pre-wrap"> </span>WFSMarshallerPool.getInstance().recycle(marshaller);</div>
<div><span style="white-space:pre-wrap"> </span>System.out.println(sw.toString());</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
</div>
<div><br>
</div>
<div>So, if someone can explain how to link FeatureType and
FeaturePropertyType and all the other stuff, i'd be grateful
:-) !</div>
<div><br>
</div>
<div>François</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
Geotoolkit mailing list
<a href="mailto:Geotoolkit@lists.osgeo.org" target="_blank">Geotoolkit@lists.osgeo.org</a>
<a href="http://lists.osgeo.org/mailman/listinfo/geotoolkit" target="_blank">http://lists.osgeo.org/mailman/listinfo/geotoolkit</a></pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
Geotoolkit mailing list<br>
<a href="mailto:Geotoolkit@lists.osgeo.org">Geotoolkit@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/geotoolkit" target="_blank">http://lists.osgeo.org/mailman/listinfo/geotoolkit</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>-------------------------<br>
François ANDRE
</div>