use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary in project geotoolkit by Geomatys.
the class AbstractJTSGeometry method getBoundary.
/**
* Returns the boundary of this geometry. Returns null if the boundary is
* empty.
*/
@Override
public Boundary getBoundary() {
// PENDING(CSD):
// Need to find out if MultiPrimitives are handled correctly. (I think
// they are, but 19107's boundary semantics for multi-primitives are
// not well-specified.)
// Need to find out if GeometryCollections are handled correctly. (I
// don't think they are, but it's not clear what it would mean, nor is
// it obvious why anyone would call it in the first place.)
org.locationtech.jts.geom.Geometry jtsGeom = getJTSGeometry();
// compute the boundary of a collection object in 19107.
if (jtsGeom instanceof org.locationtech.jts.geom.GeometryCollection) {
throw new UnsupportedOperationException("Boundary cannot be computed for multi-primitives.");
}
org.locationtech.jts.geom.Geometry jtsBoundary = jtsGeom.getBoundary();
int d = jtsGeom.getDimension();
if (d == 0) {
// be NULL.
return null;
} else if (d == 1) {
// If d is 1, then the boundary is either empty (if it's a ring) or
// it's two points at either end of the curve.
// We've ruled out the possibility of multi-primitives (see the
// instanceof check above), so we know that the boundary can't be
// more than 2 points.
org.locationtech.jts.geom.Coordinate[] coords = jtsBoundary.getCoordinates();
// null).
if ((coords == null) || (coords.length == 0)) {
JTSCurveBoundary result = new JTSCurveBoundary(getCoordinateReferenceSystem(), null, null);
return result;
} else {
// endpoints.
if (coords.length != 2) {
// Should this be an assert instead?
throw new RuntimeException("ERROR: One dimensional " + "primitive had wrong number of boundary points (" + coords.length + ")");
}
CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
JTSCurveBoundary result = new JTSCurveBoundary(crs, new JTSPoint(JTSUtils.coordinateToDirectPosition(coords[0], crs)), new JTSPoint(JTSUtils.coordinateToDirectPosition(coords[1], crs)));
return result;
}
} else if (d == 2) {
// If d == 2, then the boundary is a collection of rings.
// In particular, the JTS tests indicate that it'll be a
// MultiLineString.
org.locationtech.jts.geom.MultiLineString mls = (org.locationtech.jts.geom.MultiLineString) jtsBoundary;
int n = mls.getNumGeometries();
CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
Ring exteriorRing = JTSUtils.linearRingToRing((org.locationtech.jts.geom.LineString) mls.getGeometryN(0), crs);
Ring[] interiorRings = new Ring[n - 1];
for (int i = 1; i < n; i++) {
interiorRings[n - 1] = JTSUtils.linearRingToRing((org.locationtech.jts.geom.LineString) mls.getGeometryN(i), crs);
}
JTSSurfaceBoundary result = new JTSSurfaceBoundary(crs, exteriorRing, interiorRings);
return result;
} else {
throw new UnsupportedOperationException("Computing the boundary " + "for geometries of dimension larger than 2 is not " + "supported.");
}
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method PolyHedralSurfaceUnmarshalingTest.
/**
* Test PolyHedral surface Unmarshalling.
*/
@Test
public void PolyHedralSurfaceUnmarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
JTSPolyhedralSurface expResult = new JTSPolyhedralSurface(crs);
/*
* FIRST POLYGON
*/
// EXTERIOR
JTSRing exterior1 = new JTSRing(crs);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString c1l1 = new JTSLineString();
DirectPosition c1l1p1 = new GeneralDirectPosition(crs);
c1l1p1.setOrdinate(0, 401500);
c1l1p1.setOrdinate(1, 3334500);
DirectPosition c1l1p2 = new GeneralDirectPosition(crs);
c1l1p2.setOrdinate(0, 401700);
c1l1p2.setOrdinate(1, 3334850);
DirectPosition c1l1p3 = new GeneralDirectPosition(crs);
c1l1p3.setOrdinate(0, 402200);
c1l1p3.setOrdinate(1, 3335200);
DirectPosition c1l2p1 = new GeneralDirectPosition(crs);
c1l2p1.setOrdinate(0, 402320);
c1l2p1.setOrdinate(1, 3334850);
DirectPosition c1l2p2 = new GeneralDirectPosition(crs);
c1l2p2.setOrdinate(0, 402200);
c1l2p2.setOrdinate(1, 3335200);
c1l1.getControlPoints().add(c1l1p1);
c1l1.getControlPoints().add(c1l1p2);
c1l1.getControlPoints().add(c1l1p3);
c1l1.getControlPoints().add(c1l2p1);
c1l1.getControlPoints().add(c1l2p2);
c1.getSegments().add(c1l1);
exterior1.getElements().add(c1);
// INTERIOR
Ring[] interiors1 = new Ring[1];
JTSRing interior1 = new JTSRing(crs);
JTSCurve c2 = new JTSCurve(crs);
JTSLineString c2l1 = new JTSLineString();
DirectPosition c2l1p1 = new GeneralDirectPosition(crs);
c2l1p1.setOrdinate(0, 401500);
c2l1p1.setOrdinate(1, 3334500);
DirectPosition c2l1p2 = new GeneralDirectPosition(crs);
c2l1p2.setOrdinate(0, 401700);
c2l1p2.setOrdinate(1, 3334850);
DirectPosition c2l1p3 = new GeneralDirectPosition(crs);
c2l1p3.setOrdinate(0, 402200);
c2l1p3.setOrdinate(1, 3335200);
c2l1.getControlPoints().add(c2l1p1);
c2l1.getControlPoints().add(c2l1p2);
c2l1.getControlPoints().add(c2l1p3);
c2.getSegments().add(c2l1);
interior1.getElements().add(c2);
interiors1[0] = interior1;
JTSSurfaceBoundary bound1 = new JTSSurfaceBoundary(crs, exterior1, interiors1);
JTSPolygon p1 = new JTSPolygon(bound1);
/*
* SECOND POLYGON
*/
// EXTERIOR
JTSRing exterior2 = new JTSRing(crs);
JTSCurve c3 = new JTSCurve(crs);
JTSLineString c3l1 = new JTSLineString();
DirectPosition c3l1p1 = new GeneralDirectPosition(crs);
c3l1p1.setOrdinate(0, 401500);
c3l1p1.setOrdinate(1, 3334500);
DirectPosition c3l1p2 = new GeneralDirectPosition(crs);
c3l1p2.setOrdinate(0, 401700);
c3l1p2.setOrdinate(1, 3334850);
DirectPosition c3l1p3 = new GeneralDirectPosition(crs);
c3l1p3.setOrdinate(0, 402200);
c3l1p3.setOrdinate(1, 3335200);
c3l1.getControlPoints().add(c3l1p1);
c3l1.getControlPoints().add(c3l1p2);
c3l1.getControlPoints().add(c3l1p3);
c3.getSegments().add(c3l1);
exterior2.getElements().add(c3);
// INTERIOR
JTSRing interior2 = new JTSRing(crs);
JTSCurve c4 = new JTSCurve(crs);
JTSLineString c4l1 = new JTSLineString();
DirectPosition c4l1p1 = new GeneralDirectPosition(crs);
c4l1p1.setOrdinate(0, 401500);
c4l1p1.setOrdinate(1, 3334500);
DirectPosition c4l1p2 = new GeneralDirectPosition(crs);
c4l1p2.setOrdinate(0, 401700);
c4l1p2.setOrdinate(1, 3334850);
DirectPosition c4l1p3 = new GeneralDirectPosition(crs);
c4l1p3.setOrdinate(0, 402200);
c4l1p3.setOrdinate(1, 3335200);
c4l1.getControlPoints().add(c4l1p1);
c4l1.getControlPoints().add(c4l1p2);
c4l1.getControlPoints().add(c4l1p3);
c4.getSegments().add(c4l1);
interior2.getElements().add(c4);
Ring[] interiors2 = new Ring[1];
interiors2[0] = interior2;
JTSSurfaceBoundary bound2 = new JTSSurfaceBoundary(crs, exterior2, interiors2);
JTSPolygon p2 = new JTSPolygon(bound2);
expResult.getPatches().add(p1);
expResult.getPatches().add(p2);
// TODO remove the srsName
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:PolyhedralSurface srsName=\"urn:ogc:def:crs:epsg::27572\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:polygonPatches>" + '\n' + " <gml:PolygonPatch>" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0 402320.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " <gml:interior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:interior>" + '\n' + " </gml:PolygonPatch>" + '\n' + " <gml:PolygonPatch>" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " <gml:interior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:interior>" + '\n' + " </gml:PolygonPatch>" + '\n' + " </gml:polygonPatches>" + '\n' + "</gml:PolyhedralSurface>" + '\n';
PolyhedralSurfaceType tmp = (PolyhedralSurfaceType) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
JTSPolyhedralSurface result = tmp.getIsoPolyHedralSurface();
JTSSurfaceBoundary expBoundary = (JTSSurfaceBoundary) expResult.getPatches().get(0).getBoundary();
JTSSurfaceBoundary resBoundary = (JTSSurfaceBoundary) result.getPatches().get(0).getBoundary();
JTSCurve expCurve = (JTSCurve) expBoundary.getExterior().getElements().iterator().next();
JTSCurve resCurve = (JTSCurve) resBoundary.getExterior().getElements().iterator().next();
assertEquals(((JTSLineString) expCurve.getSegments().get(0)).getControlPoints().get(0), ((JTSLineString) resCurve.getSegments().get(0)).getControlPoints().get(0));
assertEquals(expCurve.getSegments().get(0), resCurve.getSegments().get(0));
assertEquals(expCurve, resCurve);
assertEquals(expBoundary.getExterior(), resBoundary.getExterior());
assertEquals(expBoundary.getInteriors(), resBoundary.getInteriors());
assertEquals(expBoundary, resBoundary);
assertEquals(expResult.getPatches().get(0), result.getPatches().get(0));
assertEquals(expResult.getPatches().get(1), result.getPatches().get(1));
assertEquals(expResult.getPatches(), result.getPatches());
assertEquals(expResult, result);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method MultiPolygonUnmarshalingTest.
/**
* Test Ring Unmarshalling.
*/
@Test
public void MultiPolygonUnmarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
// EXTERIOR
JTSRing exterior1 = new JTSRing(crs);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString c1l1 = new JTSLineString(crs);
DirectPosition c1l1p1 = new GeneralDirectPosition(crs);
c1l1p1.setOrdinate(0, 401500);
c1l1p1.setOrdinate(1, 3334500);
DirectPosition c1l1p2 = new GeneralDirectPosition(crs);
c1l1p2.setOrdinate(0, 401700);
c1l1p2.setOrdinate(1, 3334850);
DirectPosition c1l1p3 = new GeneralDirectPosition(crs);
c1l1p3.setOrdinate(0, 402200);
c1l1p3.setOrdinate(1, 3335200);
c1l1.getControlPoints().add(c1l1p1);
c1l1.getControlPoints().add(c1l1p2);
c1l1.getControlPoints().add(c1l1p3);
DirectPosition c1l2p1 = new GeneralDirectPosition(crs);
c1l2p1.setOrdinate(0, 402320);
c1l2p1.setOrdinate(1, 3334850);
DirectPosition c1l2p2 = new GeneralDirectPosition(crs);
c1l2p2.setOrdinate(0, 402200);
c1l2p2.setOrdinate(1, 3335200);
c1l1.getControlPoints().add(c1l2p1);
c1l1.getControlPoints().add(c1l2p2);
c1.getSegments().add(c1l1);
exterior1.getElements().add(c1);
// INTERIOR
Ring[] interiors1 = new Ring[1];
JTSRing interior1 = new JTSRing(crs);
JTSCurve c2 = new JTSCurve(crs);
JTSLineString c2l1 = new JTSLineString(crs);
DirectPosition c2l1p1 = new GeneralDirectPosition(crs);
c2l1p1.setOrdinate(0, 401500);
c2l1p1.setOrdinate(1, 3334500);
DirectPosition c2l1p2 = new GeneralDirectPosition(crs);
c2l1p2.setOrdinate(0, 401700);
c2l1p2.setOrdinate(1, 3334850);
DirectPosition c2l1p3 = new GeneralDirectPosition(crs);
c2l1p3.setOrdinate(0, 402200);
c2l1p3.setOrdinate(1, 3335200);
c2l1.getControlPoints().add(c2l1p1);
c2l1.getControlPoints().add(c2l1p2);
c2l1.getControlPoints().add(c2l1p3);
c2.getSegments().add(c2l1);
interior1.getElements().add(c2);
interiors1[0] = interior1;
JTSSurfaceBoundary bound1 = new JTSSurfaceBoundary(crs, exterior1, interiors1);
JTSPolygon expPoly = new JTSPolygon(bound1);
JTSMultiPolygon expResult = new JTSMultiPolygon(crs);
expResult.getElements().add(expPoly);
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiPolygon xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:polygonMember>" + '\n' + " <gml:Polygon srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0 402320.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " <gml:interior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:interior>" + '\n' + " </gml:Polygon>" + '\n' + " </gml:polygonMember>" + '\n' + "</gml:MultiPolygon>\n";
JTSMultiPolygon result = (JTSMultiPolygon) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
result.applyCRSOnchild();
assertEquals(expResult, result);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method MultiPrimitiveUnmarshalingTest.
/**
* Test Composite curve Marshalling.
*/
@Test
public void MultiPrimitiveUnmarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
DirectPosition p1 = new GeneralDirectPosition(crs);
p1.setOrdinate(0, 402000);
p1.setOrdinate(1, 3334850);
DirectPosition p2 = new GeneralDirectPosition(crs);
p2.setOrdinate(0, 402200);
p2.setOrdinate(1, 3335200);
JTSLineString l1 = new JTSLineString(crs);
l1.getControlPoints().add(p1);
l1.getControlPoints().add(p2);
JTSCurve c2 = new JTSCurve(crs);
c2.getSegments().add(l1);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString l2 = new JTSLineString(crs);
DirectPosition p21 = new GeneralDirectPosition(crs);
p21.setOrdinate(0, 401500);
p21.setOrdinate(1, 3334500);
DirectPosition p22 = new GeneralDirectPosition(crs);
p22.setOrdinate(0, 401700);
p22.setOrdinate(1, 3334850);
DirectPosition p23 = new GeneralDirectPosition(crs);
p23.setOrdinate(0, 402200);
p23.setOrdinate(1, 3335200);
l2.getControlPoints().add(p21);
l2.getControlPoints().add(p22);
l2.getControlPoints().add(p23);
c1.getSegments().add(l2);
JTSLineString l3 = new JTSLineString(crs);
DirectPosition p31 = new GeneralDirectPosition(crs);
p31.setOrdinate(0, 402320);
p31.setOrdinate(1, 3334850);
DirectPosition p32 = new GeneralDirectPosition(crs);
p32.setOrdinate(0, 402200);
p32.setOrdinate(1, 3335200);
l3.getControlPoints().add(p31);
l3.getControlPoints().add(p32);
c1.getSegments().add(l3);
JTSMultiPrimitive expResult = new JTSMultiPrimitive();
expResult.getElements().add(c1);
expResult.getElements().add(c2);
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiGeometry xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:geometryMember>" + '\n' + " <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:segments>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>401500.0 3334500.0</gml:pos>" + '\n' + " <gml:pos>401700.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>402320.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " </gml:segments>" + '\n' + " </gml:Curve>" + '\n' + " </gml:geometryMember>" + '\n' + " <gml:geometryMember>" + '\n' + " <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:segments>" + '\n' + " <gml:LineStringSegment interpolation=\"linear\">" + '\n' + " <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:LineStringSegment>" + '\n' + " </gml:segments>" + '\n' + " </gml:Curve>" + '\n' + " </gml:geometryMember>" + '\n' + "</gml:MultiGeometry>" + '\n';
JTSMultiPrimitive result = (JTSMultiPrimitive) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
assertEquals(expResult.getElements().size(), result.getElements().size());
assertEquals(2, result.getElements().size());
Iterator expIt = expResult.getElements().iterator();
Iterator resIt = result.getElements().iterator();
assertEquals(expIt.next(), resIt.next());
assertEquals(expIt.next(), resIt.next());
expIt = expResult.getElements().iterator();
resIt = result.getElements().iterator();
assertEquals(expIt.next().hashCode(), resIt.next().hashCode());
assertEquals(expIt.next().hashCode(), resIt.next().hashCode());
assertEquals(expResult.getElements(), result.getElements());
assertEquals(expResult, result);
crs = CRS.forCode("urn:ogc:def:crs:epsg::27593");
assertTrue(crs != null);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiGeometry xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:geometryMember>" + '\n' + " <gml:PolyhedralSurface srsName=\"urn:ogc:def:crs:epsg::27593\">" + '\n' + " <gml:polygonPatches>" + '\n' + " <gml:PolygonPatch>" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>656216.1977884835 38574.31079256255 656209.434300029 38569.570186997764</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " </gml:PolygonPatch>" + '\n' + " </gml:polygonPatches>" + '\n' + " </gml:PolyhedralSurface>" + '\n' + " </gml:geometryMember>" + '\n' + "</gml:MultiGeometry>" + '\n';
result = (JTSMultiPrimitive) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
/*
* FIRST POLYGON
*/
// EXTERIOR
JTSRing exterior1 = new JTSRing(crs);
JTSCurve cu1 = new JTSCurve(crs);
JTSLineString c1l1 = new JTSLineString();
DirectPosition dp1 = new GeneralDirectPosition(crs);
dp1.setOrdinate(0, 656216.1977884835);
dp1.setOrdinate(1, 38574.31079256255);
DirectPosition dp2 = new GeneralDirectPosition(crs);
dp2.setOrdinate(0, 656209.434300029);
dp2.setOrdinate(1, 38569.570186997764);
c1l1.getControlPoints().add(dp1);
c1l1.getControlPoints().add(dp2);
cu1.getSegments().add(c1l1);
exterior1.getElements().add(cu1);
// INTERIOR
Ring[] interiors1 = null;
JTSSurfaceBoundary bound1 = new JTSSurfaceBoundary(crs, exterior1, interiors1);
JTSPolygon poly1 = new JTSPolygon(bound1);
JTSPolyhedralSurface PS = new JTSPolyhedralSurface(crs);
PS.getPatches().add(poly1);
expResult = new JTSMultiPrimitive();
expResult.getElements().add(PS);
JTSPolyhedralSurface expPoly = (JTSPolyhedralSurface) expResult.getElements().iterator().next();
JTSPolyhedralSurface resPoly = (JTSPolyhedralSurface) result.getElements().iterator().next();
assertEquals(expPoly.getPatches().get(0).getBoundary().getExterior(), resPoly.getPatches().get(0).getBoundary().getExterior());
assertEquals(expPoly.getPatches().get(0).getBoundary().getInteriors(), resPoly.getPatches().get(0).getBoundary().getInteriors());
assertEquals(expPoly.getPatches().get(0).getBoundary(), resPoly.getPatches().get(0).getBoundary());
assertEquals(expPoly.getPatches().get(0).getInterpolation(), resPoly.getPatches().get(0).getInterpolation());
assertEquals(expPoly.getPatches().get(0).getSurface(), resPoly.getPatches().get(0).getSurface());
assertEquals(expPoly.getPatches().get(0), resPoly.getPatches().get(0));
assertEquals(expPoly.getPatches(), resPoly.getPatches());
assertEquals(expPoly, resPoly);
assertEquals(expResult.getElements(), result.getElements());
assertEquals(expResult, result);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiGeometry xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:geometryMember>" + '\n' + " <gml:Polygon srsName=\"urn:ogc:def:crs:epsg::4326\">" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>-1.0 0.0 0.0 1.0 1.0 0.0 0.0 -1.0 -1.0 0.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " </gml:Polygon>" + '\n' + " </gml:geometryMember>" + '\n' + "</gml:MultiGeometry>" + '\n';
result = (JTSMultiPrimitive) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
crs = CRS.forCode("urn:ogc:def:crs:epsg::4326");
// EXTERIOR
exterior1 = new JTSRing(crs);
cu1 = new JTSCurve(crs);
c1l1 = new JTSLineString(crs);
dp1 = new GeneralDirectPosition(crs);
dp1.setOrdinate(0, -1.0);
dp1.setOrdinate(1, 0.0);
dp2 = new GeneralDirectPosition(crs);
dp2.setOrdinate(0, 0.0);
dp2.setOrdinate(1, 1.0);
GeneralDirectPosition dp3 = new GeneralDirectPosition(crs);
dp3.setOrdinate(0, 1.0);
dp3.setOrdinate(1, 0.0);
GeneralDirectPosition dp4 = new GeneralDirectPosition(crs);
dp4.setOrdinate(0, 0.0);
dp4.setOrdinate(1, -1.0);
GeneralDirectPosition dp5 = new GeneralDirectPosition(crs);
dp5.setOrdinate(0, -1.0);
dp5.setOrdinate(1, 0.0);
c1l1.getControlPoints().add(dp1);
c1l1.getControlPoints().add(dp2);
c1l1.getControlPoints().add(dp3);
c1l1.getControlPoints().add(dp4);
c1l1.getControlPoints().add(dp5);
cu1.getSegments().add(c1l1);
exterior1.getElements().add(cu1);
// INTERIOR
interiors1 = new Ring[0];
bound1 = new JTSSurfaceBoundary(crs, exterior1, interiors1);
poly1 = new JTSPolygon(bound1);
poly1.setCoordinateReferenceSystem(crs);
expResult = new JTSMultiPrimitive();
expResult.getElements().add(poly1);
assertEquals(expResult.getElements().size(), result.getElements().size());
JTSPolygon expPolygon = (JTSPolygon) expResult.getElements().iterator().next();
JTSPolygon resPolygon = (JTSPolygon) result.getElements().iterator().next();
assertEquals(expPolygon.getCoordinateReferenceSystem(), resPolygon.getCoordinateReferenceSystem());
assertEquals(expPolygon.getBoundary().getCoordinateReferenceSystem(), resPolygon.getBoundary().getCoordinateReferenceSystem());
JTSCurve expCurve = (JTSCurve) expPolygon.getBoundary().getExterior().getElements().iterator().next();
JTSCurve resCurve = (JTSCurve) resPolygon.getBoundary().getExterior().getElements().iterator().next();
JTSLineString expLine = (JTSLineString) expCurve.getSegments().get(0);
JTSLineString resLine = (JTSLineString) resCurve.getSegments().get(0);
assertEquals(expLine.getCoordinateReferenceSystem(), resLine.getCoordinateReferenceSystem());
assertEquals(expLine, resLine);
assertEquals(expCurve.getSegments().get(0), resCurve.getSegments().get(0));
assertEquals(expCurve.getSegments(), resCurve.getSegments());
assertEquals(expCurve, resCurve);
assertEquals(expPolygon.getBoundary().getExterior(), resPolygon.getBoundary().getExterior());
assertEquals(expPolygon.getBoundary().getInteriors(), resPolygon.getBoundary().getInteriors());
assertEquals(expPolygon.getBoundary(), resPolygon.getBoundary());
assertEquals(expPolygon, resPolygon);
assertEquals(expResult.getElements(), result.getElements());
assertEquals(expResult, result);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method MultiPolygonMarshalingTest.
/**
* Test Ring Unmarshalling.
*/
@Test
public void MultiPolygonMarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
// EXTERIOR
JTSRing exterior1 = new JTSRing(crs);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString c1l1 = new JTSLineString();
DirectPosition c1l1p1 = new GeneralDirectPosition(crs);
c1l1p1.setOrdinate(0, 401500);
c1l1p1.setOrdinate(1, 3334500);
DirectPosition c1l1p2 = new GeneralDirectPosition(crs);
c1l1p2.setOrdinate(0, 401700);
c1l1p2.setOrdinate(1, 3334850);
DirectPosition c1l1p3 = new GeneralDirectPosition(crs);
c1l1p3.setOrdinate(0, 402200);
c1l1p3.setOrdinate(1, 3335200);
DirectPosition c1l2p1 = new GeneralDirectPosition(crs);
c1l2p1.setOrdinate(0, 402320);
c1l2p1.setOrdinate(1, 3334850);
DirectPosition c1l2p2 = new GeneralDirectPosition(crs);
c1l2p2.setOrdinate(0, 402200);
c1l2p2.setOrdinate(1, 3335200);
c1l1.getControlPoints().add(c1l1p1);
c1l1.getControlPoints().add(c1l1p2);
c1l1.getControlPoints().add(c1l1p3);
c1l1.getControlPoints().add(c1l2p1);
c1l1.getControlPoints().add(c1l2p2);
c1.getSegments().add(c1l1);
exterior1.getElements().add(c1);
// INTERIOR
Ring[] interiors1 = new Ring[1];
JTSRing interior1 = new JTSRing(crs);
JTSCurve c2 = new JTSCurve(crs);
JTSLineString c2l1 = new JTSLineString();
DirectPosition c2l1p1 = new GeneralDirectPosition(crs);
c2l1p1.setOrdinate(0, 401500);
c2l1p1.setOrdinate(1, 3334500);
DirectPosition c2l1p2 = new GeneralDirectPosition(crs);
c2l1p2.setOrdinate(0, 401700);
c2l1p2.setOrdinate(1, 3334850);
DirectPosition c2l1p3 = new GeneralDirectPosition(crs);
c2l1p3.setOrdinate(0, 402200);
c2l1p3.setOrdinate(1, 3335200);
c2l1.getControlPoints().add(c2l1p1);
c2l1.getControlPoints().add(c2l1p2);
c2l1.getControlPoints().add(c2l1p3);
c2.getSegments().add(c2l1);
interior1.getElements().add(c2);
interiors1[0] = interior1;
JTSSurfaceBoundary bound1 = new JTSSurfaceBoundary(crs, exterior1, interiors1);
JTSPolygon polygon = new JTSPolygon(bound1);
JTSMultiPolygon multiPolygon = new JTSMultiPolygon(crs);
multiPolygon.getElements().add(polygon);
StringWriter sw = new StringWriter();
m.marshal(factory.createJTSMultiPolygon(multiPolygon), sw);
String result = sw.toString();
result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiPolygon xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::27572\" >" + '\n' + " <gml:polygonMember>" + '\n' + " <gml:Polygon srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:exterior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0 402320.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:exterior>" + '\n' + " <gml:interior>" + '\n' + " <gml:LinearRing>" + '\n' + " <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + " </gml:LinearRing>" + '\n' + " </gml:interior>" + '\n' + " </gml:Polygon>" + '\n' + " </gml:polygonMember>" + '\n' + "</gml:MultiPolygon>\n";
assertXmlEquals(expResult, result, "xmlns:*");
}
Aggregations