<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">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>
<br>
final GeometryFactory gf = new GeometryFactory();<br>
<br>
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();<br>
ftb.setName("station:stationType");<br>
ftb.add("name", String.class);<br>
CoordinateReferenceSystem wgs84 = CRS.forCode("CRS:84");<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>
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
cite="mid:CAKzx2SK=aqRFsnQ39ATHHr2GVcCM24k3HJZxTJ318D8Gcec2Ow@mail.gmail.com"
type="cite">
<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 moz-do-not-send="true"
href="http://www.resif.fr/station" target="_blank">http://www.resif.fr/station</a> <a
moz-do-not-send="true"
href="http://localhost/wfs/schema.xsd" target="_blank">http://localhost/wfs/schema.xsd</a> <a
moz-do-not-send="true" href="http://www.opengis.net/wfs"
target="_blank">http://www.opengis.net/wfs</a> <a
moz-do-not-send="true"
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 moz-do-not-send="true"
href="http://www.resif.fr/station" target="_blank">http://www.resif.fr/station</a>" </div>
<div> xmlns:ogc="<a moz-do-not-send="true"
href="http://www.opengis.net/ogc" target="_blank">http://www.opengis.net/ogc</a>" </div>
<div> xmlns:wfs="<a moz-do-not-send="true"
href="http://www.opengis.net/wfs" target="_blank">http://www.opengis.net/wfs</a>" </div>
<div> xmlns:xsi="<a moz-do-not-send="true"
href="http://www.w3.org/2001/XMLSchema-instance"
target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>" </div>
<div> xmlns:gml="<a moz-do-not-send="true"
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
moz-do-not-send="true"
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 moz-do-not-send="true"
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 class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Geotoolkit mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Geotoolkit@lists.osgeo.org">Geotoolkit@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/geotoolkit">http://lists.osgeo.org/mailman/listinfo/geotoolkit</a></pre>
</blockquote>
<br>
</body>
</html>