wms-client

A client for interacting with an OGC Web Map Service (WMS) compliant servers.

Usage no npm install needed!

<script type="module">
  import wmsClient from 'https://cdn.skypack.dev/wms-client';
</script>

README

node-wms-client

A client for interacting with a WMS service.

Installation

npm install wms-client

Usage

wmsclient = require("wms-client");

var url = "http://geocarto.igac.gov.co/geoservicios/wms";
var wms = wmsclient(url);

// Get WMS Service Title
wms.capabilities(function(err, capabilities) {
  if (err) return console.log(err);
  console.log(capabilities.service.title)
});

  • Conversion from XML to JSON is done via the simple-xml2json npm module.
  • All tags and attributes are lowercased after conversion from XML to JSON.

API

Initialization

wmsclient = require("wms-client");

wmsclient(wmsBaseUrl, [requestOptions])

Returns an instance of wms client for a specific URL. You can use this object for calling the API's methods.

  • {Object} requestOptions. Some extra request options for every WMS request; e.g.: {version: "1.1.1"}

Important: By default, every request will be made with WMS version 1.3.0. Initialize wms-client passing requestOptions like {version:"1.1.1"} for a specific version.

Usage

var url = "http://geocarto.igac.gov.co/geoservicios/wms",
  wms = require("wms-client")(url);

WMS related calls

wms.capabilities ([queryOptions], callback(err,capabilities) )

Gets the capabilities reported by the WMS as a javascript object

Example

var url = "http://geocarto.igac.gov.co/geoservicios/wms",
  wms = require("wms-client")(url);

wms.capabilities(function(err, capabilities) {
  console.log(capabilities);
});

wms.layers ([queryOptions], callback(err,layers))

Gets layers reported in the capabilities as a javascript array

Example

var url = "http://geocarto.igac.gov.co/geoservicios/wms",
  wms = require("wms-client")(url);

wms.layers(function(err, layers) {
  console.log(layers);
});

wms.serviceMetadata ([queryOptions], callback(err,serviceMetadata))

Gets service metadata reported in the capabilities under the ervice key/tag as a javascript object

Example

var url = "http://geocarto.igac.gov.co/geoservicios/wms",
  wms = require("wms-client")(url);

wms.serviceMetadata(function(err, serviceMetadata) {
  console.log(serviceMetadata);
});

wms.supportedCrs ([queryOptions], callback(err,supportedcrs))

Gets supported CRS/SRS reported in the capabilities as a javascript array

Example

var url = "http://geocarto.igac.gov.co/geoservicios/wms",
  wms = require("wms-client")(url);

wms.supportedCrs(function(err, supportedcrs) {
  console.log(supportedcrs);

});

wms.getMap([queryOptions], callback(err, image))

Makes a GetMap WMS request and lets you access the generated image as Buffer or as a stream.

Getting the image as a buffer

callback will be called with err and a buffer representing the image generated by the WMS service.

Getting the image as a stream

If you call pipe on the stream returned by wms.getMap() then the parameter callback will be ignored and you can pipe the request to a write stream.

[Object] queryOptions

  • {String} crs. For WMS 1.3.0 requests, the default. The coordinate reference system.
  • {String} srs. For WMS 1.1.1 requests. The spatial reference system.
  • {String} layers. The comma-separated list of layers to query.
  • {Object|String} bbox. Should have minx, miny, maxx, maxy keys with left, lower, right and upper bounds of bounding box with units in CRS. You can also pass bbox as a string of comma separated values with the bounds.
  • {integer} width. The width in pixels for the generated image.
  • {integer} height. The height in pixels for the generated image.

Example getting a GetMap image as a stream

This examples makes a GetMap request and pipes the response to a file called streamed.png.

var wmsUrl = "http://geocarto.igac.gov.co/geoservicios/wms",
  wms = require("wms-client")(wmsUrl),
  fs = require("fs");

var CRS = "EPSG:4686"
var l = "dos_mil:Aeropuerto_PoligonoD";
var writeStream = fs.createWriteStream('./streamed.png');

var stream = wms.getMap({
  layers: l,
  crs: CRS,
  bbox: {
    minx: 10.8735990610001,
    miny: -74.7945542649999,
    maxx: 10.9022271370001,
    maxy: -74.7692014769999
  },
  width: 1024,
  height: 1024
});
stream.pipe(writeStream);

Example getting a GetMap image as a buffer

This examples makes a GetMap request and writes the buffer to a file called buffered.png.

var wmsUrl = "http://geocarto.igac.gov.co/geoservicios/wms",
  wms = require("wms-client")(wmsUrl),
  fs = require("fs");

var CRS = "EPSG:4686";
var l = layers[4];

var stream = wms.getMap({
  layers: l.Name,
  crs: CRS,
  bbox: {
    minx: 10.8735990610001,
    miny: -74.7945542649999,
    maxx: 10.9022271370001,
    maxy: -74.7692014769999
  },
  width: 1024,
  height: 1024
}, function(err, image) {
  if (err) {
    return false;
  }
  fs.writeFile(__dirname + "/buffered.png", image, function(err) {
    if (!err) {
      console.log("Image written to ./buffered.png");
    }
  });
});

wms.getFeatureInfo(xy, [queryOptions], callback(err, featureInfo))

Makes a GetFeatureInfo WMS request.n pipe the request to a write stream.

{Object} xy

  • x: pixel column for the query [0 to width]
  • y: pixel row for the query [0 to height]

{Object} queryOptions

  • {String} crs. For WMS 1.3.0 requests, the default. The coordinate reference system.
  • {String} srs. For WMS 1.1.1 requests. The spatial reference system.
  • {String} layers. The comma-separated list of layers to query.
  • {Object|String} bbox. Should have minx, miny, maxx, maxy keys with left, lower, right and upper bounds of bounding box with units in CRS. You can also pass bbox as a string of comma separated values with the bounds.
  • {integer} width. The width in pixels for the generated image.
  • {integer} height. The height in pixels for the generated image.

License

The MIT License (MIT)

Copyright (c) 2014-2015 Oscar López <oskosk@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.