Repository navigation
Expand file tree
/
Copy pathcrazy-query.sparql
More file actions
101 lines (84 loc) · 4.58 KB
/
Copy pathcrazy-query.sparql
File metadata and controls
101 lines (84 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Author: https://github.com/MathiasVDA
PREFIX gsp: <http://www.opengis.net/ont/geosparql#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT * WHERE
{
FILTER (?short_name_iso2 != 'RU')
{
SELECT ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 (STRDT(CONCAT("POLYGON(",GROUP_CONCAT(CONCAT(?coordinate_string); SEPARATOR=", "),")"), gsp:wktLiteral) AS ?wkt)
WHERE {
SELECT ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 ?polygon_index (CONCAT("(",GROUP_CONCAT(CONCAT(?wkt_coordinate); SEPARATOR=", "),")") AS ?coordinate_string)
WHERE {
SERVICE <x-sparql-anything:location:> {
fx:properties fx:location "https://raw.githubusercontent.com/leakyMirror/map-of-europe/refs/heads/master/GeoJSON/europe.geojson" ;
fx:media-type "application/json" .
?s xyz:type "Feature";
xyz:geometry ?geom;
xyz:properties ?props.
?props xyz:NAME ?name;
xyz:FIPS ?short_name_fips;
xyz:ISO2 ?short_name_iso2;
xyz:ISO3 ?short_name_iso3.
?geom xyz:type ?wkt_type;
xyz:coordinates ?multi_polygon.
?multi_polygon ?list_polygon_element ?polygon .
BIND (xsd:integer(replace(STR(?list_polygon_element),'http://www.w3.org/1999/02/22-rdf-syntax-ns#_','')) AS ?polygon_index)
?polygon ?list_coordinate_element ?coordinate .
BIND (xsd:integer(replace(STR(?list_coordinate_element),'http://www.w3.org/1999/02/22-rdf-syntax-ns#_','')) AS ?coordinate_index)
?coordinate rdf:_1 ?longitude;
rdf:_2 ?latitude.
BIND (CONCAT(str(?longitude), " ", str(?latitude)) AS ?wkt_coordinate)
FILTER (str(?wkt_type) = "Polygon")
}
}
GROUP BY ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 ?polygon_index
ORDER BY ?coordinate_index
}
GROUP BY ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3
ORDER BY ?polygon_index
}
UNION
{
SELECT ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 (STRDT(CONCAT("MULTIPOLYGON(",GROUP_CONCAT(CONCAT(?polygon_string); SEPARATOR=", "),")"), gsp:wktLiteral) AS ?wkt)
WHERE {
SELECT ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 ?multipolygon_index (CONCAT("(",GROUP_CONCAT(CONCAT(?coordinate_string); SEPARATOR="), ("),")") AS ?polygon_string)
WHERE {
SELECT ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 ?multipolygon_index ?polygon_index (CONCAT("(",GROUP_CONCAT(CONCAT(?wkt_coordinate); SEPARATOR=", "),")") AS ?coordinate_string)
WHERE {
SERVICE <x-sparql-anything:location:> {
fx:properties fx:location "https://raw.githubusercontent.com/leakyMirror/map-of-europe/refs/heads/master/GeoJSON/europe.geojson" ;
fx:media-type "application/json" .
?s xyz:type "Feature";
xyz:geometry ?geom;
xyz:properties ?props.
?props xyz:NAME ?name;
xyz:FIPS ?short_name_fips;
xyz:ISO2 ?short_name_iso2;
xyz:ISO3 ?short_name_iso3.
?geom xyz:type ?wkt_type;
xyz:coordinates ?multi_polygon_collection.
?multi_polygon_collection ?list_multipolygon_element ?multi_polygon.
BIND (xsd:integer(replace(STR(?list_multipolygon_element),'http://www.w3.org/1999/02/22-rdf-syntax-ns#_','')) AS ?multipolygon_index)
?multi_polygon ?list_polygon_element ?polygon .
BIND (xsd:integer(replace(STR(?list_polygon_element),'http://www.w3.org/1999/02/22-rdf-syntax-ns#_','')) AS ?polygon_index)
?polygon ?list_coordinate_element ?coordinate .
BIND (xsd:integer(replace(STR(?list_coordinate_element),'http://www.w3.org/1999/02/22-rdf-syntax-ns#_','')) AS ?coordinate_index)
?coordinate rdf:_1 ?longitude;
rdf:_2 ?latitude.
BIND (CONCAT(str(?longitude), " ", str(?latitude)) AS ?wkt_coordinate)
FILTER (str(?wkt_type) = "MultiPolygon")
}
}
GROUP BY ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 ?multipolygon_index ?polygon_index
ORDER BY ?coordinate_index
}
GROUP BY ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3 ?multipolygon_index
ORDER BY ?polygon_index
}
GROUP BY ?name ?short_name_fips ?short_name_iso2 ?short_name_iso3
ORDER BY ?multipolygon_index
}
}