use of org.openstreetmap.atlas.geography.GeometricSurface in project atlas by osmlab.
the class WithinTest method testPolygonIsWithin.
@Test
public void testPolygonIsWithin() {
final GeometricSurface surface1 = rectOne();
final GeometricSurface surface2 = rectTwo();
final Polygon polygon1 = Polygon.random(NUMBER_POINTS, (Rectangle) surface1);
final Polygon polygon2 = Polygon.random(NUMBER_POINTS, (Rectangle) surface2);
Assert.assertTrue(polygon1.within(surface1));
Assert.assertTrue(polygon2.within(surface2));
Assert.assertFalse(polygon1.within(surface2));
Assert.assertFalse(polygon2.within(surface1));
}
use of org.openstreetmap.atlas.geography.GeometricSurface in project atlas by osmlab.
the class WithinTest method testPolyLineIsWithin.
@Test
public void testPolyLineIsWithin() {
final GeometricSurface surface1 = rectOne();
final GeometricSurface surface2 = rectTwo();
final PolyLine polyLine1 = PolyLine.random(NUMBER_POINTS, (Rectangle) surface1);
final PolyLine polyLine2 = PolyLine.random(NUMBER_POINTS, (Rectangle) surface2);
Assert.assertTrue(polyLine1.within(surface1));
Assert.assertTrue(polyLine2.within(surface2));
Assert.assertFalse(polyLine1.within(surface2));
Assert.assertFalse(polyLine2.within(surface1));
}
use of org.openstreetmap.atlas.geography.GeometricSurface in project atlas by osmlab.
the class GeometryOperationTest method testMultiplePolygons.
@Test
public void testMultiplePolygons() {
final GeometricSurface result = GeometryOperation.union(this.multiPolygon1, this.multiPolygon2, this.multiPolygon3, this.multiPolygon4, this.multiPolygon5).orElseThrow(() -> new CoreException("fail"));
Assert.assertEquals("MULTIPOLYGON (((55.455052 -4.6419746, 55.4550627 -4.6425627, 55.4547516 -4.6426162, 55.4547355 -4.6429263," + " 55.4542978 -4.6429263, 55.4534019 -4.6427926, 55.4530065 -4.6429939, 55.4528842 -4.6430798," + " 55.4525876 -4.6431737, 55.4522369 -4.6431817, 55.4520144 -4.6430778, 55.4519884 -4.642868," + " 55.4521828 -4.6425984, 55.452295 -4.6424066, 55.4524513 -4.6423687, 55.4521123 -4.6420173," + " 55.4518462 -4.6417019, 55.4515222 -4.6414934, 55.4516639 -4.6412474, 55.4524503 -4.6415682," + " 55.4530565 -4.6416484, 55.4534824 -4.6417286, 55.4531906 -4.6421243, 55.4532925 -4.642429," + " 55.4546121 -4.6423007, 55.4546357 -4.6419264, 55.455052 -4.6419746))," + " ((55.4704179 -4.6550696, 55.4722205 -4.6581544, 55.4702705 -4.6603804, 55.467663 -4.6590245," + " 55.4665973 -4.6614991, 55.4665025 -4.6616483, 55.466354 -4.6617547, 55.465372 -4.662019," + " 55.4643567 -4.6610388, 55.4631883 -4.6606733, 55.4629301 -4.6609095, 55.4626936 -4.6606842," + " 55.4627858 -4.659018, 55.463193 -4.6585292, 55.4628348 -4.65804, 55.4629354 -4.656064," + " 55.4621532 -4.654595, 55.4659511 -4.6540752, 55.4661665 -4.6560414, 55.46891 -4.6564482," + " 55.4691254 -4.6553182, 55.4684792 -4.6544368, 55.4694089 -4.6539848, 55.4704179 -4.6550696))," + " ((55.4209807 -4.6276984, 55.4206769 -4.6281207, 55.4209344 -4.6283079, 55.4204624 -4.6293345," + " 55.4201512 -4.629666, 55.4195558 -4.6294307, 55.419346 -4.6289794, 55.4199796 -4.6284897," + " 55.4203385 -4.6274556, 55.4192661 -4.6270567, 55.41844 -4.626383, 55.4174315 -4.62495," + " 55.4172652 -4.6247896, 55.417807 -4.6243847, 55.4188101 -4.6245759, 55.419411 -4.6250624," + " 55.4200493 -4.6253365, 55.4203658 -4.6257736, 55.4201352 -4.6261051, 55.4203712 -4.6265181," + " 55.4203122 -4.6268858, 55.4207682 -4.6270421, 55.4209505 -4.6268376, 55.4213314 -4.6269499," + " 55.4213636 -4.6271103, 55.4211268 -4.6274921, 55.4209807 -4.6276984)))", result.toWkt());
}
use of org.openstreetmap.atlas.geography.GeometricSurface in project atlas by osmlab.
the class GeometryOperationTest method testOverlappingPolygons.
@Test
public void testOverlappingPolygons() {
final GeometricSurface result = GeometryOperation.union(this.multiPolygon1, this.multiPolygon1).orElseThrow(() -> new CoreException("fail"));
Assert.assertEquals("POLYGON ((55.4527599 -4.6423107, 55.4529644 -4.6425404, 55.4528862 -4.6426603, 55.4528762 -4.6428181," + " 55.4530065 -4.6429939, 55.4528842 -4.6430798, 55.4525876 -4.6431737, 55.4522369 -4.6431817," + " 55.4520144 -4.6430778, 55.4519884 -4.642868, 55.4521828 -4.6425984, 55.452295 -4.6424066," + " 55.4524513 -4.6423687, 55.4527599 -4.6423107))", result.toWkt());
}
use of org.openstreetmap.atlas.geography.GeometricSurface in project atlas-checks by osmlab.
the class ShadowDetectionCheck method neighboringPart.
/**
* Checks if two {@link AtlasObject}s are building parts and overlap each other.
*
* @param part
* a known building part to check against
* @return true if {@code object} is a building part and overlaps {@code part}
*/
private boolean neighboringPart(final AtlasObject object, final AtlasObject part, final Set<AtlasObject> checked) {
try {
// Get the polygons of the parts, either single or multi
final GeometricSurface partPolygon = part instanceof Area ? ((Area) part).asPolygon() : MULTI_POLYGON_CONVERTER.convert((Relation) part);
final GeometricSurface objectPolygon = object instanceof Area ? ((Area) object).asPolygon() : MULTI_POLYGON_CONVERTER.convert((Relation) object);
// Check if it is a building part, and overlaps.
return !checked.contains(object) && (this.isBuildingOrPart(object) || this.isBuildingRelationMember(object)) && // Check 2D overlap
(partPolygon instanceof Polygon ? objectPolygon.overlaps((Polygon) partPolygon) : objectPolygon.overlaps((MultiPolygon) partPolygon)) && // Check 3D overlap
neighborsHeightContains(part, object);
}// Ignore malformed MultiPolygons
catch (final CoreException invalidMultiPolygon) {
return false;
}
}
Aggregations