Search code examples
rdfsparqlgeospatialgeospatial-query

Get area of municipality


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" ... ... ...


Solution

  • 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)