org.opengis.cite.iso19136.data.spatial.LineStringTests Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ets-gml32 Show documentation
Show all versions of ets-gml32 Show documentation
Checks GML application schemas or data sets for conformance to ISO 19136:2007.
package org.opengis.cite.iso19136.data.spatial;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.apache.xerces.xs.XSElementDeclaration;
import org.geotoolkit.gml.xml.v321.LineStringType;
import org.geotoolkit.xml.MarshallerPool;
import org.opengis.cite.geomatics.gml.GmlUtils;
import org.opengis.cite.iso19136.data.DataFixture;
import org.opengis.cite.iso19136.general.GML32;
import org.opengis.cite.iso19136.util.TestSuiteLogger;
import org.opengis.cite.iso19136.util.XMLSchemaModelUtils;
import org.opengis.cite.iso19136.util.XMLUtils;
import org.opengis.util.FactoryException;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* Validates the content of a gml:LineString element (or any element in its
* substitution group). In GML a LineString is a regarded as a special curve
* that consists of a single (implicit) segment with linear interpolation; it
* must have two or more coordinate tuples. Note that in ISO 19107 a
* GM_LineString is treated as a curve segment, not as a geometry type.
*
* Sources
*
* - ISO 19136:2007, cl. 10.4.4: LineStringType, LineString
* - ISO 19107:2003, cl. 6.4.10: GM_LineString
*
*/
public class LineStringTests extends DataFixture {
NodeList lineNodes;
List lineElems = new ArrayList();
/**
* A configuration method ({@code BeforeClass}) that looks for
* gml:LineString elements in the GML document under test. If none are found
* all test methods defined in the class will be skipped.
*/
@BeforeClass(alwaysRun = true)
public void findLineStrings() {
Source data = new StreamSource(this.dataFile);
this.lineElems.add(new QName(GML32.NS_NAME, GML32.LINE_STRING));
if (null != this.model) {
XSElementDeclaration gmlCurve = this.model.getElementDeclaration(
GML32.LINE_STRING, GML32.NS_NAME);
List lineDecls = XMLSchemaModelUtils
.getElementsByAffiliation(this.model, gmlCurve);
for (XSElementDeclaration decl : lineDecls) {
this.lineElems.add(new QName(decl.getNamespace(), decl
.getName()));
}
}
Map namespaceBindings = new HashMap();
String xpath = generateXPathExpression(this.lineElems,
namespaceBindings);
try {
this.lineNodes = (NodeList) XMLUtils.evaluateXPath(data, xpath,
namespaceBindings, XPathConstants.NODESET);
} catch (XPathExpressionException xpe) { // won't happen
throw new RuntimeException(xpe);
}
if (this.lineNodes.getLength() == 0) {
throw new SkipException("No gml:Curve elements were found.");
}
}
/**
* [{@code Test}] Verifies that a gml:LineString element has a valid CRS
* reference.
*
* Sources
*
* - ISO 19136, cl. 9.10, 10.1.3.2
* - ISO 19107, cl. 6.2.2.17 (Coordinate Reference System association)
*
*/
@Test(description = "See ISO 19136: 9.10, 10.1.3.2; ISO 19107: 6.2.2.17")
public void lineHasValidCRS() {
for (int i = 0; i < this.lineNodes.getLength(); i++) {
Element geom = (Element) this.lineNodes.item(i);
GeometryAssert.assertValidCRS(geom);
}
}
/**
* [{@code Test}] Verifies that a gml:LineString element contains at least
* two coordinate tuples and that it lies within the valid area of the CRS.
*
* Sources
*
* - ISO 19136, 10.4.4: LineStringType, LineString
*
*/
@Test(description = "See ISO 19136: 10.4.4")
public void validLineString() throws DOMException, FactoryException {
Unmarshaller gmlUnmarshaller;
try {
MarshallerPool pool = new MarshallerPool(
"org.geotoolkit.gml.xml.v321");
gmlUnmarshaller = pool.acquireUnmarshaller();
} catch (JAXBException jxe) {
throw new RuntimeException(jxe);
}
for (int i = 0; i < this.lineNodes.getLength(); i++) {
Element lineElem = (Element) this.lineNodes.item(i);
GmlUtils.findCRSReference(lineElem);
GeometryAssert.assertAllCurveSegmentsHaveRequiredLength(lineElem);
LineStringType line;
try {
JAXBElement result = gmlUnmarshaller.unmarshal(
lineElem, LineStringType.class);
line = result.getValue();
} catch (JAXBException e) {
TestSuiteLogger.log(Level.WARNING,
"Failed to unmarshal LineString geometry.", e);
continue;
}
GeometryAssert.assertGeometryCoveredByValidArea(line);
}
}
}