Thursday, 30 May 2019

geoserver - Loading WMS layer from external server in Leaflet?


I'm trying to use the WMS service documented here in a leaflet map. The documentation shows an example for openlayers:


var wms = new OpenLayers.Layer.WMS(
"Population Density",
"http://sedac.ciesin.columbia.edu/geoserver/gwc/service/wms",
{layers: 'gpw-v3:gpw-v3-population-density_2000'}
);

but I want to use this with leaflet. My own WMS hosted layers work fine with the following syntax:



var wmsRivers = L.tileLayer.wms("http://zzz.zzz.zzz.zz:8080/geoserver/opengeo/wms", {
layers: 'opengeo:rivers',
format: 'image/png',
transparent: true,
version: '1.1.0',
attribution: ""
}).addTo(map);

The following does not:


var wmsFootprint = new L.tileLayer.wms("http://sedac.ciesin.columbia.edu/geoserver/gwc/service/wms", {

layers: 'gpw-v3:gpw-v3-population-density_2000',
format: 'image/png',
version: '1.1.0',
transparent: true,
attribution: ""
}).addTo(map);

After several minutes waiting for sedac.ciesen.colombia.edu, I get a 400 Failed to load resource: the server responded with a status of 400 (Bad Request)


Is there a way to ping the server to know it's functioning? What about version, I assume this refers to geoserver; how do I know what version they are running? Any other parameters I may be missing?



Answer




When exploring a new WMS you should always do a getcapablities request to start with - this will give you all sorts of useful information (including if the server is working). So first we try


http://sedac.ciesin.columbia.edu/geoserver/gwc/service/wms?request=getcapabilities


which responds with an xml document - so the server is up, opening the file it starts with





so you should probably ask for version 1.1.1


searching for the layer name gives me:


    
gpw-v3:gpw-v3-population-density_2000

Population Density 2000
Gridded Population of the World: Future Estimates (GPWFE) consists of estimates of human population for the years 2005, 2010, 2015 by 2.5 arc-minute grid cells. Population density estimates were also created using the GPWv3 land area grid for the year 2000 (also 2.5 arc-minute resolution). The data products include a population grid (raw counts), and a population density grid (per square km). These products vary in GIS-compatible data formats and geographic extents (global, continent [Antarctica not included], and country levels). Spatial reference metadata refers to global extent. A proportional allocation gridding algorithm, utilizing more than 300,000 national and sub-national administrative units, is used to assign population values to grid cells. Additional global grids are created from the 2.5 arc-minute grid at 1/4, 1/2, and 1 degree resolutions. (Spatial reference metadata refers to global extent, 2.5 arc-minute resoulution). GPWFE is produced by the Columbia University Center for International Earth Science Information Network (CIESIN) in collaboration with the United Nations Food and Agriculture Programme (FAO) and the Centro Internacional de Agricultura Tropical (CIAT).
EPSG:4326
EPSG:900913





so you can only request maps in epsg:4326 or epsg:900913 - you haven't shown enough code for me to see what projection you are using.



Finally look in firebug (or other debugger) to see what the url being requested is and try opening it in your browser - may be there is an error message being returned?


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...