Strabon
changeset 394:4cb6a34a8877
Real fix of store for GML/WKT
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Thu Jun 28 01:08:23 2012 +0300 (2012-06-28) |
parents | c29ca6696591 |
children | e34f3de6c128 |
files | evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java |
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java Wed Jun 27 23:05:24 2012 +0300 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java Thu Jun 28 01:08:23 2012 +0300 1.3 @@ -97,11 +97,19 @@ 1.4 * @param representation 1.5 * @throws Exception 1.6 */ 1.7 - public StrabonPolyhedron(String representation) { 1.8 + public StrabonPolyhedron(String representation) throws IllegalArgumentException { 1.9 try { 1.10 // try first as WKT 1.11 geometry = jts.WKTread(representation); 1.12 1.13 + /** 1.14 + * SPECIAL NOTICE: When <tt>representation</tt> is in GML, 1.15 + * WKTReader does not throw any ParseException! It silently 1.16 + * returns NULL. That's why we have the following check. 1.17 + */ 1.18 + if (geometry == null) { 1.19 + throw new ParseException("Invalid WKT."); 1.20 + } 1.21 } catch (ParseException e) { 1.22 try { 1.23 // try as GML
2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Wed Jun 27 23:05:24 2012 +0300 2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Thu Jun 28 01:08:23 2012 +0300 2.3 @@ -9,11 +9,19 @@ 2.4 import java.sql.SQLException; 2.5 import java.sql.Timestamp; 2.6 import java.lang.IllegalArgumentException; 2.7 + 2.8 +import javax.xml.bind.JAXBException; 2.9 + 2.10 import org.openrdf.sail.generaldb.exceptions.conversionException; 2.11 import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 2.12 +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 2.13 +import org.openrdf.query.algebra.evaluation.util.JTSWrapper; 2.14 import org.slf4j.Logger; 2.15 import org.slf4j.LoggerFactory; 2.16 2.17 +import com.vividsolutions.jts.geom.Geometry; 2.18 +import com.vividsolutions.jts.io.ParseException; 2.19 + 2.20 /** 2.21 * A Facade to the five literal value tables. Which are labels, languages, 2.22 * datatypes, numeric values, and dateTime values. 2.23 @@ -192,24 +200,17 @@ 2.24 //the new version will actually deal with WKB 2.25 public void insertWKT(Number id, String label, String datatype,Timestamp start,Timestamp end) throws SQLException, NullPointerException,InterruptedException,IllegalArgumentException 2.26 { 2.27 - Integer srid; 2.28 - byte[] geomWKB = null; 2.29 - 2.30 try { 2.31 + Geometry geom = JTSWrapper.getInstance().WKTread(label); 2.32 + if (geom == null) { 2.33 + throw new IllegalArgumentException("Invalid WKT."); 2.34 + 2.35 + } 2.36 + geoSpatialTable.insert(id, WKTHelper.getSRID(label),/* start,end,*/ JTSWrapper.getInstance().WKBwrite(geom)); 2.37 2.38 - StrabonPolyhedron polyhedron = new StrabonPolyhedron(label);//current algorithm selected: approx convex partition 2.39 - if(polyhedron.getGeometry().getSRID() > 0) 2.40 - { 2.41 - srid = polyhedron.getGeometry().getSRID(); 2.42 - //System.out.println("SRID="+srid); 2.43 - } 2.44 - geomWKB = polyhedron.toWKB(); 2.45 - 2.46 - } catch (Exception e) { 2.47 - e.printStackTrace(); 2.48 + } catch (ParseException e) { 2.49 + throw new IllegalArgumentException(e); 2.50 } 2.51 - srid= findSRID(label); 2.52 - geoSpatialTable.insert(id,srid,/* start,end,*/ geomWKB); 2.53 } 2.54 2.55 /** 2.56 @@ -226,13 +227,17 @@ 2.57 * @throws IllegalArgumentException 2.58 */ 2.59 public void insertGML(Number id, String gml, String datatype, Timestamp start, Timestamp end) throws SQLException, NullPointerException,InterruptedException,IllegalArgumentException { 2.60 - StrabonPolyhedron geomValue = new StrabonPolyhedron(gml); 2.61 + Geometry geom; 2.62 + try { 2.63 + geom = JTSWrapper.getInstance().GMLread(gml); 2.64 + geoSpatialTable.insert(id, geom.getSRID(),/* start,end,*/ JTSWrapper.getInstance().WKBwrite(geom)); 2.65 2.66 - geoSpatialTable.insert(id, geomValue.getGeometry().getSRID(),/* start,end,*/ geomValue.toByteArray()); 2.67 + } catch (JAXBException e) { 2.68 + logger.error("[Strabon.insertGML] Error during insertion of GML literal.", e); 2.69 + } 2.70 + 2.71 } 2.72 2.73 - 2.74 - /********************************************************************/ 2.75 public void insertNumeric(Number id, String label, String datatype, double value) 2.76 throws SQLException, InterruptedException 2.77 {