Changeset 1529:74abaa6b1821


Ignore:
Timestamp:
09/22/16 15:27:25 (12 months ago)
Author:
George Stamoulis <gstam@…>
Branch:
temporals
Message:

We now use the GMLReader() to extract a Geometry from a GML string in the JTSWrapper.java, instead of the JAXB unmarshaller.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java

    r1528 r1529  
    1010package org.openrdf.query.algebra.evaluation.util; 
    1111 
     12import java.io.IOException; 
    1213import java.io.StringReader; 
     14import java.util.regex.Matcher; 
     15import java.util.regex.Pattern; 
     16import java.util.regex.PatternSyntaxException; 
    1317 
    1418import javax.xml.bind.JAXBContext; 
    1519import javax.xml.bind.JAXBException; 
    1620import javax.xml.bind.Unmarshaller; 
     21import javax.xml.parsers.ParserConfigurationException; 
    1722 
    1823import org.geotools.geometry.jts.JTS; 
     
    2732import org.slf4j.Logger; 
    2833import org.slf4j.LoggerFactory; 
     34import org.xml.sax.SAXException; 
    2935 
    3036import com.vividsolutions.jts.geom.Geometry; 
     37import com.vividsolutions.jts.geom.GeometryFactory; 
     38import com.vividsolutions.jts.geom.PrecisionModel; 
    3139import com.vividsolutions.jts.io.ParseException; 
    3240import com.vividsolutions.jts.io.WKBReader; 
     
    189197         * @return 
    190198         * @throws JAXBException 
    191          */ 
    192         public Geometry GMLread(String gml) throws JAXBException { 
     199         * @throws ParserConfigurationException  
     200         * @throws IOException  
     201         * @throws SAXException  
     202         */ 
     203        public Geometry GMLread(String gml) throws JAXBException, SAXException, IOException, ParserConfigurationException { 
     204                /* 
    193205                StringReader reader = new StringReader(gml); 
    194206 
     
    198210                 
    199211                reader.close(); 
    200                  
     212                */ 
    201213                /** 
    202214                 * When unmarshalling GML, GML-JTS tries to parse srsName as EPSG code using the following patterns: 
     
    216228                 * then we have the string that represents the srid and we need to extract it and set it in the geometry inastance. 
    217229                 */ 
     230                 
     231                int SRID = 4326; 
     232                try { 
     233                        Pattern pattern = Pattern.compile("srsName=\"(.*)\""); 
     234                        Matcher matcher = pattern.matcher(gml); 
     235                        if (matcher.find()) { 
     236                                SRID = Integer.parseInt(matcher.group(1).substring(matcher.group(1).indexOf(":")+1, matcher.group(1).length())); 
     237                        } 
     238                } catch (PatternSyntaxException e) { 
     239                        logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 
     240                         
     241                } catch (NumberFormatException e) { 
     242                        logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 
     243                         
     244                } catch (IllegalStateException e) { 
     245                        logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 
     246                         
     247                } catch (IndexOutOfBoundsException e) { 
     248                        logger.error("[GML read] No SRID found for the Geometry: {}", e.getMessage()); 
     249                } 
     250                 
     251                GMLReader gmlReader = new GMLReader(); 
     252                GeometryFactory geomFactory = new GeometryFactory(new PrecisionModel(), SRID); 
     253                Geometry geometry = (Geometry) gmlReader.read(gml, geomFactory);                 
     254                 
    218255                if (geometry.getUserData() != null) { 
    219256                        geometry.setSRID(WKTHelper.getSRID((String)geometry.getUserData())); 
  • resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java

    r1528 r1529  
    1717import javax.xml.bind.JAXBException; 
    1818import javax.xml.namespace.QName; 
     19import javax.xml.parsers.ParserConfigurationException; 
    1920 
    2021import org.geotools.kml.KML; 
     
    3839import org.slf4j.Logger; 
    3940import org.slf4j.LoggerFactory; 
     41import org.xml.sax.SAXException; 
    4042 
    4143import com.vividsolutions.jts.geom.Geometry; 
     
    478480                        logger.error("[Strabon.KMLWriter] Parse error exception of geometry: {}", e.getMessage()); 
    479481                         
     482                } catch (ParserConfigurationException e) { 
     483                        logger.error("[Strabon.KMLWriter] Parse configuration exception of geometry factory: {}", e.getMessage()); 
     484 
     485                } catch (SAXException e) { 
     486                        logger.error("[Strabon.KMLWriter] SAX exception: {}", e.getMessage()); 
     487                         
    480488                } catch (IOException e) { 
    481                         logger.error("[Strabon.KMLWriter] IOException during KML encoding of geometry: {}",     e.getMessage()); 
     489                        logger.error("[Strabon.KMLWriter] IOException during KML encoding of geometry: {}", e.getMessage()); 
    482490                         
    483491                } catch (JAXBException e) { 
    484492                        logger.error("[Strabon.KMLWriter] Exception during GML parsing: {}", e.getMessage()); 
    485493                } 
     494 
    486495                 
    487496                return kml; 
Note: See TracChangeset for help on using the changeset viewer.