use of org.geotoolkit.kml.xml.v220.LineStringType in project tiamat by entur.
the class PathLinkImportTest method publicationDeliveryWithPathLink.
@Test
public void publicationDeliveryWithPathLink() throws Exception {
StopPlace fromStopPlace = new StopPlace().withId("RUT:StopPlace:123123").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("9")).withLongitude(new BigDecimal("71"))));
StopPlace toStopPlace = new StopPlace().withId("RUT:StopPlace:321654").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("9.6")).withLongitude(new BigDecimal("76"))));
LineStringType lineStringType = new LineStringType().withId("LineString").withPosList(new DirectPositionListType().withSrsDimension(BigInteger.valueOf(new GeometryFactoryConfig().geometryFactory().getSRID())).withValue(9.1, 71.1, 9.5, 74.1));
Duration duration = Duration.ofMillis(10000);
PathLink netexPathLink = new PathLink().withId("NRI:ConnectionLink:762130479_762130479").withVersion("1").withAllowedUse(PathDirectionEnumeration.TWO_WAY).withTransferDuration(new TransferDurationStructure().withDefaultDuration(duration)).withLineString(lineStringType).withFrom(new PathLinkEndStructure().withPlaceRef(new PlaceRefStructure().withRef(fromStopPlace.getId()))).withTo(new PathLinkEndStructure().withPlaceRef(new PlaceRefStructure().withRef(toStopPlace.getId()).withVersion("1")));
PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(fromStopPlace, toStopPlace);
publicationDeliveryTestHelper.addPathLinks(publicationDelivery, netexPathLink);
PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
List<PathLink> result = publicationDeliveryTestHelper.extractPathLinks(response);
assertThat(result).as("Expecting path link in return").hasSize(1);
PathLink importedPathLink = result.get(0);
assertThat(importedPathLink.getAllowedUse()).isEqualTo(netexPathLink.getAllowedUse());
assertThat(importedPathLink.getFrom().getPlaceRef().getRef()).contains(fromStopPlace.getClass().getSimpleName());
assertThat(importedPathLink.getTo().getPlaceRef().getRef()).contains(toStopPlace.getClass().getSimpleName());
assertThat(importedPathLink.getTransferDuration().getDefaultDuration()).isEqualTo(duration);
assertThat(importedPathLink.getLineString()).isNotNull();
assertThat(importedPathLink.getLineString().getPosList()).isNotNull();
assertThat(importedPathLink.getLineString().getPosList().getValue()).hasSize(4);
}
use of org.geotoolkit.kml.xml.v220.LineStringType in project tiamat by entur.
the class LineStringConverterTest method convertFromLineStringToNetexGmlLineStringType.
@Test
public void convertFromLineStringToNetexGmlLineStringType() throws Exception {
Coordinate[] coordinates = new Coordinate[2];
coordinates[0] = new Coordinate(11, 60);
coordinates[1] = new Coordinate(11.1, 60.1);
CoordinateSequence points = new CoordinateArraySequence(coordinates);
LineString lineString = new LineString(points, geometryFactory);
LineStringType gisLineString = lineStringConverter.convertFrom(lineString, new TypeBuilder<LineStringType>() {
}.build(), mappingContext);
assertThat(gisLineString).isNotNull();
assertThat(gisLineString.getPosList().getCount().intValue()).isEqualTo(4);
assertThat(gisLineString.getId()).isNotEmpty();
// Check that the format is Y,X
assertThat(gisLineString.getPosList().getValue().get(0)).isEqualTo(coordinates[0].y);
assertThat(gisLineString.getPosList().getValue().get(1)).isEqualTo(coordinates[0].x);
assertThat(gisLineString.getPosList().getValue().get(2)).isEqualTo(coordinates[1].y);
assertThat(gisLineString.getPosList().getValue().get(3)).isEqualTo(coordinates[1].x);
assertThat(gisLineString.getSrsDimension().intValue()).isEqualTo(2);
}
use of org.geotoolkit.kml.xml.v220.LineStringType 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