# Stardog Support for Geospatial Function NearBy

**URL:** <https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524>\
**Category:** Support\
**Created:** [August 22, 2017, 12:54pm UTC](https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524 "2017-08-22T12:54:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kris](https://community.stardog.com/u/Kris)\
**Post date:** [August 22, 2017, 12:54pm UTC](https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524/1 "2017-08-22T12:54:09Z")

</div>

Hi There,

I have uploaded a small ttl file using the following command (I am working with stardog 5.0.2-beta):

stardog-admin db create -n myDb -o spatial.enabled=true – dbpedia\_test.ttl

myFile is as follows:

```auto
@prefix geo: <http://www.opengis.net/ont/geosparql#>.
@prefix dbr: xxx
dbr:Bord_Gáis_Energy_Theatre geo:hasGeometry _:b34949384 .
_:b34949384 geo:asWKT "POINT(53.3442497253418 -6.240039825439453)"^^geo:wktLiteral .

```

I now want to run Nearby:

```auto
PREFIX geos: xxx
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX geo: xxx

SELECT * WHERE{
  ?loc geos:hasGeometry ?feature .
  ?feature geof:nearby(53.3442497253418 -6.240039825439453 2 <http://qudt.org/vocab/unit#Kilometer>).
}

```

I am about 95 percent sure this worked for me before, but now it does not appear to be returning anything.

Any idea what I am missing here?

Kind regards,

Kris.

---

<div class="post-metadata">

**Author:** ![Kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kris](https://community.stardog.com/u/Kris)\
**Post date:** [August 23, 2017, 9:04am UTC](https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524/2 "2017-08-23T09:04:07Z")

</div>

Hi All,

Just so you know, I can run this by using the geometry returned, so:

```auto
SELECT * WHERE{
  ?loc geos:hasGeometry ?geo .
  ?feature geof:nearby(?geo 2 <http://qudt.org/vocab/unit#Kilometer>).
}

```

But, I was sure I had a nearby working using a lat and long variable as a parameter. Similar to this - [Apache Jena - Spatial searches with SPARQL](https://jena.apache.org/documentation/query/spatial-query.html)

Kind regards,

Kris.

---

<div class="post-metadata">

**Author:** ![Kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Kris](https://community.stardog.com/u/Kris)\
**Post date:** [August 23, 2017, 2:49pm UTC](https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524/3 "2017-08-23T14:49:34Z")

</div>

To add to above comments. I want to search across two graphs using nearby.

Since I am unable to do a nearby search for geometries by given a lat and long I tried the following query:

```auto
SELECT * WHERE{
  ?loc geos:hasGeometry ?geo .
  ?geo geos:asWKT "POINT(53.3442497253418 -6.240039825439453)"^^geos:wktLiteral.
  ?feature geof:nearby (?geo 1 <http://qudt.org/vocab/unit#Kilometer>) .
}

```

I want to return all geometries nearby the one specified. I know I have multiple geometries from another graph in the database (I can return them). But when I run this query, I only return the one geometry with that WKT value.

I imagine I am doing something wrong which is obvious?

Any help much appreciated!

Thanks,

Kris.

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [August 23, 2017, 3:42pm UTC](https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524/4 "2017-08-23T15:42:31Z")

</div>

Hi Kris, apologies for the late reply, but I myself was having trouble figuring out what you needed to do.

It turns out that (for the first post at least), you are doing something wrong, it’s just painfully NOT obvious. When defining a POINT as a wktLiteral, the parameters are reversed. It’s actually `POINT(long lat)`…but then geof:nearby expects (lat long …)

This explains why specifying the POINT again is working, but not the individual values. It also explains why using the geometry itself is also fine. If you flip them around in your query, you will see the desired results:

```auto
(Given POINT(53.3442497253418 -6.240039825439453) and POINT(long lat))

SELECT * WHERE{
?loc geos:hasGeometry ?feature .
?feature geof:nearby(-6.24003982543 53.344249725 2 <http://qudt.org/vocab/unit#Kilometer>).
}

+---------------------------------+------------------------------------------------+
| loc | feature |
+---------------------------------+------------------------------------------------+
| urn:dbrBord_Gáis_Energy_Theatre | _:bnode_7eaa8cb1_4c61_43ee_b72d_20fad59d8f1c_2 |
+---------------------------------+------------------------------------------------+

```

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [August 23, 2017, 3:52pm UTC](https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524/5 "2017-08-23T15:52:10Z")

</div>

And as for the query spanning multiple graphs, you will either need to add a `GRAPH <urn:whatever> {}` block to your query, or ensure that `query.all.graphs=true` is specified in your stardog.properties file

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [September 6, 2017, 3:52pm UTC](https://community.stardog.com/t/stardog-support-for-geospatial-function-nearby/524/6 "2017-09-06T15:52:18Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
