Skip to content

Commit

Permalink
data types for qgis columns
Browse files Browse the repository at this point in the history
  • Loading branch information
situx committed Oct 7, 2024
1 parent 3473c09 commit 05ae5cc
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 54 deletions.
2 changes: 1 addition & 1 deletion tasks/processing/extractlayertask.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(self):
g.parse(self.graphname, format="ttl")
for toex in self.toextract:
if "owl" not in str(toex) and "rdf" not in str(toex):
QgsMessageLog.logMessage(str(toex),MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage(str(toex),MESSAGE_CATEGORY, Qgis.Info)
layergraph = Graph()
for sub in g.subjects(RDF.type, URIRef(toex),True):
QgsMessageLog.logMessage(str(sub),MESSAGE_CATEGORY, Qgis.Info)
Expand Down
68 changes: 39 additions & 29 deletions tasks/query/data/querylayertask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from ....util.style.styleutils import StyleUtils
from ....util.doc.docconfig import DocConfig
from ....util.layerutils import LayerUtils
from ....util.sparqlutils import SPARQLUtils
from qgis.utils import iface
Expand Down Expand Up @@ -114,6 +115,7 @@ def addFeatureToCorrectCollection(self,feature,features,nongeofeatures,crsset):
del feature["crs"]



## Processes query results and reformats them to a QGIS layer.
# @param self The object pointer.
# @param results The query results
Expand All @@ -134,79 +136,86 @@ def processResults(self, results, reproject, mandatoryvars, geooptional):
if self.concept is not None and "item" not in result:
result["item"]={"value":self.concept}
if "item" in result and "rel" in result and "val" in result:
QgsMessageLog.logMessage('rel val' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
if "geo" in result and (item == "" or result["item"]["value"] != item) and "geo" in mandatoryvars:
QgsMessageLog.logMessage('rel val + geo' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('rel val' + str(len(features))+" "+str(result["val"]),MESSAGE_CATEGORY, Qgis.Info)
if "geo" in result and (item == "" or result["item"]["value"] != item):
#QgsMessageLog.logMessage('rel val + geo' + str(len(features)),
# MESSAGE_CATEGORY, Qgis.Info)
if item != "":
self.addFeatureToCorrectCollection(LayerUtils.processLiteral(result["geo"]["value"], (
result["geo"]["datatype"] if "datatype" in result["geo"] else ""), reproject,
{'id':result["item"]["value"],'type': 'Feature', 'properties': self.dropUnwantedKeys(properties),
'geometry': {}},
{'id':result["item"]["value"],'type': 'Feature', 'properties': self.dropUnwantedKeys(properties),'geometry': {}},
self.triplestoreconf),features,nongeofeatures,crsset)
lastaddeditem=result["item"]["value"]
elif "lat" in result and "lon" in result and (
properties = {}
item = result["item"]["value"]
elif "lat" in result and "lon" in result and (
item == "" or result["item"]["value"] != item) and "lat" in mandatoryvars and "lon" in mandatoryvars:
QgsMessageLog.logMessage('rel val + lat lon' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('rel val + lat lon' + str(len(features)),
# MESSAGE_CATEGORY, Qgis.Info)
if item != "":
self.addFeatureToCorrectCollection(LayerUtils.processLiteral(
"POINT(" + str(float(result[lonval]["value"])) + " " + str(
float(result[latval]["value"])) + ")", "wkt", reproject,{'id':result["item"]["value"],'type': 'Feature', 'properties': self.dropUnwantedKeys(properties),
'geometry': {}},self.triplestoreconf),features,nongeofeatures,crsset)
lastaddeditem = result["item"]["value"]
properties = {}
item = result["item"]["value"]
elif geooptional and (item == "" or result["item"]["value"] != item):
QgsMessageLog.logMessage('rel val + no geo' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('rel val + no geo' + str(len(features)),
# MESSAGE_CATEGORY, Qgis.Info)
if item != "":
self.addFeatureToCorrectCollection({'id':result["item"]["value"],'type': 'Feature', 'properties': self.dropUnwantedKeys(properties),
'geometry': {}},features,nongeofeatures,crsset)
lastaddeditem = result["item"]["value"]
properties = {}
item = result["item"]["value"]
properties = {}
item = result["item"]["value"]
elif "rel" not in result and "val" not in result:
properties = {}
for var in results["head"]["vars"]:
if var in result:
if var=="item":
item = result["item"]["value"]
if var == "rel" and "val" in result:
if self.shortenURIs:
if "datatype" in result["val"]:
properties[SPARQLUtils.labelFromURI(result["val"]["value"])]=LayerUtils.detectDataType(result["val"])
elif self.shortenURIs:
properties[SPARQLUtils.labelFromURI(result[var]["value"])] = result["val"]["value"]
elif self.shortenURIs==1:
properties[SPARQLUtils.labelFromURI(result[var]["value"])] = SPARQLUtils.labelFromURI(result["val"]["value"])
else:
properties[result[var]["value"]] = result["val"]["value"]
if var=="rel2" in result and "val2"!=self.triplestoreconf["typeproperty"] and "val2" in result:
if self.shortenURIs:
if "datatype" in result["val2"]:
properties[SPARQLUtils.labelFromURI(result["val2"]["value"])]=LayerUtils.detectDataType(result["val2"])
elif self.shortenURIs:
properties["_"+SPARQLUtils.labelFromURI(result["rel2"]["value"])] = result["val2"]["value"]
elif self.shortenURIs==1:
properties[SPARQLUtils.labelFromURI(result[var]["value"])] = SPARQLUtils.labelFromURI(result["val"]["value"])
else:
properties["_"+result[var]["value"]] = result["val2"]["value"]
elif var != "val" and var!="val2":
if self.shortenURIs:
if "datatype" in result[var]:
properties[SPARQLUtils.labelFromURI(result[var]["value"])]=LayerUtils.detectDataType(result[var])
elif self.shortenURIs:
properties[SPARQLUtils.labelFromURI(var)] = result[var]["value"]
elif self.shortenURIs==1:
properties[SPARQLUtils.labelFromURI(result[var]["value"])] = SPARQLUtils.labelFromURI(result["val"]["value"])
properties[SPARQLUtils.labelFromURI(var)] = SPARQLUtils.labelFromURI(result[var]["value"])
else:
properties[var] = result[var]["value"]
if "rel" not in result and "val" not in result:
QgsMessageLog.logMessage('Not rel val ' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('Not rel val ' + str(len(features)),MESSAGE_CATEGORY, Qgis.Info)
if "geo" in result:
QgsMessageLog.logMessage('Not rel val + geo' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('Not rel val + geo' + str(len(features)),
# MESSAGE_CATEGORY, Qgis.Info)
self.addFeatureToCorrectCollection(LayerUtils.processLiteral(result["geo"]["value"], (
result["geo"]["datatype"] if "datatype" in result["geo"] else ""), reproject,
{'id': result["item"]["value"], 'type': 'Feature',
'properties': self.dropUnwantedKeys(properties),'geometry': {}},
self.triplestoreconf),features,nongeofeatures,crsset)
lastaddeditem = result["item"]["value"]
elif latval in result and lonval in result:
QgsMessageLog.logMessage('Not rel val + lat lon' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('Not rel val + lat lon' + str(len(features)),
# MESSAGE_CATEGORY, Qgis.Info)
self.addFeatureToCorrectCollection(LayerUtils.processLiteral(
"POINT(" + str(float(result[lonval]["value"])) + " " + str(float(result[latval]["value"])) + ")",
"wkt", reproject,
Expand All @@ -215,11 +224,10 @@ def processResults(self, results, reproject, mandatoryvars, geooptional):
self.triplestoreconf),features,nongeofeatures,crsset)
lastaddeditem = result["item"]["value"]
elif "geo" not in result and geooptional:
QgsMessageLog.logMessage('Not rel val + no geo' + str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('Not rel val + no geo' + str(len(features)),
# MESSAGE_CATEGORY, Qgis.Info)
self.addFeatureToCorrectCollection({'id':result["item"]["value"],'type': 'Feature', 'properties': self.dropUnwantedKeys(properties), 'geometry': {}},features,nongeofeatures,crsset)
lastaddeditem = result["item"]["value"]

if len(results)>0 and lastaddeditem!=item:
if "geo" in properties:
self.addFeatureToCorrectCollection(LayerUtils.processLiteral(result["geo"]["value"], (
Expand All @@ -232,13 +240,15 @@ def processResults(self, results, reproject, mandatoryvars, geooptional):
"wkt", reproject,{'id':result["item"]["value"], 'type': 'Feature', 'properties': self.dropUnwantedKeys(properties), 'geometry': {}},self.triplestoreconf),features,nongeofeatures,crsset)
else:
self.addFeatureToCorrectCollection({'id':result["item"]["value"], 'type': 'Feature', 'properties': self.dropUnwantedKeys(properties), 'geometry': {}},features,nongeofeatures,crsset)
QgsMessageLog.logMessage('Number of features '+str(len(features)),
MESSAGE_CATEGORY, Qgis.Info)
#QgsMessageLog.logMessage('Number of features '+str(len(features)),
#MESSAGE_CATEGORY, Qgis.Info)
if features == [] and len(results["results"]["bindings"]) == 0:
return [None,None,None]
#if features == [] and len(results["results"]["bindings"]) > 0:
# return len(results["results"]["bindings"])
geojson = {'type': 'FeatureCollection', 'features': features}
#QgsMessageLog.logMessage(str(geojson),
# MESSAGE_CATEGORY, Qgis.Info)
if len(nongeofeatures)>0:
geojsonnongeo = {'type': 'FeatureCollection', 'features': nongeofeatures}
else:
Expand Down
8 changes: 8 additions & 0 deletions util/doc/docconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ class DocConfig:
"prop": "http://www.w3.org/2000/01/rdf-schema#member"}
}

integertypes=["http://www.w3.org/2001/XMLSchema#nonPositiveInteger","http://www.w3.org/2001/XMLSchema#negativeInteger",
"http://www.w3.org/2001/XMLSchema#nonNegativeInteger","http://www.w3.org/2001/XMLSchema#positiveInteger",
"http://www.w3.org/2001/XMLSchema#unsignedLong","http://www.w3.org/2001/XMLSchema#usignedInt",
"http://www.w3.org/2001/XMLSchema#unsignedShort","http://www.w3.org/2001/XMLSchema#integer",
"http://www.w3.org/2001/XMLSchema#int","http://www.w3.org/2001/XMLSchema#short"]

floattypes=["http://www.w3.org/2001/XMLSchema#float","http://www.w3.org/2001/XMLSchema#double","http://www.w3.org/2001/XMLSchema#decimal"]

geoliteraltypes = ["http://www.opengis.net/ont/geosparql#wktLiteral",
"http://www.opengis.net/ont/geosparql#gmlLiteral",
"http://www.opengis.net/ont/geosparql#kmlLiteral",
Expand Down
2 changes: 1 addition & 1 deletion util/export/layer/layerexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def layerToTTLString(layer, prefixes, vocab="GeoSPARQL", literaltype=["WKT"], ur
graph.add((URIRef(str(curid)),RDF.type,URIRef(curclassid)))
if first == 0:
graph.add((URIRef(str(curclassid)), RDFS.subClassOf, GEO.Feature))
graph.add((URIRef(str(curclassid)), RDFS.type, OWL.Class))
graph.add((URIRef(str(curclassid)), RDF.type, OWL.Class))
else:
curclassid = f["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
graph = LayerUtils.exportGeometryType(curid, geom, vocab, literaltype, init, graph)
Expand Down
Loading

0 comments on commit 05ae5cc

Please sign in to comment.