Search in sources :

Example 1 with JtsPointConverter

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

the class WkbLocationConverter method convert.

@Override
public byte[] convert(final Location location) {
    final Geometry geometry = new JtsPointConverter().convert(location);
    final byte[] wkb = new WKBWriter().write(geometry);
    return wkb;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) WKBWriter(org.locationtech.jts.io.WKBWriter) JtsPointConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter)

Example 2 with JtsPointConverter

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

the class WKTShardCommand method printPointOutput.

private void printPointOutput(final String wktOrShard, final Geometry geometry, final Sharding sharding, final CountryBoundaryMap countryBoundaryMap) {
    this.outputDelegate.printlnStdout(wktOrShard + " covered by:", TTYAttribute.BOLD);
    final Location location = new JtsPointConverter().backwardConvert((Point) geometry);
    if (sharding != null) {
        final Iterable<? extends Shard> shards = sharding.shardsCovering(location);
        for (final Shard shard : shards) {
            this.outputDelegate.printlnStdout(shard.toString(), TTYAttribute.GREEN);
        }
    }
    if (countryBoundaryMap != null) {
        final List<CountryBoundary> boundaries = countryBoundaryMap.boundaries(location);
        for (final CountryBoundary boundary : boundaries) {
            this.outputDelegate.printlnStdout(boundary.getCountryName(), TTYAttribute.GREEN);
        }
    }
}
Also used : CountryBoundary(org.openstreetmap.atlas.geography.boundary.CountryBoundary) Shard(org.openstreetmap.atlas.geography.sharding.Shard) JtsPointConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter) Location(org.openstreetmap.atlas.geography.Location)

Example 3 with JtsPointConverter

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

the class AtlasSearchCommand method entityContainsWktGeometry.

private // NOSONAR
boolean entityContainsWktGeometry(// NOSONAR
final AtlasEntity entity, // NOSONAR
final String wkt) {
    if (entity.getType() == ItemType.RELATION) {
        return false;
    }
    final Geometry geometry = parseWkt(wkt);
    if (geometry == null) {
        return false;
    }
    Location inputLocation = null;
    PolyLine inputPolyline = null;
    if (geometry instanceof Point) {
        inputLocation = new JtsPointConverter().backwardConvert((Point) geometry);
    } else if (geometry instanceof LineString) {
        inputPolyline = new JtsPolyLineConverter().backwardConvert((LineString) geometry);
    } else {
        this.outputDelegate.printlnErrorMessage("--" + SUB_GEOMETRY_OPTION_LONG + " only supports POINT and LINESTRING, found " + geometry.getClass().getName());
        return false;
    }
    boolean matchedSomething;
    if (entity.getType() == ItemType.POINT || entity.getType() == ItemType.NODE) {
        final Location location = ((LocationItem) entity).getLocation();
        if (inputLocation != null) {
            matchedSomething = location.equals(inputLocation);
            return matchedSomething;
        }
    } else if (entity.getType() == ItemType.LINE || entity.getType() == ItemType.EDGE) {
        final PolyLine line = ((LineItem) entity).asPolyLine();
        if (inputLocation != null) {
            matchedSomething = line.contains(inputLocation);
            if (matchedSomething) {
                return true;
            }
        }
        if (inputPolyline != null) {
            matchedSomething = line.overlapsShapeOf(inputPolyline);
            return matchedSomething;
        }
    } else if (entity.getType() == ItemType.AREA) {
        final Polygon polygon = ((Area) entity).asPolygon();
        if (inputLocation != null) {
            matchedSomething = polygon.contains(inputLocation);
            if (matchedSomething) {
                return true;
            }
        }
        if (inputPolyline != null) {
            matchedSomething = polygon.overlapsShapeOf(inputPolyline);
            return matchedSomething;
        }
    }
    return false;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Area(org.openstreetmap.atlas.geography.atlas.items.Area) LineString(org.locationtech.jts.geom.LineString) LocationItem(org.openstreetmap.atlas.geography.atlas.items.LocationItem) PolyLine(org.openstreetmap.atlas.geography.PolyLine) Point(org.locationtech.jts.geom.Point) Polygon(org.openstreetmap.atlas.geography.Polygon) JtsPointConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter) JtsPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter) Location(org.openstreetmap.atlas.geography.Location)

Example 4 with JtsPointConverter

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

the class Polygon method fullyGeometricallyEnclosesJTS.

/**
 * Tests if this {@link Polygon} fully encloses (geometrically contains) a {@link Location}
 * according to the JTS definition, which includes points touching all boundaries of the
 * polygon.
 *
 * @param location
 *            The location to test
 * @return True if the {@link Polygon} fully encloses (geometrically contains) the
 *         {@link Location}
 */
public boolean fullyGeometricallyEnclosesJTS(final Location location) {
    final org.locationtech.jts.geom.Polygon polygon = JTS_POLYGON_CONVERTER.convert(this);
    final Point point = new JtsPointConverter().convert(location);
    return polygon.covers(point);
}
Also used : Point(org.locationtech.jts.geom.Point) JtsPointConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter)

Example 5 with JtsPointConverter

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

the class WkbLocationConverter method backwardConvert.

@Override
public Location backwardConvert(final byte[] wkb) {
    Point geometry = null;
    final WKBReader myReader = new WKBReader();
    try {
        geometry = (Point) myReader.read(wkb);
    } catch (final ParseException | ClassCastException e) {
        throw new CoreException("Cannot parse wkb : {}", WKBWriter.toHex(wkb), e);
    }
    return new JtsPointConverter().backwardConvert(geometry);
}
Also used : CoreException(org.openstreetmap.atlas.exception.CoreException) Point(org.locationtech.jts.geom.Point) ParseException(org.locationtech.jts.io.ParseException) JtsPointConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter) WKBReader(org.locationtech.jts.io.WKBReader)

Aggregations

JtsPointConverter (org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter)8 Point (org.locationtech.jts.geom.Point)5 Geometry (org.locationtech.jts.geom.Geometry)4 Location (org.openstreetmap.atlas.geography.Location)3 LineString (org.locationtech.jts.geom.LineString)2 ParseException (org.locationtech.jts.io.ParseException)2 CoreException (org.openstreetmap.atlas.exception.CoreException)2 PolyLine (org.openstreetmap.atlas.geography.PolyLine)2 Polygon (org.openstreetmap.atlas.geography.Polygon)2 Area (org.openstreetmap.atlas.geography.atlas.items.Area)2 LocationItem (org.openstreetmap.atlas.geography.atlas.items.LocationItem)2 JtsPolyLineConverter (org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter)2 WKBReader (org.locationtech.jts.io.WKBReader)1 WKBWriter (org.locationtech.jts.io.WKBWriter)1 WKTReader (org.locationtech.jts.io.WKTReader)1 WKTWriter (org.locationtech.jts.io.WKTWriter)1 CountryBoundary (org.openstreetmap.atlas.geography.boundary.CountryBoundary)1 JtsPolygonConverter (org.openstreetmap.atlas.geography.converters.jts.JtsPolygonConverter)1 Shard (org.openstreetmap.atlas.geography.sharding.Shard)1