Search in sources :

Example 1 with JtsMultiPolygonConverter

use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.

the class CountryBoundaryMapArchiver method geometryForShard.

protected Geometry geometryForShard(final Rectangle shardBounds, final CountryBoundaryMap boundaryMap) {
    final JtsMultiPolygonConverter multiPolyConverter = new JtsMultiPolygonConverter();
    final JtsPolygonConverter polyConverter = new JtsPolygonConverter();
    final GeometryFactory factory = new GeometryFactory();
    final List<CountryBoundary> boundaries = boundaryMap.boundaries(shardBounds);
    // jts version of the initial shard bounds
    org.locationtech.jts.geom.Geometry shardPolyJts = polyConverter.convert(shardBounds);
    // remove country boundaries from the ocean tile one by one
    for (final CountryBoundary boundary : boundaries) {
        final Set<Polygon> boundaryPolygons = multiPolyConverter.convert(boundary.getBoundary());
        final org.locationtech.jts.geom.MultiPolygon countryGeometry = factory.createMultiPolygon(boundaryPolygons.toArray(new Polygon[boundaryPolygons.size()]));
        shardPolyJts = shardPolyJts.difference(countryGeometry);
    }
    return shardPolyJts;
}
Also used : JtsPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolygonConverter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) JtsMultiPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter) Geometry(org.locationtech.jts.geom.Geometry) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 2 with JtsMultiPolygonConverter

use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.

the class CountryBoundaryMapArchiver method generateOceanBoundaryMap.

protected CountryBoundaryMap generateOceanBoundaryMap(final CountryBoundaryMap boundaryMap, final Iterable<SlippyTile> allTiles) {
    final CountryBoundaryMap finalBoundaryMap = new CountryBoundaryMap();
    int oceanCountryCount = 0;
    // add all ocean boundaries to the new boundary map
    logger.info("Calculating ocean boundaries...");
    for (final SlippyTile tile : allTiles) {
        final Time start = Time.now();
        final String countryCode = String.format("O%02d", oceanCountryCount);
        final Geometry countryGeometry = geometryForShard(tile.bounds(), boundaryMap);
        if (!countryGeometry.isEmpty()) {
            if (countryGeometry instanceof Polygon) {
                finalBoundaryMap.addCountry(countryCode, (Polygon) countryGeometry);
            }
            if (countryGeometry instanceof MultiPolygon) {
                finalBoundaryMap.addCountry(countryCode, (MultiPolygon) countryGeometry);
            }
            logger.info("Added Ocean Country {} in {}", countryCode, start.elapsedSince());
            oceanCountryCount++;
        } else {
            logger.info("Skipped Ocean Country {} in {}. It is land covered.", tile.getName(), start.elapsedSince());
        }
    }
    // add all countries from the input boundary map to the new boundary map
    logger.info("Adding back country boundaries to the new ocean boundary map");
    final JtsMultiPolygonConverter multiPolyConverter = new JtsMultiPolygonConverter();
    for (final String country : boundaryMap.allCountryNames()) {
        for (final CountryBoundary countryBoundary : boundaryMap.countryBoundary(country)) {
            final GeometryFactory factory = new GeometryFactory();
            final Set<org.locationtech.jts.geom.Polygon> boundaryPolygons = multiPolyConverter.convert(countryBoundary.getBoundary());
            final org.locationtech.jts.geom.MultiPolygon countryGeometry = factory.createMultiPolygon(boundaryPolygons.toArray(new Polygon[boundaryPolygons.size()]));
            finalBoundaryMap.addCountry(country, countryGeometry);
        }
    }
    return finalBoundaryMap;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SlippyTile(org.openstreetmap.atlas.geography.sharding.SlippyTile) Time(org.openstreetmap.atlas.utilities.time.Time) Geometry(org.locationtech.jts.geom.Geometry) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) JtsMultiPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 3 with JtsMultiPolygonConverter

use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.

the class MultiPolygonClipper method processMultiPolygon.

private MultiPolygon processMultiPolygon(final Geometry intersections) {
    MultiPolygon result = new MultiPolygon(new MultiMap<>());
    if (intersections instanceof GeometryCollection) {
        final GeometryCollection collection = (GeometryCollection) intersections;
        final int numGeometries = collection.getNumGeometries();
        for (int n = 0; n < numGeometries; n++) {
            final Geometry geometry = collection.getGeometryN(n);
            result = result.merge(processMultiPolygon(geometry));
        }
    } else if (intersections instanceof org.locationtech.jts.geom.Polygon) {
        final Set<org.locationtech.jts.geom.Polygon> set = new HashSet<>();
        set.add((org.locationtech.jts.geom.Polygon) intersections);
        result = result.merge(new JtsMultiPolygonConverter().backwardConvert(set));
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Geometry(org.locationtech.jts.geom.Geometry) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) JtsMultiPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter) Polygon(org.openstreetmap.atlas.geography.Polygon) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon)

Example 4 with JtsMultiPolygonConverter

use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.

the class MultiPolygonClipper method runMultiPolygonClipping.

private MultiPolygon runMultiPolygonClipping(final MultiPolygon subject, final BiFunction<Geometry, Geometry, Geometry> application) {
    MultiPolygon result = new MultiPolygon(new MultiMap<>());
    final Set<org.locationtech.jts.geom.Polygon> jtsSubjects = new JtsMultiPolygonConverter().convert(subject);
    for (final org.locationtech.jts.geom.Polygon jtsClipping : this.jtsClippings) {
        for (final org.locationtech.jts.geom.Polygon jtsSubject : jtsSubjects) {
            result = result.merge(processMultiPolygon(application.apply(jtsSubject, jtsClipping)));
        }
    }
    return result;
}
Also used : MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) JtsMultiPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter) Polygon(org.openstreetmap.atlas.geography.Polygon) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon)

Aggregations

JtsMultiPolygonConverter (org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter)4 Geometry (org.locationtech.jts.geom.Geometry)3 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)2 Polygon (org.locationtech.jts.geom.Polygon)2 MultiPolygon (org.openstreetmap.atlas.geography.MultiPolygon)2 Polygon (org.openstreetmap.atlas.geography.Polygon)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)1 JtsPolygonConverter (org.openstreetmap.atlas.geography.converters.jts.JtsPolygonConverter)1 SlippyTile (org.openstreetmap.atlas.geography.sharding.SlippyTile)1 Time (org.openstreetmap.atlas.utilities.time.Time)1