X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.core%2Fsrc%2Forg%2Fargeo%2Fapp%2Fgeo%2FGeoUtils.java;fp=org.argeo.app.core%2Fsrc%2Forg%2Fargeo%2Fapp%2Fgeo%2FGeoUtils.java;h=1b9ce72555d86130b4f6b77dd2fae53c03bb531e;hb=0d802e48f2cafd249149f9b322fd11f96a83a947;hp=8da7c4efbd27c6e0d074aa0e90bb8e758775f3a6;hpb=8e76163658cc6275b0ca4206f6ea4b3eee09d787;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.core/src/org/argeo/app/geo/GeoUtils.java b/org.argeo.app.core/src/org/argeo/app/geo/GeoUtils.java index 8da7c4e..1b9ce72 100644 --- a/org.argeo.app.core/src/org/argeo/app/geo/GeoUtils.java +++ b/org.argeo.app.core/src/org/argeo/app/geo/GeoUtils.java @@ -1,11 +1,19 @@ package org.argeo.app.geo; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + import javax.measure.Quantity; import javax.measure.quantity.Area; +import org.geotools.data.simple.SimpleFeatureCollection; +import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; import org.geotools.referencing.crs.DefaultGeographicCRS; +import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.Polygon; import org.opengis.feature.simple.SimpleFeature; @@ -38,6 +46,63 @@ public class GeoUtils { } } + public static void exportToSvg(SimpleFeatureCollection features, Writer out, int width, int height) { + try { + double minY = Double.POSITIVE_INFINITY; + double maxY = Double.NEGATIVE_INFINITY; + double minX = Double.POSITIVE_INFINITY; + double maxX = Double.NEGATIVE_INFINITY; + List shapes = new ArrayList<>(); + for (SimpleFeatureIterator it = features.features(); it.hasNext();) { + SimpleFeature feature = it.next(); + StringBuffer sb = new StringBuffer(); + sb.append(" maxX) + maxX = x; + double y = -coord.y; + if (y < minY) + minY = y; + if (y > maxY) + maxY = y; + sb.append(x + "," + y + " "); + } + sb.append("\">"); + sb.append("\n"); + shapes.add(sb.toString()); + + } + double viewportHeight = maxY - minY; + double viewportWidth = maxX - minX; + out.write("\n"); + for (String shape : shapes) { + out.write(shape); + out.write("\n"); + } + out.write(""); + } catch (IOException | FactoryException | MismatchedDimensionException | TransformException e) { + throw new RuntimeException("Cannot export to SVG", e); + } + } + /** Singleton. */ private GeoUtils() { }