# functions documentation - geovistory/wiki Wiki

# Documentation

An implementation of GeoSPARQL 1.0 standard for SPARQL query or API.

Integration with Fuseki is provided either by using the GeoSPARQL assembler or using the self-contained original jena-fuseki-geosparql. In either case, this page describes the GeoSPARQL supported features.

## Measurement units

(Source : Apache Jena GeoSPARQL)

Measurement units use the OGC Units of Measure 1.0 vocabulary

The following table gives some examples of units that are supported (additional
units can be added to the `UnitsRegistry`

using the `javax.measure.Unit`

API.
These URI are all in the namespace `http://www.opengis.net/def/uom/OGC/1.0/`

and
here use the prefix `units`

.

URI | Description |
---|---|

units:kilometre or units:kilometer | Kilometres |

units:metre or units:meter | Metres |

units:mile or units:statuteMile | Miles |

units:degree | Degrees |

units:radian | Radians |

Full listing of default Units can be found in
`org.apache.jena.geosparql.implementation.vocabulary.Unit_URI`

.

## Spatial and geometry property functions

Original documentation (before integration into Jena): galbiston / geosparql-jena

### Apache Jena Spatial Functions/WGS84 Geo Predicates

The `jena-spatial`

module contains several SPARQL functions for querying datasets using the WGS84 Geo predicates for latitude (`http://www.w3.org/2003/01/geo/wgs84_pos#lat`

) and longitude (`http://www.w3.org/2003/01/geo/wgs84_pos#long`

).
These `jena-spatial`

functions are supported for both Geo
predicates and Geometry Literals, i.e. a GeoSPARQL dataset.
Additional SPARQL filter functions have been provided to convert Geo
predicate properties into WKT strings and calculate Great Circle and
Euclidean distances.

#### Supported Features

The Geo predicate form of spatial representation is
restricted to only 'Point' shapes in the WGS84 spatial/coordinate
reference system.
The Geo predicates are properties of the `Feature`

and do not use the properties and structure of the GeoSPARQL standard, including Geometry Literals.
Methods are available to convert datasets from Geo predicates to GeoSPARQL structure, see: `io.github.galbiston.geosparql_jena.configuration.GeoSPARQLOperations`

The spatial relations and query re-writing of GeoSPARQL outlined previously has been implemented for Geo predicates.
However, only certain spatial relations are valid for `Point`

to `Point`

relationships.
Refer to pages 8-10 of 11-052r4 GeoSPARQL standard for more details.

Geo predicates can be converted to Geometry Literals in query and then used with the GeoSPARQL filter functions.

```
?subj wgs:lat ?lat .
?subj wgs:long ?lon .
BIND(spatialF:convertLatLon(?lat, ?lon) as ?point) .
BIND("POLYGON((...))"^^<http://www.opengis.net/ont/geosparql#wktLiteral> AS ?box) . #Coordinate order is Lon/Lat without stated SRS URI.
FILTER(geof:sfContains(?box, ?point))
```

Alternatively, utilising more shapes, relations and spatial reference systems can be achieved by converting the dataset to the GeoSPARQL structure.

```
?subj geo:hasGeometry ?geom .
?geom geo:hasSerialization ?geomLit .
BIND("POLYGON((...))"^^<http://www.opengis.net/ont/geosparql#wktLiteral> AS ?box) . #Coordinate order is Lon/Lat without stated SRS URI.
FILTER(geof:sfContains(?box, ?geomLit))
```

Datasets can contain both Geo predicates and Geometry Literals without interference.
However, a dataset containing both types will only examine those `Features`

which have Geometry Literals for spatial relations, i.e. the check for
Geo predicates is a fallback when Geometry Literals aren't found.
Therefore, it is **not** recommended to insert new Geo
predicate properties after a dataset has been converted to GeoSPARQL
structure (unless corresponding Geometry and Geometry Literals are
included).

#### Filter Functions

These filter functions are available in the **`http://jena.apache.org/function/spatial#`

namespace** and here use the prefix `spatialF`

.

Function Name | Description |
---|---|

?wktString spatialF:convertLatLon(?lat, ?lon) | Converts Lat and Lon double values into WKT string of a Point with WGS84 SRS. |

?wktString spatialF:convertLatLonBox(?latMin, ?lonMin, ?latMax, ?lonMax) | Converts Lat and Lon double values into WKT string of a Polygon forming a box with WGS84 SRS. |

?boolean spatialF:equals(?geomLit1, ?geomLit2) | True, if geomLit1 is spatially equal to geomLit2. |

?boolean spatialF:nearby(?geomLit1, ?geomLit2, ?distance, ?unitsURI) | True, if geomLit1 is within distance of geomLit2 using the distance units. |

?boolean spatialF:withinCircle(?geomLit1, ?geomLit2, ?distance, ?unitsURI) | True, if geomLit1 is within distance of geomLit2 using the distance units. |

?radians spatialF:angle(?x1, ?y1, ?x2, ?y2) | Angle clockwise from y-axis from Point(x1,y1) to Point (x2,y2) in 0 to 2π radians. |

?degrees spatialF:angleDeg(?x, ?y1, ?x2, ?y2) | Angle clockwise from y-axis from Point(x1,y1) to Point (x2,y2) in 0 to 360 degrees. |

?distance spatialF:distance(?geomLit1, ?geomLit2, ?unitsURI) | Distance between two Geometry Literals in distance units. Chooses distance measure based on SRS type. Great Circle distance for Geographic SRS and Euclidean otherwise. |

?radians spatialF:azimuth(?lat1, ?lon1, ?lat2, ?lon2) | Forward azimuth clockwise from North between two Lat/Lon Points in 0 to 2π radians. |

?degrees spatialF:azimuthDeg(?lat1, ?lon1, ?lat2, ?lon2) | Forward azimuth clockwise from North between two Lat/Lon Points in 0 to 360 degrees. |

?distance spatialF:greatCircle(?lat1, ?lon1, ?lat2, ?lon2, ?unitsURI) | Great Circle distance (Vincenty formula) between two Lat/Lon Points in distance units. |

?distance spatialF:greatCircleGeom(?geomLit1, ?geomLit2, ?unitsURI) | Great Circle distance (Vincenty formula) between two Geometry Literals in distance units. Use http://www.opengis.net/def/function/geosparql/distance from GeoSPARQL standard for Euclidean distance. |

?geomLit2 spatialF:transform(?geomLit1, ?datatypeURI, ?srsURI) | Transform Geometry Literal by Datatype and SRS. |

?geomLit2 spatialF:transformDatatype(?geomLit1, ?datatypeURI) | Transform Geometry Literal by Datatype. |

?geomLit2 spatialF:transformSRS(?geomLit1, ?srsURI) | Transform Geometry Literal by SRS. |

A dataset that follows the GeoSPARQL
Feature-Geometry-GeometryLiteral can have simpler SPARQL queries without
needing to use these functions by taking advantage of the Query
Rewriting functionality.
The `geof:isValid`

filter function and `geo:isValid`

property for a Geometry resource are not part of the GeoSPARQL standard but have been included as a minor variation.