use of net.opengis.gml.AbstractRingType in project arctic-sea by 52North.
the class GmlEncoderv311 method createPolygonFromJtsGeometry.
/**
* Creates a XML Polygon from a SOS Polygon.
*
* @param jtsPolygon
* SOS Polygon
* @param xbPolType
* XML Polygon
*/
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
for (int i = 0; i < jtsPolygons.size(); i++) {
Polygon pol = (Polygon) jtsPolygons.get(i);
AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
AbstractRingType xbArt = xbArpt.addNewRing();
LinearRingType xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());
// Exterior ring
LineString ring = pol.getExteriorRing();
String coords = JTSHelper.getCoordinatesString(ring);
DirectPositionListType xbPosList = xbLrt.addNewPosList();
xbPosList.setSrsName(getSrsName(jtsPolygon));
// switch coordinates
xbPosList.setStringValue(coords);
xbArt.set(xbLrt);
// Rename element name for output
XmlCursor cursor = xbArpt.newCursor();
if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
cursor.setName(GmlConstants.QN_LINEAR_RING);
}
// Interior ring
int numberOfInteriorRings = pol.getNumInteriorRing();
for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
xbArpt = xbPolType.addNewInterior();
xbArt = xbArpt.addNewRing();
xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());
ring = pol.getInteriorRingN(ringNumber);
xbPosList = xbLrt.addNewPosList();
xbPosList.setSrsName(getSrsName(jtsPolygon));
xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
xbArt.set(xbLrt);
// Rename element name for output
cursor = xbArpt.newCursor();
if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
cursor.setName(GmlConstants.QN_LINEAR_RING);
}
}
}
}
Aggregations