query-8891975637030d69a7c694e5bb7ba7d5
Can I query items that their geolocation is in a given polygon ?Is there a way to query over a polygon area and not a bounding box or a radius? 16:21, 14 August 2020 (UTC)) talk (Bouzinac), I encounter a timeout, could you help improving that query ? logs • contribs • talk (Dipsacus fullonum and run this query... Re (Q4115189)Wikidata Sandbox 1 to (P1335)coordinates of westernmost point (P1334)coordinates of easternmost point (P1333)coordinates of southernmost point (P1332)coordinates of northernmost point Hello there, I think there could be a workaround. Input your polygon data into 18:05, 13 August 2020 (UTC)) talk (Dipsacus fullonum: Not to my knowledge, but you can make outer bounding box or outer cicle around the polygon, and then check every found point if it is in the polygon. --Tazary4@
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
#defaultView:Map
SELECT ?item ?country ?coord {
VALUES ?country { wd:Q4115189 } . #select a country here, works also with any item having east, west, south and north bounds
?country p:P1332 [ ps:P1332 ?north; psv:P1332 ?nValue ];
p:P1333 [ ps:P1333 ?south; psv:P1333 ?sValue ];
p:P1334 [ ps:P1334 ?east; psv:P1334 ?eValue ];
p:P1335 [ ps:P1335 ?west; psv:P1335 ?wValue ].
?nValue wikibase:geoLatitude ?nLat .
?sValue wikibase:geoLatitude ?sLat .
?eValue wikibase:geoLongitude ?eLon .
?wValue wikibase:geoLongitude ?wLon .
?item p:P625 [ a wikibase:BestRank; ps:P625 ?coord; psv:P625 ?cValue ] .
?cValue wikibase:geoLatitude ?lat .
?cValue wikibase:geoLongitude ?lon .
?cValue wikibase:geoGlobe ?globe .
BIND(COALESCE(?globe,wd:Q2) as ?Globe)
FILTER (?Globe =wd:Q2) #select only Earth-like coordinates
MINUS { ?item wdt:P17 [] } . #has the item any P17 value ?
MINUS { ?item (wdt:P31/wdt:P279*) wd:Q4830453. } # exclude ENTREPRISES
MINUS { ?item (wdt:P31/wdt:P279*) wd:Q15893266. } # exclude old entities
MINUS { ?item wdt:P576 _:b2. } # remove items with P576 (dissolved, abolished or demolished) as a main property
FILTER( ?sLat < ?lat && ?lat < ?nLat ) . #modify here to
FILTER( ?wLon < ?lon && ?lon < ?eLon ) .
} limit 100