[Mapproxy-java] SF.net SVN: mapproxy:[27] core
Brought to you by:
pborissow
From: <pbo...@us...> - 2011-05-09 08:13:59
|
Revision: 27 http://mapproxy.svn.sourceforge.net/mapproxy/?rev=27&view=rev Author: pborissow Date: 2011-05-09 08:13:52 +0000 (Mon, 09 May 2011) Log Message: ----------- Added parser for TMS Capabilities. Modified Paths: -------------- Main.java core/BBox.java core/Layer.java core/SRS.java core/Service.java core/grid/TileGrid.java core/request/RequestParams.java Modified: Main.java =================================================================== --- Main.java 2011-04-14 00:55:30 UTC (rev 26) +++ Main.java 2011-05-09 08:13:52 UTC (rev 27) @@ -29,7 +29,18 @@ * @param args the command line arguments */ public static void main(String[] args) throws Exception { - new Main(args); + //new Main(args); + + String url = "http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/"; + //url = "http://geoposer.com:443/server/services/osm.xml"; + + Service service = new Service(url); + System.out.println("Name: " + service.getName() ); + System.out.println("Title: " + service.getTitle() ); + for (mapproxy.core.Layer layer : service.getLayers()){ + System.out.println(" - " + layer.getName()); + } + } @@ -61,12 +72,14 @@ args = new String[]{"C:\\Documents and Settings\\peter.borissow\\My Documents\\Java\\Libraries\\mapproxy\\src\\mapproxy\\config.xml"}; //startServer(args); - seedTest(args); + //seedTest(args); //testWebServices(); //testArcWebServices(); //testTMS(); + testWebServices(); + } @@ -88,6 +101,8 @@ int[] tile_size = new int[]{256,256}; TileGrid grid = new TileGrid(4326, tile_size); + + String url = "http://localhost:9080/tms/Default%20Basemap/2/9/13.png"; mapproxy.tms.TileRequest req = new mapproxy.tms.TileRequest(url); @@ -187,8 +202,8 @@ private void testWebServices() throws Exception { - String url = "http://localhost:9080/ArcGIS/"; - //String url = "http://services.arcgisonline.com/ArcGIS/services/USA_Topo_Maps/MapServer"; + //String url = "http://localhost:9080/ArcGIS/"; + String url = "http://services.arcgisonline.com/ArcGIS/services/USA_Topo_Maps/MapServer"; //url = "http://services.arcgisonline.com/ArcGIS/services/"; //url = "http://sampleserver1.arcgisonline.com/ArcGIS/services/"; @@ -210,8 +225,8 @@ - String fileName = "MapProxy-2781"; - msg = new javaxt.io.File("/temp/ArcGIS/" + fileName + ".xml").getText("UTF-8"); + //String fileName = "MapProxy-2781"; + //msg = new javaxt.io.File("/temp/ArcGIS/" + fileName + ".xml").getText("UTF-8"); javaxt.http.Request request = new javaxt.http.Request(url); request.setHeader("Accept", "*/*"); request.setHeader("Content-Type", "text/xml"); @@ -221,8 +236,8 @@ javaxt.http.Response response = request.getResponse(); //System.out.println(response); //System.out.println(response.getStatus() + ": " + response.getMessage()); - //System.out.println(response.getText()); - new javaxt.io.File("/temp/ArcGIS/" + fileName + "_response.xml").write(response.getText(), "UTF-8"); + System.out.println(response.getText()); + //new javaxt.io.File("/temp/ArcGIS/" + fileName + "_response.xml").write(response.getText(), "UTF-8"); } Modified: core/BBox.java =================================================================== --- core/BBox.java 2011-04-14 00:55:30 UTC (rev 26) +++ core/BBox.java 2011-05-09 08:13:52 UTC (rev 27) @@ -34,6 +34,29 @@ this(minX, minY, maxX, maxY, null); } + + //************************************************************************** + //** Constructor + //************************************************************************** + /** "bbox" as a tuple (minx, miny, maxx, maxy). */ + + public BBox(String bbox){ + + if (bbox==null) return; //Throw Exception? + + String[] arr = bbox.split(","); + double[] box = new double[4]; + for (int i=0; i<box.length; i++){ + box[i] = Double.valueOf(arr[i]); + } + minX = box[0]; + minY = box[1]; + maxX = box[2]; + maxY = box[3]; + } + + + public double getMinX(){ return minX; } @@ -63,4 +86,14 @@ public String toString(){ return minX + "," + minY + "," + maxX + "," + maxY; } + + + public double[] toArray(){ + double[] box = new double[4]; + box[0] = minX; + box[1] = minY; + box[2] = maxX; + box[3] = maxY; + return box; + } } \ No newline at end of file Modified: core/Layer.java =================================================================== --- core/Layer.java 2011-04-14 00:55:30 UTC (rev 26) +++ core/Layer.java 2011-05-09 08:13:52 UTC (rev 27) @@ -290,7 +290,20 @@ } + else if (protocol.equalsIgnoreCase("TMS")){ + if (fileCache==null){ + Object[] affected_tiles = grid.get_affected_tiles(new BBox(bbox).toArray(), new int[]{width, height}, new SRS(srs), false); + double[] box = (double[]) affected_tiles[0]; + int[] _grid = (int[]) affected_tiles[1]; + Generator<int[]> tiles = (Generator<int[]>) affected_tiles[2]; + + } + else{ + + } + } + return null; } Modified: core/SRS.java =================================================================== --- core/SRS.java 2011-04-14 00:55:30 UTC (rev 26) +++ core/SRS.java 2011-05-09 08:13:52 UTC (rev 27) @@ -73,7 +73,7 @@ * get_epsg_num(4313) returns 4313 * get_epsg_num('31466') returns 31466 */ - private static int get_epsg_num(Object epsg_code){ + public static int get_epsg_num(Object epsg_code){ if (epsg_code instanceof String){ String epsg = (String) epsg_code; Modified: core/Service.java =================================================================== --- core/Service.java 2011-04-14 00:55:30 UTC (rev 26) +++ core/Service.java 2011-05-09 08:13:52 UTC (rev 27) @@ -22,6 +22,7 @@ private String[] formats; private java.util.List<Layer> layers = new java.util.ArrayList<Layer>(); private java.util.HashMap<String, Object> params = new java.util.HashMap<String, Object>(); + private String protocol; @@ -60,7 +61,8 @@ javaxt.http.Response response = new javaxt.http.Request(url.toString()).getResponse(); String[] contentType = response.getHeader("Content-Type").split(";"); String media = contentType[0].trim().toLowerCase(); - if (media.equals("text/xml") || media.equals("application/vnd.ogc.wms_xml")){ + if (media.equals("text/xml") || media.equals("application/xml") || + media.equals("application/vnd.ogc.wms_xml")){ Document doc = response.getXML(); Node outerNode = javaxt.xml.DOM.getOuterNode(doc); @@ -69,6 +71,9 @@ outerNodeName.equalsIgnoreCase("WMS_Capabilities")){ parseWMSCapabilities(doc); } + else if(outerNodeName.equalsIgnoreCase("TileMapService")){ + parseTMSCapabilities(doc); + } } @@ -103,6 +108,16 @@ //************************************************************************** + //** getProtocol + //************************************************************************** + /** Returns the type of service. */ + + public String getProtocol(){ + return this.protocol; + } + + + //************************************************************************** //** getTitle //************************************************************************** /** Returns the title of the service. */ @@ -262,15 +277,170 @@ } -// <editor-fold defaultstate="collapsed" desc="Parse WMS and ArcGIS Capabilities Documents. Click on the + sign on the left to edit the code."> +// <editor-fold defaultstate="collapsed" desc="Parse TMS Capabilities. Click on the + sign on the left to edit the code."> + //************************************************************************** + //** parseTMSCapabilities + //************************************************************************** + /** Used to parse a TMS Capabilities Document. */ + + private void parseTMSCapabilities(Document doc){ + + protocol = "TMS"; + + //Get Service Metadata + NodeList serviceInfo = javaxt.xml.DOM.getOuterNode(doc).getChildNodes(); + for (int i=0; i<serviceInfo.getLength(); i++){ + Node node = serviceInfo.item(i); + String nodeName = node.getNodeName(); + String nodeValue = node.getTextContent(); + if (nodeName.equalsIgnoreCase("Title")){ + this.title = nodeValue; + } + else if (nodeName.equalsIgnoreCase("Abstract")){ + this.description = nodeValue; + } + } + + //Get Layers + NodeList tileMaps = doc.getElementsByTagName("TileMap"); + for (int i=0; i<tileMaps.getLength(); i++){ + Node tileMap = tileMaps.item(i); + NamedNodeMap map = tileMap.getAttributes(); + for (int j=0; j<map.getLength(); j++){ + Node attr = map.item(j); + String attrName = attr.getNodeName(); + if (attrName.contains(":")) attrName = attrName.substring(attrName.indexOf(":")+1); + if (attrName.equalsIgnoreCase("href")){ + url = attr.getNodeValue(); + Layer layer = getTMSLayer(url); + if (layer==null && url.contains("/1.0.0/1.0.0/")){ + layer = getTMSLayer(url.replace("/1.0.0/1.0.0/", "/1.0.0/")); + } + if (layer!=null) layers.add(layer); + break; + } + } + } + + } + + private Layer getTMSLayer(String url){ + javaxt.http.Response response = new javaxt.http.Request(url).getResponse(); + if (response.getStatus()==200){ + Document doc = response.getXML(); + if (doc!=null){ + String name = null; + String description = null; + String srs = "EPSG:4326"; + double minX, minY, maxX, maxY; + minX = minY = maxX = maxY = 0; + int[] tile_size = new int[]{256,256}; + String format = "png"; + + NodeList nodes = javaxt.xml.DOM.getOuterNode(doc).getChildNodes(); + for (int i=0; i<nodes.getLength(); i++){ + Node node = nodes.item(i); + String nodeName = node.getNodeName(); + String nodeValue = node.getTextContent(); + if (nodeName.equalsIgnoreCase("Title")){ + name = nodeValue; + } + else if (nodeName.equalsIgnoreCase("Abstract")){ + description = nodeValue; + } + else if (nodeName.equalsIgnoreCase("SRS")){ + srs = nodeValue; + } + else if (nodeName.equalsIgnoreCase("BoundingBox")){ + + NamedNodeMap map = node.getAttributes(); + for (int j=0; j<map.getLength(); j++){ + Node attr = map.item(j); + String coordName = attr.getNodeName(); + String coord = attr.getNodeValue(); + + if (coordName.equalsIgnoreCase("minx")){ + minX = Double.parseDouble(coord); + } + if (coordName.equalsIgnoreCase("miny")){ + minY = Double.parseDouble(coord); + } + if (coordName.equalsIgnoreCase("maxx")){ + maxX = Double.parseDouble(coord); + } + if (coordName.equalsIgnoreCase("maxy")){ + maxY = Double.parseDouble(coord); + } + } + + + } + else if (nodeName.equalsIgnoreCase("TileFormat")){ + + int w = 256; + int h = 256; + + try{ + //<TileFormat width="256" height="256" mime-type="image/png" extension="png"/> + NamedNodeMap map = node.getAttributes(); + for (int j=0; j<map.getLength(); j++){ + Node attr = map.item(j); + String attrName = attr.getNodeName(); + String attrValue = attr.getNodeValue(); + if (attrName.equalsIgnoreCase("width")){ + w = Integer.parseInt(attrValue); + } + else if (attrName.equalsIgnoreCase("height")){ + h = Integer.parseInt(attrValue); + } + else if (attrName.equalsIgnoreCase("extension")){ + format = attrValue; + } + } + } + catch(Exception e){} + + tile_size = new int[]{w,h}; + } + } + + if (name!=null){ + Layer layer = new Layer(name); + layer.setDescription(description); + layer.setBBox(new BBox(minX, minY, maxX, maxY, srs)); + layer.addSRS(srs); + layer.setParam("host", url); + //layer.setParam("layers", layers); + layer.setParam("protocol", protocol); + + int epsg = SRS.get_epsg_num(srs); + layer.setParam("grid", new mapproxy.core.grid.TileGrid(epsg, tile_size)); + layer.setParam("format", format); + + + return layer; + } + + } + } + return null; + } + // </editor-fold> + + +// <editor-fold defaultstate="collapsed" desc="Parse WMS Capabilities. Click on the + sign on the left to edit the code."> + + //************************************************************************** //** parseWMSCapabilities //************************************************************************** /** Used to parse a WMS Capabilities Document. */ private void parseWMSCapabilities(Document doc){ + protocol = "WMS"; + NodeList serviceInfo = null; NodeList capabilities = null; NodeList outerNodes = javaxt.xml.DOM.getOuterNode(doc).getChildNodes(); @@ -444,8 +614,11 @@ + // </editor-fold> +// <editor-fold defaultstate="collapsed" desc="Parse ArcGIS Capabilities. Click on the + sign on the left to edit the code."> + //************************************************************************** //** parseArcGISCapabilities //************************************************************************** @@ -453,6 +626,9 @@ * service. */ private void parseArcGISCapabilities(String json){ + + protocol = "MapServer"; + try{ //Convert the JSON string into XML @@ -612,7 +788,7 @@ - +// </editor-fold> //************************************************************************** @@ -639,8 +815,4 @@ private String getNodeValue(Node node){ return javaxt.xml.DOM.getNodeValue(node); } - - // </editor-fold> - - } \ No newline at end of file Modified: core/grid/TileGrid.java =================================================================== --- core/grid/TileGrid.java 2011-04-14 00:55:30 UTC (rev 26) +++ core/grid/TileGrid.java 2011-05-09 08:13:52 UTC (rev 27) @@ -46,9 +46,9 @@ /** Creates a new instance of TileGrid. * * @param res_type the type of the multi-resolution pyramid. res_type: - * `RES_TYPE_CUSTOM`, `RES_TYPE_GLOBAL`, `RES_TYPE_SQRT2` + * "RES_TYPE_CUSTOM", "RES_TYPE_GLOBAL", "RES_TYPE_SQRT2" * @param levels the number of levels - * @param tile_size the size of each tile in pixel ``int(with), int(height)`` + * @param tile_size the size of each tile in pixel [int(with), int(height)] * @param bbox the bbox of the grid, tiles may overlap this bbox */ public TileGrid(int epsg, double[] bbox, int[] tile_size, String res, Modified: core/request/RequestParams.java =================================================================== --- core/request/RequestParams.java 2011-04-14 00:55:30 UTC (rev 26) +++ core/request/RequestParams.java 2011-05-09 08:13:52 UTC (rev 27) @@ -105,7 +105,8 @@ while (it.hasNext()){ String key = it.next(); String value = params.get(key, ""); - str.append(key + "=" + value); //str.append(key + "=" + java.net.URLEncoder.encode(value)); + //str.append(key + "=" + value); + str.append(key + "=" + java.net.URLEncoder.encode(value)); if (it.hasNext()) str.append("&"); } return str.toString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |