- Timestamp:
- 04/23/09 14:47:18 (11 months ago)
- Location:
- tools/routingservice/branches/wrs-2.0
- Files:
-
- 8 added
- 8 modified
-
data/resources.xml (modified) (1 diff)
-
lib/geoapi-2.2-M1.jar (added)
-
lib/gt-api-2.5.2.jar (added)
-
lib/gt-epsg-extension-2.5.2.jar (added)
-
lib/gt-epsg-wkt-2.5.2.jar (added)
-
lib/gt-metadata-2.5.2.jar (added)
-
lib/gt-referencing-2.5.2.jar (added)
-
lib/jsr-275-1.0-beta-2.jar (added)
-
lib/vecmath-1.3.1.jar (added)
-
src/WRS.java (modified) (4 diffs)
-
src/geometry/Point.java (modified) (2 diffs)
-
src/handler/HandlerFactory.java (modified) (1 diff)
-
src/handler/PgRoutingHandler.java (modified) (5 diffs)
-
src/handler/ResourceHandler.java (modified) (2 diffs)
-
src/util/format/JSONParser.java (modified) (4 diffs)
-
src/util/format/TemplateFiller.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tools/routingservice/branches/wrs-2.0/data/resources.xml
r305 r306 6 6 <description>pgRouting 1.0.1, PostGIS 1.11, PostgreSQL 8.1</description> 7 7 <parameters> 8 <parameter name="srid" type="integer" key="srid" value=" 4326" />8 <parameter name="srid" type="integer" key="srid" value="EPSG:4326" /> 9 9 <parameter name="units" type="string" key="units" value="dd" /> 10 10 <parameter name="rbox" type="double" key="box" value="0.1" /> -
tools/routingservice/branches/wrs-2.0/src/WRS.java
r305 r306 37 37 38 38 import org.antlr.stringtemplate.StringTemplate; 39 import org.geotools.referencing.CRS; 40 import org.opengis.referencing.FactoryException; 41 import org.opengis.referencing.NoSuchAuthorityCodeException; 42 import org.opengis.referencing.crs.CoordinateReferenceSystem; 39 43 import org.restlet.Component; 40 44 import org.restlet.Restlet; … … 186 190 { 187 191 ResourceHandler handler = HandlerFactory.Handler 188 .valueOf(resource.get Name().toUpperCase())192 .valueOf(resource.getType().toUpperCase()) 189 193 .getInstance(); 190 194 handler.setResource(resource); … … 476 480 { 477 481 Include inc = li.next(); 478 482 479 483 switch (Includes.valueOf(inc.getName().toUpperCase())) 480 484 { … … 511 515 return conf; 512 516 } 513 517 514 518 private void readResources(String url) 515 519 { -
tools/routingservice/branches/wrs-2.0/src/geometry/Point.java
r298 r306 22 22 public class Point 23 23 { 24 private BigDecimalx;25 private BigDecimaly;24 private double x; 25 private double y; 26 26 27 27 public Point() 28 28 { 29 x = new BigDecimal(0);30 y = new BigDecimal(0);29 x = 0; 30 y = 0; 31 31 } 32 32 33 public Point( BigDecimal x, BigDecimaly)33 public Point(double x, double y) 34 34 { 35 35 this.x = x; … … 37 37 } 38 38 39 public BigDecimalgetX()39 public double getX() 40 40 { 41 41 return x; 42 42 } 43 43 44 public BigDecimal getX(float value)45 {46 return x.add(new BigDecimal(value));47 }48 44 49 public BigDecimalgetY()45 public double getY() 50 46 { 51 47 return y; 52 48 } 53 49 54 public BigDecimal getY(float value) 55 { 56 return y.add(new BigDecimal(value)); 57 } 58 59 public void setX(BigDecimal x) 50 public void setX(double x) 60 51 { 61 52 this.x = x; 62 53 } 63 54 64 public void setY( BigDecimaly)55 public void setY(double y) 65 56 { 66 57 this.y = y; -
tools/routingservice/branches/wrs-2.0/src/handler/HandlerFactory.java
r298 r306 22 22 public static enum Handler 23 23 { 24 PGROUTING(PgRoutingHandler.class);24 DATABASE(PgRoutingHandler.class); 25 25 26 26 private Class<? extends ResourceHandler> mappedClass; -
tools/routingservice/branches/wrs-2.0/src/handler/PgRoutingHandler.java
r305 r306 42 42 43 43 import org.antlr.stringtemplate.StringTemplate; 44 import org.opengis.geometry.MismatchedDimensionException; 45 import org.opengis.referencing.FactoryException; 46 import org.opengis.referencing.NoSuchAuthorityCodeException; 47 import org.opengis.referencing.operation.TransformException; 48 49 import com.vividsolutions.jts.io.ParseException; 44 50 45 51 public class PgRoutingHandler extends ResourceHandler … … 71 77 ArrayList getParameters() 72 78 { 73 String[] p = { "table", "x1", "y1", "distance", "rbox", "cost_value",74 " reverse_cost_value", "directed", "hasrc" };79 String[] p = { "table", "x1", "y1", "distance", "rbox", 80 "cost_value", "reverse_cost_value", "directed", "hasrc" }; 75 81 return new ArrayList(Arrays.asList(p)); 76 82 } … … 100 106 String query = fillQueryTemplate(this.resource.getQuery(), request 101 107 .getService(), request.getParameters()); 102 108 103 109 System.out.println("Query:" + query); 104 110 … … 202 208 Parameter p = parameters.get(key); 203 209 String value = p.getValue(); 210 211 // Check if we need to re-project coordinates 212 if (p.getType().toLowerCase().equals(DOUBLE) 213 && key.toLowerCase().startsWith("x")) 214 { 215 try 216 { 217 int srid_in = Integer.parseInt(parameters 218 .get("srid_in").getValue()); 219 int srid_out = Integer.parseInt(resource 220 .getParameters().get("srid").getValue()); 221 222 if (srid_in != srid_out) 223 { 224 // try to find Y coordinate 225 String yKey = key.toLowerCase().replaceFirst("x", 226 "y"); 227 Parameter yP = parameters.get(yKey); 228 String yValue = yP.getValue(); 229 String[] transformed = transformPoint(value, yValue, 230 srid_in, srid_out); 231 p.setValue(transformed[0]); 232 yP.setValue(transformed[1]); 233 } 234 } 235 catch (NullPointerException e) 236 { 237 //Can't find srid_in or srid_out 238 //Do nothing 239 } 240 catch (MismatchedDimensionException e) 241 { 242 // TODO Auto-generated catch block 243 e.printStackTrace(); 244 } 245 catch (NoSuchAuthorityCodeException e) 246 { 247 // TODO Auto-generated catch block 248 e.printStackTrace(); 249 } 250 catch (FactoryException e) 251 { 252 // TODO Auto-generated catch block 253 e.printStackTrace(); 254 } 255 catch (ParseException e) 256 { 257 // TODO Auto-generated catch block 258 e.printStackTrace(); 259 } 260 catch (TransformException e) 261 { 262 // TODO Auto-generated catch block 263 e.printStackTrace(); 264 } 265 } 266 204 267 if (p.getType().toLowerCase().equals(STRING)) 205 268 { … … 242 305 { 243 306 Point point = new Point(); 244 point.setX( new BigDecimal(wkt2[j].split(" ")[0]));245 point.setY( new BigDecimal(wkt2[j].split(" ")[1]));307 point.setX(Double.parseDouble(wkt2[j].split(" ")[0])); 308 point.setY(Double.parseDouble(wkt2[j].split(" ")[1])); 246 309 points.add(point); 247 310 } -
tools/routingservice/branches/wrs-2.0/src/handler/ResourceHandler.java
r298 r306 22 22 import java.util.Hashtable; 23 23 import java.util.Vector; 24 25 import org.geotools.geometry.jts.JTS; 26 import org.geotools.referencing.CRS; 27 28 import org.opengis.geometry.MismatchedDimensionException; 29 import org.opengis.referencing.FactoryException; 30 import org.opengis.referencing.NoSuchAuthorityCodeException; 31 import org.opengis.referencing.crs.CoordinateReferenceSystem; 32 import org.opengis.referencing.operation.MathTransform; 33 import org.opengis.referencing.operation.TransformException; 34 35 import com.vividsolutions.jts.geom.Geometry; 36 import com.vividsolutions.jts.io.ParseException; 37 import com.vividsolutions.jts.io.WKTReader; 24 38 25 39 import exception.InvalidServiceException; … … 65 79 66 80 public abstract ArrayList<Point> parseGeometry(String geometry); 81 82 public String[] transformPoint(String x, String y, int srid_in, int srid_out) throws NoSuchAuthorityCodeException, FactoryException, ParseException, MismatchedDimensionException, TransformException 83 { 84 CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:"+srid_in); 85 CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:"+srid_out); 86 MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true); 87 88 Geometry point = new WKTReader().read("POINT ("+x+" "+y+")"); 89 Geometry targetPoint = JTS.transform( point, transform); 90 91 String[] result = {String.valueOf(targetPoint.getCoordinate().x), String.valueOf(targetPoint.getCoordinate().y)}; 92 return result; 93 } 67 94 68 95 } -
tools/routingservice/branches/wrs-2.0/src/util/format/JSONParser.java
r298 r306 59 59 x.setName("x" + i); 60 60 x.setSource("url"); 61 x.setValue(sst.nextToken() );61 x.setValue(sst.nextToken().trim()); 62 62 x.setType(ResourceHandler.DOUBLE); 63 63 … … 67 67 y.setName("y" + i); 68 68 y.setSource("url"); 69 y.setValue(sst.nextToken() );69 y.setValue(sst.nextToken().trim()); 70 70 y.setType(ResourceHandler.DOUBLE); 71 71 72 params.add(x);73 72 params.add(y); 74 73 ++i; … … 76 75 break; 77 76 case DISTANCE: 78 String distance = json.getString(key) ;77 String distance = json.getString(key).trim(); 79 78 Parameter dist = new Parameter(); 80 79 dist.setName("distance"); … … 83 82 dist.setType(ResourceHandler.DOUBLE); 84 83 params.add(dist); 84 break; 85 case CRS: 86 String crs = json.getString(key); 87 StringTokenizer crsst = new StringTokenizer(crs, ","); 88 89 Parameter in = new Parameter(); 90 in.setName("srid_in"); 91 in.setSource("url"); 92 in.setValue(crsst.nextToken().trim()); 93 in.setType(ResourceHandler.INTEGER); 94 95 params.add(in); 96 97 if (crsst.hasMoreTokens()) 98 { 99 Parameter out = new Parameter(); 100 out.setName("srid_out"); 101 out.setSource("url"); 102 out.setValue(crsst.nextToken().trim()); 103 out.setType(ResourceHandler.INTEGER); 104 105 params.add(out); 106 } 85 107 break; 86 108 } -
tools/routingservice/branches/wrs-2.0/src/util/format/TemplateFiller.java
r298 r306 24 24 import java.util.HashMap; 25 25 import java.util.Iterator; 26 import java.util.ListIterator; 26 27 27 28 import org.antlr.stringtemplate.StringTemplate; 29 import org.opengis.geometry.MismatchedDimensionException; 30 import org.opengis.referencing.FactoryException; 31 import org.opengis.referencing.NoSuchAuthorityCodeException; 32 import org.opengis.referencing.operation.TransformException; 33 34 import com.vividsolutions.jts.io.ParseException; 28 35 29 36 import util.Log; … … 34 41 { 35 42 protected abstract String getGeometryString(ArrayList<Point> points); 36 43 37 44 public String fillOutputTemplate(ServiceRequest serviceRequest, 38 ArrayList<HashMap<String, Parameter>> output, ResourceHandler handler, Log log) 45 ArrayList<HashMap<String, Parameter>> output, 46 ResourceHandler handler, Log log) 39 47 { 40 48 StringTemplate template = new StringTemplate(serviceRequest … … 43 51 ArrayList<HashMap<String, String>> out = new ArrayList<HashMap<String, String>>(); 44 52 Iterator<HashMap<String, Parameter>> it = output.iterator(); 45 while (it.hasNext())53 while (it.hasNext()) 46 54 { 47 55 HashMap<String, Parameter> paraMap = it.next(); 48 56 HashMap<String, String> stringMap = new HashMap<String, String>(); 49 57 Iterator<String> keys = paraMap.keySet().iterator(); 50 while (keys.hasNext())58 while (keys.hasNext()) 51 59 { 52 60 String key = keys.next(); 53 61 Parameter p = paraMap.get(key); 54 62 String value = p.getValue(); 55 // Geometry string needs to be handled in a special way56 if (p.getType().toLowerCase().equals(ResourceHandler.GEOMETRY))63 // Geometry string needs to be handled in a special way 64 if (p.getType().toLowerCase().equals(ResourceHandler.GEOMETRY)) 57 65 { 58 value = getGeometryString(handler.parseGeometry(value)); 66 ArrayList<Point> points = handler.parseGeometry(value); 67 try 68 { 69 //Check if we need to re-project points 70 int srid_in = Integer.parseInt(serviceRequest.getResource() 71 .getParameters().get("srid").getValue()); 72 int srid_out = Integer.parseInt(serviceRequest 73 .getParameters().get("srid_out").getValue()); 74 if (srid_in != srid_out) 75 { 76 ListIterator<Point> pi = points.listIterator(); 77 while(pi.hasNext()) 78 { 79 Point point = pi.next(); 80 String x = String.valueOf(point.getX()); 81 String y = String.valueOf(point.getY()); 82 String[] transformed = handler.transformPoint(x, y, srid_in, srid_out); 83 point.setX(Double.parseDouble(transformed[0])); 84 point.setY(Double.parseDouble(transformed[1])); 85 } 86 } 87 } 88 catch (NullPointerException e) 89 { 90 //Can't find srid_in or srid_out 91 //Do nothing 92 } 93 catch (MismatchedDimensionException e) 94 { 95 // TODO Auto-generated catch block 96 e.printStackTrace(); 97 } 98 catch (NoSuchAuthorityCodeException e) 99 { 100 // TODO Auto-generated catch block 101 e.printStackTrace(); 102 } 103 catch (FactoryException e) 104 { 105 // TODO Auto-generated catch block 106 e.printStackTrace(); 107 } 108 catch (ParseException e) 109 { 110 // TODO Auto-generated catch block 111 e.printStackTrace(); 112 } 113 catch (TransformException e) 114 { 115 // TODO Auto-generated catch block 116 e.printStackTrace(); 117 } 118 119 value = getGeometryString(points); 59 120 } 60 121 stringMap.put(key, value);
