public Set<Range<Double>> getValidScaleRanges() { HashSet<Range<Double>> ranges = new HashSet<Range<Double>>(); try { Layer layer = context.getGeoResource().resolve(Layer.class, ProgressManager.instance().get()); double min = layer.getScaleDenominatorMin(); double max = layer.getScaleDenominatorMax(); if (invalidScale(min) && invalidScale(max)) { return ranges; } if (invalidScale(min)) { min = Double.MIN_VALUE; } if (invalidScale(max)) { max = Double.MAX_VALUE; } if (min < max) { ranges.add(new Range<Double>(Double.class, min, max)); } else { ranges.add(new Range<Double>(Double.class, max, min)); } } catch (IOException e) { throw (RuntimeException) new RuntimeException().initCause(e); } return ranges; }
private Layer getLayer(WebMapServer server, String layerName) { for (Layer layer : server.getCapabilities().getLayerList()) { if (layerName.equals(layer.getName())) { return layer; } } throw new IllegalArgumentException("Could not find layer " + layerName); }
private static boolean matchEPSG(List<Layer> layers, String epsgCode) { boolean match = true; for (Layer layer : layers) { Set<String> srs = layer.getSrs(); if (!srs.contains(epsgCode)) { match = false; break; } } return match; }
private Collection<Layer> getWMSLayers() { String zp = Geospace.get().getProperties().getProperty(WMS_LAYER_PROPERTY + "." + _wms_index); ArrayList<Layer> layers = new ArrayList<Layer>(); for (Layer l : WMSUtils.getNamedLayers(_wms.getCapabilities())) { if (zp == null || (zp != null && zp.contains(l.getName()))) { layers.add(l); } } return layers; }
public Integer getCascadedHopCount(LayerInfo layer) { if (!(layer.getResource() instanceof WMSLayerInfo)) { return null; } WMSLayerInfo wmsLayerInfo = (WMSLayerInfo) layer.getResource(); Layer wmsLayer; int cascaded = 1; try { wmsLayer = wmsLayerInfo.getWMSLayer(null); cascaded = 1 + wmsLayer.getCascaded(); } catch (IOException e) { LOGGER.log(Level.INFO, "Unable to determina WMSLayer cascaded hop count", e); } return cascaded; }
/** * We have made this visible so that WMSDescribeLayer (used by InfoView2) can figure out how to * make the *exact* same request in order to a getInfo operation. We should really store the last * request on the layer blackboard for this intra module communication. * * @return SRS code */ public static String findRequestCRS( List<Layer> layers, CoordinateReferenceSystem viewportCRS, IMap map) { String requestCRS = null; if (layers == null || layers.isEmpty()) { return null; } Collection<String> viewportEPSG = extractEPSG(map, viewportCRS); if (viewportEPSG != null) { String match = matchEPSG(layers, viewportEPSG); if (match != null) return match; } if (matchEPSG(layers, EPSG_4326)) return EPSG_4326; if (matchEPSG(layers, EPSG_4269)) { return EPSG_4269; } Layer firstLayer = layers.get(0); for (Object object : firstLayer.getSrs()) { String epsgCode = (String) object; try { // Check to see if *we* can actually use this code first. CRS.decode(epsgCode); } catch (NoSuchAuthorityCodeException e) { continue; } catch (FactoryException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (matchEPSG(layers, epsgCode)) { requestCRS = epsgCode; return requestCRS; } } if (requestCRS == null) { // Hmm. Our layers have no SRS in common - we are in an illegal state WMSPlugin.log( "ERROR: Illegal State: Basic WMS Renderer contains layers with no common CRS. Unable to perform request."); //$NON-NLS-1$ return null; } return requestCRS; }
public static ReferencedEnvelope getLayersBoundingBox( CoordinateReferenceSystem crs, List<Layer> layers, String version) { ReferencedEnvelope envelope = null; for (Layer layer : layers) { GeneralEnvelope temp = layer.getEnvelope(crs); if (temp != null) { ReferencedEnvelope jtsTemp = ReferencedEnvelope.reference(temp); // if( version != null && version.startsWith("1.3")){ // jtsTemp = swapAxis(jtsTemp); // } if (envelope == null) { envelope = jtsTemp; } else { envelope.expandToInclude(jtsTemp); } } } return envelope; }
// XXX: Consider doing more SLD when WMS post is a go public boolean canStyle(String SyleID, Object value) { if (value == null) return false; if (value instanceof Style) return !Double.isNaN(SLDs.rasterOpacity((Style) value)); if (value instanceof StyleImpl && getRenderContext().getGeoResource().canResolve(Layer.class)) { try { Layer layer = getRenderContext() .getGeoResource() .resolve(Layer.class, ProgressManager.instance().get()); if (layer.getStyles().contains(value)) { return true; } else { return false; } } catch (IOException e) { return false; } } return false; }
/** Returns true if the layer can be queried */ public boolean isQueryable(LayerInfo layer) { try { if (layer.getResource() instanceof WMSLayerInfo) { WMSLayerInfo info = (WMSLayerInfo) layer.getResource(); Layer wl = info.getWMSLayer(null); if (!wl.isQueryable()) { return false; } WMSCapabilities caps = info.getStore().getWebMapServer(null).getCapabilities(); OperationType featureInfo = caps.getRequest().getGetFeatureInfo(); if (featureInfo == null || !featureInfo.getFormats().contains("application/vnd.ogc.gml")) { return false; } } return layer.isQueryable(); } catch (IOException e) { LOGGER.log(Level.INFO, "Failed to determin if the layer is queryable, assuming it's not", e); return false; } }
public ImageDescriptor createWMSGylph(Layer target) { if (target.isType(WebMapServer.class)) return null; try { WebMapServer wms = target.getResource(WebMapServer.class, null); org.geotools.data.ows.Layer layer = target.getResource(org.geotools.data.ows.Layer.class, null); if (wms.getCapabilities().getRequest().getGetLegendGraphic() != null) { GetLegendGraphicRequest request = wms.createGetLegendGraphicRequest(); request.setLayer(layer.getName()); String desiredFormat = null; List formats = wms.getCapabilities().getRequest().getGetLegendGraphic().getFormats(); if (formats.contains("image/png")) { // $NON-NLS-1$ desiredFormat = "image/png"; // $NON-NLS-1$ } if (desiredFormat == null && formats.contains("image/gif")) { // $NON-NLS-1$ desiredFormat = "image/gif"; // $NON-NLS-1$ } if (desiredFormat == null) { return null; } request.setFormat(desiredFormat); return ImageDescriptor.createFromURL(request.getFinalURL()); } } catch (Exception e) { // darn } return null; /* * BufferedImage image = createBufferedImage( target, 16, 16); Graphics2D g2 = (Graphics2D) * image.getGraphics(); g2.setColor(Color.GREEN); g2.fillRect(1, 1, 14, 14); * g2.setColor(Color.BLACK); g2.drawRect(0, 0, 15, 15); return createImageDescriptor(image); */ }
public static void main(String[] args) { URL url = null; try { url = new URL( // "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?VERSION=1.1.0&REQUEST=GetCapabilities"); "http://sigel.aneel.gov.br/arcgis/services/SIGEL/Geracao/MapServer/WMSServer?request=getcapabilities"); // "http://www2.sipam.gov.br/geoserver/wms?service=WMS&request=GetCapabilities"); } catch (MalformedURLException e) { // will not happen } WebMapServer wms = null; try { wms = new WebMapServer(url); WMSCapabilities capabilities = wms.getCapabilities(); String serverName = capabilities.getService().getName(); String serverTitle = capabilities.getService().getTitle(); System.out.println( "Capabilities retrieved from server: " + serverName + " (" + serverTitle + ")"); System.out.println(capabilities.getService().getOnlineResource()); // gets the top most layer, which will contain all the others Layer rootLayer = capabilities.getLayer(); System.out.println(rootLayer.getName()); System.out.println("==============="); Layer[] layers2 = WMSUtils.getNamedLayers(capabilities); List<Layer> layers = capabilities.getLayerList(); CRSEnvelope env = null; int i = 0; for (Layer layer : layers2) { i++; System.out.println("Layer: (" + i + ")" + layer.getName()); System.out.println(" " + layer.getTitle()); System.out.println(" " + layer.getChildren().length); System.out.println(" " + layer.getBoundingBoxes()); env = layer.getLatLonBoundingBox(); System.out.println(" " + env.getLowerCorner() + " x " + env.getUpperCorner()); List<String> formats = wms.getCapabilities().getRequest().getGetMap().getFormats(); System.out.println("formats: " + formats); } System.out.println("==============="); GetMapRequest request = wms.createGetMapRequest(); request.setFormat("image/png"); request.setDimensions( "583", "420"); // sets the dimensions of the image to be returned from the server request.setTransparent(true); request.setSRS("EPSG:4326"); request.setBBox(env); request.addLayer(layers.get(layers.size() - 1)); System.out.println(request.getFinalURL()); GetMapResponse response = (GetMapResponse) wms.issueRequest(request); ImageIO.write( ImageIO.read(response.getInputStream()), "png", new File("/Users/otos/development/projeto/demoiselle-spatial/tmp/file.png")); System.out.println(request.getFinalURL()); } catch (IOException e) { // There was an error communicating with the server // For example, the server is down } catch (ServiceException e) { // The server returned a ServiceException (unusual in this case) } catch (SAXException e) { // Unable to parse the response from the server // For example, the capabilities it returned was not valid } }
private static void writeLayer(ILayer layer, BufferedWriter out) throws IOException { Layer wmsLayer = layer.getResource(Layer.class, null); WebMapServer wms = layer.getResource(WebMapServer.class, null); WMSCapabilities caps = wms.getCapabilities(); String version = caps.getVersion(); String title = wms.getCapabilities().getService().getTitle(); int hidden = layer.isVisible() ? 1 : 0; int info = layer.isApplicable("info") ? 1 : 0; // $NON-NLS-1$ String get = caps.getRequest().getGetCapabilities().getGet().toExternalForm(); System.out.println(get); if (get.endsWith("&")) get = get.substring(0, get.length() - 1); // $NON-NLS-1$ append( 4, out, "<Layer hidden=\"" + hidden + "\" queryable=\"" + info + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ append( 6, out, "<Server service=\"OGC:WMS\" title=\"" + title + "\" version=\"" + version + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ append( 8, out, "<OnlineResource method=\"GET\" xlink:href=\"" + get + "\" xlink:type=\"simple\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ append(6, out, "</Server>"); // $NON-NLS-1$ append(6, out, "<Name>" + wmsLayer.getName() + "</Name>"); // $NON-NLS-1$ //$NON-NLS-2$ append(6, out, "<Title>" + wmsLayer.getTitle() + "</Title>"); // $NON-NLS-1$ //$NON-NLS-2$ if (!Double.isNaN(wmsLayer.getScaleHintMin())) append( 6, out, "<sld:MinScaleDenominator>" + wmsLayer.getScaleHintMin() + "</sld:MinScaleDenominator>"); //$NON-NLS-1$ //$NON-NLS-2$ if (!Double.isNaN(wmsLayer.getScaleHintMax())) append( 6, out, "<sld:MaxScaleDenominator>" + wmsLayer.getScaleHintMax() + "</sld:MaxScaleDenominator>"); //$NON-NLS-1$ //$NON-NLS-2$ for (String srs : (Set<String>) wmsLayer.getSrs()) { append(6, out, "<SRS>" + srs + "</SRS>"); // $NON-NLS-1$ //$NON-NLS-2$ } append(6, out, "<FormatList>"); // $NON-NLS-1$ boolean first = true; // TODO: look up preferences? for (String format : caps.getRequest().getGetMap().getFormats()) { if (first) { append( 8, out, "<Format current=\"1\">" + format + "</Format>"); // $NON-NLS-1$ //$NON-NLS-2$ first = false; } append(8, out, "<Format>" + format + "</Format>"); // $NON-NLS-1$ //$NON-NLS-2$ } append(6, out, "</FormatList>"); // $NON-NLS-1$ first = true; // TODO: look up on styleblackboard? append(6, out, "<StyleList>"); // $NON-NLS-1$ Object styles = wmsLayer.getStyles(); List list; if (styles instanceof String) list = Collections.singletonList(styles); else if (styles instanceof List) list = (List) styles; else list = Collections.emptyList(); for (Iterator<Object> iter = list.iterator(); iter.hasNext(); ) { Object next = iter.next(); if (next instanceof String) { String style = (String) next; first = writeStyle(style, style, first, out); } else if (next instanceof StyleImpl) { StyleImpl style = (StyleImpl) next; writeStyle(style.getName(), style.getTitle().toString(), first, out); } } append(6, out, "</StyleList>"); // $NON-NLS-1$ append(4, out, "</Layer>"); // $NON-NLS-1$ }