Search in sources :

Example 1 with Geometry

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();
}
Also used : Geometry(org.openlca.geo.geojson.Geometry) LayerConfig(org.openlca.app.components.mapview.LayerConfig) M(org.openlca.app.M) MapView(org.openlca.app.components.mapview.MapView) Labels(org.openlca.app.util.Labels) Popup(org.openlca.app.util.Popup) HashMap(java.util.HashMap) Location(org.openlca.core.model.Location) ArrayList(java.util.ArrayList) Bounds(org.openlca.geo.calc.Bounds) Actions(org.openlca.app.util.Actions) Composite(org.eclipse.swt.widgets.Composite) ErrorReporter(org.openlca.app.util.ErrorReporter) Map(java.util.Map) Icon(org.openlca.app.rcp.images.Icon) Feature(org.openlca.geo.geojson.Feature) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) FillLayout(org.eclipse.swt.layout.FillLayout) Section(org.eclipse.ui.forms.widgets.Section) Geometry(org.openlca.geo.geojson.Geometry) GeoJSON(org.openlca.geo.geojson.GeoJSON) FeatureCollection(org.openlca.geo.geojson.FeatureCollection) Pair(org.openlca.util.Pair) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) MsgBox(org.openlca.app.util.MsgBox) List(java.util.List) UI(org.openlca.app.util.UI) Contribution(org.openlca.core.results.Contribution) FileChooser(org.openlca.app.components.FileChooser) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) FeatureCollection(org.openlca.geo.geojson.FeatureCollection) ArrayList(java.util.ArrayList) Feature(org.openlca.geo.geojson.Feature) Pair(org.openlca.util.Pair) Location(org.openlca.core.model.Location)

Example 2 with Geometry

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);
}
Also used : Geometry(org.openlca.geo.geojson.Geometry) ArrayList(java.util.ArrayList) Feature(org.openlca.geo.geojson.Feature)

Example 3 with Geometry

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());
}
Also used : Geometry(org.openlca.geo.geojson.Geometry) IntStream(java.util.stream.IntStream) Geometry(org.openlca.geo.geojson.Geometry) List(java.util.List) Stream(java.util.stream.Stream) FeatureCollection(org.openlca.geo.geojson.FeatureCollection) Pair(org.openlca.util.Pair) Feature(org.openlca.geo.geojson.Feature) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList)

Example 4 with Geometry

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;
}
Also used : Geometry(org.openlca.geo.geojson.Geometry)

Example 5 with Geometry

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);
}
Also used : Geometry(org.openlca.geo.geojson.Geometry) LineString(org.openlca.geo.geojson.LineString) Point(org.openlca.geo.geojson.Point) Pair(org.openlca.util.Pair) Test(org.junit.Test)

Aggregations

Geometry (org.openlca.geo.geojson.Geometry)5 ArrayList (java.util.ArrayList)3 Feature (org.openlca.geo.geojson.Feature)3 Pair (org.openlca.util.Pair)3 List (java.util.List)2 FeatureCollection (org.openlca.geo.geojson.FeatureCollection)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)1 Section (org.eclipse.ui.forms.widgets.Section)1 Test (org.junit.Test)1 M (org.openlca.app.M)1 FileChooser (org.openlca.app.components.FileChooser)1 LayerConfig (org.openlca.app.components.mapview.LayerConfig)1 MapView (org.openlca.app.components.mapview.MapView)1