68 System.out.println(query);
69 System.out.println(model);
72 RepositoryConnection con =
repo.getConnection();
81 TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
83 TupleQueryResult qresult = tupleQuery.evaluate();
87 List<JSONArray> allfeatures=
new LinkedList<JSONArray>();
88 JSONObject result=
new JSONObject();
89 JSONArray geojsonresults=
new JSONArray();
90 JSONArray obj=
new JSONArray();
92 while(qresult.hasNext()) {
93 BindingSet bindingSet = qresult.next();
94 JSONObject jsonobj=
new JSONObject();
95 JSONObject properties=
new JSONObject();
96 List<JSONObject> geoms=
new LinkedList<JSONObject>();
98 for(String name:bindingSet.getBindingNames()) {
99 if(name.endsWith(
"_geom")) {
102 JSONObject geojsonresult=
new JSONObject();
103 geojsonresult.put(
"type",
"FeatureCollection");
104 geojsonresult.put(
"name", name);
105 JSONArray features=
new JSONArray();
106 allfeatures.add(features);
108 geojsonresults.put(geojsonresult);
109 geojsonresults.getJSONObject(geojsonresults.length()-1).put(
"features",features);
112 AsGeoJSON geojson=
new AsGeoJSON();
113 Value val=bindingSet.getValue(name);
114 Literal lit=(Literal)val;
117 if(LiteralRegistry.getLiteral(lit.getDatatype().toString())!=
null){
118 LiteralType l=LiteralRegistry.getLiteral(lit.getDatatype().toString());
119 Geometry geom=((VectorLiteral)l).read(bindingSet.getValue(name).stringValue());
120 String geojsonstring=geojson.operation(geom);
121 JSONObject geomobj=
new JSONObject(geojsonstring);
126 jsonobj.put(name, bindingSet.getValue(name));
127 properties.put(name, bindingSet.getValue(name));
132 for(JSONObject geom:geoms) {
133 JSONObject geojsonobj=
new JSONObject();
134 geojsonobj.put(
"type",
"Feature");
135 geojsonobj.put(
"properties", properties);
136 geojsonobj.put(
"geometry", geom);
137 allfeatures.get(geomcounter%geomvars).put(geojsonobj);
141 result.put(
"geojson", geojsonresults);
142 result.put(
"data", obj);
144 return result.toString();
static final TripleStoreConnection INSTANCE
Definition: TripleStoreConnection.java:36
static final String prefixCollection
Definition: TripleStoreConnection.java:38