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;
}
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);
}
}
}
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;
}
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);
}
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);
}
Aggregations