3

I am using stSPARQL and the ref says:

xsd:float strdf:area(strdf:geometry A): Returns the area of the surface if it is a polygon or multi-polygon.

and so I am trying:

PREFIX geo: <http://geo.linkedopendata.gr/gag/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX strdf: <http://strdf.di.uoa.gr/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
...
?municipality geo:has_geometry ?geometry . // so far so good (checked)
FILTER(strdf:area(?geometry) = ?area) .

and I am getting nothing as a result. My overall goal is to get the total area of all municipalities, but I can not even get one! Any idea?

Note that's my first time I am using spatial metric functions, thus what I am trying to do is to collect and show the result of strdf:area(), but I am failing!

The 1st result of ?geometry is:

"MULTIPOLYGON(((476162.8125 3949684,476195.687499999 3949675,476216.000000001 3949675,476226.1875 3... more


EDIT:

If I try with this: ?area = strdf:area(?geometry) ., I will get an error:

Encountered " "=" "= "" at line 15, column 9. Was expecting one of: "(" ... "!" ... "^" ... "a" ... ... ...

gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • `Filter( ... = ?area)` only makes sense if another part of your query binds `?area`. Are you doing that? (You haven't shown us your complete query. ) and without seeing your data, we can't know what things *should* return. – Joshua Taylor Jan 10 '16 at 13:53
  • @JoshuaTaylor I haven't done that. I haven't shown the rest of the query because all it does is finding the correct municipalities, thus it's irrelevant. I am trying to find the area of a municipality and I have no clue on how to do that! So yes, I am not surprised that my code doesn't make much sense... I am trying to collect the result of `strdf:area()`, but I do not seem to succeed in it. :/ – gsamaras Jan 10 '16 at 16:31

2 Answers2

5

I think what you want to do with a function that has a return value is you should use it in your select clause somehow. For example:

PREFIX geo: ...
PREFIX rdf: ...
PREFIX strdf: ...
PREFIX xsd: ...
...
SELECT (strdf:area(?geometry) AS ?myarea)
WHERE {
        ?municipality geo:has_geometry ?geometry .
}

Supposedly this gives you all the areas you need to add, just use the SUM(?myarea) function. This adds all the answers that the "area" function found. In the previous situation your select clause would be something like:

SELECT (SUM(strdf:area(?geometry)) AS ?myarea)
gsamaras
  • 71,951
  • 46
  • 188
  • 305
Cartman
  • 68
  • 7
4

FILTER does not set variables.

From your comment about wanting to collect the result of strdf:area(), either

BIND(strdf:area(?geometry) AS ?area)

or

SELECT ... (strdf:area(?geometry) AS ?area) ...
AndyS
  • 16,345
  • 17
  • 21