Strabon
changeset 1529:74abaa6b1821 temporals
We now use the GMLReader() to extract a Geometry from a GML string in the JTSWrapper.java, instead of the JAXB unmarshaller.
author | George Stamoulis <gstam@di.uoa.gr> |
---|---|
date | Thu Sep 22 15:27:25 2016 +0300 (2016-09-22) |
parents | 6cc6a1963350 |
children | b372e69a8936 |
files | evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java |
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java Mon Jan 04 17:47:18 2016 +0200 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java Thu Sep 22 15:27:25 2016 +0300 1.3 @@ -9,11 +9,16 @@ 1.4 */ 1.5 package org.openrdf.query.algebra.evaluation.util; 1.6 1.7 +import java.io.IOException; 1.8 import java.io.StringReader; 1.9 +import java.util.regex.Matcher; 1.10 +import java.util.regex.Pattern; 1.11 +import java.util.regex.PatternSyntaxException; 1.12 1.13 import javax.xml.bind.JAXBContext; 1.14 import javax.xml.bind.JAXBException; 1.15 import javax.xml.bind.Unmarshaller; 1.16 +import javax.xml.parsers.ParserConfigurationException; 1.17 1.18 import org.geotools.geometry.jts.JTS; 1.19 import org.geotools.referencing.CRS; 1.20 @@ -26,8 +31,11 @@ 1.21 import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 1.22 import org.slf4j.Logger; 1.23 import org.slf4j.LoggerFactory; 1.24 +import org.xml.sax.SAXException; 1.25 1.26 import com.vividsolutions.jts.geom.Geometry; 1.27 +import com.vividsolutions.jts.geom.GeometryFactory; 1.28 +import com.vividsolutions.jts.geom.PrecisionModel; 1.29 import com.vividsolutions.jts.io.ParseException; 1.30 import com.vividsolutions.jts.io.WKBReader; 1.31 import com.vividsolutions.jts.io.WKBWriter; 1.32 @@ -188,8 +196,12 @@ 1.33 * @param gml 1.34 * @return 1.35 * @throws JAXBException 1.36 + * @throws ParserConfigurationException 1.37 + * @throws IOException 1.38 + * @throws SAXException 1.39 */ 1.40 - public Geometry GMLread(String gml) throws JAXBException { 1.41 + public Geometry GMLread(String gml) throws JAXBException, SAXException, IOException, ParserConfigurationException { 1.42 + /* 1.43 StringReader reader = new StringReader(gml); 1.44 1.45 JAXBContext context = JAXBContext.newInstance("org.jvnet.ogc.gml.v_3_1_1.jts"); 1.46 @@ -197,7 +209,7 @@ 1.47 Geometry geometry = (Geometry) unmarshaller.unmarshal(reader); 1.48 1.49 reader.close(); 1.50 - 1.51 + */ 1.52 /** 1.53 * When unmarshalling GML, GML-JTS tries to parse srsName as EPSG code using the following patterns: 1.54 * EPSG:{0,number,integer} 1.55 @@ -215,6 +227,31 @@ 1.56 * we check the userData variable of the geometry after the unmarshal call. If it is not null, 1.57 * then we have the string that represents the srid and we need to extract it and set it in the geometry inastance. 1.58 */ 1.59 + 1.60 + int SRID = 4326; 1.61 + try { 1.62 + Pattern pattern = Pattern.compile("srsName=\"(.*)\""); 1.63 + Matcher matcher = pattern.matcher(gml); 1.64 + if (matcher.find()) { 1.65 + SRID = Integer.parseInt(matcher.group(1).substring(matcher.group(1).indexOf(":")+1, matcher.group(1).length())); 1.66 + } 1.67 + } catch (PatternSyntaxException e) { 1.68 + logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 1.69 + 1.70 + } catch (NumberFormatException e) { 1.71 + logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 1.72 + 1.73 + } catch (IllegalStateException e) { 1.74 + logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 1.75 + 1.76 + } catch (IndexOutOfBoundsException e) { 1.77 + logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 1.78 + } 1.79 + 1.80 + GMLReader gmlReader = new GMLReader(); 1.81 + GeometryFactory geomFactory = new GeometryFactory(new PrecisionModel(), SRID); 1.82 + Geometry geometry = (Geometry) gmlReader.read(gml, geomFactory); 1.83 + 1.84 if (geometry.getUserData() != null) { 1.85 geometry.setSRID(WKTHelper.getSRID((String)geometry.getUserData())); 1.86 return geometry;
2.1 --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Mon Jan 04 17:47:18 2016 +0200 2.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Thu Sep 22 15:27:25 2016 +0300 2.3 @@ -16,6 +16,7 @@ 2.4 2.5 import javax.xml.bind.JAXBException; 2.6 import javax.xml.namespace.QName; 2.7 +import javax.xml.parsers.ParserConfigurationException; 2.8 2.9 import org.geotools.kml.KML; 2.10 import org.geotools.kml.KMLConfiguration; 2.11 @@ -37,6 +38,7 @@ 2.12 import org.openrdf.sail.generaldb.model.XMLGSDatatypeUtil; 2.13 import org.slf4j.Logger; 2.14 import org.slf4j.LoggerFactory; 2.15 +import org.xml.sax.SAXException; 2.16 2.17 import com.vividsolutions.jts.geom.Geometry; 2.18 import com.vividsolutions.jts.geom.GeometryCollection; 2.19 @@ -477,12 +479,19 @@ 2.20 } catch (ParseException e) { 2.21 logger.error("[Strabon.KMLWriter] Parse error exception of geometry: {}", e.getMessage()); 2.22 2.23 + } catch (ParserConfigurationException e) { 2.24 + logger.error("[Strabon.KMLWriter] Parse configuration exception of geometry factory: {}", e.getMessage()); 2.25 + 2.26 + } catch (SAXException e) { 2.27 + logger.error("[Strabon.KMLWriter] SAX exception: {}", e.getMessage()); 2.28 + 2.29 } catch (IOException e) { 2.30 - logger.error("[Strabon.KMLWriter] IOException during KML encoding of geometry: {}", e.getMessage()); 2.31 + logger.error("[Strabon.KMLWriter] IOException during KML encoding of geometry: {}", e.getMessage()); 2.32 2.33 } catch (JAXBException e) { 2.34 logger.error("[Strabon.KMLWriter] Exception during GML parsing: {}", e.getMessage()); 2.35 } 2.36 + 2.37 2.38 return kml; 2.39 }