use of org.openlca.geo.geojson.Geometry in project olca-app by GreenDelta.
the class ResultMap method update.
void update(Object selection, List<Contribution<Location>> contributions) {
if (map == null)
return;
if (layer != null) {
map.removeLayer(layer);
}
if (contributions == null || contributions.isEmpty()) {
coll = null;
map.update();
return;
}
coll = new FeatureCollection();
List<Pair<Location, Feature>> pairs = new ArrayList<>();
for (Contribution<Location> c : contributions) {
Location loc = c.item;
if (loc == null || loc.geodata == null)
continue;
FeatureCollection fc = GeoJSON.unpack(loc.geodata);
if (fc == null || fc.features.isEmpty())
continue;
Geometry g = fc.features.get(0).geometry;
if (g == null)
continue;
Feature feature = new Feature();
feature.geometry = g;
feature.properties = new HashMap<>();
feature.properties.put("result", c.amount);
addMetaData(loc, feature, selection);
pairs.add(Pair.of(loc, feature));
}
if (pairs.isEmpty())
return;
pairs.stream().sorted((p1, p2) -> {
return Double.compare(bsize(p2), bsize(p1));
}).forEach(p -> coll.features.add(p.second));
layer = map.addLayer(coll).fillScale("result").center();
map.update();
}
use of org.openlca.geo.geojson.Geometry in project olca-modules by GreenDelta.
the class IntersectionCalculator method on.
public static IntersectionCalculator on(FeatureCollection coll, Projection projection) {
if (coll == null) {
return new IntersectionCalculator(new Feature[0], new org.locationtech.jts.geom.Geometry[0], projection);
}
// we make sure that there is always a corresponding JTS geometry
// for a feature.
List<Feature> features = new ArrayList<>();
List<org.locationtech.jts.geom.Geometry> geometries = new ArrayList<>();
for (Feature feature : coll.features) {
if (feature.geometry == null)
continue;
Geometry g = feature.geometry;
if (projection != null) {
g = g.copy();
projection.project(g);
}
org.locationtech.jts.geom.Geometry jts = JTS.fromGeoJSON(g);
if (jts == null)
continue;
features.add(feature);
geometries.add(jts);
}
return new IntersectionCalculator(features.toArray(new Feature[0]), geometries.toArray(new org.locationtech.jts.geom.Geometry[0]), projection);
}
use of org.openlca.geo.geojson.Geometry in project olca-modules by GreenDelta.
the class IntersectionCalculator method jts.
/**
* Calculates the intersection geometries based on JTS geometries and
* returns the non-empty intersections.
*/
private Stream<Pair<Feature, org.locationtech.jts.geom.Geometry>> jts(Geometry g) {
if (g == null)
return Stream.empty();
org.locationtech.jts.geom.Geometry jts;
if (projection == null) {
jts = JTS.fromGeoJSON(g);
} else {
Geometry clone = g.copy();
projection.project(clone);
jts = JTS.fromGeoJSON(clone);
}
if (jts == null)
return Stream.empty();
return IntStream.range(0, features.length).parallel().mapToObj(i -> Pair.of(features[i], geometries[i].intersection(jts))).filter(p -> p.second != null && !p.second.isEmpty());
}
use of org.openlca.geo.geojson.Geometry in project olca-modules by GreenDelta.
the class WebMercator method project.
public static Geometry project(Geometry geometry, int zoom) {
if (geometry == null)
return null;
Geometry g = geometry.copy();
new WebMercator(zoom).project(g);
return g;
}
use of org.openlca.geo.geojson.Geometry in project olca-modules by GreenDelta.
the class IntersectionTest method testLineIntersection.
@Test
public void testLineIntersection() {
LineString a = new LineString();
a.points.add(new Point(0, 0));
a.points.add(new Point(10, 10));
LineString b = new LineString();
b.points.add(new Point(0, 10));
b.points.add(new Point(10, 0));
IntersectionCalculator calc = IntersectionCalculator.on(FeatureCollection.of(a));
List<Pair<Feature, Geometry>> r = calc.calculate(b);
Assert.assertEquals(1, r.size());
Geometry g = r.get(0).second;
Assert.assertTrue(g instanceof Point);
Point p = (Point) g;
Assert.assertEquals(5.0, p.x, 1e-16);
Assert.assertEquals(5.0, p.y, 1e-16);
}
Aggregations