use of net.opengis.gml._3.DirectPositionListType in project ddf by codice.
the class CswJTSToGML311LinearRingConverter method doCreateGeometryType.
/**
* @see {@code JTSToGML311LinearRingConverter#doCreateGeometryType}
*/
@Override
protected LinearRingType doCreateGeometryType(LinearRing linearRing) {
final LinearRingType resultLinearRing;
if (usePosList) {
resultLinearRing = getObjectFactory().createLinearRingType();
List<Double> posDoubleList = new ArrayList<Double>();
for (Coordinate coordinate : linearRing.getCoordinates()) {
posDoubleList.add(coordinate.x);
posDoubleList.add(coordinate.y);
}
DirectPositionListType directPosListType = new DirectPositionListType();
directPosListType.setValue(posDoubleList);
resultLinearRing.setPosList(directPosListType);
} else {
resultLinearRing = super.doCreateGeometryType(linearRing);
}
return resultLinearRing;
}
use of net.opengis.gml._3.DirectPositionListType in project arctic-sea by 52North.
the class GmlDecoderv321 method parseLineStringType.
private Geometry parseLineStringType(LineStringType xbLineStringType) throws DecodingException {
int srid = -1;
if (xbLineStringType.getSrsName() != null) {
srid = CRSHelper.parseSrsName(xbLineStringType.getSrsName());
}
DirectPositionType[] xbPositions = xbLineStringType.getPosArray();
String geomWKT;
if (xbPositions != null && xbPositions.length > 0) {
if (srid == -1 && xbPositions[0].getSrsName() != null && !(xbPositions[0].getSrsName().isEmpty())) {
srid = CRSHelper.parseSrsName(xbPositions[0].getSrsName());
}
geomWKT = "LINESTRING" + getString4PosArray(xbLineStringType.getPosArray(), false) + "";
} else if (xbLineStringType.getPosList() != null) {
StringBuilder builder = new StringBuilder();
builder.append("LINESTRING(");
DirectPositionListType posList = xbLineStringType.getPosList();
int dim;
if (posList.getSrsDimension() == null) {
dim = 2;
} else {
dim = posList.getSrsDimension().intValue();
}
if (posList.getListValue().size() % dim != 0) {
throw new DecodingException("posList does not contain a multiple of %d coordinates", dim);
}
@SuppressWarnings("unchecked") Iterator<Double> iterator = posList.getListValue().iterator();
if (iterator.hasNext()) {
builder.append(iterator.next());
for (int i = 1; i < dim; ++i) {
builder.append(' ').append(iterator.next());
}
while (iterator.hasNext()) {
builder.append(", ");
builder.append(iterator.next());
for (int i = 1; i < dim; ++i) {
builder.append(' ').append(iterator.next());
}
}
}
builder.append(")");
geomWKT = builder.toString();
} else {
geomWKT = null;
}
srid = setDefaultForUnsetSrid(srid);
if (geomWKT != null) {
try {
return JTSHelper.createGeometryFromWKT(geomWKT, srid);
} catch (ParseException ex) {
throw new DecodingException(ex);
}
} else {
return JTSHelper.getGeometryFactoryForSRID(srid).createGeometryCollection(null);
}
}
use of net.opengis.gml._3.DirectPositionListType in project arctic-sea by 52North.
the class GmlDecoderv321 method getCoordString4LinearRing.
/**
* method parses the passed linearRing(generated thru XmlBEans) and returns a string containing the coordinate
* values of the passed ring
*
* @param xbLinearRing linearRing(generated thru XmlBEans)
*
* @return Returns a string containing the coordinate values of the passed ring
*
* @throws DecodingException * if parsing the linear Ring failed
*/
private String getCoordString4LinearRing(LinearRingType xbLinearRing) throws DecodingException {
String result = "";
DirectPositionListType xbPosList = xbLinearRing.getPosList();
CoordinatesType xbCoordinates = xbLinearRing.getCoordinates();
DirectPositionType[] xbPosArray = xbLinearRing.getPosArray();
if (xbPosList != null && !(xbPosList.getStringValue().isEmpty())) {
result = getString4PosList(xbPosList);
} else if (xbCoordinates != null && !(xbCoordinates.getStringValue().isEmpty())) {
result = getString4Coordinates(xbCoordinates);
} else if (xbPosArray != null && xbPosArray.length > 0) {
result = getString4PosArray(xbPosArray, true);
} else {
throw new DecodingException("The Polygon must contain the following elements " + "<gml:exterior><gml:LinearRing><gml:posList>, " + "<gml:exterior><gml:LinearRing><gml:coordinates> " + "or <gml:exterior><gml:LinearRing><gml:pos>{<gml:pos>}!");
}
return result;
}
use of net.opengis.gml._3.DirectPositionListType in project arctic-sea by 52North.
the class AbstractRectifiedGridCoverageTypeEncoder method encodeDomainSet.
private XmlObject encodeDomainSet(RectifiedGridCoverage rectifiedGridCoverage) {
List<ComparableValue<?, ?>> domainSet = rectifiedGridCoverage.getDomainSet();
if (!checkForRange(domainSet)) {
SimpleMultiPointDocument smpd = SimpleMultiPointDocument.Factory.newInstance();
SimpleMultiPointType smpt = smpd.addNewSimpleMultiPoint();
smpt.setId("smp_" + rectifiedGridCoverage.getGmlId());
DirectPositionListType dplt = smpt.addNewPosList();
List<String> uoms = getUoms(domainSet);
if (!uoms.isEmpty()) {
dplt.setUomLabels(Lists.newArrayList(uoms));
}
dplt.setListValue(getList(rectifiedGridCoverage.getDomainSet()));
return smpd;
} else {
LineStringDocument lsd = LineStringDocument.Factory.newInstance();
LineStringType lst = lsd.addNewLineString();
lst.setId("ls_" + rectifiedGridCoverage.getGmlId());
lst.setUomLabels(getUoms(domainSet));
for (ComparableValue<?, ?> quantityValued : domainSet) {
Object value = quantityValued.getValue();
if (value instanceof Double) {
lst.addNewPos().setListValue(Lists.newArrayList((Double) value));
} else if (value instanceof RangeValue) {
lst.addNewPos().setListValue(((RangeValue) value).getRangeAsList());
}
}
return lsd;
}
}
use of net.opengis.gml._3.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("bound-1", 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=\"" + GML + '"' + " 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';
assertXmlEquals(expResult, result, "xmlns:*");
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=\"" + GML + "\">\n" + " <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
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=\"" + GML + "\">\n" + " <gml:pos>1.1 1.2</gml:pos>" + '\n' + " <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
}
Aggregations