Search in sources :

Example 6 with TypeBuilder

use of ma.glasnost.orika.metadata.TypeBuilder 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);
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) Coordinate(org.locationtech.jts.geom.Coordinate) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) HashMap(java.util.HashMap) PolygonType(net.opengis.gml._3.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test)

Example 7 with TypeBuilder

use of ma.glasnost.orika.metadata.TypeBuilder 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);
    }
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) Coordinate(org.locationtech.jts.geom.Coordinate) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) HashMap(java.util.HashMap) PolygonType(net.opengis.gml._3.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test)

Aggregations

TypeBuilder (ma.glasnost.orika.metadata.TypeBuilder)7 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 MappingContext (ma.glasnost.orika.MappingContext)4 PolygonType (net.opengis.gml._3.PolygonType)4 Polygon (org.locationtech.jts.geom.Polygon)4 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 CoordinateArraySequence (org.locationtech.jts.geom.impl.CoordinateArraySequence)3 ArrayList (java.util.ArrayList)2 AbstractRingPropertyType (net.opengis.gml._3.AbstractRingPropertyType)2 LineStringType (net.opengis.gml._3.LineStringType)2 LinearRingType (net.opengis.gml._3.LinearRingType)2 LineString (org.locationtech.jts.geom.LineString)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1 ApiOperation (io.swagger.annotations.ApiOperation)1 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)1 DoubleValuesToCoordinateSequence (org.rutebanken.tiamat.geo.DoubleValuesToCoordinateSequence)1