use of net.opengis.gml._3.PolygonType in project tiamat by entur.
the class PolygonConverterTest method convertFrom.
@Test
public void convertFrom() throws Exception {
List<Double> values = new ArrayList<>();
values.add(9.8468);
values.add(59.2649);
values.add(9.8456);
values.add(59.2654);
values.add(9.8457);
values.add(59.2655);
values.add(values.get(0));
values.add(values.get(1));
DirectPositionListType positionList = new DirectPositionListType().withValue(values);
LinearRingType linearRing = new LinearRingType().withPosList(positionList);
PolygonType polygonType = new PolygonType().withId("KVE-07").withExterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing)));
Polygon polygon = polygonConverter.convertFrom(polygonType, new TypeBuilder<Polygon>() {
}.build(), new MappingContext(new HashMap<>()));
assertThat(polygon).isExactlyInstanceOf(Polygon.class).isNotNull();
assertThat(polygon.getExteriorRing().getCoordinates()).hasSize(values.size() / 2);
assertCoordinatesMatch(polygon.getExteriorRing(), values, "Exterior ring");
}
use of net.opengis.gml._3.PolygonType in project tiamat by entur.
the class PolygonConverterTest method convertToWithHoles.
@Test
public void convertToWithHoles() throws Exception {
Coordinate[] coordinates = new Coordinate[] { new Coordinate(9.8468, 59.2649), new Coordinate(9.8456, 59.2654), new Coordinate(9.8457, 59.2655), new Coordinate(9.8468, 59.2649) };
LinearRing linearRing = new LinearRing(new CoordinateArraySequence(coordinates), geometryFactory);
LinearRing[] holes = new LinearRing[] { new LinearRing(new CoordinateArraySequence(coordinates), geometryFactory) };
Polygon polygon = new Polygon(linearRing, holes, geometryFactory);
PolygonType actual = polygonConverter.convertTo(polygon, new TypeBuilder<PolygonType>() {
}.build(), new MappingContext(new HashMap<>()));
assertThat(actual).isNotNull();
List<Double> actualDoublevalues = polygonConverter.extractValues(actual.getExterior());
assertThat(actualDoublevalues).hasSize(coordinates.length * 2);
List<Double> actualHoleDoubleValues = polygonConverter.extractValues(actual.getInterior().get(0));
assertThat(actualHoleDoubleValues).hasSize(coordinates.length * 2);
}
use of net.opengis.gml._3.PolygonType in project tiamat by entur.
the class PolygonConverterTest method convertTo.
@Test
public void convertTo() throws Exception {
Coordinate[] coordinates = new Coordinate[] { new Coordinate(9.8468, 59.2649), new Coordinate(9.8456, 59.2654), new Coordinate(9.8457, 59.2655), new Coordinate(9.8468, 59.2649) };
LinearRing linearRing = new LinearRing(new CoordinateArraySequence(coordinates), geometryFactory);
Polygon polygon = new Polygon(linearRing, null, geometryFactory);
PolygonType actual = polygonConverter.convertTo(polygon, new TypeBuilder<PolygonType>() {
}.build(), new MappingContext(new HashMap<>()));
assertThat(actual).isNotNull();
assertThat(actual.getId()).isNotEmpty();
List<Double> values = polygonConverter.extractValues(actual.getExterior());
assertThat(values).hasSize(coordinates.length * 2);
// Tiamat is storing polygons with X, Y
// In NeTEx we receive polygons with Y, X
// Expect Y, X when converting to PolygonType (Netex)
int counter = 0;
for (Coordinate coordinate : coordinates) {
assertThat(values.get(counter++).doubleValue()).isEqualTo(coordinate.y);
assertThat(values.get(counter++).doubleValue()).isEqualTo(coordinate.x);
}
}
use of net.opengis.gml._3.PolygonType in project geotoolkit by Geomatys.
the class KMLStore method convert.
private static Geometry convert(Object geomType) throws DataStoreException {
if (geomType instanceof JAXBElement)
geomType = ((JAXBElement) geomType).getValue();
Geometry geom = null;
if (geomType instanceof ModelType) {
final ModelType modelType = (ModelType) geomType;
final LocationType location = modelType.getLocation();
geom = GF.createPoint(new Coordinate(location.getLongitude(), location.getLatitude()));
} else if (geomType instanceof PointType) {
final PointType pointType = (PointType) geomType;
final List<String> coordinates = pointType.getCoordinates();
geom = GF.createPoint(toCoordinates(coordinates, 1, false));
} else if (geomType instanceof PolygonType) {
final PolygonType polygonType = (PolygonType) geomType;
final CoordinateSequence outter = toCoordinates(polygonType.getOuterBoundaryIs().getLinearRing().getCoordinates(), 3, true);
final List<BoundaryType> inners = polygonType.getInnerBoundaryIs();
final LinearRing[] holes = new LinearRing[inners.size()];
for (int i = 0; i < holes.length; i++) {
holes[i] = GF.createLinearRing(toCoordinates(inners.get(i).getLinearRing().getCoordinates(), 3, true));
}
geom = GF.createPolygon(GF.createLinearRing(outter), holes);
} else if (geomType instanceof LinearRingType) {
final LinearRingType linearRingType = (LinearRingType) geomType;
geom = GF.createLineString(toCoordinates(linearRingType.getCoordinates(), 3, true));
} else if (geomType instanceof MultiGeometryType) {
final MultiGeometryType multigeometryType = (MultiGeometryType) geomType;
final List<JAXBElement<? extends AbstractGeometryType>> children = multigeometryType.getAbstractGeometryGroup();
final Geometry[] childs = new Geometry[children.size()];
for (int i = 0; i < childs.length; i++) {
childs[i] = convert(children.get(i));
}
geom = GF.createGeometryCollection(childs);
} else if (geomType instanceof LineStringType) {
final LineStringType lineStringType = (LineStringType) geomType;
geom = GF.createLineString(toCoordinates(lineStringType.getCoordinates(), 2, false));
}
if (geom != null) {
JTS.setCRS(geom, CRS);
}
return geom;
}
Aggregations