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

sosijs

v0.0.11

Published

Library for reading .SOS-files, dump to GeoJson or TopoJson

Downloads

158

Readme

sosi.js

Library to read SOSI files in Javascript

Status

This is just an attempt to see if it's possible to parse SOSI-files at all in javascript without too much hassle. The data/testfile.sos is the example file found in the document "SOSI standard - versjon 4.5 Del 1: Realisering i SOSI-format og GML" (pdf).

There will obviously be some shortcuts, so the goals are as follows:

  • Focus on utf-8 SOSI documents
  • Defer the axis ordering issue
  • get the following geometry-types to work
    • PUNKT
    • KURVE
    • FLATE
    • TRASE (perhaps)
  • ignore the rest for now
  • use SRID instead of the sosi-specific codes
  • lightweight
  • good test coverage
  • learn a bit more about the format
  • output features as either:
    • geoJSON (implemented)
    • TopoJSON (implemented)
    • OpenLayers (2 or 3) features
    • Leaflet Layers
  • ignore backwards compability

Versions

The dist folder contains two versions of sosi.js:

  • SOSI.js (and SOSI.min.js)
  • SOSI_lite.js (and SOSI_lite.min.js)

The difference (and hence the file size difference) stems from the fact that the full version includes a lookup table to translate the SOSI attribute names into their logical names according to the specification (Thanks to Thomas Hirsch). If this is unimportant for you, you can save about 85K in minified size by choosing the SOSI_lite.min.js version.

Demo

See: https://rawgithub.com/atlefren/sosi.js/master/example/index.html

Usage

//create a parser
var parser = new SOSI.Parser();

//parse SOSI-data (must be a newline-separated string!)
var sosidata = parser.parse(my_data);

//get the "hode"
var hode = sosidata.hode;
var srid = hode.srid; //get srid
var bbox = hode.bbox; //get bbox
//etc

//get number of features
var num_features = sosidata.features.length();

//get all features
var features = sosidata.features.all();

//get all features in the order they appear in the SOSI file
var features = sosidata.features.all(true);

//get feature by index
var feature1 = sosidata.features.at(0); //0-indexed

//get feature by ID:
var feature1 = sosidata.features.getById(200);

//get as GeoJSON
var geojson = sosidata.dumps("geojson");

//get as TopoJSON (non-quantized for now)
var geojson = sosidata.dumps("topojson", "name_of_objects");

Building

  • checkout the project $ npm install $ grunt

Running tests

$ buster-server &
$ buster-test

Dependencies

The only hard dependency is underscore.js (although jQuery is used for the tests and leaflet and backbone is used for the example) Optional support for proj4js (loads the proj4 definitions for CRSes known to sosi.js)

Contribute

All contributions welcome! If you speak SOSI and Javascript fluently you are more than welcome to take over. Otherwise, send pull requests or ask for commit privileges. If you by chance have any SOSI files that are freely usable I'd appreciate some input so that the test set can be expanded.

Contributors

In addition to myself (atlefren) some people have contributed code and/or input to this project:

  • Thomas Hirsch (relet)
  • Torbjørn Auglænd Vilhelmsen (torbjvi)
  • SigTill

Disclaimer

This lib must not be used for critical applications, as the test set is rather limited.