use of org.opengis.util.FactoryException in project jena by apache.
the class UnionFF method exec.
@Override
public NodeValue exec(NodeValue v1, NodeValue v2) {
try {
GeometryWrapper geometry1 = GeometryWrapper.extract(v1, GeometryIndex.PRIMARY);
GeometryWrapper geometry2 = GeometryWrapper.extract(v2, GeometryIndex.SECONDARY);
GeometryWrapper union = geometry1.union(geometry2);
return union.asNodeValue();
} catch (DatatypeFormatException ex) {
throw new ExprEvalException(ex.getMessage(), ex);
} catch (FactoryException | MismatchedDimensionException | TransformException ex) {
throw new ExprEvalException(ex.getMessage() + ": " + FmtUtils.stringForNode(v1.asNode()) + ", " + FmtUtils.stringForNode(v2.asNode()), ex);
}
}
use of org.opengis.util.FactoryException in project jena by apache.
the class SpatialIndex method getGeometryLiteralIndexItems.
/**
* @param model
* @param srsURI
* @return GeometryLiteral items prepared for adding to SpatialIndex.
* @throws SpatialIndexException
*/
private static Collection<SpatialIndexItem> getGeometryLiteralIndexItems(Model model, String srsURI) throws SpatialIndexException {
List<SpatialIndexItem> items = new ArrayList<>();
StmtIterator stmtIt = model.listStatements(null, Geo.HAS_GEOMETRY_PROP, (Resource) null);
while (stmtIt.hasNext()) {
Statement stmt = stmtIt.nextStatement();
Resource feature = stmt.getSubject();
Resource geometry = stmt.getResource();
ExtendedIterator<RDFNode> nodeIter = model.listObjectsOfProperty(geometry, Geo.HAS_SERIALIZATION_PROP);
if (!nodeIter.hasNext()) {
NodeIterator wktNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_WKT_PROP);
NodeIterator gmlNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_GML_PROP);
nodeIter = wktNodeIter.andThen(gmlNodeIter);
}
while (nodeIter.hasNext()) {
Literal geometryLiteral = nodeIter.next().asLiteral();
GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometryLiteral);
try {
// Ensure all entries in the target SRS URI.
GeometryWrapper transformedGeometryWrapper = geometryWrapper.convertSRS(srsURI);
Envelope envelope = transformedGeometryWrapper.getEnvelope();
SpatialIndexItem item = new SpatialIndexItem(envelope, feature);
items.add(item);
} catch (FactoryException | MismatchedDimensionException | TransformException ex) {
throw new SpatialIndexException("Transformation Exception: " + geometryLiteral + ". " + ex.getMessage());
}
}
}
return items;
}
use of org.opengis.util.FactoryException in project jena by apache.
the class SearchEnvelope method build.
public static SearchEnvelope build(GeometryWrapper geometryWrapper, SRSInfo srsInfo, double radius, String unitsURI) {
try {
// Get the envelope of the target GeometryWrapper and convert to SRS URI, in case it is a complex polygon.
GeometryWrapper envelopeGeometryWrapper = geometryWrapper.envelope();
// Convert to SRS URI.
GeometryWrapper srsGeometryWrapper = envelopeGeometryWrapper.convertSRS(srsInfo.getSrsURI());
Envelope envelope = srsGeometryWrapper.getEnvelope();
// Expand the envelope by the radius distance in all directions,
// i.e. a bigger box rather than circle. More precise checks made later.
SearchEnvelope searchEnvelope;
if (srsInfo.isGeographic()) {
double radiusMetres = UnitsOfMeasure.convertToMetres(radius, unitsURI, srsGeometryWrapper.getLatitude());
searchEnvelope = expandGeographicEnvelope(envelope, radiusMetres, srsInfo);
} else {
String targetUnitsURI = srsInfo.getUnitsOfMeasure().getUnitURI();
double targetRadius = UnitsOfMeasure.conversion(radius, unitsURI, targetUnitsURI);
searchEnvelope = expandEnvelope(envelope, targetRadius, srsInfo);
}
return searchEnvelope;
} catch (FactoryException | MismatchedDimensionException | TransformException ex) {
throw new ExprEvalException(ex.getMessage() + ": " + geometryWrapper.asLiteral(), ex);
}
}
use of org.opengis.util.FactoryException in project jena by apache.
the class TransformSRSFF method exec.
@Override
public NodeValue exec(NodeValue v1, NodeValue v2) {
try {
if (!(v2.isIRI() || v2.isString())) {
throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(v2.asNode()));
}
String srsURI;
if (v2.isIRI()) {
srsURI = v2.asNode().getURI();
} else {
srsURI = v2.asString();
}
GeometryWrapper geometry = GeometryWrapper.extract(v1, GeometryLiteralIndex.GeometryIndex.PRIMARY);
GeometryWrapper convertedGeom = geometry.transform(srsURI);
return convertedGeom.asNodeValue();
} catch (DatatypeFormatException | TransformException | FactoryException ex) {
throw new ExprEvalException(ex.getMessage(), ex);
}
}
use of org.opengis.util.FactoryException in project jena by apache.
the class SRSRegistryTest method testGetDefaultWKTCRS.
/**
* Test of getCRS method, of class SRSRegistry.
*/
@Test
public void testGetDefaultWKTCRS() {
try {
String srsURI = SRS_URI.DEFAULT_WKT_CRS84;
String default_CRS_WKT = "GeodeticCRS[\"WGS 84\",\n" + " Datum[\"World Geodetic System 1984\",\n" + " Ellipsoid[\"WGS 84\", 6378137.0, 298.257223563]],\n" + " CS[ellipsoidal, 2],\n" + " Axis[\"Geodetic longitude (Lon)\", east],\n" + " Axis[\"Geodetic latitude (Lat)\", north],\n" + " Unit[\"degree\", 0.017453292519943295],\n" + " Scope[\"Horizontal component of 3D system. Used by the GPS satellite navigation system and for NATO military geodetic surveying.\"],\n" + " Area[\"World.\"],\n" + " BBox[-90.00, -180.00, 90.00, 180.00],\n" + " Id[\"CRS\", 84, Citation[\"WMS\"], URI[\"urn:ogc:def:crs:OGC:1.3:CRS84\"]]]";
CoordinateReferenceSystem expResult = CRS.fromWKT(default_CRS_WKT);
CoordinateReferenceSystem result = SRSRegistry.getCRS(srsURI);
assertEquals(expResult.toWKT(), result.toWKT());
} catch (FactoryException ex) {
}
}
Aggregations