Parse OGC Geography Markup Language in Pure JavaScript
npm install geography-markup-languagebash
npm install geography-markup-language
`usage
- Envelope
- LineString
- Polygon
- Point
- Geometry$3
`js
import { Envelope } from "geography-markup-language";const xml =
;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]
]
]
}
}
`$3
`js
import { LineString } from "geography-markup-language";const xml =
;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]
]
}
}
`$3
`js
import { Polygon } from "geography-markup-language";const xml =
;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]
]
]
}
}
`$3
`js
import { Point } from "geography-markup-language";// xml for Hawaii
const xml =
;Point(xml, { format: "geojson" })
{
type: "Feature",
properties: {},
geometry: {
type: "Point",
coordinates: [-155.844437, 19.741755]
}
}
`$3
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.
`js
import { Geometry } from "geography-markup-language";// xml for Hawaii
const xml =
;Geometry(xml, { format: "geojson" })
{
type: "Feature",
properties: {},
geometry: {
type: "Point",
coordinates: [-155.844437, 19.741755]
}
}
``