Strabon

changeset 22:b11832da5ee5

Update MonetDB JDBC client
author Kostis Kyzirakos <kkyzir@di.uoa.gr>
date Wed Feb 22 17:31:02 2012 +0200 (2012-02-22)
parents 8b551eacb5d6
children e46020b5867f
files monetdb/pom.xml query.sh runtime/pom.xml runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java
line diff
     1.1 --- a/monetdb/pom.xml	Mon Feb 20 18:04:00 2012 +0200
     1.2 +++ b/monetdb/pom.xml	Wed Feb 22 17:31:02 2012 +0200
     1.3 @@ -98,7 +98,7 @@
     1.4  	    <dependency>
     1.5  	    	<groupId>monetdb</groupId>
     1.6  	    	<artifactId>jdbcclient</artifactId>
     1.7 -	    	<version>3.0.0</version>
     1.8 +	    	<version>3.1.0</version>
     1.9  	    </dependency>
    1.10  	<!--
    1.11  	    <dependency>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/query.sh	Wed Feb 22 17:31:02 2012 +0200
     2.3 @@ -0,0 +1,15 @@
     2.4 +#!/bin/bash
     2.5 +#BASE=/home/strabon/experiments/data/naive/10mil
     2.6 +#10mil  0.01     11552771
     2.7 +#100mil 0.0034   99758140
     2.8 +#500mil 0.0015  512505143
     2.9 +#1bil   0.001  1153249211
    2.10 +
    2.11 +DB="10mil"
    2.12 +LOGPATH="/home/strabon/experiments/logs"
    2.13 +STEP="0.01"
    2.14 +TOTALTRIPLES="11552771"
    2.15 +
    2.16 +(cd jars/target &&
    2.17 +java -cp $(for file in `ls -1 *.jar`; do myVar=$myVar./$file":"; done; echo $myVar;) eu.earthobservatory.runtime.monetdb.QueryOp localhost 50000 10mil monetdb monetdb "SELECT ?x WHERE {?x ?y ?z} LIMIT 10")
    2.18 +
     3.1 --- a/runtime/pom.xml	Mon Feb 20 18:04:00 2012 +0200
     3.2 +++ b/runtime/pom.xml	Wed Feb 22 17:31:02 2012 +0200
     3.3 @@ -299,7 +299,7 @@
     3.4  			<dependency>
     3.5  				<groupId>monetdb</groupId>
     3.6  				<artifactId>jdbcclient</artifactId>
     3.7 -				<version>3.0.0</version>
     3.8 +				<version>3.1.0</version>
     3.9  			</dependency>
    3.10  			<!--
    3.11  			<dependency>
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Mon Feb 20 18:04:00 2012 +0200
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed Feb 22 17:31:02 2012 +0200
     4.3 @@ -202,6 +202,220 @@
     4.4  		else if (resultsFormat.equalsIgnoreCase("XML")) {
     4.5  			System.out.println("Serializing results (XML)");
     4.6  			tupleQuery.evaluate(new stSPARQLResultsXMLWriter(retStream));
     4.7 +		} 
     4.8 +		else if ( resultsFormat.equalsIgnoreCase("KMZ") ) {
     4.9 +			//GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);
    4.10 +			GeometryFactory gf = new GeometryFactory(new PrecisionModel(),4326);
    4.11 +			WKTReader reader = new WKTReader(gf);
    4.12 +			ByteArrayOutputStream baos = new ByteArrayOutputStream();
    4.13 +			
    4.14 +			DataOutputStream dos = new DataOutputStream(baos);
    4.15 +	
    4.16 +			//used to construct the entire kml document
    4.17 +			StringBuilder sb = new StringBuilder();
    4.18 +	
    4.19 +			TupleQueryResult result = null;
    4.20 +			try {
    4.21 +				result = tupleQuery.evaluate();
    4.22 +			} catch (QueryEvaluationException e1) {
    4.23 +				// TODO Auto-generated catch block
    4.24 +				e1.printStackTrace();
    4.25 +			}
    4.26 +			//System.out.println("-------------------------------------------");
    4.27 +			//System.out.println("-                RESULTS                  -");
    4.28 +			//System.out.println("-------------------------------------------");
    4.29 +	
    4.30 +			int resultCounter = 0;
    4.31 +			try {
    4.32 +				while (result.hasNext()) {
    4.33 +					BindingSet bindingSet = result.next();	
    4.34 +					ret.add(bindingSet.toString());
    4.35 +					Set<String> bindingNames = bindingSet.getBindingNames();
    4.36 +					resultCounter++;
    4.37 +					int geometryCounter = 0;
    4.38 +					for(String bindingName : bindingNames)
    4.39 +					{
    4.40 +						String unparsed = bindingSet.getBinding(bindingName).getValue().toString();
    4.41 +						String corrResult = unparsed.substring(1,unparsed.length()-1);
    4.42 +	
    4.43 +						try {
    4.44 +							Geometry geom = reader.read(corrResult);
    4.45 +							geom.setSRID(4326);
    4.46 +							//geom.setSRID(32630);
    4.47 +							
    4.48 +							//CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32630");
    4.49 +							//CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
    4.50 +							
    4.51 +							//MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
    4.52 +							
    4.53 +							//geom = JTS.transform(geom, transform);
    4.54 +							//geom.geometryChanged();
    4.55 +							geometryCounter++;
    4.56 +							//Only way to reach this point is if the corrResult is indeed in the form of WKT
    4.57 +							QName geometryType = null;
    4.58 +							if(geom instanceof Point)
    4.59 +							{
    4.60 +								geometryType = KML.Point;
    4.61 +							}
    4.62 +							else if(geom instanceof Polygon)
    4.63 +							{
    4.64 +								geometryType = KML.Polygon;
    4.65 +							}
    4.66 +							else if(geom instanceof LineString)
    4.67 +							{
    4.68 +								geometryType = KML.LineString;
    4.69 +							}
    4.70 +							else if(geom instanceof MultiPoint)
    4.71 +							{
    4.72 +								geometryType = KML.MultiGeometry;
    4.73 +							}
    4.74 +							else if(geom instanceof MultiLineString)
    4.75 +							{
    4.76 +								geometryType = KML.MultiGeometry;
    4.77 +	
    4.78 +							}
    4.79 +							else if(geom instanceof MultiPolygon)
    4.80 +							{
    4.81 +								geometryType = KML.MultiGeometry;
    4.82 +	
    4.83 +							}
    4.84 +							else if(geom instanceof GeometryCollection)
    4.85 +							{
    4.86 +								geometryType = KML.MultiGeometry;
    4.87 +	
    4.88 +							}
    4.89 +							else //TODO exception should be thrown here --> Specialize it
    4.90 +							{
    4.91 +								//System.out.println("Wrong Handling--> "+geometryType.toString());
    4.92 +								throw new Exception("Wrong Handling--> "+geom.toString());
    4.93 +	
    4.94 +							}
    4.95 +	
    4.96 +							//Encoding to KML
    4.97 +							Encoder encoder = new Encoder(new KMLConfiguration());
    4.98 +							encoder.setIndenting(true);
    4.99 +							//encoder.encode(geom, geometryType, dos);
   4.100 +							encoder.encode(geom, geometryType, baos);
   4.101 +							//storing the freshly produced kml element
   4.102 +							corrResult = baos.toString();
   4.103 +							//removing the xml header
   4.104 +							corrResult = corrResult.substring(38);
   4.105 +	
   4.106 +							//Constructing each individual element
   4.107 +							sb.append("\n<Placemark>");
   4.108 +							corrResult = corrResult.replaceAll("xmlns:kml=\"http://earth.google.com/kml/2.1\"","").replaceAll("kml:","");
   4.109 +							sb.append("\n<name> Geometry"+resultCounter+"_"+geometryCounter+"</name>");
   4.110 +							sb.append("\n<description>");
   4.111 +							//Time to fill the description
   4.112 +	
   4.113 +							if(bindingNames.size() > 1)
   4.114 +							{
   4.115 +								//Creating Row1 --> names
   4.116 +								sb.append("<![CDATA[<table border=\"1\"> <tr>");
   4.117 +								for(String otherBinding: bindingNames)
   4.118 +								{
   4.119 +									if(!otherBinding.equals(bindingName))
   4.120 +									{
   4.121 +										sb.append("<td>");
   4.122 +										sb.append(otherBinding);
   4.123 +										sb.append("</td>");
   4.124 +									}
   4.125 +								}
   4.126 +								sb.append("</tr>");
   4.127 +	
   4.128 +								sb.append("<tr>");
   4.129 +								for(String otherBinding: bindingNames)
   4.130 +								{
   4.131 +									if(!otherBinding.equals(bindingName))
   4.132 +									{
   4.133 +										sb.append("<td>");
   4.134 +										
   4.135 +										String bindingValue = bindingSet.getBinding(otherBinding).getValue().toString();
   4.136 +										sb.append(bindingValue);
   4.137 +										sb.append("</td>");
   4.138 +									}
   4.139 +								}
   4.140 +								sb.append("</table>]]>");
   4.141 +							}
   4.142 +							else
   4.143 +							{
   4.144 +								sb.append("mantalakia");
   4.145 +							}
   4.146 +							sb.append("</description>");
   4.147 +	
   4.148 +							sb.append(corrResult);
   4.149 +							sb.append("\n</Placemark>\n");
   4.150 +	
   4.151 +							//emptying the buffer
   4.152 +							baos.reset();
   4.153 +	
   4.154 +						} catch (ParseException e) {
   4.155 +							//Den prokeitai gia WKT
   4.156 +							//System.out.println(bindingSet.toString());
   4.157 +							//e.printStackTrace();
   4.158 +						} catch (Exception e) {
   4.159 +							e.printStackTrace();
   4.160 +						}
   4.161 +	
   4.162 +						//Start populating KML here
   4.163 +					}
   4.164 +					//				System.out.println(bindingSet.toString());
   4.165 +					//				out.writeChars(bindingSet.toString());
   4.166 +				}
   4.167 +			} catch (QueryEvaluationException e) {
   4.168 +				// TODO Auto-generated catch block
   4.169 +				e.printStackTrace();
   4.170 +			}
   4.171 +			try {
   4.172 +				dos.close();
   4.173 +			} catch (IOException e) {
   4.174 +				// TODO Auto-generated catch block
   4.175 +				e.printStackTrace();
   4.176 +			}
   4.177 +	
   4.178 +			//Finishing the structure of the kml document
   4.179 +			sb.insert(0,"<?xml version=\"1.0\" encoding=\"UTF-8\"?> <kml xmlns=\"http://www.opengis.net/kml/2.2\"> <Folder>");
   4.180 +			sb.append("</Folder></kml>");
   4.181 +	
   4.182 +			//System.out.println(sb.toString());
   4.183 +			//System.out.println(baos.toString());
   4.184 +	
   4.185 +			//			StringBuilder sb = new StringBuilder(); 
   4.186 +			//			sb.append(baos.toString().replaceAll("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>",""));
   4.187 +			//			sb.insert(0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <kml xmlns=\"http://www.opengis.net/kml/2.2\">" +
   4.188 +			//					"<kml:Placemark xmlns:kml=\"http://www.opengis.net/kml/2.2\">");
   4.189 +			//			sb.append("</kml:Placemark></kml>");
   4.190 +	
   4.191 +	
   4.192 +			//System.out.println("*******************************");
   4.193 +			//sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
   4.194 +			//System.out.println(sb.toString());
   4.195 +	
   4.196 +			//System.out.println(sb.toString());
   4.197 +	
   4.198 +			//XXX Probably not needed after all
   4.199 +			//			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   4.200 +			//			DocumentBuilder builder = factory.newDocumentBuilder();
   4.201 +			//			StringReader sr = new StringReader(sb.toString());
   4.202 +			//			Document document = builder.parse(new InputSource(sr));
   4.203 +	
   4.204 +	
   4.205 +			//System.out.println("-------------------------------------------");
   4.206 +			System.out.flush();
   4.207 +	
   4.208 +			try {
   4.209 +				//String cstr = new String("aa", "UTF8");
   4.210 +				String newString = new String(sb.toString().getBytes(), Charset.availableCharsets().get("UTF-8"));
   4.211 +				writeOut.write(newString);
   4.212 +				//out.writeBytes(newString);
   4.213 +				
   4.214 +//				out.writeBytes(sb.toString());
   4.215 +				
   4.216 +			} catch (IOException e) {
   4.217 +				// TODO Auto-generated catch block
   4.218 +				e.printStackTrace();
   4.219 +			}
   4.220 +		
   4.221  		}
   4.222  		else if ( resultsFormat.equalsIgnoreCase("KML") ) {
   4.223  			//GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);