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

@sean_kenny/coloured-bitmap-to-geojson-polygons-js

v0.2.0

Published

A library for convering colour segmented bitmaps to a GeoJSON file of polygons.

Downloads

354

Readme

coloured-bitmap-to-geojson-js

This is a TypeScript library which contains a function which converts .bmp bitmap files into a GeoJSON file.

Version Downloads/week

Installation and Usage

$ npm install --save-dev @sean_kenny/coloured-bitmap-to-geojson-polygons-js
# or
$ yarn add -D @sean_kenny/coloured-bitmap-to-geojson-polygons-js

An output can then be generated by calling the exportColouredBitmapToGeoJSONPolygons function, which is the only function in the library. colourToPropertiesMap is an argument which can be used to attach properties (besides colourHexCode) to regions in your bitmap of a particular colour. Keys in colourToPropertiesMap must be lowercase (Ex. ff0000 rather than FF0000).

const { outputGeoJSON, bmpFileMetadata } = await exportColouredBitmapToGeoJSONPolygons({
  inputFilePath: '/path/to/your/file/your_file.bmp',
  colourToPropertiesMap: {
    "#ff0000": {
      zone: "The red zone"
    },
    "#00ff00": {
      zone: "The green zone"
    },
  }
})

bmpFileMetadata will contain some data in the following format:

{
  "header": {
    "signature": "BM",
    "fileSizeBytes": 120054,
    "reservedField": "00000000",
    "dataOffsetBytes": 54
  },
  "infoHeader": {
    "bitsPerPixel": "TWENTY_FOUR_BIT_RGB",
    "bmpHeightPx": 200,
    "bmpWidthPx": 200,
    "compressionType": "BI_RGB",
    "horizontalPixelsPerMetre": 0,
    "imageCompressedSizeBytes": 0,
    "infoHeaderSizeBytes": 40,
    "numberOfColoursUsed": 0,
    "numberOfImportantColours": 0,
    "numberOfPlanes": 1,
    "verticalPixelsPerMetre": 0
  },
  "colourMap": {}
}

And outputGeoJSON will contain some data in the following format:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-180, 90],
            [-180, -90],
            ...
          ]
        ]
      },
      "properties": {
        "colourHexCode": "#ff0000",
        "data": { "zone": "The red zone" }
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-176.4, 90],
            [-176.4, 89.1],
            ...
          ]
        ]
      },
      "properties": {
        "colourHexCode": "#00ff00",
        "data": { "zone": "The green zone" }
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [1.8000000000000114, 1.7999999999999972],
            [1.8000000000000114, 0],
            ...
          ]
        ]
      },
      "properties": {
        "colourHexCode": "#0000ff",
        "data": null
      }
    }
  ]
}

Some sample inputs and outputs

Original BMP file | Output GeoJSON file :-------------------------:|:-------------------------: | |

Acknowledgements

There's some interesting reading about the exact structure of a bitmap file here which is what a lot of this library is based on.

All files whose name follows the pattern provinces-XXXXXXX.bmp which are used for testing are pulled directly from the ab937cf899b75f74662a17574bd0d46072793beb version of Anbennar which was published to Bitbucket on August 23rd 2024. All credit for those bitmaps goes to their creator. ``bmp-24.bmp` was generously made public by the University of South Carolina.

You're welcome to use this library for anything you'd like. Please keep in mind this hasn't been thoroughly tested with a large variety of bitmap files so this may or may not work for your use case. Please reach out if you have a bitmap file which is not processed properly by this library and I'd be happy to work on something to make it work for you.