Function | AllegroGraph 9.0.1
Author: Franz Incorporated

Copyright (c) 2005 - 2026 Franz, Incorporated
Last updated 27 May 2026 at 10:35

# SPARQL Function

- Documentation Index
  - Release Notes
  - Quick Start
  - SSL/TLS Quick Start
  - Introduction
  - Setup and Configuration
    - Download
    - Server Installation
    - Server Configuration and Control
    - WebView
    - Database Upgrading
    - Managing Users
  - Server Management
    - Performance Tuning
    - Deleting Duplicate Triples
    - Purging Deleted Triples
    - Auditing
    - Managing Users
    - Replication
    - Point-in-Time Recovery
    - Transaction Log Archiving
    - Security Overview
    - Security Implementation
  - Tools
    - agtool
    - Data Loading
    - Data Export
    - Backup and Restore
    - Querying
    - RDFS++
    - Materializer
    - Event Scheduler
    - SHACL
  - Details
    - Triple Indices
    - Freetext Indices
    - Encoded IDs
    - Connection Pooling
    - N-dimensional Geospatial Overview
    - 2-D Geospatial
    - Temporal
    - Social Network
    - JavaScript
    - Datatypes
    - Data Conversion (Rapper)
    - Stored Procedures
    - Triple Attributes
    - Lineparse Format
  - Querying
    - SPARQL documentation summary
    - SPARQL Reference
    - SPIN
    - SPARQL Magic Properties
    - Prolog
  - 3rd-party tools
    - Solr text Indices
    - MongoDB integration
    - TopBraid Composer Plugin
    - Cloudera
  - Client APIs
    - Gruff
    - GraphTalker
    - REST/HTTP interface
    - HTTP reference
    - Javadocs (Sesame and Jena)
    - Python API
    - Lisp Reference
    - JavaScript
  - Tutorials
    - N-dimensional Geospatial
    - SPARQL Tutorial
    - Java Sesame
    - Java Jena
    - Python Sesame
    - Lisp
    - Prolog
    - More...
  - Other
    - Conferences and Seminars
    - Source Code on Github
    - Amazon EC2
    - Copyrights
  - Franz, Inc.

## http://franz.com/ns/allegrograph/5.0/geo/nd/fn#haversineLatLonLatLon

Returns the haversine distance between <`lat1`, `lon1`> and <`lat2`, `lon2`>. `lat1`, `lon1`, `lat2`, and `lon2` specify two points in spherical coordinates and must be bound to numeric values.

For example:

    PREFIX ndfn: <http://franz.com/ns/allegrograph/5.0/geo/nd/fn#>
    PREFIX :     <http://franz.com/ns/keyword#>
    SELECT * \{
      bind(ndfn:haversineLatLonLatLon(38.889, -77.035, 38.889, -77.050, :km) as ?distance)
    \}

An optional fifth argument may be http://franz.com/ns/keyword#km (default) or http://franz.com/ns/keyword#miles to specify the units of the result.

## http://franz.com/ns/allegrograph/5.0/geo/nd/fn#haversineLatLonLoc

Returns the haversine distance between <`lat`, `lon`> and the location specified by the nD encoded literal `loc`. `lat` and `lon` must be bound to numeric values, and the datatype encoding of `loc` must have one :latitude and one :longitude type ordinate.

For example:

    PREFIX ndfn: <http://franz.com/ns/allegrograph/5.0/geo/nd/fn#>
    PREFIX ex:   <http://ex.com/>
    PREFIX :     <http://franz.com/ns/keyword#>
    SELECT ?distance \{
      ex:WashingtonMonument ex:location ?loc .
      bind(ndfn:haversineLatLonLoc(38.889, -77.035, ?loc, :miles) as ?distance)
    \}

An optional fourth argument may be http://franz.com/ns/keyword#km (default) or http://franz.com/ns/keyword#miles to specify the units of the result.

## http://franz.com/ns/allegrograph/5.0/geo/nd/fn#haversineLocLoc

Returns the haversine distance between `loc1` and `loc2` which must be nD encoded literals.. The nD encoding datatypes of `loc1` and `loc2` need not be the same, but each must have one :latitude and one :longitude type ordinate.

For example:

    PREFIX ndfn: <http://franz.com/ns/allegrograph/5.0/geo/nd/fn#>
    PREFIX ex:   <http://ex.com/>
    SELECT ?distance \{
      ex:WashingtonMonument ex:location ?loc1 .
      ex:LincolnMemorial    ex:location ?loc2 .
      bind(ndfn:haversineLocLoc(?loc1, ?loc2) as ?distance)
    \}

An optional third argument may be http://franz.com/ns/keyword#km (default) or http://franz.com/ns/keyword#miles to specify the units of the result.

## http://franz.com/ns/allegrograph/5.0/geo/nd/fn#ordinateValue

Returns the value of a named ordinate from an n-Dimensionally encoded literal.

For example, if ?point is bound to an n-Dimensionally encoded literal, then the following expression would retrieve the value of the ordinate named latitude:

    bind(ndfn:ordinateValue(?point, :latitude) as ?lat)

Note that this assumes the usual default namespaces and that ?point has been bound previously in the query.

## http://franz.com/ns/allegrograph/5.0/geo/nd/fn#ordinatesToValue

Encodes a list of keys and values into an n-Dimensional literal.

For example, if http://example.com/phone-calls#phoneCallTargetLocation is an n-Dimensional subtype defined with time, latitude, and longitude, then the following expression would encode the tuple into the literal bound to ?plist:

    bind(ndfn:ordinatesToValue(
      <http://example.com/phone-calls#phoneCallTargetLocation>,
      :time, ?time, :longitude, 37.8, :longitude, -122.5) as ?plist)

Note that this assumes the usual default namespaces and that ?time has been bound previously in the query.

### Notes

The following namespace abbreviations are used:

- fti - <http://franz.com/ns/allegrograph/2.2/textindex/>
- geo - <http://franz.com/ns/allegrograph/3.0/geospatial/>
- geofn - <http://franz.com/ns/allegrograph/3.0/geospatial/fn/>
- nd - <http://franz.com/ns/allegrograph/5.0/geo/nd#>
- ndfn - <http://franz.com/ns/allegrograph/5.0/geo/nd/fn#>
- sna - <http://franz.com/ns/allegrograph/4.11/sna/>

The SPARQL magic properties reference has additional information on using AllegroGraph magic properties and functions.