[geotk] How to generate a WFS GetFeature response with geotoolkit ?

Francois ANDRE francois-andre at laposte.net
Wed Apr 16 05:04:56 PDT 2014


Hello Guilhem,

Thank you so much for your code, this is what i was looking for and it
opens good perspectives for my software !

I wasn't aware of FeatureStoreUtilities and of JAXPStreamFeatureWriter.

Thank you again

François


2014-04-16 11:26 GMT+02:00 Guilhem <guilhem.legal at geomatys.fr>:

>  hi François,
>
> To write feature collection, you can't use MarshallerPool (JAXB) because
> its dynamical.
> You must use JAXP feature writer.
> here is a piece of code doing what you are trying to do:
>
>        final GeometryFactory gf = new GeometryFactory();
>
>         final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
>         ftb.setName("station:stationType");
>         ftb.add("name", String.class);
>         CoordinateReferenceSystem wgs84 = CRS.forCode("CRS:84");
>
>         ftb.add("the_geom", PointType.class, wgs84);
>         ftb.setDefaultGeometry("the_geom");
>         final SimpleFeatureType sft = ftb.buildSimpleFeatureType();
>         SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(sft);
>         sfb.set("name", "Toulouse");
>         sfb.set("the_geom", gf.createPoint(new Coordinate(1.4526,
> 43.5957)));
>         final Feature feat = sfb.buildFeature("id-0");
>
>         FeatureCollection collection =
> FeatureStoreUtilities.collection(sft, Arrays.asList(feat));
>
>         final JAXPStreamFeatureWriter writer = new
> JAXPStreamFeatureWriter("3.2.1", "1.1.0", new HashMap<String, String>());
>         writer.setOutput(System.out);
>         writer.writeFeatureCollection(collection, false, 1);
>
>
> Guilhem Legal
>
> Le 15/04/2014 22:50, Francois Andre a écrit :
>
> Hi everybody,
>
>  I'd like to generate a WFS GetFeature response with geotoolkit.
>
>  I've found here and there some clues but I just don't really know how to
> link everything together
>
>  Here is the XML i'd like to generate:
>
>  <?xml version="1.0" encoding="UTF-8"?>
> <wfs:FeatureCollection numberOfFeatures="1"
> timeStamp="2014-04-15T15:22:49.133+02:00"
>       xsi:schemaLocation="http://www.resif.fr/station
> http://localhost/wfs/schema.xsd http://www.opengis.net/wfs
> http://ogo.heig-vd.ch:80/geoserver/schemas/wfs/1.1.0/wfs.xsd<http://ogo.heig-vd.ch/geoserver/schemas/wfs/1.1.0/wfs.xsd>
> "
>       xmlns:station="http://www.resif.fr/station"
>       xmlns:ogc="http://www.opengis.net/ogc"
>       xmlns:wfs="http://www.opengis.net/wfs"
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xmlns:gml="http://www.opengis.net/gml"  >
>
>        <gml:featureMembers>
>       <station:station gml:id="cities.248">
>         <station:station_name>Toulouse</station:station_name>
>         <station:the_geom>
>           <gml:Point srsDimension="2" srsName="
> http://www.opengis.net/gml/srs/epsg.xml#4326">
>             <gml:pos>1.4434 43.6045</gml:pos>
>           </gml:Point>
>         </station:the_geom>
>       </station:station>
>       </gml:featureMembers>
>
>       </wfs:FeatureCollection>
>
>  Here is my unworking coding attempt :
>
>  @Test
>  public void GetFeatureTest() throws Exception
>  {
>  final GeometryFactory gf = new GeometryFactory();
>  GregorianCalendar c = new GregorianCalendar();
>  XMLGregorianCalendar timeStamp =
> DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
>  String version = "1.1.0";
>  FeatureCollectionType response = (FeatureCollectionType)
> WFSXmlFactory.buildFeatureCollection(version, "id", 2, timeStamp);
>   final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
>  ftb.setName("station:stationType");
>  ftb.add("name", String.class);
>  DefaultGeographicCRS wgs84 = DefaultGeographicCRS.WGS84;
>  ftb.add("the_geom", PointType.class, wgs84);
>  ftb.setDefaultGeometry("the_geom");
>   final SimpleFeatureType sft = ftb.buildSimpleFeatureType();
>  SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(sft);
>  sfb.set("name", "Toulouse");
>  sfb.set("the_geom", gf.createPoint(new Coordinate(1.4526, 43.5957)));
>  final Feature feat = sfb.buildFeature("id-0");
>
>  Marshaller marshaller =
> WFSMarshallerPool.getInstance().acquireMarshaller();
>  final StringWriter sw = new StringWriter();
>  marshaller.marshal(response, sw);
>  WFSMarshallerPool.getInstance().recycle(marshaller);
>  System.out.println(sw.toString());
>  }
>
>  So, if someone can explain how to link FeatureType and
> FeaturePropertyType and all the other stuff, i'd be grateful :-) !
>
>  François
>
>
> _______________________________________________
> Geotoolkit mailing listGeotoolkit at lists.osgeo.orghttp://lists.osgeo.org/mailman/listinfo/geotoolkit
>
>
>
> _______________________________________________
> Geotoolkit mailing list
> Geotoolkit at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geotoolkit
>



-- 
-------------------------
François ANDRE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geotoolkit/attachments/20140416/cdb2d33c/attachment.html>


More information about the Geotoolkit mailing list