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

georender-pack

v4.2.5

Published

pack and unpack osm data based on the peermaps buffer schema

Downloads

38

Readme

georender-pack

pack osm data into a buffer based on the georender schema. also includes code to unpack buffers in the above schema.

this is part of the peermaps pipeline.

example

encode

var fs = require('fs')
var through = require('through2')
var parseOSM = require('osm-pbf-parser')
var encode = require('georender-pack/encode')
 
var osm = parseOSM()
var allItems = {}
var itemsRefsObject = {}

fs.createReadStream(process.argv[2])
  .pipe(osm)
  .pipe(through.obj(write, end))

function write (items, enc, next) {
  items.forEach(function (item) {
    if (item.type === 'node') {
      allItems[item.id] = item
    }
    else if (item.type === 'way') {
      allItems[item.id] = item
      item.refs.forEach(function (ref) {
        if (!itemsRefsObject[ref]) itemsRefsObject[ref] = allItems[ref]
        else return
      })
    }
  })
  next()
}
function end (next) {
  Object.values(allItems).forEach(function (item) {
    console.log(encode(item, itemsRefsObject))
  })
}

to run this example, first, open the terminal and navigate to the directory where you've cloned your repo. run npm run get-data. if that worked correctly, the example directory should have a file called alexandria.pbf. once you have alexandria.pbf, do npm run encode-example. if everything worked correctly, you should see a bunch of buffer data in your terminal that looks something like this:

<Buffer 02 c0 00 00 00 00 00 00 1c 38 cc a4 41 0e 00 b4 ca ee 41 35 12 f9 41 e5 c9 ee 41 09 12 f9 41 83 c9 ee 41 ee 11 f9 41 31 c9 ee 41 e5 11 f9 41 eb c8 ee ... 77 more bytes>
<Buffer 02 c0 00 00 00 00 00 00 46 38 cc a4 41 14 00 65 c8 ee 41 2d 17 f9 41 99 c8 ee 41 ac 16 f9 41 b0 c8 ee 41 55 16 f9 41 be c8 ee 41 da 15 f9 41 be c8 ee ... 125 more bytes>

decode

var decode = require('../decode.js')

var buffers = [
  Buffer.from('029b038c948b7004b17cef41a98ef941b47def411490f941a77eef413391f941f97eef418f91f94100', 'hex'),
  Buffer.from('029b038f948b7003f95fef418190f941c95fef412d90f941955fef41d28ff94100', 'hex'),
  Buffer.from('01f105f0b48997015bc0ef415dfaf941163dd985d8b2d984d982d8a7d98620d8abd8b1d988d8aa00', 'hex')
]

console.log(decode(buffers))

to run this example, do npm run decode-example. you should see output like this:

{ point:
   { types: Float32Array [ 277 ],
     ids: Float32Array [ 3882630912, 0 ],
     positions: Float32Array [ 30.080724716186523, 31.168306350708008 ] },
  line:
   { types: Float32Array [ 200, 200, 200, 200, 200, 200 ], ...

api

you can load both the encode and decode methods:

var geo = require('georender-pack')

or you can load just the method that you need:

var encode = require('georender-pack/encode')

var decode = require('georender-pack/decode')

encode(item[, itemDependencies])

input is a single osm entry for a node, way, or relation processed through osm-pbf-parser. there is a second, optional argument for any dependencies for the first argument (for example, if the first argument is a way, the second argument should contain data for all the points that make up the way).

output is a single buffer based on the georender schema.

decode(buffers)

input is an array of buffers based on the georender schema.

output is an object containing buffer data in this structure:

{
  point: {
    types: Float32Array [],
    ids: Float32Array [],
    positions: Float32Array [],
    labels: {} // id => [ label strings ]
  },
  line: {
    types: Float32Array [],
    ids: Float32Array [],
    positions: Float32Array [],
    labels: {} // id => [ label strings ]
  },
  area: {
    types: Float32Array [],
    ids: Float32Array [],
    positions: Float32Array [],
    cells: Uint32Array [],
    labels: {} // id => [ label strings ]
  }
}

the output data does not come out as one array for each point/line/area, but in arrays that include all the point/line/area data. points that make up each point/line/area are accessible by offset into these arrays.

here's an example of what an array of label strings might look like:

['=Toshkent', 'aa=Tashkent', 'en=Tashkent', 'alt:uz=Тoшкент']

installation

in your terminal, run npm install georender-pack.

license

MIT