Good morning Bart:

I have not had an opportunity to assist, some of the code you are trying
represents my attempt to get this working when it was initially written. I
find that the best approach is to look at a geotools test-case which does
what you want - and then step through with a debugger to see how the
objects were setup and to review the structure of the objects (in this case
a GMLConfiguration).

I searched using:
https://github.com/geotools/geotools/search?l=Java&q=3.2+gml+simplefeature+test

And found:
https://github.com/geotools/geotools/blob/main/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java




--
Jody Garnett


On Mon, Apr 3, 2023 at 4:11 AM Bart Adriaanse <bart.adriaa...@gmail.com>
wrote:

> Hi there,
>
> I have been struggling with this for some time, even after investigating
> the source code of both Geotools and GeoServer i cannot seem to get this to
> work.
>
> I have a extremely simple WFS 1.0 interface in an application and need to
> update this to WFS 2.0 but i am stuck at encoding a SimpleFeatureCollection
> to GML 3.2
>
> I would be very grateful if someone who is very familiar with Geotools can
> find some time to see what is wrong with my code, here is a copy of the
> Junit test i am trying to get to work:
>
> import org.geotools.data.DataUtilities;
> import org.geotools.data.collection.ListFeatureCollection;
> import org.geotools.data.simple.SimpleFeatureCollection;
> import org.geotools.feature.simple.SimpleFeatureBuilder;
> import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
> import org.geotools.gml3.v3_2.GML;
> import org.geotools.gml3.v3_2.GMLConfiguration;
> import org.geotools.wfs.WFS;
> import org.geotools.xsd.Encoder;
> import org.junit.Assert;
> import org.junit.Test;
> import org.locationtech.jts.geom.Coordinate;
> import org.locationtech.jts.geom.GeometryFactory;
> import org.locationtech.jts.geom.Point;
> import org.opengis.feature.simple.SimpleFeature;
> import org.opengis.feature.simple.SimpleFeatureType;
>
> import javax.xml.namespace.QName;
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
> import java.nio.charset.StandardCharsets;
>
> public class EncodeGML3_2Example {
>
> @Test
> public void encodeGML32() {
> try {
> // Create a SimpleFeatureType
> SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
> typeBuilder.setName("SampleFeature");
> typeBuilder.add("geom", Point.class);
> typeBuilder.add("name", String.class);
> SimpleFeatureType featureType = typeBuilder.buildFeatureType();
>
> // Create and add features to SimpleFeatureCollection
> ListFeatureCollection featureList = new ListFeatureCollection(featureType
> );
> SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType
> );
> GeometryFactory geometryFactory = new GeometryFactory();
> Point point1 = geometryFactory.createPoint(new Coordinate(10, 10));
> featureBuilder.add(point1);
> featureBuilder.add("Point 1");
> SimpleFeature feature1 = featureBuilder.buildFeature("1");
> Point point2 = geometryFactory.createPoint(new Coordinate(20, 20));
> featureBuilder.add(point2);
> featureBuilder.add("Point 2");
> SimpleFeature feature2 = featureBuilder.buildFeature("2");
> featureList.add(feature1);
> featureList.add(feature2);
> SimpleFeatureCollection featureCollection = DataUtilities.collection(
> featureList);
>
> // Encode the SimpleFeatureCollection as GML 3.2
> GMLConfiguration gmlConfig = new GMLConfiguration(true);
> Encoder encoder = new Encoder(gmlConfig);
> encoder.setSchemaLocation("http://www.opengis.net/gml";, "
> http://schemas.opengis.net/gml/3.2.1/gml.xsd";);
> encoder.setNamespaceAware(true);
> encoder.setRootElementType(WFS.FeatureCollection);
> String gml = encoder.encodeAsString(featureCollection, GML.
> FeatureCollection);
>
> Assert.assertTrue(!gml.isEmpty());
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
> _______________________________________________
> GeoTools-GT2-Users mailing list
> GeoTools-GT2-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to