Gianpaolo Coro 2013-05-20 16:08:38 +00:00
parent 335d4deb4a
commit 52e9b2ee36
2 changed files with 26 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.geo.meta.OGCFormatter; import org.gcube.dataanalysis.geo.meta.OGCFormatter;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing; import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Point;
@ -131,12 +132,15 @@ public class EnvDataExplorer {
GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326); GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
Polygon p = null; Polygon p = null;
if (coords != null) { if (coords != null) {
Coordinate[] coordarray = new Coordinate[coords.size()]; Coordinate[] coordarray = new Coordinate[coords.size()];
int i=0; int i=0;
for (double[] pair:coords){ for (double[] pair:coords){
coordarray[i] = new Coordinate(pair[0],pair[1]); coordarray[i] = new Coordinate(pair[0],pair[1]);
i++; i++;
} }
//TODO: build a multipoly if the ring is not closed!
CoordinateArraySequence coordseq = new CoordinateArraySequence(coordarray); CoordinateArraySequence coordseq = new CoordinateArraySequence(coordarray);
LinearRing ring = new LinearRing(coordseq, factory); LinearRing ring = new LinearRing(coordseq, factory);
p = new Polygon(ring, new LinearRing[] {}, factory); p = new Polygon(ring, new LinearRing[] {}, factory);
@ -157,10 +161,30 @@ public class EnvDataExplorer {
return fpolygons; return fpolygons;
} catch (Exception e) { } catch (Exception e) {
AnalysisLogger.getLogger().debug("EnvDataExplorer-> Error in getting properties"); AnalysisLogger.getLogger().debug("EnvDataExplorer-> Error in getting properties");
e.printStackTrace();
return null; return null;
} }
} }
public static Geometry buildGeometryFromCoordinates(List<double[]> 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<double[]> WFS2Coordinates(String wfsgeometry) { public static List<double[]> 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]]]}}, // 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]]]}},

View File

@ -2,10 +2,11 @@ package org.gcube.dataanalysis.geo.utils;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.geom.Polygon;
public class FeaturedPolygon { public class FeaturedPolygon {
public Polygon p; public Geometry p;
public LinkedHashMap<String, String> features; public LinkedHashMap<String, String> features;
public Double value; public Double value;
public FeaturedPolygon(){ public FeaturedPolygon(){