From 52e9b2ee3676e9cecfe748398bd6d27cee4218fe Mon Sep 17 00:00:00 2001 From: Gianpaolo Coro Date: Mon, 20 May 2013 16:08:38 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineGeoSpatialExtension@75155 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../geo/utils/EnvDataExplorer.java | 24 +++++++++++++++++++ .../geo/utils/FeaturedPolygon.java | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/dataanalysis/geo/utils/EnvDataExplorer.java b/src/main/java/org/gcube/dataanalysis/geo/utils/EnvDataExplorer.java index 5285edf..5f1632d 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/utils/EnvDataExplorer.java +++ b/src/main/java/org/gcube/dataanalysis/geo/utils/EnvDataExplorer.java @@ -10,6 +10,7 @@ import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger; import org.gcube.dataanalysis.geo.meta.OGCFormatter; import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LinearRing; import com.vividsolutions.jts.geom.Point; @@ -131,12 +132,15 @@ public class EnvDataExplorer { GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326); Polygon p = null; if (coords != null) { + Coordinate[] coordarray = new Coordinate[coords.size()]; int i=0; for (double[] pair:coords){ coordarray[i] = new Coordinate(pair[0],pair[1]); + i++; } + //TODO: build a multipoly if the ring is not closed! CoordinateArraySequence coordseq = new CoordinateArraySequence(coordarray); LinearRing ring = new LinearRing(coordseq, factory); p = new Polygon(ring, new LinearRing[] {}, factory); @@ -157,10 +161,30 @@ public class EnvDataExplorer { return fpolygons; } catch (Exception e) { AnalysisLogger.getLogger().debug("EnvDataExplorer-> Error in getting properties"); + e.printStackTrace(); return null; } } + + public static Geometry buildGeometryFromCoordinates(List coords){ + Geometry p = null; + GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326); + Coordinate[] coordarray = new Coordinate[coords.size()]; + int i=0; + for (double[] pair:coords){ + coordarray[i] = new Coordinate(pair[0],pair[1]); + + i++; + } + //TODO: build a multipoly if the ring is not closed! + CoordinateArraySequence coordseq = new CoordinateArraySequence(coordarray); + LinearRing ring = new LinearRing(coordseq, factory); + p = new Polygon(ring, new LinearRing[] {}, factory); + + return p; + } + public static List WFS2Coordinates(String wfsgeometry) { // geometry935133b1-ba3c-493d-8e18-6fb496ced995={type=MultiPolygon, coordinates={966a275c-23aa-4a43-a943-7e1c7eaf5d65=[[[1.5,125.00000000000011],[1.5,124.5],[2.000000000000057,124.5],[2.000000000000057,125.00000000000011],[1.5,125.00000000000011]]]}}, diff --git a/src/main/java/org/gcube/dataanalysis/geo/utils/FeaturedPolygon.java b/src/main/java/org/gcube/dataanalysis/geo/utils/FeaturedPolygon.java index 991b453..31b5c7d 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/utils/FeaturedPolygon.java +++ b/src/main/java/org/gcube/dataanalysis/geo/utils/FeaturedPolygon.java @@ -2,10 +2,11 @@ package org.gcube.dataanalysis.geo.utils; import java.util.LinkedHashMap; +import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Polygon; public class FeaturedPolygon { - public Polygon p; + public Geometry p; public LinkedHashMap features; public Double value; public FeaturedPolygon(){