You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Markus Neumann <mn...@meteomatics.com> on 2018/08/24 09:47:59 UTC

Spatial distance in Fuseki

Hi,

I'm quite new to both Fuseki and mailinglists, so please be patient with me.

I've managed to set up a Fuseki 2 server together with a Lucene spatial index.
E.g the following query works as expected:

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
PREFIX mm: <http://rdf.meteomatics.com/mm/>
PREFIX spatial: <http://jena.apache.org/spatial#>
SELECT *
WHERE {
  ?loc spatial:nearby (47.5 8.5 5 'km') .
  ?loc a mm:Location;
       geo:lat ?lat;
       geo:long ?long;
       geosparql:asWKT ?wkt;
       mm:station_name ?name.
}

Now I would like to run the following:

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
PREFIX mm: <http://rdf.meteomatics.com/mm/>
PREFIX spatial: <http://jena.apache.org/spatial#>
PREFIX ogcf: <http://www.opengis.net/rdf/functions#>
SELECT ?distance WHERE {
  BIND(mm-locations:8515451 as ?wil)
  ?wil spatial:nearby(?lat ?lon 8 'km') .
  ?wil geosparql:asWKT ?wil_wkt .
  ?loc a mm:Location;
       geo:lat ?lat;
       geo:long ?lon;
       geosparql:asWKT ?wkt.
  BIND( ogcf:distance(?wil_wkt, ?wkt, 'km') as ?distance)
} 

The query completes and gets the correct amount of results, but all wihout value.
In the log pops up this message:

[2018-08-24 09:45:33] exec       WARN  URI <http://www.opengis.net/rdf/functions#distance> has no registered function factory

Is there a way to get this to work? Or is there another way to compute spatial distances?

Many thanks for your time.

Best regards
Markus


RE: GeoSPARQL modules Was: Spatial distance in Fuseki

Posted by Greg Albiston <gr...@hotmail.com>.
Hi,

I'll try to address all the points that have come up so far below.
It's not clear to me whether JTS can be used with Apache SIS for point 3 and perhaps Martin can help?

If Apache SIS does integrate with JTS then a switch away from GeoTools should be possible.
However, I can't find any examples or documentation explaining this for Apache SIS.

Thanks,

Greg

"Are your modules "pure" functions (i.e. agnostic to backend) or do they take advantage of Jena's spatial index module?"
- The Property and Filter functions are agnostic to the backend. There is no use of jena-spatial as it was intended to be used with minimal upfront setup (no index building) and configuration (one line of code). Pre-calculation of the pairwise results across all 24 spatial relations (some are equivalent) also seemed very heavy when many/most may not be required by a user, so upfront index building/loading was avoided. There is in-memory caching of recently parsed geometry literals or likely re-used information (e.g. Coordinate Reference System (CRS) descriptions, CRS transformations). This reduces the parsing and allows use of the optimised JTS Prepared Geometry for spatial relations.

"JTS now that is available under EDL form is OK."
- The latest version 1.15 (org.locationtech.jts-core) is licenced under EDL/EPL but the current GeoTools is using 1.14 (com.vividsolutions.jts-core) under LGPL. The next version of GeoTools is due to make the switch across (https://osgeo-org.atlassian.net/browse/GEOT-5954) so until that is released both projects are LGPL. When the new version of GeoTools is released I'll upgrade.

Apache SIS replacing GeoTools
- The functionality provided by GeoTools seems to be covered by Apache SIS. However, the relevant sections of the Developer Guide (http://sis.apache.org/book/en/developer-guide.html#GetCRS) are marked as TODO. The main requirements fulfilled by GeoTools are:

1) Look up CRS from authority by URI.
2) Look up math transformation between source and target CRS.
3) Apply the math transformation to a source Geometry to produce a target Geometry (i.e. JTS Geometry).
4) Provide unit of measures (GeoTools uses javax.measure.unit) support derived from the CRS to allow conversions of distances (SI and non-SI units).

-----Original Message-----
From: Andy Seaborne <an...@apache.org> 
Sent: 27 August 2018 12:08
To: users@jena.apache.org
Subject: Re: GeoSPARQL modules Was: Spatial distance in Fuseki

Yes - this sounds very interesting. I can help with moving this forward, as either contribution or extending project.  There is something to be said for starting separately (release is not coupled to Jena release
cycles) then contribute if you want to go that route.

It would be useful whether it has index support or not.

JTS now that is available under EDL form is OK. IIRC when jena-spatial was done, it was LGPL so it had to be an optional extra.

The LGPL for GeoTools is something to work on but it can be done.

