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

Francois Andre francois.andre.prof at gmail.com
Tue Apr 15 13:50:11 PDT 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geotoolkit/attachments/20140415/985e5567/attachment.html>


More information about the Geotoolkit mailing list