oskosk / node-wms-client

A client for interacting with an OGC WMS service.
MIT License
8 stars 2 forks source link

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)
});

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.

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

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

{Object} queryOptions

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.