Is there anything in the Eclipse location domain that can provide some of what GeoTools is used for? If so, geotools can be an optional extra which is the normal way to deal with the situation.

     Andy

Someone recently collected all the Apache projects logos and created the "powered by" versions:

https://www.apache.org/logos/comdev-test/poweredby/jena.png

On 24/08/18 19:38, ajs6f wrote:
> Greg--
> 
> That sounds like a great contribution, although it might indeed make a lot of sense as a sidecar module, or even built up as a package with Fuseki and jena-spatial. Are your modules "pure" functions (i.e. agnostic to backend) or do they take advantage of Jena's spatial index module?
> 
> JTS is Eclipse-licensed [1], which (IIUC) should be cool, but GeoTools seems to use LGPL [2], which I believe may present some problems for Jena (which is, of course, licensed as Apache 2.0).
> 
> ajs6f
> 
> [1] https://github.com/locationtech/jts/blob/master/LICENSES.md
> [2] 
> http://docs.geotools.org/latest/userguide/faq.html#q-what-licence-does
> -geotools-use
> 
>> On Aug 24, 2018, at 2:14 PM, Greg Albiston <gr...@hotmail.com> wrote:
>>
>> Hello,
>>
>> Since the topic has come up. I've put together an implementation of all the GeoSPARQL modules which I was getting around to discussing contributing.
>>
>> It has dependencies on JTS, for spatial relations and distances etc., and GeoTools, for coordinate reference system conversions. I think the remainder are Apache dependencies.
>>
>> The only item to implement was additional unit tests.
>>
>> Would this be suitable for incorporating into Jena or better as an extending project?
>>
>> Also, the GeoSPARQL function namespace mentioned by the OP seems incorrect. The published namespace is:
>>
>> geof: http://www.opengis.net/def/function/geosparql/
>>
>> Thanks,
>>
>> Greg
>>
>>
>> From: Andy Seaborne
>> Sent: Friday 24 August, 18:29
>> Subject: Re: Spatial distance in Fuseki
>> To: users@jena.apache.org
>>
>>
>> (PS JENA-664 is the open JIRA for GeoSPARQL) A complete example with 
>> imports etc: 
>> https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and also 
>> below. This is for doing everything in one java program. It is the 
>> simplest way and runs in an IDE for debugging. > My main problems in 
>> understandig are: > - where to put the java code and how to name it 
>> It will have a URI name. From the example below: // Register the 
>> function FunctionRegistry ref = FunctionRegistry.get(); 
>> ref.put("http://my/num", MyFunction.class); using the global function 
>> registry (you can have one uique to the dataset if you want as well 
>> but the joy of globally unique URIs is that putting it the 
>> JVM-registry just works. > - how to include it with Fuseki The 
>> example below is the simplest way using embedded Fuseki. It's a plain 
>> Java program and avoids the need to repack jar files which for 
>> development makes things easier and can be debugged in an IDE. If you 
>> want to create a packaged standalone jar file, this is a a template: 
>> "basic" is a standalone jar using embedded Fuseki and with a command 
>> line interface. 
>> https://github.com/apache/jena/tree/master/jena-fuseki2/jena-fuseki-b
>> asic It makes: 
>> http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html#fus
>> eki-basic so using that, adding your own code and making the command 
>> line start register the function should work. > - how to call it in 
>> the SPARQL query Functions are invoked like: (?Z) which is URI + 
>> arguments. The URI can a prefixed name as well; prefixes and expanded 
>> during parsing and it is the URI that matters. BIND ((?Z) AS ?X ) 
>> FILTER((?Z) = "number") Andy ------------------------ 
>> https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and with 
>> slight reformatting: public class FuFunctionEx { /** Our function */ 
>> public static class MyFunction extends FunctionBase1 { @Override 
>> public NodeValue exec(NodeValue v) { if ( v.isNumber() ) return 
>> NodeValue.makeString("number"); return NodeValue.makeString("not a 
>> number"); } } public static void main(String...a) { 
>> FusekiLogging.setLogging(); // Register the function FunctionRegistry 
>> ref = FunctionRegistry.get(); ref.put("http://my/num", 
>> MyFunction.class); int PORT = FusekiLib.choosePort(); // Some empty 
>> dataset DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); 
>> FusekiServer server = FusekiServer.create() .setPort(PORT) 
>> .add("/ds", dsg) .build(); server.start(); // Test query. String 
>> queryString = StrUtils.strjoinNL( "SELECT * { " , " VALUES ?Z { 123 
>> 'abc'}" , " BIND ((?Z) AS ?X )" ,"}" ); try { String url = 
>> "http://localhost:"+PORT+"/ds"; // Connect to the server and execute 
>> the query. try ( RDFConnection conn = 
>> RDFConnectionFactory.connect(url) ) { // Using Java8 features. 
>> conn.queryResultSet(queryString, ResultSetFormatter::out); // Without 
>> Java8 features try ( QueryExecution qExec = conn.query(queryString) ) 
>> { ResultSet rs = qExec.execSelect(); ResultSetFormatter.out(rs); } } 
>> } catch (Exception ex) { ex.printStackTrace(); } finally { 
>> server.stop(); } } } Andy
>>
> 

