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

geography-markup-language

v0.2.0

Published

Parse OGC Geography Markup Language in Pure JavaScript

Downloads

435

Readme

geography-markup-language

Parse Geography Markup Language in Pure JavaScript

install

npm install geography-markup-language

usage

envelope

import { Envelope } from "geography-markup-language";

const xml = `
<gml:Envelope>
  <gml:lowerCorner>42.943 -71.032</gml:lowerCorner>
   <gml:upperCorner>43.039 -69.856</gml:upperCorner>
</gml:Envelope>
`;

Envelope(xml)
{
  srs: null,
  corners: [
    [42.943, -71.032], // lower corner
    [43.039, -69.856] // upper corner
  ]
}

// convert Envelope to GeoJSON
Envelope(xml, { format: "geojson" })
{
  type: "Feature",
  bbox: [-71.032, 42.943, -69.856, 43.039],
  properties: {},
  geometry: {
    type: "Polygon",
    coordinates: [
      [
        [-71.032, 43.039],
        [-71.032, 42.943],
        [-69.856, 42.943],
        [-69.856, 43.039],
        [-71.032, 43.039]
      ]
    ]
  }
}

LineString

import { LineString } from "geography-markup-language";

const xml = `
  <gml:LineString>
    <gml:posList>
      45.256 -110.45 46.46 -109.48 43.84 -109.86
    </gml:posList>
  </gml:LineString>
`;

LineString(xml)
{
  type: "LineString",
  coords: [
    [45.256, -110.45],
    [46.46, -109.48],
    [43.84, -109.86]
  ]
}

// convert line string into geojson
LineString(xml, { format: "geojson" });
 {
  type: "Feature",
  properties: {},
  geometry: {
    type: "LineString",
    coordinates: [
      [-110.45, 45.256],
      [-109.48, 46.46],
      [-109.86, 43.84]
    ]
  }
}

Polygon

import { Polygon } from "geography-markup-language";

const xml = `
<gml:Polygon>
    <gml:outerBoundaryIs>
        <gml:LinearRing>
            <gml:coordinates>0,0 100,0 100,100 0,100 0,0</gml:coordinates>
        </gml:LinearRing>
    </gml:outerBoundaryIs>
    <gml:innerBoundaryIs>
        <gml:LinearRing>
            <gml:coordinates>1,1 99,1 99,99 1,99 1,1</gml:coordinates>
        </gml:LinearRing>
    </gml:innerBoundaryIs>
</gml:Polygon>
`;

Polygon(xml, { format: "geojson" });
{
  type: "Feature",
  properties: {},
  geometry: {
    type: "Polygon",
    coordinates: [
      [
        [0, 0],
        [0, 100],
        [100, 100],
        [100, 0],
        [0, 0]
      ],
      [
        [1, 1],
        [1, 99],
        [99, 99],
        [99, 1],
        [1, 1]
      ]
    ]
  }
}

Point

import { Point } from "geography-markup-language";

// xml for Hawaii
const xml = `<gml:Point><gml:pos> 19.741755 -155.844437 </gml:pos></gml:Point>`;

Point(xml, { format: "geojson" })
{
  type: "Feature",
  properties: {},
  geometry: {
    type: "Point",
    coordinates: [-155.844437, 19.741755]
  }
}

Geometry

If you are not sure what type of geometry you are parsing, you can call Geometry. It will automatically determine which geometry is being parsed and internally call Envelope, LineString, Point, or Polygon accordingly.

import { Geometry } from "geography-markup-language";

// xml for Hawaii
const xml = `<gml:Point><gml:pos> 19.741755 -155.844437 </gml:pos></gml:Point>`;

Geometry(xml, { format: "geojson" })
{
  type: "Feature",
  properties: {},
  geometry: {
    type: "Point",
    coordinates: [-155.844437, 19.741755]
  }
}

references