npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wms-client

v3.0.1

Published

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

Downloads

411

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 <[email protected]>

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.