CREATE SERVER linkedgeodata FOREIGN DATA WRAPPER rdf_fdw OPTIONS (endpoint 'http://linkedgeodata.org/sparql'); /* * LinkedGeoData Cities * List all that contain a WKT literal and a * label written in English. This example requires the extension PostGIS! */ CREATE FOREIGN TABLE cities ( uri text OPTIONS (variable '?city'), city text OPTIONS (variable '?label'), country_code text OPTIONS (variable '?countryCode'), wkt text OPTIONS (variable '?wkt') ) SERVER linkedgeodata OPTIONS ( log_sparql 'true', sparql ' SELECT * WHERE { ?city a . ?city ?label . ?city ?geo . ?geo ?wkt . FILTER(LANG(?label) = "en") OPTIONAL { ?city ?countryCode } } '); /* * Select all records that overlap with a given bbox */ SELECT uri, city, country_code, wkt::geometry FROM cities WHERE ST_Contains( 'SRID=4326;POLYGON ((-8.613281 52.268157, -8.613281 56.218923, 0.878906 56.218923, 0.878906 52.268157, -8.613281 52.268157))', ST_SetSRID(wkt::geometry,4326));