-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1035 from lat-lon/geometryFixes-28
Add geometry fixes
- Loading branch information
Showing
80 changed files
with
1,808 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,29 +38,36 @@ | |
import static org.deegree.geometry.primitive.segments.CurveSegment.CurveSegmentType.ARC; | ||
import static org.deegree.geometry.primitive.segments.CurveSegment.CurveSegmentType.LINE_STRING_SEGMENT; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.deegree.cs.coordinatesystems.ICRS; | ||
import org.deegree.cs.persistence.CRSManager; | ||
import org.deegree.geometry.GeometryFactory; | ||
import org.deegree.geometry.composite.CompositeCurve; | ||
import org.deegree.geometry.points.Points; | ||
import org.deegree.geometry.primitive.Curve; | ||
import org.deegree.geometry.primitive.Curve.CurveType; | ||
import org.deegree.geometry.primitive.Point; | ||
import org.deegree.geometry.primitive.Ring; | ||
import org.deegree.geometry.primitive.segments.CurveSegment; | ||
import org.deegree.geometry.standard.composite.DefaultCompositeCurve; | ||
import org.deegree.geometry.standard.curvesegments.DefaultLineStringSegment; | ||
import org.deegree.geometry.standard.points.PointsArray; | ||
import org.deegree.geometry.standard.primitive.DefaultCurve; | ||
import org.deegree.geometry.standard.primitive.DefaultRing; | ||
import org.deegree.geometry.validation.event.GeometryValidationEvent; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Lyn Goltz</a> | ||
* @author last edited by: $Author: lyn $ | ||
* | ||
* @version $Revision: $, $Date: $ | ||
* @author <a href="mailto:[email protected]">Stephan Reichhelm</a> | ||
*/ | ||
public class GeometryFixerTest { | ||
|
||
|
@@ -105,6 +112,112 @@ public void testInvertOrientationOfACurveWithMultipleSegments() { | |
assertTrue( invertedCurve.isClosed() ); | ||
} | ||
|
||
@Test | ||
public void testForceOrientationWithArcString() { | ||
// Test that forceOrientation accepts combinations of LineStringSegment and ArcString | ||
Curve curve = createCurve( createFirstSegment(), createSecondSegmentAsArcString(), createThirdSegment() ); | ||
Ring ring = createRing( curve ); | ||
|
||
Ring fixedA = GeometryFixer.forceOrientation( ring, true ); | ||
List<CurveSegment> curveSegmentsA = fixedA.getCurveSegments(); | ||
assertThat( curveSegmentsA.size(), is( 3 ) ); | ||
|
||
Ring fixedB = GeometryFixer.forceOrientation( ring, false ); | ||
List<CurveSegment> curveSegmentsB = fixedB.getCurveSegments(); | ||
assertThat( curveSegmentsB.size(), is( 3 ) ); | ||
} | ||
|
||
@Test | ||
public void testForceOrientationWithArc() { | ||
// Test that forceOrientation accepts combinations of LineStringSegment and Arc | ||
Curve curve = createCurve( createFirstSegment(), createSecondSegment(), createThirdSegment() ); | ||
Ring ring = createRing( curve ); | ||
|
||
Ring fixedA = GeometryFixer.forceOrientation( ring, true ); | ||
List<CurveSegment> curveSegmentsA = fixedA.getCurveSegments(); | ||
assertThat( curveSegmentsA.size(), is( 3 ) ); | ||
|
||
Ring fixedB = GeometryFixer.forceOrientation( ring, false ); | ||
List<CurveSegment> curveSegmentsB = fixedB.getCurveSegments(); | ||
assertThat( curveSegmentsB.size(), is( 3 ) ); | ||
} | ||
|
||
@Test | ||
public void testInvertOfCompoundCurve() { | ||
CountingValidationEventHandler valevent = new CountingValidationEventHandler(); | ||
GeometryValidator validator = new GeometryValidator( valevent ); | ||
|
||
Curve curve1 = createCurve( createFirstSegment() ); | ||
Curve curve2 = createCurve( createSecondSegment() ); | ||
Curve curve3 = createCurve( createThirdAltSegment() ); | ||
CompositeCurve ocomp = createCompositeCurve( curve1, curve2, curve3 ); | ||
|
||
assertThat( ocomp.size(), is( 3 ) ); | ||
assertFalse( "Compound is open", ocomp.isClosed() ); | ||
|
||
assertTrue( "Source is valid", validator.validateGeometry( ocomp ) ); | ||
assertEquals( "No validation errors", 0, valevent.getEvents().size() ); | ||
|
||
Curve icurve = GeometryFixer.invertOrientation( ocomp ); | ||
|
||
assertThat( "Result is CompositeCurve", icurve.getCurveType(), is( CurveType.CompositeCurve ) ); | ||
CompositeCurve icomp = (CompositeCurve) icurve; | ||
|
||
assertThat( icomp.size(), is( 3 ) ); | ||
assertFalse( "Compound is open", icomp.isClosed() ); | ||
|
||
assertTrue( "Inverted is valid", validator.validateGeometry( icomp ) ); | ||
assertEquals( "No validation errors", 0, valevent.getEvents().size() ); | ||
|
||
// Check that the composite curve was inverted (compare inverted start with original end) | ||
assertThat( "Invert S/E", icomp.getStartPoint().get0(), is( ocomp.getEndPoint().get0() ) ); | ||
assertThat( "Invert S/E", icomp.getStartPoint().get1(), is( ocomp.getEndPoint().get1() ) ); | ||
|
||
assertThat( "Invert E/S", icomp.getEndPoint().get0(), is( ocomp.getStartPoint().get0() ) ); | ||
assertThat( "Invert E/S", icomp.getEndPoint().get1(), is( ocomp.getStartPoint().get1() ) ); | ||
} | ||
|
||
@Test | ||
public void testInvertOfRing() { | ||
CountingValidationEventHandler valevent = new CountingValidationEventHandler(); | ||
GeometryValidator validator = new GeometryValidator( valevent ); | ||
|
||
Curve curve1 = createCurve( createFirstSegment() ); | ||
Curve curve2 = createCurve( createSecondSegment() ); | ||
Curve curve3 = createCurve( createThirdSegment() ); | ||
Ring oring = createRing( curve1, curve2, curve3 ); | ||
|
||
assertThat( oring.getMembers().size(), is( 3 ) ); | ||
|
||
assertTrue( "Source is valid", validator.validateGeometry( oring ) ); | ||
assertEquals( "No validation errors", 0, valevent.getEvents().size() ); | ||
|
||
Curve cinv = GeometryFixer.invertOrientation( oring ); | ||
|
||
assertThat( "Result is Ring", cinv.getCurveType(), is( CurveType.Ring ) ); | ||
Ring iring = (Ring) cinv; | ||
|
||
assertTrue( "Inverted is valid", validator.validateGeometry( cinv ) ); | ||
assertEquals( "Inverted has no validation errors", 0, valevent.getEvents().size() ); | ||
|
||
assertThat( iring.getMembers().size(), is( 3 ) ); | ||
|
||
// Check that the composite ring was inverted | ||
Point second = iring.getMembers().get( 0 ).getControlPoints().get( 1 ); | ||
int lastCurveCnt = oring.getMembers().get( 2 ).getControlPoints().size(); | ||
Point beforeLast = oring.getMembers().get( 2 ).getControlPoints().get( lastCurveCnt - 2 ); | ||
assertThat( "Original 2 equals inverted n-1", second.get0(), is( beforeLast.get0() ) ); | ||
assertThat( "Original 2 equals inverted n-1", second.get1(), is( beforeLast.get1() ) ); | ||
} | ||
|
||
private CompositeCurve createCompositeCurve( Curve... curves ) { | ||
return new DefaultCompositeCurve( "id", CRS, null, Arrays.asList( curves ) ); | ||
} | ||
|
||
private Ring createRing( Curve... curves ) { | ||
return new DefaultRing( "id", CRS, null, Arrays.asList( curves ) ); | ||
} | ||
|
||
private Curve createCurve() { | ||
return createCurve( createFirstSegment(), createSecondSegment(), createThirdSegment() ); | ||
} | ||
|
@@ -134,6 +247,14 @@ private CurveSegment createSecondSegment() { | |
return GEOM_FACTORY.createArc( point1, point2, point3 ); | ||
} | ||
|
||
private CurveSegment createSecondSegmentAsArcString() { | ||
Point point1 = GEOM_FACTORY.createPoint( "idpa1", 553976.438, 5937165.552, CRS ); | ||
Point point2 = GEOM_FACTORY.createPoint( "idpa2", 553974.601, 5937161.092, CRS ); | ||
Point point3 = GEOM_FACTORY.createPoint( "idpa3", 553969.988, 5937159.683, CRS ); | ||
Points points = new PointsArray( point1, point2, point3 ); | ||
return GEOM_FACTORY.createArcString( points ); | ||
} | ||
|
||
private CurveSegment createThirdSegment() { | ||
Point point1 = GEOM_FACTORY.createPoint( "idp21", 553969.988, 5937159.683, CRS ); | ||
Point point2 = GEOM_FACTORY.createPoint( "idp22", 553938.699, 5937160.863, CRS ); | ||
|
@@ -149,4 +270,31 @@ private CurveSegment createThirdSegment() { | |
return new DefaultLineStringSegment( points ); | ||
} | ||
|
||
private CurveSegment createThirdAltSegment() { | ||
// Create non closing this segment | ||
Point point1 = GEOM_FACTORY.createPoint( "idp21", 553969.988, 5937159.683, CRS ); | ||
Point point2 = GEOM_FACTORY.createPoint( "idp22", 553938.699, 5937160.863, CRS ); | ||
Point point3 = GEOM_FACTORY.createPoint( "idp23", 553903.017, 5937162.213, CRS ); | ||
Point point4 = GEOM_FACTORY.createPoint( "idp24", 553897.200, 5937200.469, CRS ); | ||
Point point5 = GEOM_FACTORY.createPoint( "idp25", 553897.613, 5937236.333, CRS ); | ||
Points points = new PointsArray( point1, point2, point3, point4, point5 ); | ||
return new DefaultLineStringSegment( points ); | ||
} | ||
|
||
class CountingValidationEventHandler implements GeometryValidationEventHandler { | ||
|
||
private final List<GeometryValidationEvent> events = new ArrayList<GeometryValidationEvent>(); | ||
|
||
@Override | ||
public boolean fireEvent( GeometryValidationEvent event ) { | ||
events.add( event ); | ||
// to count all errors return true | ||
return true; | ||
} | ||
|
||
List<GeometryValidationEvent> getEvents() { | ||
return events; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.