use of org.geotoolkit.gml.xml.v321.DirectPositionListType in project geotoolkit by Geomatys.
the class GmlXMLBindingTest method marshallingTest.
/**
* Test simple Record Marshalling.
*
* @throws JAXBException
*/
@Test
public void marshallingTest() throws Exception {
DirectPositionType lower = new DirectPositionType(-30.711, 134.196);
DirectPositionType upper = new DirectPositionType(-30.702, 134.205);
EnvelopeType env = new EnvelopeType(lower, upper, "urn:ogc:def:crs:EPSG:6.8:4283");
StringWriter sw = new StringWriter();
marshaller.marshal(FACTORY.createEnvelope(env), sw);
String result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
String expResult = "<gml:Envelope xmlns:gml=\"http://www.opengis.net/gml/3.2\" srsName=\"urn:ogc:def:crs:EPSG:6.8:4283\" >" + '\n' + " <gml:lowerCorner>-30.711 134.196</gml:lowerCorner>" + '\n' + " <gml:upperCorner>-30.702 134.205</gml:upperCorner>" + '\n' + "</gml:Envelope>" + '\n';
DocumentComparator comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
Duration d1 = javax.xml.datatype.DatatypeFactory.newInstance().newDuration("P2D");
TimePeriodType tp = new TimePeriodType(d1);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
TimePositionType tpos = new TimePositionType("2002-08-15");
tp = new TimePeriodType(tpos);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
// System.out.println(sw.toString());
LineStringSegmentType ls = new LineStringSegmentType();
DirectPositionListType posList = new DirectPositionListType();
posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
ls.setPosList(posList);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
ls = new LineStringSegmentType();
DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
ls.getPos().add(pos1);
ls.getPos().add(pos2);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:pos>1.1 1.2</gml:pos>" + '\n' + " <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
}
use of org.geotoolkit.gml.xml.v321.DirectPositionListType in project tiamat by entur.
the class LineStringConverterTest method convertToLineString.
@Test
public void convertToLineString() throws Exception {
LineStringType lineStringType = new LineStringType().withId("LineString").withPosList(new DirectPositionListType().withSrsDimension(BigInteger.valueOf(2L)).withValue(71.1, 9.1, 4.1, 9.5));
LineString lineString = lineStringConverter.convertTo(lineStringType, new TypeBuilder<LineString>() {
}.build(), mappingContext);
assertThat(lineString).isNotNull();
assertThat(lineString.getCoordinates()).hasSize(2);
assertThat(lineString.getCoordinates()[0].x).isEqualTo(lineStringType.getPosList().getValue().get(1));
assertThat(lineString.getCoordinates()[0].y).isEqualTo(lineStringType.getPosList().getValue().get(0));
assertThat(lineString.getCoordinates()[1].x).isEqualTo(lineStringType.getPosList().getValue().get(3));
assertThat(lineString.getCoordinates()[1].y).isEqualTo(lineStringType.getPosList().getValue().get(2));
}
use of org.geotoolkit.gml.xml.v321.DirectPositionListType in project tiamat by entur.
the class PolygonConverterTest method convertFromWithHoles.
@Test
public void convertFromWithHoles() 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))).withInterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing)));
Polygon polygon = polygonConverter.convertFrom(polygonType, new TypeBuilder<Polygon>() {
}.build(), new MappingContext(new HashMap<>()));
assertThat(polygon).isNotNull();
assertThat(polygon.getExteriorRing().getCoordinates()).hasSize(values.size() / 2);
assertThat(polygon.getNumInteriorRing()).isEqualTo(1);
assertCoordinatesMatch(polygon.getExteriorRing(), values, "Exterior ring");
assertInteriorRingsMatch(polygon, Arrays.asList(values));
}
use of org.geotoolkit.gml.xml.v321.DirectPositionListType in project OpenTripPlanner by opentripplanner.
the class ServiceLinkMapperTest method createServiceLink.
private ServiceLink createServiceLink(String id, double distance, Double[] coordinates) {
DirectPositionListType directPositionListType = new DirectPositionListType().withValue(coordinates);
LinkSequenceProjection linkSequenceProjection = new LinkSequenceProjection().withLineString(new LineStringType().withPosList(directPositionListType));
JAXBElement<LinkSequenceProjection_VersionStructure> linkSequenceProjection_versionStructure = MappingSupport.createJaxbElement(linkSequenceProjection);
Projections_RelStructure projections_relStructure = new Projections_RelStructure().withProjectionRefOrProjection(linkSequenceProjection_versionStructure);
return new ServiceLink().withId(id).withDistance(new BigDecimal(distance)).withProjections(projections_relStructure);
}
use of org.geotoolkit.gml.xml.v321.DirectPositionListType in project arctic-sea by 52North.
the class GmlEncoderv321 method createLineStringFromJtsGeometry.
/**
* Creates a XML LineString from a SOS LineString.
*
* @param jtsLineString
* SOS LineString
* @param xbLst
* XML LinetSring
*/
private void createLineStringFromJtsGeometry(LineString jtsLineString, LineStringType xbLst) {
String srsName = getSrsName(jtsLineString);
xbLst.setSrsName(srsName);
DirectPositionListType xbPosList = xbLst.addNewPosList();
xbPosList.setSrsName(srsName);
xbPosList.setStringValue(JTSHelper.getCoordinatesString(jtsLineString));
}
Aggregations