1.6.0 • Published 6 years ago

idly-faster-osm-parser v1.6.0

Weekly downloads
7
License
ISC
Repository
github
Last release
6 years ago

An insanely fast osm parser

The idly-faster-osm-parser is roughly 3kb's gzipped.

This parser parses on the basis of the shape of an .osm file. It tries to avoid using any kind of xml parser and treats the xml as a simple string, hence you can parse gigabytes of data.

Please note it only supports .osm files.

Introduction

npm install idly-faster-osm-parser

How fast

You can run the benchmarks in the benchmark folder. Below is a sample result of processing a 428kb .osm file

ParsersTime
faster-osm-parser0s, 41.30629ms
osmium0s, 50.834623ms
node-faster-osm-parse0s, 56.342906ms
iD-xml-parser0s, 126.757749ms
osmtogeojson0s, 156.496379ms

Browser

The idly-faster-osm-parser is roughly 3kb's gzipped. You can import it just like any npm module

Usage

import idlyParser from 'idly-faster-osm-parser'

const XML2 = `
    <?xml version="1.0" encoding="UTF-8"?>
    <osm>
        <node id="1" version="1" changeset="1" lat="0" lon="0" visible="true" timestamp="2009-03-07T03:26:33Z"></node>
    </osm>`;

const items = idlyParser(XML2);
[
//   {
//     attributes: {
//       changeset: '1',
//       timestamp: '2009-03-07T03:26:33Z',
//       uid: undefined,
//       user: undefined,
//       version: '1',
//       visible: true,
//     },
//     id: 'n1',
//     loc: { lon: 0, lat: 0 },
//     tags: {},
//     type: 'node',
//   },
// ];

parser(xmlString, options)

Returns an array of Osm Entities.

ParameterTypeDescription
xmlStringstringThe xml string to parse
optionsObjectOptional. Specifies the fields to return for the resulting object /objects. Omit this parameter to return all fields.
options.prependEntityCharboolean (default=true)prepending n, w, r to the id of entity

Shape of Entities

interface Node {
   id: EntityId;
   tags: Tags;
   type: EntityType.NODE;
   loc: {
        lat: number;
        lon: number;
    };
   attributes: {
         visible?: boolean;
         version?: string;
         timestamp?: string;
         changeset?: string;
         uid?: string;
         user?: string;
    };
}

interface Way {
    id: EntityId;
    type: EntityType.WAY;
    tags: {
        [index: string]: string;
    };
    nodes: [string];
    attributes: {
         visible?: boolean;
         version?: string;
         timestamp?: string;
         changeset?: string;
         uid?: string;
         user?: string;
    }
}

interface Relation {
    id: EntityId;
    type: EntityType.RELATION;
    tags: {
        [index: string]: string;
    };
    members: [
        {
            id?: string;
            ref?: string;
            type?: string;
            role?: string;
        }
    ];
    attributes: {
         visible?: boolean;
         version?: string;
         timestamp?: string;
         changeset?: string;
         uid?: string;
         user?: string;
    };
}
1.6.0

6 years ago

1.5.0

6 years ago

1.4.6

6 years ago

1.4.0

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago