Skip to content

Commit

Permalink
Merge pull request #4 from janschulte/feature/coding-improvements
Browse files Browse the repository at this point in the history
Feature/coding improvements
  • Loading branch information
CarstenHollmann authored May 4, 2017
2 parents f9f923f + f0311d0 commit 26e52dd
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 12 deletions.
44 changes: 32 additions & 12 deletions xmlbeans/src/main/java/org/n52/svalbard/decode/GmlDecoderv321.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
import net.opengis.gml.x32.VerticalDatumPropertyType;

import com.vividsolutions.jts.io.ParseException;
import net.opengis.gml.x32.FeatureCollectionDocument;
import net.opengis.gml.x32.FeatureCollectionType;
import org.n52.shetland.ogc.gml.AbstractFeature;
import org.n52.shetland.ogc.om.features.FeatureCollection;

/**
* @since 4.0.0
Expand All @@ -96,8 +100,8 @@ public class GmlDecoderv321 extends AbstractGmlDecoderv321<XmlObject, Object> {
EnvelopeType.class, TimeInstantType.class, TimePeriodType.class, TimeInstantDocument.class,
TimePeriodDocument.class, ReferenceType.class, MeasureType.class, PointType.class, PointDocument.class,
LineStringType.class, PolygonType.class, CompositeSurfaceType.class, CodeWithAuthorityType.class,
CodeType.class, FeaturePropertyType.class, GeometryPropertyType.class, VerticalDatumPropertyType.class

CodeType.class, FeaturePropertyType.class, GeometryPropertyType.class, VerticalDatumPropertyType.class,
FeatureCollectionDocument.class, FeatureCollectionType.class
), CodingHelper.decoderKeysForElements(MeasureType.type.toString(), MeasureType.class));

private static final String CS = ",";
Expand Down Expand Up @@ -154,6 +158,10 @@ public Object decode(XmlObject xmlObject) throws DecodingException {
return parseGeometryPropertyType((GeometryPropertyType) xmlObject);
} else if (xmlObject instanceof VerticalDatumPropertyType) {
return parseVerticalDatumPropertyType((VerticalDatumPropertyType) xmlObject);
} else if (xmlObject instanceof FeatureCollectionDocument) {
return parseFeatureCollectionDocument((FeatureCollectionDocument) xmlObject);
} else if (xmlObject instanceof FeatureCollectionType) {
return parseFeatureCollectionType((FeatureCollectionType) xmlObject);
} else {
throw new UnsupportedDecoderXmlInputException(this, xmlObject);
}
Expand Down Expand Up @@ -203,6 +211,19 @@ private Object parseFeaturePropertyType(FeaturePropertyType featurePropertyType)
return feature;
}

private FeatureCollection parseFeatureCollectionDocument(FeatureCollectionDocument featureCollectionDocument) throws DecodingException {
return parseFeatureCollectionType(featureCollectionDocument.getFeatureCollection());
}

private FeatureCollection parseFeatureCollectionType(FeatureCollectionType featureCollectionType) throws DecodingException {
final FeatureCollection feaColl = new FeatureCollection();
for (FeaturePropertyType feaPropType : featureCollectionType.getFeatureMemberArray()) {
Object decoded = decodeXmlElement(feaPropType);
feaColl.addMember((AbstractFeature) decoded);
}
return feaColl;
}

/**
* parses the BBOX element of the featureOfInterest element contained in the
* GetObservation request and returns a String representing the BOX in
Expand Down Expand Up @@ -334,11 +355,8 @@ private Object parsePointType(PointType xbPointType) throws DecodingException {
+ "'gml:pos' and 'gml:coordinates' are allowed " + "in the feature of interest parameter!");
}

checkSrid(srid);
if (srid == -1) {
throw new DecodingException("No SrsName ist specified for geometry!");
}

srid = setDefaultForUnsetSrid(srid);

try {
return JTSHelper.createGeometryFromWKT(geomWKT, srid);
} catch (ParseException ex) {
Expand All @@ -363,7 +381,7 @@ private Object parseLineStringType(LineStringType xbLineStringType) throws Decod
}
String geomWKT = "LINESTRING" + positions.toString() + "";

checkSrid(srid);
srid = setDefaultForUnsetSrid(srid);

try {
return JTSHelper.createGeometryFromWKT(geomWKT, srid);
Expand Down Expand Up @@ -411,7 +429,7 @@ private Object parsePolygonType(PolygonType xbPolygonType) throws DecodingExcept
geomWKT.append(interiorCoordString);
geomWKT.append(")");

checkSrid(srid);
srid = setDefaultForUnsetSrid(srid);
try {
return JTSHelper.createGeometryFromWKT(geomWKT.toString(), srid);
} catch (ParseException ex) {
Expand Down Expand Up @@ -441,7 +459,7 @@ private Geometry parseCompositeSurfaceType(CompositeSurfaceType xbCompositeSurfa
if (polygons.isEmpty()) {
throw new DecodingException("The FeatureType: %s does not contain any member!", xbCompositeSurface);
}
checkSrid(srid);
srid = setDefaultForUnsetSrid(srid);
GeometryFactory factory = new GeometryFactory();
Geometry geom = factory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
geom.setSRID(srid);
Expand Down Expand Up @@ -584,9 +602,11 @@ private String getString4Coordinates(CoordinatesType xbCoordinates) {
return coordinateString;
}

private void checkSrid(int srid) throws DecodingException {
private int setDefaultForUnsetSrid(int srid) throws DecodingException {
if (srid == 0 || srid == -1) {
throw new DecodingException("No SrsName is specified for geometry!");
srid = 4326;
LOGGER.warn("No SrsName is specified for geometry, instead the default 4326 is taken!");
}
return srid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2016-2017 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.n52.svalbard.encode;

import org.n52.shetland.ogc.ows.service.OwsServiceRequest;
import org.n52.shetland.ogc.sos.Sos2Constants;
import org.n52.shetland.ogc.sos.SosConstants;
import org.n52.shetland.ogc.swes.SwesConstants;

/**
* @author <a href="mailto:[email protected]">Jan Schulte</a>
*/
public abstract class AbstractSwesRequestEncoder<T extends OwsServiceRequest> extends AbstractRequestEncoder<T> {

public AbstractSwesRequestEncoder(String operation, Class<T> responseType) {
super(SosConstants.SOS, Sos2Constants.SERVICEVERSION, operation, SwesConstants.NS_SWES_20,
SwesConstants.NS_SWES_PREFIX, responseType);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2016-2017 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.n52.svalbard.encode;

import java.util.Collections;
import java.util.Set;
import net.opengis.swes.x20.DescribeSensorDocument;
import net.opengis.swes.x20.DescribeSensorType;
import org.apache.xmlbeans.XmlObject;
import org.n52.shetland.ogc.sos.Sos2Constants;
import org.n52.shetland.ogc.sos.SosConstants;
import org.n52.shetland.ogc.sos.request.DescribeSensorRequest;
import org.n52.shetland.w3c.SchemaLocation;
import org.n52.svalbard.encode.exception.EncodingException;

/**
* @author <a href="mailto:[email protected]">Jan Schulte</a>
*/
public class DescribeSensorV2RequestEncoder extends AbstractSwesRequestEncoder<DescribeSensorRequest> {

public DescribeSensorV2RequestEncoder() {
super(SosConstants.Operations.DescribeSensor.name(), DescribeSensorRequest.class);
}

@Override
protected Set<SchemaLocation> getConcreteSchemaLocations() {
return Collections.emptySet();
}

@Override
protected XmlObject create(DescribeSensorRequest request) throws EncodingException {
DescribeSensorDocument doc = DescribeSensorDocument.Factory.newInstance(getXmlOptions());
DescribeSensorType descSensType = doc.addNewDescribeSensor();
addVersion(descSensType, request);
addService(descSensType, request);
addProcedure(descSensType, request);
addOutputFormat(descSensType, request);
return doc;
}

private void addVersion(DescribeSensorType descSensType, DescribeSensorRequest request) {
if (request.getVersion() != null) {
descSensType.setVersion(request.getVersion());
} else {
descSensType.setVersion(Sos2Constants.SERVICEVERSION);
}
}

private void addService(DescribeSensorType descSensType, DescribeSensorRequest request) {
if (request.getService() != null) {
descSensType.setService(request.getService());
} else {
descSensType.setService(SosConstants.SOS);
}
}

private void addProcedure(DescribeSensorType descSensType, DescribeSensorRequest request) {
descSensType.setProcedure(request.getProcedure());
}

private void addOutputFormat(DescribeSensorType descSensType, DescribeSensorRequest request) {
descSensType.setProcedureDescriptionFormat(request.getProcedureDescriptionFormat());
}

}

0 comments on commit 26e52dd

Please sign in to comment.