<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head profile="http://internetalchemy.org/2003/02/profile"> <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" /> <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" /> <meta name="dc.title" content="14. RDF Data Access and Data Management" /> <meta name="dc.subject" content="14. RDF Data Access and Data Management" /> <meta name="dc.creator" content="OpenLink Software Documentation Team ; " /> <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" /> <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" /> <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" /> <link rel="parent" href="rdfandsparql.html" title="Chapter Contents" /> <link rel="prev" href="rdfsparqlrule.html" title="Inference Rules & Reasoning" /> <link rel="next" href="rdfperformancetuning.html" title="RDF Performance Tuning" /> <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" /> <link rel="stylesheet" type="text/css" href="doc.css" /> <link rel="stylesheet" type="text/css" href="/doc/translation.css" /> <title>14. RDF Data Access and Data Management</title> <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" /> <meta name="author" content="OpenLink Software Documentation Team ; " /> <meta name="copyright" content="OpenLink Software, 1999 - 2009" /> <meta name="keywords" content="" /> <meta name="GENERATOR" content="OpenLink XSLT Team" /> </head> <body> <div id="header"> <a name="rdfsparqlgeospat" /> <img src="../images/misc/logo.jpg" alt="" /> <h1>14. RDF Data Access and Data Management</h1> </div> <div id="navbartop"> <div> <a class="link" href="rdfandsparql.html">Chapter Contents</a> | <a class="link" href="rdfsparqlrule.html" title="Inference Rules & Reasoning">Prev</a> | <a class="link" href="rdfperformancetuning.html" title="RDF Performance Tuning">Next</a> </div> </div> <div id="currenttoc"> <form method="post" action="/doc/adv_search.vspx"> <div class="search">Keyword Search: <br /> <input type="text" name="q" /> <input type="submit" name="go" value="Go" /> </div> </form> <div> <a href="http://www.openlinksw.com/">www.openlinksw.com</a> </div> <div> <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a> </div> <br /> <div> <a href="index.html">Book Home</a> </div> <br /> <div> <a href="contents.html">Contents</a> </div> <div> <a href="preface.html">Preface</a> </div> <br /> <div class="selected"> <a href="rdfandsparql.html">RDF Data Access and Data Management</a> </div> <br /> <div> <a href="rdfdatarepresentation.html">Data Representation</a> </div> <div> <a href="rdfsparql.html">SPARQL</a> </div> <div> <a href="sparqlextensions.html">Extensions</a> </div> <div> <a href="rdfgraphsecurity.html">RDF Graphs Security</a> </div> <div> <a href="rdfviews.html">Linked Data Views over RDBMS Data Source</a> </div> <div> <a href="rdfrdfviewgnr.html">Automated Generation of RDF Views over Relational Data Sources</a> </div> <div> <a href="rdfviewsenterpr.html">Examples of Linked Data Views</a> </div> <div> <a href="rdfinsertmethods.html">RDF Insert Methods in Virtuoso</a> </div> <div> <a href="virtuososponger.html">RDFizer Middleware (Sponger)</a> </div> <div> <a href="virtuosospongerfacetinstall.html">Virtuoso Faceted Browser Installation and configuration</a> </div> <div> <a href="virtuosospongerfacent.html">Virtuoso Faceted Web Service</a> </div> <div> <a href="rdfiridereferencing.html">Linked Data</a> </div> <div> <a href="rdfsparqlrule.html">Inference Rules & Reasoning</a> </div> <div class="selected"> <a href="rdfsparqlgeospat.html">RDF and Geometry</a> <div> <a href="#rdfsparqlgeospatprog" title="Programmatic Manipulation of Geometries in RDF">Programmatic Manipulation of Geometries in RDF</a> <a href="#rdfsparqlgeospatcrg" title="Creating Geometries From RDF Data">Creating Geometries From RDF Data</a> <a href="#rdfsparqlgeospatusg" title="Using Geometries With Existing Databases">Using Geometries With Existing Databases</a> <a href="#rdfsparqlgeospatexmp" title="GEO Spatial Examples">GEO Spatial Examples</a> </div> </div> <div> <a href="rdfperformancetuning.html">RDF Performance Tuning</a> </div> <div> <a href="rdfnativestorageproviders.html">RDF Data Access Providers (Drivers)</a> </div> <div> <a href="rdfgraphreplication.html">RDF Graph Replication</a> </div> <br /> </div> <div id="text"> <a name="rdfsparqlgeospat" /> <h2>14.14. RDF and Geometry</h2> <p>A geometry may occur as an object of an RDF quad. The SQL MM functions can then be used for geospatial queries. </p> <p> For geometry functions, see the <a href="">SQL Geometry support section</a>. </p> <p>A geometry may occur as an object value in an RDF quad. In such a case, the bare geometry object is not used but instead a special RDF typed literal is made with the type virtrdf:Geometry. Such a literal is automatically indexed in an R tree index containing all distinct geometries occurring in any quad of any graph under any predicate. Normally, WGS84, SRID 4326 is the SRID of any such geometry. </p> <p>In this section, the geo namespace prefix is used to mean <http://www.w3.org/2003/01/geo/wgs84_pos#>. </p> <p>The preferred way of adding geometries to RDF graphs is with the ttlp and related functions which parse a text string in the Turtle syntax and insert the result in a graph. </p> <p>For example:</p> <div> <pre class="programlisting"> ttlp ('@prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#> <point> geo:geometry "point(1.2 22.4"^^virtrdf:Geometry .', 'xxx', 'graph'); </pre> </div> <p>A typed literal whose text is a WKT representation of a geometry and whose type is virtrdf:geometry creates a geometry object and adds it to the R tree index of all RDF geometries. </p> <p> Geometries can be queried with geometry predicates, st_intersects, st_contains and st_within, as follows. As usual, the bif: namespace is used since these are SQL built-in functions. </p> <div> <pre class="programlisting"> SQL> SPARQL SELECT ?c COUNT (*) WHERE { ?m geo:geometry ?geo . ?m a ?c . FILTER (bif:st_intersects (?geo, bif:st_point (0, 52), 100)) } GROUP BY ?c ORDER BY DESC 2; c callret-1 VARCHAR VARCHAR ____________________________________________________________ http://linkedgeodata.org/vocabulary#node 2317684 http://linkedgeodata.org/vocabulary#way 85315 http://linkedgeodata.org/vocabulary#building 14257 http://dbpedia.org/class/yago/Landmark108624891 9093 http://linkedgeodata.org/vocabulary#wood 7155 http://linkedgeodata.org/vocabulary#gate 7079 http://www.w3.org/2002/07/owl#Thing 6788 http://linkedgeodata.org/vocabulary#post_box 6144 http://linkedgeodata.org/vocabulary#pub 5697 http://dbpedia.org/ontology/Place 5670 http://linkedgeodata.org/vocabulary#hedge 5391 ... </pre> </div> <p> This would return the classes of things within 100 km of 0, 52, which is near London. </p> <div> <pre class="programlisting"> SQL> SPARQL SELECT ?m (bif:st_distance (?geo, bif:st_point (0, 52))) WHERE { ?m geo:geometry ?geo . ?m a <http://dbpedia.org/ontology/City> . FILTER (bif:st_intersects (?geo, bif:st_point (0, 52), 30)) } ORDER BY DESC 2 LIMIT 20; m callret-1 VARCHAR VARCHAR _______________________________________________________________________________ http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 39.13180985471543 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 39.13180985471543 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 39.13180985471543 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 39.13180985471543 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 37.36907252285992 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 34.49432513061792 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 33.7676326404143 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 33.24238654570499 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 32.60139660515003 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 32.60139660515003 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 32.17414911350438 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 31.45681319171456 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 31.17750625349044 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 31.115377038 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 31.115377038 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 30.56388658524301 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 29.89662974046085 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 29.85090625132639 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 29.82605254366244 http://dbpedia.org/resource/Kingston%2C_Cambridgeshire 29.60102064794003 20 Rows. -- 13600 msec. </pre> </div> <p>This would be the cities within 20 km of 0, 52, ordered by increasing distance from this point. </p> <p>When SPARQL is called from SQL, the geometries can be bound to SQL variables as anything else returned from SPARQL. The <strong>st_</strong> functions can then be used for retrieving properties of these objects. </p> <div class="tip"> <div class="tiptitle">See Also</div> <p> <a href="">st_point</a> </p> <p> <a href="">st_x</a> </p> <p> <a href="">st_y</a> </p> <p> <a href="">st_distance</a> </p> <p> <a href="">st_srid</a> </p> <p> <a href="">st_setsrid</a> </p> <p> <a href="">st_astext</a> </p> <p> <a href="">st_geomfromtext</a> </p> <p> <a href="">st_contains</a> </p> <p> <a href="">st_intersects</a> </p> <p> <a href="">st_within</a> </p> <p> <a href="">isgeometry</a> </p> <p> <a href="">geo_insert</a> </p> <p> <a href="">geo_delete</a> </p> </div> <a name="rdfsparqlgeospatprog" /> <h3>14.14.1. Programmatic Manipulation of Geometries in RDF</h3> <p>The <a href="fn_ttlp.html">ttlp</a> function is the preferred way of inserting geometries. The more are inserted at one time, the more efficient the operation is. This loader function will also deal with cluster message optimization. </p> <p>For deleting quads with geometries, normal <a href="rdfsparql.html#rdfsparqlimplementationextent">SPARUL operations</a> apply. </p> <p>A geometry occurring in an RDF quad object is a member of the RDF box data type. This data type stands for a typed RDF literal. The type of all geometries is 256. This is mapped to a URI in the RDF_DATATYPE system table. </p> <p>A geometry does not occur directly in the object position of a quad. It is referenced by an id that is stored in the RDF typed literal box and references RO_ID of the RDF_OBJ system table. To translate a geometry into a RDF box that can be stored, do as in the example below: </p> <div> <pre class="programlisting"> INSERT INTO RDF_QUAD (g, s, p, o) VALUES ( "g", "s", iri_to_id ('http://www.w3.org/2003/01/geo/wgs84_pos#geometry'), DB.DBA.rdf_geo_add (rdf_box (st_point (lng, lat), 256, 257, 0, 1))); </pre> </div> <p>The DB.DBA.RDF_GEO_ADD function looks if an identical geometry already exists and if so assigns the existing id to it. If the geometry is new, it gets a new ID and is stored in the RDF literals table RDF_OBJ. At this time it is also automatically inserted into the RDF geometry index. </p> <p>In a cluster situation one should use the dpipe mechanism for inserting into RDF quad so as to get large numbers of inserts into a single message. This is essential for performance. </p> <br /> <a name="rdfsparqlgeospatcrg" /> <h3>14.14.2. Creating Geometries From RDF Data</h3> <p>Many data sets use the geo:lat and geo:long properties for describing a position. Virtuoso comes with a function for converting these properties into geometries. This operation reads through all graphs and for each subject with at least one geo:lat and geo:long, a point geometry is made for each distinct lat/long pair where lat and long are in the same graph. It should not happen in practice that a single subject has multiple lats or long within one graph. If this still happens, a geometry is made for each combination. The geometry is added to the subject with the lat and long as the value of the geo:geometry property. This is added to the same graph where the lat and long were. </p> <p>The SQL procedure DB.DBA.RDF_GEO_FILL () performs this operation. This is performed in parallel on multiple threads and is optimized for cluster execution. This is done without transaction logging and is not transactional. To make the result persistent, the operator should do an explicit checkpoint. This is done by executing:</p> <div> <pre class="programlisting"> SQL>cl_exec ('checkpoint'); </pre> </div> <p>on any process of a cluster or single server. Otherwise the result may be lost if the server terminates abnormally before an automatic checkpoint is made. </p> <p>The DB.DBA.RDF_GEO_FILL procedure may in principle be called several times but it will read every lat and long in the database. This is inefficient if there are large numbers of geometries. </p> <p>Application logic must generally be used for constructing geometries and adding these to RDF subjects. It is easiest for the application to construct a text representation of the geometries in TTL and to use the <a href="fn_ttlp.html">ttlp</a> function for loading this. </p> <br /> <a name="rdfsparqlgeospatusg" /> <h3>14.14.3. Using Geometries With Existing Databases</h3> <p> The geometry feature is compatible with any Virtuoso 6 databases. Once geometries are used, the database should not be opened with a server older than the one used for first inserting geometries, older servers will consider the storage format a physical corruption. </p> <br /> <a name="rdfsparqlgeospatexmp" /> <h3>14.14.4. GEO Spatial Examples</h3> <a name="rdfsparqlgeospatexmp1" /> <h4>14.14.4.1. Example 1</h4> <div> <pre class="programlisting"> ## Get All Stuff For Given Coordinates SQL>SPARQL SELECT ?c COUNT (*) WHERE { ?m geo:geometry ?geo . ?m a ?c . FILTER (bif:st_intersects (?geo, bif:st_point (0, 52), 100)) } GROUP BY ?c ORDER BY desc 2; c callret-1 VARCHAR VARCHAR _______________________________________________________________________________ http://linkedgeodata.org/vocabulary#node 2317684 http://linkedgeodata.org/vocabulary#way 85315 http://linkedgeodata.org/vocabulary#building 14257 http://dbpedia.org/class/yago/Landmark108624891 9093 http://linkedgeodata.org/vocabulary#wood 7155 .... </pre> </div> <br /> <a name="rdfsparqlgeospatexmp2" /> <h4>14.14.4.2. Example 2</h4> <div> <pre class="programlisting"> ## Get City Stuff Around Catholic Churches In Paris SQL> SPARQL SELECT ?m (bif:st_distance (?geo, bif:st_point (0, 52))) WHERE { ?m geo:geometry ?geo . ?m a <http://dbpedia.org/ontology/City> . FILTER (bif:st_intersects (?geo, bif:st_point (0, 52), 30)) } ORDER BY DESC 2 LIMIT 20; m callret-1 VARCHAR VARCHAR _______________________________________________________________________________ http://dbpedia.org/resource/Stansted_Mountfitchet 39.13180985471543 http://dbpedia.org/resource/Stansted_Mountfitchet 39.13180985471543 http://dbpedia.org/resource/Stansted_Mountfitchet 39.13180985471543 http://dbpedia.org/resource/Stansted_Mountfitchet 39.13180985471543 http://dbpedia.org/resource/Stansted_Mountfitchet 37.36907252285992 http://dbpedia.org/resource/Stansted_Mountfitchet 34.49432513061792 http://dbpedia.org/resource/Stansted_Mountfitchet 33.7676326404143 http://dbpedia.org/resource/Stansted_Mountfitchet 33.24238654570499 http://dbpedia.org/resource/Stansted_Mountfitchet 32.60139660515003 http://dbpedia.org/resource/Stansted_Mountfitchet 32.60139660515003 http://dbpedia.org/resource/Stansted_Mountfitchet 31.45681319171456 http://dbpedia.org/resource/Stansted_Mountfitchet 31.115377038 http://dbpedia.org/resource/Stansted_Mountfitchet 31.115377038 http://dbpedia.org/resource/Stansted_Mountfitchet 30.56388658524301 http://dbpedia.org/resource/Stansted_Mountfitchet 29.89662974046085 http://dbpedia.org/resource/Stansted_Mountfitchet 29.85090625132639 http://dbpedia.org/resource/Stansted_Mountfitchet 29.82605254366244 http://dbpedia.org/resource/Stansted_Mountfitchet 29.60102064794003 http://dbpedia.org/resource/Stansted_Mountfitchet 29.44147385851453 http://dbpedia.org/resource/Stansted_Mountfitchet 29.421242437379 </pre> </div> <br /> <a name="rdfsparqlgeospatexmp3" /> <h4>14.14.4.3. Example 3</h4> <div> <pre class="programlisting"> ## Get City Stuff Around Catholic Churches In Paris Extended SQL> SPARQL SELECT ?m (bif:st_distance (?geo, bif:st_point (0, 52))) WHERE { ?m geo:geometry ?geo . ?m a <http://dbpedia.org/ontology/City> . FILTER (bif:st_intersects (?geo, bif:st_point (0, 52), 100)) } ORDER BY DESC 2 LIMIT 20; m callret-1 VARCHAR VARCHAR _______________________________________________________________________________ http://dbpedia.org/resource/Weston-on-Trent 138.7082197019335 http://dbpedia.org/resource/Weston-on-Trent 137.7213767969613 http://dbpedia.org/resource/Weston-on-Trent 136.4597167847218 http://dbpedia.org/resource/Weston-on-Trent 134.1807668663677 http://dbpedia.org/resource/Weston-on-Trent 133.104337839536 http://dbpedia.org/resource/Weston-on-Trent 133.104337839536 http://dbpedia.org/resource/Nonington 132.7368236183588 http://dbpedia.org/resource/Nonington 132.1339163200362 http://dbpedia.org/resource/Nonington 132.1339163200362 http://dbpedia.org/resource/Nonington 130.5478483560461 http://dbpedia.org/resource/Nonington 130.1620410981843 http://dbpedia.org/resource/Nonington 129.8549842943355 http://dbpedia.org/resource/Nonington 129.6459280567849 http://dbpedia.org/resource/Nonington 129.4504858595742 http://dbpedia.org/resource/Nonington 129.2790713235814 http://dbpedia.org/resource/Nonington 128.9081040147881 http://dbpedia.org/resource/Nonington 128.8845164618929 http://dbpedia.org/resource/Nonington 128.6676189617872 http://dbpedia.org/resource/Nonington 128.2565253458452 http://dbpedia.org/resource/Nonington 128.2551696344652 20 Rows. -- 120 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp4" /> <h4>14.14.4.4. Example 4</h4> <div> <pre class="programlisting"> ## Text Or Geo SQL> SPARQL SELECT ?c COUNT (*) WHERE { ?m geo:geometry ?geo . ?m a ?c . FILTER (bif:st_intersects (?geo, bif:st_point (0, 52), 100) && REGEX (str (?c), "London") ) } GROUP BY ?c ORDER BY DESC 2 LIMIT 10; c callret-1 ____________________________________________________________________________ http://dbpedia.org/class/yago/DistrictsOfLondon 861 http://dbpedia.org/class/yago/GradeIListedBuildingsInLondon 199 http://dbpedia.org/class/yago/MuseumsInLondon 107 http://dbpedia.org/class/yago/ArtMuseumsAndGalleriesInLondon 92 http://dbpedia.org/class/yago/GradeIIListedBuildingsInLondon 89 http://dbpedia.org/class/yago/SportsVenuesInLondon 80 http://dbpedia.org/class/yago/RoyalBuildingsInLondon 72 http://dbpedia.org/class/yago/LondonOvergroundStations 69 http://dbpedia.org/class/yago/NationalGovernmentBuildingsInLondon 69 http://dbpedia.org/class/yago/SkyscrapersInLondon 60 </pre> </div> <br /> <a name="rdfsparqlgeospatexmp5" /> <h4>14.14.4.5. Example 5</h4> <div> <pre class="programlisting"> ## Example "Places Of Worship, Within 5 km Of Paris": ## Describes places of worship, within 5 km of Paris, ## that have cafes in close proximity(0.2 km). ## The query requires V6 or higher. SQL> PREFIX lgv: <http://linkedgeodata.org/vocabulary#> DESCRIBE ?cafe ?church WHERE { ?church a lgv:place_of_worship . ?church geo:geometry ?churchgeo . ?church lgv:name ?churchname . ?cafe a lgv:cafe . ?cafe lgv:name ?cafename . ?cafe geo:geometry ?cafegeo . ?cafe geo:lat ?lat . ?cafe geo:long ?long . FILTER ( bif:st_intersects ( ?churchgeo, bif:st_point ( 2.3498, 48.853 ), 5 ) && bif:st_intersects ( ?cafegeo, ?churchgeo, 0.2 ) ) } LIMIT 10; @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix ns1: <http://linkedgeodata.org/triplify/node/243360870#> . @prefix ns2: <http://linkedgeodata.org/vocabulary#> . ns1:id rdf:type ns2:place_of_worship , ns2:node . @prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> . ns1:id geo:lat 48.8794 ; geo:long 2.3748 ; ns2:created_by "Potlatch 0.6c" ; ns2:name "Saint-Georges de la Villette" ; ns2:religion "christian" , ns2:christian . @prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#> . ns1:id geo:geometry "POINT(2.3748 48.8794)"^^virtrdf:Geometry . @prefix ns5: <http://linkedgeodata.org/triplify/node/266632049#> . ns5:id rdf:type ns2:node , ns2:cafe ; geo:lat 48.8518 ; geo:long 2.325 ; ns2:created_by "Potlatch 0.9a" ; ns2:name "Le Babylone" ; geo:geometry "POINT(2.325 48.8518)"^^virtrdf:Geometry . .... </pre> </div> <br /> <a name="rdfsparqlgeospatexmp6" /> <h4>14.14.4.6. Example 6</h4> <div> <pre class="programlisting"> ## Count Geo SQL> SPARQL SELECT ?c COUNT (*) WHERE { ?s geo:geometry ?geo . FILTER (bif:st_intersects (?geo, bif:st_point (2.3498, 48.853), 5)) . ?s a ?c } GROUP BY ?c ORDER BY desc 2 LIMIT 10; c callret-1 VARCHAR VARCHAR _______________________________________________________________________________ http://linkedgeodata.org/vocabulary#node 37792 http://dbpedia.org/class/yago/Landmark108624891 4003 http://linkedgeodata.org/vocabulary#way 1688 http://linkedgeodata.org/vocabulary#building 719 http://linkedgeodata.org/vocabulary#station 257 http://linkedgeodata.org/vocabulary#post_box 247 http://www.w3.org/2002/07/owl#Thing 227 http://linkedgeodata.org/vocabulary#park 208 http://linkedgeodata.org/vocabulary#restaurant 198 http://dbpedia.org/ontology/Place 192 10 Rows. -- 932 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp7" /> <h4>14.14.4.7. Example 7</h4> <div> <pre class="programlisting"> ## Get Stuff Around Notre Dame De Paris SQL> SPARQL SELECT ?c COUNT (*) WHERE { ?s a ?c . ?s geo:geometry ?geo . FILTER (bif:st_intersects (?geo, bif:st_point (2.3498, 48.853), 0.3)) } GROUP BY ?c ORDER BY desc 2 LIMIT 10; c callret-1 VARCHAR VARCHAR _______________________________________________________________________________ http://linkedgeodata.org/vocabulary#node 408 http://dbpedia.org/class/yago/Landmark108624891 134 http://linkedgeodata.org/vocabulary#way 17 http://dbpedia.org/class/yago/RomanCatholicChurchesInParis 17 http://dbpedia.org/class/yago/TallBuildingsAndStructuresInParis 13 http://dbpedia.org/class/yago/CathedralsInFrance 13 http://sw.opencyc.org/2008/06/10/concept/Mx4rvVigPpwpEbGdrcN5Y29ycA 13 http://sw.opencyc.org/2008/06/10/concept/Mx4rjm5QanS6EdaAAACgyZzFrg 13 http://sw.opencyc.org/2008/06/10/concept/Mx4rwQwtGpwpEbGdrcN5Y29ycA 13 http://www.w3.org/2002/07/owl#Thing 10 10 Rows. -- 241 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp8" /> <h4>14.14.4.8. Example 8</h4> <div> <pre class="programlisting"> ## Things within 10 km proximity of place of worship SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> SELECT ?c COUNT (*) WHERE { ?s a ?c . ?s a lgv:place_of_worship . ?s geo:geometry ?geo . FILTER (bif:st_intersects (?geo, bif:st_point (2.3498, 48.853), 10)) } GROUP BY ?c ORDER BY desc 2 LIMIT 10; c callret-1 VARCHAR VARCHAR _______________________________________________________________________________ http://linkedgeodata.org/vocabulary#place_of_worship 147 http://linkedgeodata.org/vocabulary#node 146 http://linkedgeodata.org/vocabulary#way 46 http://linkedgeodata.org/vocabulary#building 36 http://linkedgeodata.org/vocabulary#attraction 3 http://linkedgeodata.org/vocabulary#church 1 6 Rows. -- 120 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp9" /> <h4>14.14.4.9. Example 9</h4> <div> <pre class="programlisting"> ## Get Stuff Around Notre Dame De Paris with Names SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> SELECT ?cn WHERE { ?s lgv:name ?cn . ?s geo:geometry ?geo . FILTER (bif:st_intersects (?geo, bif:st_point (2.3498, 48.853), 0.3)) } LIMIT 20; cn VARCHAR _______________________________________________________________________________ Parking Lagrange Maitre Albert B&B Le Grenier de Notre Dame Eglise Saint-Julien-le-Pauvre Eglise Saint Julien le Pauvre Polly Magoo Point 0 des Routes de France Square Jean XXIII .... 20 Rows. -- 140 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp10" /> <h4>14.14.4.10. Example 10</h4> <div> <pre class="programlisting"> ## Get Churches With The Most Bars SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> SELECT ?churchname ?cafename (bif:st_distance (?churchgeo, ?cafegeo)) WHERE { ?church a lgv:place_of_worship . ?church geo:geometry ?churchgeo . ?church lgv:name ?churchname . ?cafe a lgv:cafe . ?cafe lgv:name ?cafename . ?cafe geo:geometry ?cafegeo . FILTER (bif:st_intersects (?churchgeo, bif:st_point (2.3498, 48.853), 5) && bif:st_intersects (?cafegeo, ?churchgeo, 0.2)) } LIMIT 10; churchname cafename callret-2 VARCHAR VARCHAR VARCHAR _______________________________________________________________________________ Eglise Saint-Julien-le-Pauvre Le Saint R+?-?gis 0.09759308692691648 Eglise Saint-Germain des Pr+?-?s Caf+?-? de Flore 0.08774468391412803 Eglise Saint-Germain des Pr+?-?s Les Deux Magots 0.05235923473923059 Eglise Saint-Germain des Pr+?-?s Caf+?-? Mabillon 0.1712042770289815 Eglise Saint-Germain-des-Pr+?-?s Caf+?-? de Flore 0.1466502865197912 Eglise Saint-Germain-des-Pr+?-?s Les Deux Magots 0.1096767137079839 Eglise Saint-Germain-des-Pr+?-?s Bar du march+?-? 0.1831441251868126 Eglise Saint-Germain-des-Pr+?-?s Caf+?-? Mabillon 0.1174051745495528 Synagogue La Chaise au Plafond 0.1038387283609551 Synagogue Le Loir dans la Th+?-?i+?-?re 0.1632848322062273 10 Rows. -- 511225 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp11" /> <h4>14.14.4.11. Example 11</h4> <div> <pre class="programlisting"> ## Things around highly populated places SQL> SPARQL SELECT ?s ( sql:num_or_null (?o) ) COUNT (*) WHERE { ?s <http://dbpedia.org/ontology/populationTotal> ?o . FILTER ( sql:num_or_null (?o) > 6000000 ) . ?s geo:geometry ?geo . FILTER ( bif:st_intersects (?pt, ?geo,2) ) . ?xx geo:geometry ?pt } GROUP BY ?s ( sql:num_or_null (?o) ) ORDER BY desc 3 LIMIT 20; s callret-1 callret-2 VARCHAR VARCHAR VARCHAR _______________________________________________________________________________ http://dbpedia.org/resource/London 7556900 312307 http://dbpedia.org/resource/Toronto 8102163 115859 http://dbpedia.org/resource/New_York_City 8363710 95629 http://dbpedia.org/resource/The_Hague 6659300 84410 http://dbpedia.org/resource/Tokyo 12790000 78618 http://dbpedia.org/resource/Philadelphia 6385461 67115 http://dbpedia.org/resource/Los_Angeles 17755322 64394 http://dbpedia.org/resource/Bangkok 8160522 62519 http://dbpedia.org/resource/Barcelona 2147483648 57635 http://dbpedia.org/resource/Cairo 6758581 52738 http://dbpedia.org/resource/Istanbul 12697164 50745 http://dbpedia.org/resource/Seoul 10421782 43962 http://dbpedia.org/resource/Beijing 17430000 35979 http://dbpedia.org/resource/Purmerend 6659300 33508 http://dbpedia.org/resource/Baghdad 6554126 33426 http://dbpedia.org/resource/Bogot%C3%A1 6776009 30429 http://dbpedia.org/resource/Mexico_City 8836045 30127 http://dbpedia.org/resource/Jakarta 8500000 28944 http://dbpedia.org/resource/Boston 7514759 27705 http://dbpedia.org/resource/Baden-W%C3%BCrttemberg 10755000 25112 20 Rows. -- 4296 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp12" /> <h4>14.14.4.12. Example 12</h4> <div> <pre class="programlisting"> ## Example "Places Of Worship, Within 5 km Of Paris": ## Constructs a custom Linked Data Mesh (graph) about ## places of worship, within 5 km of Paris, that have ## cafes in close proximity(0.2 km). ## Note: we have distinct pin colors that identify ## for places of worship distinct from cafes. ## The query requires V6 or higher. SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> PREFIX rtb: <http://www.openlinksw.com/schemas/oat/rdftabs#> CONSTRUCT { ?cafe geo:geometry ?cafegeo ; rtb:useMarker '01' ; lgv:name ?cafename . ?church geo:geometry ?churchgeo ; rtb:useMarker '02' ; lgv:name ?churchname . } WHERE { ?church a lgv:place_of_worship . ?church geo:geometry ?churchgeo . ?church lgv:name ?churchname . ?cafe a lgv:cafe . ?cafe lgv:name ?cafename . ?cafe geo:geometry ?cafegeo . ?cafe geo:lat ?lat . ?cafe geo:long ?long . FILTER ( bif:st_intersects ( ?churchgeo, bif:st_point ( 2.3498, 48.853 ), 5 ) && bif:st_intersects ( ?cafegeo, ?churchgeo, 0.2 ) ) } LIMIT 10; @prefix ns0: <http://linkedgeodata.org/vocabulary#> . @prefix ns1: <http://linkedgeodata.org/triplify/node/237435716#> . ns1:id ns0:name "Chapelle du Val de Gr\u00C3\u00A2ce" . @prefix ns2: <http://www.openlinksw.com/schemas/oat/rdftabs#> . ns1:id ns2:useMarker "02" . @prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#> . @prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> . ns1:id geo:geometry "POINT(2.3418 48.8406)"^^virtrdf:Geometry . @prefix ns5: <http://linkedgeodata.org/triplify/node/218147750#> . ns5:id ns0:name "Synagogue" ; ns2:useMarker "02" ; geo:geometry "POINT(2.3593 48.857)"^^virtrdf:Geometry . @prefix ns6: <http://linkedgeodata.org/triplify/node/218145208#> . ns6:id ns0:name "Synagogue" ; ns2:useMarker "02" ; geo:geometry "POINT(2.3589 48.8567)"^^virtrdf:Geometry . ... </pre> </div> <br /> <a name="rdfsparqlgeospatexmp13" /> <h4>14.14.4.13. Example 13</h4> <div> <pre class="programlisting"> ## Example "Places Of Worship, Within 5 km Of Paris": ## Asks for places of worship, within 5 km of Paris, ## that have cafes in close proximity(0.2 km). ## The query requires V6 or higher. SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> ASK WHERE { ?church a lgv:place_of_worship . ?church geo:geometry ?churchgeo . ?church lgv:name ?churchname . ?cafe a lgv:cafe . ?cafe lgv:name ?cafename . ?cafe geo:geometry ?cafegeo . ?cafe geo:lat ?lat . ?cafe geo:long ?long . FILTER ( bif:st_intersects ( ?churchgeo, bif:st_point ( 2.3498, 48.853 ), 5 ) && bif:st_intersects ( ?cafegeo, ?churchgeo, 0.2 ) ) }; Done. true </pre> </div> <br /> <a name="rdfsparqlgeospatexmp14" /> <h4>14.14.4.14. Example 14</h4> <div> <pre class="programlisting"> ## Places of worship, within 5 km of Paris, ## that have cafes in close proximity(0.2 km) SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> SELECT DISTINCT ?cafe ?lat ?long ?cafename ?churchname (bif:round(bif:st_distance (?churchgeo, ?cafegeo))) WHERE { ?church a lgv:place_of_worship . ?church geo:geometry ?churchgeo . ?church lgv:name ?churchname . ?cafe a lgv:cafe . ?cafe lgv:name ?cafename . ?cafe geo:geometry ?cafegeo . ?cafe geo:lat ?lat. ?cafe geo:long ?long. FILTER ( bif:st_intersects (?churchgeo, bif:st_point (2.3498, 48.853), 5) && bif:st_intersects (?cafegeo, ?churchgeo, 0.2) ) } LIMIT 10; cafe lat long cafename churchname callret-5 VARCHAR VARCHAR VARCHAR VARCHAR VARCHAR VARCHAR _______________________________________________________________________________________________________________________________________________________________ http://linkedgeodata.org/triplify/node/321932192#id 48.8522 2.3484 Le Saint R+?-?gis Eglise Saint-Julien-le-Pauvre 0 http://linkedgeodata.org/triplify/node/251699776#id 48.8541 2.3326 Caf+?-? de Flore Eglise Saint-Germain des Pr+?-?s 0 http://linkedgeodata.org/triplify/node/251699775#id 48.854 2.3331 Les Deux Magots Eglise Saint-Germain des Pr+?-?s 0 http://linkedgeodata.org/triplify/node/315769036#id 48.8533 2.3358 Caf+?-? Mabillon Eglise Saint-Germain des Pr+?-?s 0 http://linkedgeodata.org/triplify/node/251699776#id 48.8541 2.3326 Caf+?-? de Flore Eglise Saint-Germain-des-Pr+?-?s 0 http://linkedgeodata.org/triplify/node/251699775#id 48.854 2.3331 Les Deux Magots Eglise Saint-Germain-des-Pr+?-?s 0 http://linkedgeodata.org/triplify/node/315769035#id 48.8539 2.3371 Bar du march+?-? Eglise Saint-Germain-des-Pr+?-?s 0 http://linkedgeodata.org/triplify/node/315769036#id 48.8533 2.3358 Caf+?-? Mabillon Eglise Saint-Germain-des-Pr+?-?s 0 http://linkedgeodata.org/triplify/node/251126326#id 48.8572 2.3577 La Chaise au Plafond Synagogue 0 http://linkedgeodata.org/triplify/node/251043135#id 48.8562 2.361 Le Loir dans la Th+?-?i+?-?re Synagogue 0 10 Rows. -- 120 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp15" /> <h4>14.14.4.15. Example 15</h4> <div> <pre class="programlisting"> ## Stuff around Notre Dame de Paris SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> SELECT ?s ?cn ?lat ?long WHERE { ?s lgv:name ?cn . ?s geo:geometry ?geo . ?s geo:lat ?lat. ?s geo:long ?long. FILTER ( bif:st_intersects (?geo, bif:st_point (2.3498, 48.853), 0.3) ) } LIMIT 20; s cn lat long VARCHAR VARCHAR VARCHAR VARCHAR ______________________________________________________________________________________________________________ http://linkedgeodata.org/triplify/node/237004656#id Parking Lagrange 48.8506 2.3487 http://linkedgeodata.org/triplify/node/237003117#id Mus+?-?e de l'Assistance Publique H+?-¦pitaux de Paris 48.8507 2.3519 http://linkedgeodata.org/triplify/way/23071565#id Jardin de la Rue de Bi+?-?vre 48.8504 2.3502 http://linkedgeodata.org/triplify/node/251652818#id Maitre Albert B&B 48.8507 2.3496 http://linkedgeodata.org/triplify/node/251373384#id Le Grenier de Notre Dame 48.8513 2.35 http://linkedgeodata.org/triplify/node/205266764#id Eglise Saint-Julien-le-Pauvre 48.852 2.3471 http://linkedgeodata.org/triplify/way/19741083#id Eglise Saint Julien le Pauvre 48.8521 2.3469 http://linkedgeodata.org/triplify/node/251474112#id Polly Magoo 48.8526 2.3467 http://linkedgeodata.org/triplify/node/251531803#id H+?-¦tel Esmerelda 48.8523 2.3468 http://linkedgeodata.org/triplify/node/191031796#id Point 0 des Routes de France 48.8533 2.3489 http://linkedgeodata.org/triplify/way/20444455#id Square Jean XXIII 48.8529 2.3511 http://linkedgeodata.org/triplify/way/19740745#id Square Ren+?-? Viviani 48.8525 2.3476 http://linkedgeodata.org/triplify/node/321932192#id Le Saint R+?-?gis 48.8522 2.3484 http://linkedgeodata.org/triplify/node/27440965#id Notre-Dame de Paris 48.853 2.3499 http://linkedgeodata.org/triplify/node/243461762#id Parking Notre-Dame 48.8537 2.3475 http://linkedgeodata.org/triplify/way/21816758#id Notre-Dame de Paris 48.8531 2.349 http://linkedgeodata.org/triplify/way/22972062#id La Seine 48.8538 2.3531 http://linkedgeodata.org/triplify/way/25463927#id La Seine 48.8548 2.3518 http://linkedgeodata.org/triplify/node/251128395#id H+?-¦tel Hospitel 48.854 2.3484 http://linkedgeodata.org/triplify/way/14155323#id H+?-¦tel Dieu 48.8555 2.3485 20 Rows. -- 167 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp16" /> <h4>14.14.4.16. Example 16</h4> <div> <pre class="programlisting"> ## Stuff around Notre Dame de Paris SQL> SPARQL PREFIX lgv: <http://linkedgeodata.org/vocabulary#> DESCRIBE ?s WHERE { ?s lgv:name ?cn . ?s geo:geometry ?geo . ?s geo:lat ?lat. ?s geo:long ?long. FILTER (bif:st_intersects (?geo, bif:st_point (2.3498, 48.853), 0.3)) } LIMIT 20; @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix ns1: <http://linkedgeodata.org/triplify/node/27440966#> . @prefix ns2: <http://linkedgeodata.org/vocabulary#> . ns1:id rdf:type ns2:node , ns2:police . @prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> . ns1:id geo:lat 48.8542 ; geo:long 2.3473 ; ns2:created_by "Potlatch 0.6a" ; ns2:name "Pr\u00C3\u00A9fecture de Police de Paris" , "Pr\u00E9fecture de Police de Paris" . @prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#> . ns1:id geo:geometry "POINT(2.3473 48.8542)"^^virtrdf:Geometry . @prefix ns5: <http://linkedgeodata.org/triplify/node/27440965#> . ns5:id rdf:type ns2:node , ns2:place_of_worship ; geo:lat 48.853 ; geo:long 2.3499 ; ns2:denomination "catholic" ; ns2:name "Notre-Dame de Paris" ; ns2:religion "christian" , ns2:christian ; geo:geometry "POINT(2.3499 48.853)"^^virtrdf:Geometry . ...... </pre> </div> <br /> <a name="rdfsparqlgeospatexmp17" /> <h4>14.14.4.17. Example 17</h4> <div> <pre class="programlisting"> ## Cities within 30 km proximity of London SQL> SPARQL SELECT ?m (bif:round(bif:st_distance (?geo, ?gm))) WHERE { <http://dbpedia.org/resource/London> geo:geometry ?gm . ?m geo:geometry ?geo . ?m a <http://dbpedia.org/ontology/City> . FILTER (bif:st_intersects (?geo, ?gm, 30)) } ORDER BY DESC 2 LIMIT 20; m callret-1 VARCHAR VARCHAR ____________________________________________________________ http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Ebbsfleet_Valley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 http://dbpedia.org/resource/Bletchingley 30 20 Rows. -- 727666 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp18" /> <h4>14.14.4.18. Example 18</h4> <div> <pre class="programlisting"> ## Motorways across England & Scotland from DBpedia SQL> SPARQL PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbpprop: <http://dbpedia.org/property/> PREFIX yago: <http://dbpedia.org/class/yago/> SELECT ?road ?services ?lat ?long WHERE { { ?services dbpprop:road ?road . ?road a yago:MotorwaysInEngland . ?services dbpprop:lat ?lat . ?services dbpprop:long ?long . } UNION { ?services dbpprop:road ?road . ?road a yago:MotorwaysInScotland . ?services dbpprop:lat ?lat . ?services dbpprop:long ?long . } } LIMIT 20; road services lat long VARCHAR VARCHAR VARCHAR VARCHAR ______________________________________________________________________________________________________________________________________ http://dbpedia.org/resource/M90_motorway http://dbpedia.org/resource/Kinross_services 56.209628 -3.439257 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Leicester_Forest_East_services 52.6192 -1.206 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Woodall_services 53.3152 -1.2813 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Tibshelf_services 53.13708 -1.33179 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/London_Gateway_services 51.631 -0.264 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Donington_Park_services 52.823651 -1.305887 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Watford_Gap_services 52.3069 -1.1226 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Newport_Pagnell_services 52.083066 -0.748508 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Trowell_services 52.963198 -1.265988 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Woolley_Edge_services 53.62259 -1.549422 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Toddington_services 51.9478 -0.502075 http://dbpedia.org/resource/M1_motorway http://dbpedia.org/resource/Northampton_services 52.209201 -0.944799 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Chieveley_services 51.449 -1.3112 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Magor_services 51.58786 -2.83713 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Pont_Abraham_services 51.74712 -4.0655 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Swansea_services 51.678197 -3.994646 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Leigh_Delamere_services 51.511528 -2.159468 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Reading_services 51.424527 -1.035633 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Cardiff_West_services 51.50626 -3.30535 http://dbpedia.org/resource/M4_motorway http://dbpedia.org/resource/Heston_services 51.48807 -0.39106 20 Rows. -- 531 msec. </pre> </div> <br /> <a name="rdfsparqlgeospatexmp18" /> <h4>14.14.4.19. Example 19</h4> <div> <pre class="programlisting"> SELECT DISTINCT ?s (bif:round(?lat)) as ?lat (bif:round(?long)) as ?long WHERE { { SELECT ?g ?s WHERE { graph ?g { ?s geo:geometry ?geo } } LIMIT 100 } graph ?g { ?s geo:lat ?lat . ?s geo:long ?long . } FILTER (datatype (?lat) in (xsd:integer, xsd:float, xsd:double)) . FILTER (datatype (?long) in (xsd:integer, xsd:float, xsd:double)) } s lat long ANY ANY ANY ________________________________________________________________________________________________ http://dbpedia.org/resource/QUaD -90 -139 http://dbpedia.org/resource/Amundsen-Scott_South_Pole_Station -90 -139 http://dbpedia.org/resource/Amundsen-Scott_South_Pole_Station -90 0 http://dbpedia.org/resource/Degree_Angular_Scale_Interferometer -90 -139 http://dbpedia.org/resource/South_Pole_Telescope -90 -139 http://dbpedia.org/resource/Arcminute_Cosmology_Bolometer_Array_Receiver -90 -139 http://dbpedia.org/resource/Viper_telescope -90 -139 http://dbpedia.org/resource/Mount_Weaver -87 -154 http://dbpedia.org/resource/Axel_Heiberg_Glacier -85 -163 http://dbpedia.org/resource/Mount_Ray -85 -171 http://linkedgeodata.org/triplify/node/275487234#id -85 -142 http://linkedgeodata.org/triplify/node/303732928#id -85 -142 http://linkedgeodata.org/triplify/node/332036611#id -85 -85 http://linkedgeodata.org/triplify/node/303732935#id -85 -143 http://linkedgeodata.org/triplify/node/303732951#id -85 -144 http://linkedgeodata.org/triplify/node/303732953#id -85 -144 http://linkedgeodata.org/triplify/node/276208684#id -85 -166 </pre> </div> <br /> <a name="rdfsparqlgeospatexmp19" /> <h4>14.14.4.20. Example 19</h4> <div> <pre class="programlisting"> ## "Find things within 20km of New York City": SELECT DISTINCT ?resource ?label ?location WHERE { <http://dbpedia.org/resource/New_York_City> geo:geometry ?sourcegeo . ?resource geo:geometry ?location ; rdfs:label ?label . FILTER( bif:st_intersects( ?location, ?sourcegeo, 20 ) ) . FILTER( lang(?label) = "en" ) } </pre> </div> <br /> <a name="rdfsparqlgeospatexmp20" /> <h4>14.14.4.21. Example 20</h4> <div> <pre class="programlisting"> ## "Find Distance between New York City ## and London, England": SELECT ( bif:st_distance( ?nyl,?ln ) ) AS ?distanceBetweenNewYorkCityAndLondon WHERE { <http://dbpedia.org/resource/New_York_City> geo:geometry ?nyl . <http://dbpedia.org/resource/London> geo:geometry ?ln . } </pre> </div> <br /> <a name="rdfsparqlgeospatexmp21" /> <h4>14.14.4.22. Example 21</h4> <div> <pre class="programlisting"> ## "Find "All Educational Institutions ## within 10km of Oxford, UK; ordered by ## date of establishment": SELECT DISTINCT ?thing AS ?uri ?thingLabel AS ?name ?date AS ?established ?matchgeo AS ?location WHERE { <http://dbpedia.org/resource/Oxford> geo:geometry ?sourcegeo . ?resource geo:geometry ?matchgeo . FILTER( bif:st_intersects( ?matchgeo, ?sourcegeo, 5 ) ) . ?thing ?somelink ?resource ; <http://dbpedia.org/ontology/established> ?date ; rdfs:label ?thingLabel . FILTER( lang(?thingLabel) = "en" ) } ORDER BY ASC( ?date ) </pre> </div> <br /> <a name="rdfsparqlgeospatexmp22" /> <h4>14.14.4.23. Example 22</h4> <div> <pre class="programlisting"> ## "Find Historical cross section of events related ## to Edinburgh and the surrounding area (within 30km) ## during the 19th century": SELECT DISTINCT ?thing ?thingLabel ?dateMeaningLabel ?date ?matchgeo WHERE { { SELECT DISTINCT ?thing ?matchgeo WHERE { <http://dbpedia.org/resource/Edinburgh> geo:geometry ?sourcegeo . ?resource geo:geometry ?matchgeo . FILTER( bif:st_intersects ( ?matchgeo, ?sourcegeo, 30 ) ) . ?thing ?somelink ?resource } } { ?property rdf:type owl:DatatypeProperty ; rdfs:range xsd:date } . ?thing ?dateMeaning ?date . FILTER( ?dateMeaning IN ( ?property ) ) . FILTER( ?date >= xsd:gYear("1800") && ?date <= xsd:gYear("1900") ) ?dateMeaning rdfs:label ?dateMeaningLabel . FILTER( lang(?dateMeaningLabel) = "en" ) . ?thing rdfs:label ?thingLabel . FILTER( lang(?thingLabel) = "en" ) } ORDER BY ASC ( ?date ) </pre> </div> <br /> <br /> <table border="0" width="90%" id="navbarbottom"> <tr> <td align="left" width="33%"> <a href="rdfsparqlrule.html" title="Inference Rules & Reasoning">Previous</a> <br />Inference Rules & Reasoning</td> <td align="center" width="34%"> <a href="rdfandsparql.html">Chapter Contents</a> </td> <td align="right" width="33%"> <a href="rdfperformancetuning.html" title="RDF Performance Tuning">Next</a> <br />RDF Performance Tuning</td> </tr> </table> </div> <div id="footer"> <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div> <div id="validation"> <a href="http://validator.w3.org/check/referer"> <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /> </a> <a href="http://jigsaw.w3.org/css-validator/"> <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" /> </a> </div> </div> </body> </html>