use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class GmlEncoderv311 method createPosition.
private XmlObject createPosition(Geometry geom, Optional<Object> optional) throws UnsupportedEncoderInputException {
String gmlId = (optional != null && optional.isPresent() && optional.get() instanceof String) ? (String) optional.get() : null;
if (geom instanceof Point) {
PointType xbPoint = PointType.Factory.newInstance(getXmlOptions());
if (gmlId != null) {
xbPoint.setId(geom.getGeometryType() + "_" + gmlId);
}
createPointFromJtsGeometry((Point) geom, xbPoint);
return xbPoint;
} else if (geom instanceof LineString) {
LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
if (gmlId != null) {
xbLineString.setId(geom.getGeometryType() + "_" + gmlId);
}
createLineStringFromJtsGeometry((LineString) geom, xbLineString);
return xbLineString;
} else if (geom instanceof Polygon) {
PolygonType xbPolygon = PolygonType.Factory.newInstance(getXmlOptions());
if (gmlId != null) {
xbPolygon.setId(geom.getGeometryType() + "_" + gmlId);
}
createPolygonFromJtsGeometry((Polygon) geom, xbPolygon);
return xbPolygon;
} else {
throw new UnsupportedEncoderInputException(this, geom);
}
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class GmlEncoderv311 method encode.
@Override
public XmlObject encode(Object element, EncodingContext ctx) throws EncodingException {
XmlObject encodedObject = null;
if (element instanceof Time) {
encodedObject = createTime((Time) element, ctx);
} else if (element instanceof Geometry) {
encodedObject = createPosition((Geometry) element, ctx.get(XmlBeansEncodingFlags.GMLID));
} else if (element instanceof CategoryValue) {
encodedObject = createReferenceTypeForCategroyValue((CategoryValue) element);
} else if (element instanceof org.n52.shetland.ogc.gml.ReferenceType) {
encodedObject = createReferencType((org.n52.shetland.ogc.gml.ReferenceType) element);
} else if (element instanceof CodeWithAuthority) {
encodedObject = createCodeWithAuthorityType((CodeWithAuthority) element);
} else if (element instanceof QuantityValue) {
encodedObject = createMeasureType((QuantityValue) element);
} else if (element instanceof org.n52.shetland.ogc.gml.CodeType) {
encodedObject = createCodeType((org.n52.shetland.ogc.gml.CodeType) element);
} else if (element instanceof AbstractFeature) {
encodedObject = createFeature((AbstractFeature) element);
} else if (element instanceof ReferencedEnvelope) {
encodedObject = createEnvelope((ReferencedEnvelope) element);
} else if (element instanceof EnvelopeOrGeometry) {
EnvelopeOrGeometry geom = (EnvelopeOrGeometry) element;
if (geom.getGeometry().isPresent()) {
encodedObject = createPosition(geom.getGeometry().get(), ctx.get(XmlBeansEncodingFlags.GMLID));
} else if (geom.getEnvelope().isPresent()) {
encodedObject = createEnvelope(geom.getEnvelope().get());
} else {
throw new UnsupportedEncoderInputException(this, element);
}
} else if (element instanceof GenericMetaData) {
encodedObject = createGenericMetaData((GenericMetaData) element, ctx);
} else {
throw new UnsupportedEncoderInputException(this, element);
}
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class GmlEncoderv311 method createFeature.
private XmlObject createFeature(AbstractFeature sosAbstractFeature) throws EncodingException {
if (sosAbstractFeature instanceof SamplingFeature) {
SamplingFeature sampFeat = (SamplingFeature) sosAbstractFeature;
if (sosAbstractFeature.isSetGmlID()) {
FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
featureProperty.setHref("#" + sosAbstractFeature.getGmlId());
return featureProperty;
} else {
if (!sampFeat.isSetGeometry()) {
FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
featureProperty.setHref(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue());
if (sampFeat.isSetName()) {
featureProperty.setTitle(sampFeat.getFirstName().getValue());
}
return featureProperty;
}
StringBuilder builder = new StringBuilder();
builder.append("sf_");
builder.append(JavaHelper.generateID(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue()));
sosAbstractFeature.setGmlId(builder.toString());
Encoder<XmlObject, SamplingFeature> encoder = getEncoder(SfConstants.NS_SA, sampFeat);
return encoder.encode(sampFeat);
}
} else if (sosAbstractFeature instanceof FeatureCollection) {
return createFeatureCollection((FeatureCollection) sosAbstractFeature);
}
throw new UnsupportedEncoderInputException(this, sosAbstractFeature);
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class GmlEncoderv321 method createPosition.
private XmlObject createPosition(Geometry geom, EncodingContext ctx) throws EncodingException {
String foiId = ctx.<String>get(XmlBeansEncodingFlags.GMLID).orElse(null);
if (geom instanceof Point) {
PointType xbPoint = PointType.Factory.newInstance(getXmlOptions());
xbPoint.setId(getGmlID(geom, foiId));
createPointFromJtsGeometry((Point) geom, xbPoint);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
PointDocument xbPointDoc = PointDocument.Factory.newInstance(getXmlOptions());
xbPointDoc.setPoint(xbPoint);
return xbPointDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbPoint);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POINT_32, PointType.type);
return geometryPropertyType;
}
return xbPoint;
} else if (geom instanceof LineString) {
LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
xbLineString.setId(getGmlID(geom, foiId));
createLineStringFromJtsGeometry((LineString) geom, xbLineString);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
LineStringDocument xbLineStringDoc = LineStringDocument.Factory.newInstance(getXmlOptions());
xbLineStringDoc.setLineString(xbLineString);
return xbLineStringDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbLineString);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_LINESTRING_32, LineStringType.type);
return geometryPropertyType;
}
return xbLineString;
} else if (geom instanceof MultiLineString) {
MultiCurveType xbMultiCurve = MultiCurveType.Factory.newInstance(getXmlOptions());
xbMultiCurve.setId(getGmlID(geom, foiId));
xbMultiCurve.setSrsName(getSrsName(geom));
for (int i = 0; i < geom.getNumGeometries(); ++i) {
Geometry lineString = geom.getGeometryN(i);
LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
xbLineString.setId(getGmlID(geom, foiId));
xbLineString.addNewPosList().setStringValue(JTSHelper.getCoordinatesString(lineString));
CurvePropertyType xbCurveMember = xbMultiCurve.addNewCurveMember();
xbCurveMember.addNewAbstractCurve().set(xbLineString);
XmlHelper.substituteElement(xbCurveMember.getAbstractCurve(), xbLineString);
}
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
MultiCurveDocument xbMultiCurveDoc = MultiCurveDocument.Factory.newInstance(getXmlOptions());
xbMultiCurveDoc.setMultiCurve(xbMultiCurve);
return xbMultiCurveDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType xbGeometryProperty = GeometryPropertyType.Factory.newInstance(getXmlOptions());
xbGeometryProperty.addNewAbstractGeometry().set(xbMultiCurve);
XmlHelper.substituteElement(xbGeometryProperty.getAbstractGeometry(), xbMultiCurve);
return xbGeometryProperty;
} else {
return xbMultiCurve;
}
} else if (geom instanceof Polygon) {
PolygonType xbPolygon = PolygonType.Factory.newInstance(getXmlOptions());
xbPolygon.setId(getGmlID(geom, foiId));
createPolygonFromJtsGeometry((Polygon) geom, xbPolygon);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
PolygonDocument xbPolygonDoc = PolygonDocument.Factory.newInstance(getXmlOptions());
xbPolygonDoc.setPolygon(xbPolygon);
return xbPolygonDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbPolygon);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POLYGON_32, PolygonType.type);
return geometryPropertyType;
}
return xbPolygon;
} else if (geom instanceof MultiPoint) {
MultiPointType xbMultiPoint = MultiPointType.Factory.newInstance(getXmlOptions());
String id = getGmlID(geom, foiId);
xbMultiPoint.setId(id);
createMultiPointFromJtsGeometry((MultiPoint) geom, xbMultiPoint, id);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
MultiPointDocument xbMultiPointDoc = MultiPointDocument.Factory.newInstance(getXmlOptions());
xbMultiPointDoc.setMultiPoint(xbMultiPoint);
return xbMultiPointDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbMultiPoint);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_MULTI_POINT_32, PolygonType.type);
return geometryPropertyType;
}
return xbMultiPoint;
} else {
throw new UnsupportedEncoderInputException(this, geom);
}
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class InsertFeatureOfInterestEncoder method create.
@Override
protected XmlObject create(InsertFeatureOfInterestResponse ifoir) throws EncodingException {
if (ifoir == null) {
throw new UnsupportedEncoderInputException(this, InsertFeatureOfInterestResponse.class);
}
InsertFeatureOfInterestResponseDocument ifoird = InsertFeatureOfInterestResponseDocument.Factory.newInstance(getXmlOptions());
ifoird.addNewInsertFeatureOfInterestResponse();
return ifoird;
}
Aggregations