Re: GeoSPARQL modules Was: Spatial distance in Fuseki

Posted by Martin Desruisseaux <de...@apache.org>.
Le 28/08/2018 à 00:34, Andy Seaborne a écrit :

> Good to hear from you and about the status of Apache SIS. It would
> make it easier for the end users if there were license commonality.
>
Thanks. Apart from licensing and the "org.opengis" namespace issue, the
choice between GeoTools and Apache SIS may depend on the functionality
you want to use. For referencing by coordinates (map projections) and
metadata, Apache SIS is more advanced. For reading data file (Shapefile,
etc.), GeoTools has more support (but Apache SIS is completed by an
external project).

Martin



Re: GeoSPARQL modules Was: Spatial distance in Fuseki

Posted by Andy Seaborne <an...@apache.org>.
Hi Martin,

Good to hear from you and about the status of Apache SIS. It would make 
it easier for the end users if there were license commonality.

     Andy

On 27/08/18 14:13, Martin Desruisseaux wrote:
>
> Hello Andy, Greg and all
>
>>> It has dependencies on JTS, for spatial relations and distances 
>>> etc., and GeoTools, for coordinate reference system conversions.
>>>
> Sorry to jump in the middle of the discussion; I would like to 
> introduce some elements in case they are worth consideration. An 
> alternative to GeoTools for coordinate operations is Apache Spatial 
> Information System (SIS):
>
>     http://sis.apache.org/
>
> The use of Apache SIS would avoid the LGPL license issue. The two 
> libraries have similar API since I was the main author of GeoTools 
> coordinate reference system engine from 2002 to 2008, before I 
> migrated to Apache. But Apache SIS is more conformant to international 
> standards (for example ISO 19162 for the "Well Known Text" format), in 
> part because I'm a member of the expert group working on ISO 19111, 
> ISO 19162 and GeoAPI in the Open Geospatial Consortium and I try to 
> apply those standards as much as I can in Apache SIS.
>
> Another point is that both projects implements Java interfaces 
> published by the Open Geospatial Consortium (OGC) in the "org.opengis" 
> namespace, but GeoTools uses its own fork of the OGC standard 
> interfaces (without renaming the packages) while Apache SIS implements 
> the official GeoAPI 3.0.1 release. This will cause a namespace 
> collision if a project has GeoTools and the standard OGC GeoAPI 
> interfaces together on the module path.
>
> Apache SIS is cited by GDAL/Proj (the C/C++ library behind MapServer, 
> QGIS, PostGIS, etc) as a source of inspiration for the design of their 
> new map projection library, for which they raised a funding of  
> $144,000 (https://gdalbarn.com/).
>
> If I can be of any help in the evaluation of Apache SIS for this task, 
> I would be glad to try.
>
>     Regards,
>
>         Martin
>
>


Re: GeoSPARQL modules Was: Spatial distance in Fuseki

Posted by Martin Desruisseaux <de...@apache.org>.
Hello Andy, Greg and all

>> It has dependencies on JTS, for spatial relations and distances etc.,
>> and GeoTools, for coordinate reference system conversions.
>>
Sorry to jump in the middle of the discussion; I would like to introduce
some elements in case they are worth consideration. An alternative to
GeoTools for coordinate operations is Apache Spatial Information System
(SIS):

    http://sis.apache.org/

The use of Apache SIS would avoid the LGPL license issue. The two
libraries have similar API since I was the main author of GeoTools
coordinate reference system engine from 2002 to 2008, before I migrated
to Apache. But Apache SIS is more conformant to international standards
(for example ISO 19162 for the "Well Known Text" format), in part
because I'm a member of the expert group working on ISO 19111, ISO 19162
and GeoAPI in the Open Geospatial Consortium and I try to apply those
standards as much as I can in Apache SIS.

Another point is that both projects implements Java interfaces published
by the Open Geospatial Consortium (OGC) in the "org.opengis" namespace,
but GeoTools uses its own fork of the OGC standard interfaces (without
renaming the packages) while Apache SIS implements the official GeoAPI
3.0.1 release. This will cause a namespace collision if a project has
GeoTools and the standard OGC GeoAPI interfaces together on the module path.

Apache SIS is cited by GDAL/Proj (the C/C++ library behind MapServer,
QGIS, PostGIS, etc) as a source of inspiration for the design of their
new map projection library, for which they raised a funding of  $144,000
(https://gdalbarn.com/).

If I can be of any help in the evaluation of Apache SIS for this task, I
would be glad to try.

    Regards,

        Martin



Re: GeoSPARQL modules Was: Spatial distance in Fuseki

Posted by Andy Seaborne <an...@apache.org>.
Yes - this sounds very interesting. I can help with moving this forward, 
as either contribution or extending project.  There is something to be 
said for starting separately (release is not coupled to Jena release 
cycles) then contribute if you want to go that route.

It would be useful whether it has index support or not.

JTS now that is available under EDL form is OK. IIRC when jena-spatial 
was done, it was LGPL so it had to be an optional extra.

The LGPL for GeoTools is something to work on but it can be done.

Is there anything in the Eclipse location domain that can provide some 
of what GeoTools is used for? If so, geotools can be an optional extra 
which is the normal way to deal with the situation.

     Andy

Someone recently collected all the Apache projects logos and created the 
"powered by" versions:

https://www.apache.org/logos/comdev-test/poweredby/jena.png

On 24/08/18 19:38, ajs6f wrote:
> Greg--
> 
> That sounds like a great contribution, although it might indeed make a lot of sense as a sidecar module, or even built up as a package with Fuseki and jena-spatial. Are your modules "pure" functions (i.e. agnostic to backend) or do they take advantage of Jena's spatial index module?
> 
> JTS is Eclipse-licensed [1], which (IIUC) should be cool, but GeoTools seems to use LGPL [2], which I believe may present some problems for Jena (which is, of course, licensed as Apache 2.0).
> 
> ajs6f
> 
> [1] https://github.com/locationtech/jts/blob/master/LICENSES.md
> [2] http://docs.geotools.org/latest/userguide/faq.html#q-what-licence-does-geotools-use
> 
>> On Aug 24, 2018, at 2:14 PM, Greg Albiston <gr...@hotmail.com> wrote:
>>
>> Hello,
>>
>> Since the topic has come up. I've put together an implementation of all the GeoSPARQL modules which I was getting around to discussing contributing.
>>
>> It has dependencies on JTS, for spatial relations and distances etc., and GeoTools, for coordinate reference system conversions. I think the remainder are Apache dependencies.
>>
>> The only item to implement was additional unit tests.
>>
>> Would this be suitable for incorporating into Jena or better as an extending project?
>>
>> Also, the GeoSPARQL function namespace mentioned by the OP seems incorrect. The published namespace is:
>>
>> geof: http://www.opengis.net/def/function/geosparql/
>>
>> Thanks,
>>
>> Greg
>>
>>
>> From: Andy Seaborne
>> Sent: Friday 24 August, 18:29
>> Subject: Re: Spatial distance in Fuseki
>> To: users@jena.apache.org
>>
>>
>> (PS JENA-664 is the open JIRA for GeoSPARQL) A complete example with imports etc: https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and also below. This is for doing everything in one java program. It is the simplest way and runs in an IDE for debugging. > My main problems in understandig are: > - where to put the java code and how to name it It will have a URI name. From the example below: // Register the function FunctionRegistry ref = FunctionRegistry.get(); ref.put("http://my/num", MyFunction.class); using the global function registry (you can have one uique to the dataset if you want as well but the joy of globally unique URIs is that putting it the JVM-registry just works. > - how to include it with Fuseki The example below is the simplest way using embedded Fuseki. It's a plain Java program and avoids the need to repack jar files which for development makes things easier and can be debugged in an IDE. If you want to create a packaged standalone jar file, this is a a template: "basic" is a standalone jar using embedded Fuseki and with a command line interface. https://github.com/apache/jena/tree/master/jena-fuseki2/jena-fuseki-basic It makes: http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html#fuseki-basic so using that, adding your own code and making the command line start register the function should work. > - how to call it in the SPARQL query Functions are invoked like: (?Z) which is URI + arguments. The URI can a prefixed name as well; prefixes and expanded during parsing and it is the URI that matters. BIND ((?Z) AS ?X ) FILTER((?Z) = "number") Andy ------------------------ https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and with slight reformatting: public class FuFunctionEx { /** Our function */ public static class MyFunction extends FunctionBase1 { @Override public NodeValue exec(NodeValue v) { if ( v.isNumber() ) return NodeValue.makeString("number"); return NodeValue.makeString("not a number"); } } public static void main(String...a) { FusekiLogging.setLogging(); // Register the function FunctionRegistry ref = FunctionRegistry.get(); ref.put("http://my/num", MyFunction.class); int PORT = FusekiLib.choosePort(); // Some empty dataset DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); FusekiServer server = FusekiServer.create() .setPort(PORT) .add("/ds", dsg) .build(); server.start(); // Test query. String queryString = StrUtils.strjoinNL( "SELECT * { " , " VALUES ?Z { 123 'abc'}" , " BIND ((?Z) AS ?X )" ,"}" ); try { String url = "http://localhost:"+PORT+"/ds"; // Connect to the server and execute the query. try ( RDFConnection conn = RDFConnectionFactory.connect(url) ) { // Using Java8 features. conn.queryResultSet(queryString, ResultSetFormatter::out); // Without Java8 features try ( QueryExecution qExec = conn.query(queryString) ) { ResultSet rs = qExec.execSelect(); ResultSetFormatter.out(rs); } } } catch (Exception ex) { ex.printStackTrace(); } finally { server.stop(); } } } Andy
>>
> 

GeoSPARQL modules Was: Spatial distance in Fuseki

Posted by ajs6f <aj...@apache.org>.
Greg--

That sounds like a great contribution, although it might indeed make a lot of sense as a sidecar module, or even built up as a package with Fuseki and jena-spatial. Are your modules "pure" functions (i.e. agnostic to backend) or do they take advantage of Jena's spatial index module?

JTS is Eclipse-licensed [1], which (IIUC) should be cool, but GeoTools seems to use LGPL [2], which I believe may present some problems for Jena (which is, of course, licensed as Apache 2.0).

ajs6f

[1] https://github.com/locationtech/jts/blob/master/LICENSES.md
[2] http://docs.geotools.org/latest/userguide/faq.html#q-what-licence-does-geotools-use

> On Aug 24, 2018, at 2:14 PM, Greg Albiston <gr...@hotmail.com> wrote:
> 
> Hello,
> 
> Since the topic has come up. I've put together an implementation of all the GeoSPARQL modules which I was getting around to discussing contributing.
> 
> It has dependencies on JTS, for spatial relations and distances etc., and GeoTools, for coordinate reference system conversions. I think the remainder are Apache dependencies.
> 
> The only item to implement was additional unit tests.
> 
> Would this be suitable for incorporating into Jena or better as an extending project?
> 
> Also, the GeoSPARQL function namespace mentioned by the OP seems incorrect. The published namespace is:
> 
> geof: http://www.opengis.net/def/function/geosparql/
> 
> Thanks,
> 
> Greg
> 
> 
> From: Andy Seaborne
> Sent: Friday 24 August, 18:29
> Subject: Re: Spatial distance in Fuseki
> To: users@jena.apache.org
> 
> 
> (PS JENA-664 is the open JIRA for GeoSPARQL) A complete example with imports etc: https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and also below. This is for doing everything in one java program. It is the simplest way and runs in an IDE for debugging. > My main problems in understandig are: > - where to put the java code and how to name it It will have a URI name. From the example below: // Register the function FunctionRegistry ref = FunctionRegistry.get(); ref.put("http://my/num", MyFunction.class); using the global function registry (you can have one uique to the dataset if you want as well but the joy of globally unique URIs is that putting it the JVM-registry just works. > - how to include it with Fuseki The example below is the simplest way using embedded Fuseki. It's a plain Java program and avoids the need to repack jar files which for development makes things easier and can be debugged in an IDE. If you want to create a packaged standalone jar file, this is a a template: "basic" is a standalone jar using embedded Fuseki and with a command line interface. https://github.com/apache/jena/tree/master/jena-fuseki2/jena-fuseki-basic It makes: http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html#fuseki-basic so using that, adding your own code and making the command line start register the function should work. > - how to call it in the SPARQL query Functions are invoked like: (?Z) which is URI + arguments. The URI can a prefixed name as well; prefixes and expanded during parsing and it is the URI that matters. BIND ((?Z) AS ?X ) FILTER((?Z) = "number") Andy ------------------------ https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and with slight reformatting: public class FuFunctionEx { /** Our function */ public static class MyFunction extends FunctionBase1 { @Override public NodeValue exec(NodeValue v) { if ( v.isNumber() ) return NodeValue.makeString("number"); return NodeValue.makeString("not a number"); } } public static void main(String...a) { FusekiLogging.setLogging(); // Register the function FunctionRegistry ref = FunctionRegistry.get(); ref.put("http://my/num", MyFunction.class); int PORT = FusekiLib.choosePort(); // Some empty dataset DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); FusekiServer server = FusekiServer.create() .setPort(PORT) .add("/ds", dsg) .build(); server.start(); // Test query. String queryString = StrUtils.strjoinNL( "SELECT * { " , " VALUES ?Z { 123 'abc'}" , " BIND ((?Z) AS ?X )" ,"}" ); try { String url = "http://localhost:"+PORT+"/ds"; // Connect to the server and execute the query. try ( RDFConnection conn = RDFConnectionFactory.connect(url) ) { // Using Java8 features. conn.queryResultSet(queryString, ResultSetFormatter::out); // Without Java8 features try ( QueryExecution qExec = conn.query(queryString) ) { ResultSet rs = qExec.execSelect(); ResultSetFormatter.out(rs); } } } catch (Exception ex) { ex.printStackTrace(); } finally { server.stop(); } } } Andy
> 


Re: Spatial distance in Fuseki

Posted by Greg Albiston <gr...@hotmail.com>.
Hello,

Since the topic has come up. I've put together an implementation of all the GeoSPARQL modules which I was getting around to discussing contributing.

It has dependencies on JTS, for spatial relations and distances etc., and GeoTools, for coordinate reference system conversions. I think the remainder are Apache dependencies.

The only item to implement was additional unit tests.

Would this be suitable for incorporating into Jena or better as an extending project?

Also, the GeoSPARQL function namespace mentioned by the OP seems incorrect. The published namespace is:

geof: http://www.opengis.net/def/function/geosparql/

Thanks,

Greg


From: Andy Seaborne
Sent: Friday 24 August, 18:29
Subject: Re: Spatial distance in Fuseki
To: users@jena.apache.org


(PS JENA-664 is the open JIRA for GeoSPARQL) A complete example with imports etc: https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and also below. This is for doing everything in one java program. It is the simplest way and runs in an IDE for debugging. > My main problems in understandig are: > - where to put the java code and how to name it It will have a URI name. From the example below: // Register the function FunctionRegistry ref = FunctionRegistry.get(); ref.put("http://my/num", MyFunction.class); using the global function registry (you can have one uique to the dataset if you want as well but the joy of globally unique URIs is that putting it the JVM-registry just works. > - how to include it with Fuseki The example below is the simplest way using embedded Fuseki. It's a plain Java program and avoids the need to repack jar files which for development makes things easier and can be debugged in an IDE. If you want to create a packaged standalone jar file, this is a a template: "basic" is a standalone jar using embedded Fuseki and with a command line interface. https://github.com/apache/jena/tree/master/jena-fuseki2/jena-fuseki-basic It makes: http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html#fuseki-basic so using that, adding your own code and making the command line start register the function should work. > - how to call it in the SPARQL query Functions are invoked like: (?Z) which is URI + arguments. The URI can a prefixed name as well; prefixes and expanded during parsing and it is the URI that matters. BIND ((?Z) AS ?X ) FILTER((?Z) = "number") Andy ------------------------ https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035 and with slight reformatting: public class FuFunctionEx { /** Our function */ public static class MyFunction extends FunctionBase1 { @Override public NodeValue exec(NodeValue v) { if ( v.isNumber() ) return NodeValue.makeString("number"); return NodeValue.makeString("not a number"); } } public static void main(String...a) { FusekiLogging.setLogging(); // Register the function FunctionRegistry ref = FunctionRegistry.get(); ref.put("http://my/num", MyFunction.class); int PORT = FusekiLib.choosePort(); // Some empty dataset DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); FusekiServer server = FusekiServer.create() .setPort(PORT) .add("/ds", dsg) .build(); server.start(); // Test query. String queryString = StrUtils.strjoinNL( "SELECT * { " , " VALUES ?Z { 123 'abc'}" , " BIND ((?Z) AS ?X )" ,"}" ); try { String url = "http://localhost:"+PORT+"/ds"; // Connect to the server and execute the query. try ( RDFConnection conn = RDFConnectionFactory.connect(url) ) { // Using Java8 features. conn.queryResultSet(queryString, ResultSetFormatter::out); // Without Java8 features try ( QueryExecution qExec = conn.query(queryString) ) { ResultSet rs = qExec.execSelect(); ResultSetFormatter.out(rs); } } } catch (Exception ex) { ex.printStackTrace(); } finally { server.stop(); } } } Andy


Re: Spatial distance in Fuseki

Posted by Andy Seaborne <an...@apache.org>.
(PS  JENA-664 is the open JIRA for GeoSPARQL)

A complete example with imports etc:
https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035

and also below.

This is for doing everything in one java program. It is the simplest way 
and runs in an IDE for debugging.

> My main problems in understandig are:
> - where to put the java code and how to name it

It will have a URI name.
 From the example below:

    // Register the function
    FunctionRegistry ref = FunctionRegistry.get();
    ref.put("http://my/num", MyFunction.class);

using the global function registry (you can have one uique to the 
dataset if you want as well but the joy of globally unique URIs is that 
putting it the JVM-registry just works.

> - how to include it with Fuseki

The example below is the simplest way using embedded Fuseki. It's a 
plain Java program and avoids the need to repack jar files which for 
development makes things easier and can be debugged in an IDE.

If you want to create a packaged standalone jar file, this is a a
template: "basic" is a standalone jar using embedded Fuseki and with a 
command line interface.

https://github.com/apache/jena/tree/master/jena-fuseki2/jena-fuseki-basic

It makes:

http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html#fuseki-basic

so using that, adding your own code and making the command line start 
register the function should work.

> - how to call it in the SPARQL query

Functions are invoked like:

    <http://my/num>(?Z)

which is URI + arguments.  The URI can a prefixed name as well; prefixes 
and expanded during parsing and it is the URI that matters.

BIND (<http://my/num>(?Z) AS ?X )
FILTER(<http://my/num>(?Z) = "number")

	Andy

------------------------
https://gist.github.com/afs/a8dfe6680324110bdb675190f9c73035
and with slight reformatting:


public class FuFunctionEx {

     /** Our function */
     public static class MyFunction extends FunctionBase1 {
         @Override
         public NodeValue exec(NodeValue v) {
             if ( v.isNumber() )
                 return NodeValue.makeString("number");
             return NodeValue.makeString("not a number");
         }
     }

     public static void main(String...a) {
         FusekiLogging.setLogging();

         // Register the function
         FunctionRegistry ref = FunctionRegistry.get();
         ref.put("http://my/num", MyFunction.class);

         int PORT = FusekiLib.choosePort();

         // Some empty dataset
         DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
         FusekiServer server = FusekiServer.create()
             .setPort(PORT)
             .add("/ds", dsg)
             .build();
         server.start();

         // Test query.
         String queryString = StrUtils.strjoinNL(
             "SELECT * { "
             , "  VALUES ?Z { 123 'abc'}"
             , "  BIND (<http://my/num>(?Z) AS ?X )"
             ,"}"
             );

         try {
             String url = "http://localhost:"+PORT+"/ds";
             // Connect to the server and execute the query.
             try ( RDFConnection conn =
                           RDFConnectionFactory.connect(url) ) {
                 // Using Java8 features.
                 conn.queryResultSet(queryString,
                                     ResultSetFormatter::out);

                 // Without Java8 features
                 try ( QueryExecution qExec = conn.query(queryString) ) {
                     ResultSet rs = qExec.execSelect();
                     ResultSetFormatter.out(rs);
                 }
             }
         } catch (Exception ex) {
             ex.printStackTrace();
         } finally { server.stop(); }
     }
}

     Andy

Re: Spatial distance in Fuseki

Posted by Markus Neumann <mn...@meteomatics.com>.
Thanks for the input. I was actually just assuming, that Jena would support it in some way.

I've gone through
https://jena.apache.org/documentation/query/writing_propfuncs.html <https://jena.apache.org/documentation/query/writing_propfuncs.html>
https://jena.apache.org/documentation/query/extension.html <https://jena.apache.org/documentation/query/extension.html>
https://jena.apache.org/documentation/query/writing_functions.html <https://jena.apache.org/documentation/query/writing_functions.html>
and some other pages, but my Java knowledge is too little and too long away to really make sense of any of it.

It would be great if someone could provide a minimal example on how to include my own function definition in Fuseki.
My main problems in understandig are:
- where to put the java code and how to name it
- how to include it with Fuseki
- how to call it in the SPARQL query

Many thanks and best regards
Markus

> Am 24.08.2018 um 13:47 schrieb ajs6f <aj...@apache.org>:
> 
> I'm no expert on Jena's GeoSPARQL support, but our docs:
> 
> https://jena.apache.org/documentation/query/spatial-query.html
> 
> don't mention any such namespaces as http://www.opengis.net/rdf/functions#. Where did you see it documented that Jena supports such functions?
> 
> I only see a small and specific set of functions:
> 
> https://jena.apache.org/documentation/query/spatial-query.html#property-function-library
> 
> but you could certainly use Jena's extension mechanisms to do this kind of calculation:
> 
> https://jena.apache.org/documentation/query/writing_propfuncs.html
> 
> although it's not trivial to do that. Perhaps a committer with more knowledge about jena-spatial can help here.
> 
> ajs6f
> 
>> On Aug 24, 2018, at 5:47 AM, Markus Neumann <mn...@meteomatics.com> wrote:
>> 
>> Hi,
>> 
>> I'm quite new to both Fuseki and mailinglists, so please be patient with me.
>> 
>> I've managed to set up a Fuseki 2 server together with a Lucene spatial index.
>> E.g the following query works as expected:
>> 
>> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
>> PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
>> PREFIX mm: <http://rdf.meteomatics.com/mm/>
>> PREFIX spatial: <http://jena.apache.org/spatial#>
>> SELECT *
>> WHERE {
>> ?loc spatial:nearby (47.5 8.5 5 'km') .
>> ?loc a mm:Location;
>>      geo:lat ?lat;
>>      geo:long ?long;
>>      geosparql:asWKT ?wkt;
>>      mm:station_name ?name.
>> }
>> 
>> Now I would like to run the following:
>> 
>> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
>> PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
>> PREFIX mm: <http://rdf.meteomatics.com/mm/>
>> PREFIX spatial: <http://jena.apache.org/spatial#>
>> PREFIX ogcf: <http://www.opengis.net/rdf/functions#>
>> SELECT ?distance WHERE {
>> BIND(mm-locations:8515451 as ?wil)
>> ?wil spatial:nearby(?lat ?lon 8 'km') .
>> ?wil geosparql:asWKT ?wil_wkt .
>> ?loc a mm:Location;
>>      geo:lat ?lat;
>>      geo:long ?lon;
>>      geosparql:asWKT ?wkt.
>> BIND( ogcf:distance(?wil_wkt, ?wkt, 'km') as ?distance)
>> } 
>> 
>> The query completes and gets the correct amount of results, but all wihout value.
>> In the log pops up this message:
>> 
>> [2018-08-24 09:45:33] exec       WARN  URI <http://www.opengis.net/rdf/functions#distance> has no registered function factory
>> 
>> Is there a way to get this to work? Or is there another way to compute spatial distances?
>> 
>> Many thanks for your time.
>> 
>> Best regards
>> Markus
>> 
> 


Re: Spatial distance in Fuseki

Posted by ajs6f <aj...@apache.org>.
I'm no expert on Jena's GeoSPARQL support, but our docs:

https://jena.apache.org/documentation/query/spatial-query.html

don't mention any such namespaces as http://www.opengis.net/rdf/functions#. Where did you see it documented that Jena supports such functions?

I only see a small and specific set of functions:

https://jena.apache.org/documentation/query/spatial-query.html#property-function-library

but you could certainly use Jena's extension mechanisms to do this kind of calculation:

https://jena.apache.org/documentation/query/writing_propfuncs.html

although it's not trivial to do that. Perhaps a committer with more knowledge about jena-spatial can help here.

ajs6f

> On Aug 24, 2018, at 5:47 AM, Markus Neumann <mn...@meteomatics.com> wrote:
> 
> Hi,
> 
> I'm quite new to both Fuseki and mailinglists, so please be patient with me.
> 
> I've managed to set up a Fuseki 2 server together with a Lucene spatial index.
> E.g the following query works as expected:
> 
> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
> PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
> PREFIX mm: <http://rdf.meteomatics.com/mm/>
> PREFIX spatial: <http://jena.apache.org/spatial#>
> SELECT *
> WHERE {
>  ?loc spatial:nearby (47.5 8.5 5 'km') .
>  ?loc a mm:Location;
>       geo:lat ?lat;
>       geo:long ?long;
>       geosparql:asWKT ?wkt;
>       mm:station_name ?name.
> }
> 
> Now I would like to run the following:
> 
> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
> PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
> PREFIX mm: <http://rdf.meteomatics.com/mm/>
> PREFIX spatial: <http://jena.apache.org/spatial#>
> PREFIX ogcf: <http://www.opengis.net/rdf/functions#>
> SELECT ?distance WHERE {
>  BIND(mm-locations:8515451 as ?wil)
>  ?wil spatial:nearby(?lat ?lon 8 'km') .
>  ?wil geosparql:asWKT ?wil_wkt .
>  ?loc a mm:Location;
>       geo:lat ?lat;
>       geo:long ?lon;
>       geosparql:asWKT ?wkt.
>  BIND( ogcf:distance(?wil_wkt, ?wkt, 'km') as ?distance)
> } 
> 
> The query completes and gets the correct amount of results, but all wihout value.
> In the log pops up this message:
> 
> [2018-08-24 09:45:33] exec       WARN  URI <http://www.opengis.net/rdf/functions#distance> has no registered function factory
> 
> Is there a way to get this to work? Or is there another way to compute spatial distances?
> 
> Many thanks for your time.
> 
> Best regards
> Markus
>