- protected void encodeCollectionAsGeoJSonOld(Stream<Content> features, OutputStream out) throws IOException {
-
- // BODY PROCESSING
- try (GeoJSONWriter geoJSONWriter = new GeoJSONWriter(out)) {
- geoJSONWriter.setPrettyPrinting(true);
- geoJSONWriter.setEncodeFeatureBounds(true);
-
- boolean gpx = true;
- SimpleFeatureType TYPE;
- try {
- if (gpx)
- TYPE = DataUtilities.createType("Content",
- "the_geom:Polygon:srid=4326,path:String,type:String,name:String");
- else
- TYPE = DataUtilities.createType("Content",
- "the_geom:Point:srid=4326,path:String,type:String,name:String");
- } catch (SchemaException e) {
- throw new RuntimeException(e);
- }
- SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
-
- features.forEach((c) -> {
- Geometry the_geom;
- if (gpx) {// experimental
- Content area = c.getContent("gpx/area.gpx").orElse(null);
- if (area == null)
- return;
- try (InputStream in = area.open(InputStream.class)) {
- SimpleFeature feature = GpxUtils.parseGpxToPolygon(in);
- the_geom = (Geometry) feature.getDefaultGeometry();
- } catch (IOException e) {
- throw new UncheckedIOException("Cannot parse " + c, e);
- }
- } else {
- if (!c.hasContentClass(EntityType.geopoint))
- return;
-
- double latitude = c.get(WGS84PosName.lat, Double.class).get();
- double longitude = c.get(WGS84PosName.lon, Double.class).get();
-
- Coordinate coordinate = new Coordinate(longitude, latitude);
- the_geom = geometryFactory.createPoint(coordinate);
-
- }
-
- featureBuilder.add(the_geom);
- String pth = c.getPath();
- featureBuilder.add(pth);
- if (c.hasContentClass(EntityType.local)) {
- String type = c.attr(EntityName.type);
- featureBuilder.add(type);
- } else {
- List<QName> contentClasses = c.getContentClasses();
- if (!contentClasses.isEmpty()) {
- featureBuilder.add(NamespaceUtils.toPrefixedName(contentClasses.get(0)));
- }
- }
- featureBuilder.add(NamespaceUtils.toPrefixedName(c.getName()));
-
- String uuid = c.attr(LdapAttr.entryUUID);
-
- SimpleFeature feature = featureBuilder.buildFeature(uuid);
- try {
- geoJSONWriter.write(feature);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- });
- }
- }
-
- protected void encodeCollectionAsGML(Stream<Content> features, OutputStream out) throws IOException {
- String entityType = "entity";
- URL schemaLocation = getClass().getResource("/org/argeo/app/api/entity.xsd");
- String namespace = "http://www.argeo.org/ns/entity";
-
- GML gml = new GML(Version.WFS1_1);
- gml.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
- gml.setNamespace("local", namespace);
-
- SimpleFeatureType featureType = gml.decodeSimpleFeatureType(schemaLocation,
- new NameImpl(namespace, entityType + "Feature"));
-
-// CoordinateReferenceSystem crs=DefaultGeographicCRS.WGS84;
-// QName featureName = new QName(namespace,"apafFieldFeature");
-// GMLConfiguration configuration = new GMLConfiguration();
-// FeatureType parsed = GTXML.parseFeatureType(configuration, featureName, crs);
-// SimpleFeatureType featureType = DataUtilities.simple(parsed);
-
- SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
-
- DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
-
- features.forEach((c) -> {
-// boolean gpx = false;
- Geometry the_geom = null;
- Polygon the_area = null;
-// if (gpx) {
- Content area = c.getContent("gpx/area.gpx").orElse(null);
- if (area != null) {
-
- try (InputStream in = area.open(InputStream.class)) {
- the_area = GpxUtils.parseGpxTrackTo(in, Polygon.class);
- } catch (IOException e) {
- throw new UncheckedIOException("Cannot parse " + c, e);
- }
- }
-// } else {
- if (c.hasContentClass(EntityType.geopoint)) {
- double latitude = c.get(WGS84PosName.lat, Double.class).get();
- double longitude = c.get(WGS84PosName.lon, Double.class).get();
-
- Coordinate coordinate = new Coordinate(longitude, latitude);
- the_geom = JTS.GEOMETRY_FACTORY.createPoint(coordinate);
- }
-
+// protected void encodeCollectionAsGML(Stream<Content> features, OutputStream out) throws IOException {
+// String entityType = "entity";
+// URL schemaLocation = getClass().getResource("/org/argeo/app/api/entity.xsd");
+// String namespace = "http://www.argeo.org/ns/entity";
+//
+// GML gml = new GML(Version.WFS1_1);
+// gml.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
+// gml.setNamespace("local", namespace);
+//
+// SimpleFeatureType featureType = gml.decodeSimpleFeatureType(schemaLocation,
+// new NameImpl(namespace, entityType + "Feature"));
+//
+//// CoordinateReferenceSystem crs=DefaultGeographicCRS.WGS84;
+//// QName featureName = new QName(namespace,"apafFieldFeature");
+//// GMLConfiguration configuration = new GMLConfiguration();
+//// FeatureType parsed = GTXML.parseFeatureType(configuration, featureName, crs);
+//// SimpleFeatureType featureType = DataUtilities.simple(parsed);
+//
+// SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
+//
+// DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
+//
+// features.forEach((c) -> {
+//// boolean gpx = false;
+// Geometry the_geom = null;
+// Polygon the_area = null;
+//// if (gpx) {
+// Content area = c.getContent("gpx/area.gpx").orElse(null);
+// if (area != null) {
+//
+// try (InputStream in = area.open(InputStream.class)) {
+// the_area = GpxUtils.parseGpxTrackTo(in, Polygon.class);
+// } catch (IOException e) {
+// throw new UncheckedIOException("Cannot parse " + c, e);
+// }