use of net.opengis.gml.x32.PolygonType in project tiamat by entur.
the class PolygonConverter method convertFrom.
@Override
public Polygon convertFrom(PolygonType polygonType, Type<Polygon> type, MappingContext mappingContext) {
Optional<List<Double>> optionalExteriorValues = Optional.ofNullable(polygonType).map(PolygonType::getExterior).map(this::extractValues);
Optional<List<List<Double>>> interiorValues = Optional.ofNullable(polygonType).map(PolygonType::getInterior).map(list -> list.stream().map(this::extractValues).collect(Collectors.toList())).filter(list -> !list.isEmpty());
if (optionalExteriorValues.isPresent()) {
List<Double> exteriorValues = optionalExteriorValues.get();
CoordinateSequence exteriorCoordinateSequence = doubleValuesToCoordinateSequence.convert(exteriorValues);
LinearRing exteriorLinearRing = new LinearRing(exteriorCoordinateSequence, geometryFactory);
LinearRing[] interiorHoles = null;
if (interiorValues.isPresent()) {
interiorHoles = interiorValues.get().stream().map(doubleValuesToCoordinateSequence::convert).map(coordinateSequence -> new LinearRing(coordinateSequence, geometryFactory)).toArray(size -> new LinearRing[size]);
}
return new Polygon(exteriorLinearRing, interiorHoles, geometryFactory);
}
logger.warn("Cannot convert polygon from PolygonType. Cannot find exterior values: {}", polygonType);
return null;
}
use of net.opengis.gml.x32.PolygonType in project tiamat by entur.
the class TopographicPlaceImportTest method publicationDeliveryWithTopographicPlaceAndPolygon.
@Test
public void publicationDeliveryWithTopographicPlaceAndPolygon() 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(9.8443);
values.add(59.2663);
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)));
MultilingualString nameDescriptor = new MultilingualString().withValue("Vestfold").withLang("nb");
TopographicPlace topographicPlace = new TopographicPlace().withId("KVE:TopographicPlace:07").withName(nameDescriptor).withVersion("1").withDescriptor(new TopographicPlaceDescriptor_VersionedChildStructure().withName(nameDescriptor)).withTopographicPlaceType(TopographicPlaceTypeEnumeration.COUNTY).withCountryRef(new CountryRef().withValue("NO")).withPolygon(polygonType);
PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryTopographicPlace(topographicPlace);
PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
List<TopographicPlace> result = publicationDeliveryTestHelper.extractTopographicPlace(response);
assertThat(result).as("Expecting topographic place in return").hasSize(1);
TopographicPlace actualTopographicPlace = result.get(0);
assertThat(actualTopographicPlace.getPolygon()).as("polygon must not be null").isNotNull();
List<Double> actualExteriorValues = polygonConverter.extractValues(topographicPlace.getPolygon().getExterior());
assertThat(actualExteriorValues).isEqualTo(values);
assertThat(actualTopographicPlace.getId()).isEqualTo(topographicPlace.getId());
}
use of net.opengis.gml.x32.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.x32.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.x32.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);
}
}
Aggregations