Skip to content

Commit a91c80c

Browse files
committed
test wfs exporter
1 parent 7134a07 commit a91c80c

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/sparqlunicorn_ontdoc/docgeneration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from export.api.iiifexporter import IIIFAPIExporter
3333
from export.api.ogcapifeaturesexporter import OGCAPIFeaturesExporter
3434
from export.api.ckanexporter import CKANExporter
35+
from export.api.wfsexporter import WFSExporter
3536
from export.api.solidexporter import SolidExporter
3637

3738
import argparse
@@ -336,6 +337,7 @@ def generateOntDocForNameSpace(self, prefixnamespace,dataformat="HTML"):
336337
"{{exports}}", templates["nongeoexports"]).replace("{{bibtex}}", "")
337338
OGCAPIFeaturesExporter.generateOGCAPIFeaturesPages(outpath, self.pubconfig["deploypath"], self.htmlexporter.featurecollectionspaths,
338339
self.pubconfig["prefixns"], self.pubconfig["apis"]["ogcapifeatures"], True)
340+
WFSExporter.generateWFSPages(outpath,self.pubconfig["deploypath"], self.htmlexporter.featurecollectionspaths,self.licenseuri)
339341
indexhtml += "<p>This page shows feature collections present in the linked open data export</p><script src=\"features.js\"></script>"
340342
indexhtml += templates["maptemplate"].replace("var ajax=true", "var ajax=false").replace(
341343
"var featurecolls = {{myfeature}}", "").replace("{{relativepath}}",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
import json
3+
4+
class WFSExporter:
5+
6+
@staticmethod
7+
def generateWFSPages(outpath,deploypath, featurecollectionspaths,license):
8+
#os.mkdir(outpath+"/wfs")
9+
apihtml = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /><metaname=\"description\" content=\"SwaggerUI\"/><title>SwaggerUI</title><link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" /></head><body><div id=\"swagger-ui\"></div><script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script><script>const swaggerUrl = \"" + str(
10+
deploypath) + "/api/index.json\"; const apiUrl = \"" + str(
11+
deploypath) + "/\"; window.onload = () => {let swaggerJson = fetch(swaggerUrl).then(r => r.json().then(j => {j.servers[0].url = apiUrl; window.ui = SwaggerUIBundle({spec: j,dom_id: '#swagger-ui'});}));};</script></body></html>"
12+
apijson = {"openapi": "3.0.1", "info": {"title": str(deploypath) + " Feature Collections",
13+
"description": "Feature Collections of " + str(deploypath)},
14+
"servers": [{"url": str(deploypath)}], "paths": {}}
15+
getcapabilities=f"""
16+
<wfs:WFS_Capabilities xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:BAYSIS_Strassennetz="https://www.baysis.bayern.de/gis/admin/services/BAYSIS_Strassennetz/MapServer/WFSServer" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd https://www.baysis.bayern.de/gis/admin/services/BAYSIS_Strassennetz/MapServer/WFSServer https://www.baysis.bayern.de/gis/services/wfs/BAYSIS_Strassennetz/MapServer/WFSServer?service=wfs%26version=1.0.0%26request=DescribeFeatureType" version="1.0.0">
17+
<wfs:Service>
18+
<wfs:Name>Static WFS</wfs:Name>
19+
<wfs:Title>Static WFS for {deploypath}</wfs:Title>
20+
<wfs:Abstract>This Static WFS exposes geodata included in the knowledge grap for the inclusion into GIS applications.</wfs:Abstract>
21+
<wfs:Keywords>{deploypath}</wfs:Keywords>
22+
<wfs:OnlineResource>{deploypath}</wfs:OnlineResource>
23+
<wfs:Fees>none</wfs:Fees>
24+
<wfs:AccessConstraints>{license}</wfs:AccessConstraints>
25+
</wfs:Service>
26+
<wfs:Capability>
27+
<wfs:Request>
28+
<wfs:GetCapabilities><wfs:DCPType><wfs:HTTP><wfs:Get onlineResource="{deploypath}/wfs?"/></wfs:HTTP></wfs:DCPType>
29+
<wfs:DCPType><wfs:HTTP><wfs:Post onlineResource="{deploypath}/wfs?"/></wfs:HTTP></wfs:DCPType>
30+
</wfs:GetCapabilities>
31+
<wfs:DescribeFeatureType><wfs:SchemaDescriptionLanguage><wfs:XMLSCHEMA/></wfs:SchemaDescriptionLanguage>
32+
<wfs:DCPType><wfs:HTTP><wfs:Get onlineResource="{deploypath}/wfs?"/></wfs:HTTP></wfs:DCPType>
33+
<wfs:DCPType><wfs:HTTP><wfs:Post onlineResource="{deploypath}/wfs"/></wfs:HTTP></wfs:DCPType>
34+
</wfs:DescribeFeatureType>
35+
<wfs:GetFeature><wfs:ResultFormat><wfs:JSON/></wfs:ResultFormat>
36+
<wfs:DCPType><wfs:HTTP><wfs:Get onlineResource="{deploypath}/wfs?"/></wfs:HTTP></wfs:DCPType>
37+
<wfs:DCPType><wfs:HTTP><wfs:Post onlineResource="{deploypath}/wfs"/></wfs:HTTP></wfs:DCPType>
38+
</wfs:GetFeature>
39+
</wfs:Request>
40+
</wfs:Capability>
41+
<wfs:FeatureTypeList><wfs:Operations><wfs:Query/></wfs:Operations>
42+
"""
43+
44+
for coll in featurecollectionspaths:
45+
curcoll = None
46+
if os.path.exists(coll):
47+
with open(coll, 'r', encoding="utf-8") as infile:
48+
curcoll = json.load(infile)
49+
50+
curftype=f"""
51+
<wfs:FeatureType>
52+
<wfs:Name>{str(coll.replace(outpath,"").replace("index.geojson", "").replace(".geojson", "")[1:]).rstrip("/")}</wfs:Name>
53+
<wfs:Title>{str(coll.replace(outpath,"").replace("index.geojson", "").replace(".geojson", "")[1:]).rstrip("/")}</wfs:Title>
54+
<wfs:Abstract>FeatureCollection {str(coll.replace(outpath,"").replace("index.geojson", "").replace(".geojson", "")[1:]).rstrip("/")}</wfs:Abstract>
55+
"""
56+
if "crs" in curcoll:
57+
curftype+=f"""<wfs:SRS>{curcoll["crs"]}</wfs:SRS>"""
58+
else:
59+
curftype+="<wfs:SRS>EPSG:4326</wfs:SRS>"
60+
if "extent" in curcoll:
61+
bboxcoords=curcoll["extent"]["spatial"]["bbox"][0]
62+
curftype+=f"""<wfs:LatLongBoundingBox minx="{bboxcoords[0]}" miny="{bboxcoords[1]}" maxx="{bboxcoords[2]}" maxy="{bboxcoords[3]}"/>"""
63+
curftype+="</wfs:FeatureType>"
64+
getcapabilities+=curftype+"\n"
65+
getcapabilities += f"""</wfs:FeatureTypeList><ogc:Filter_Capabilities></ogc:Filter_Capabilities><wfs:WFS_Capabilities>"""
66+
f = open(outpath + "/wfs?request=GetCapabilities&service=WFS&version=1.0.0", "w", encoding="utf-8")
67+
f.write(json.dumps(getcapabilities))
68+
f.close()

0 commit comments

Comments
 (0)