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

svg2geojson-antecursor

v0.7.9

Published

Converts an SVG file with added geo-referencing tags into one or more GeoJSON files.

Downloads

3

Readme

SVG 2 GeoJSON

Converts an SVG file with added geo-referencing tags into one or more GeoJSON files.

Installing

npm install svg2geojson-nimrod

Geo-Referencing Tags

You must place two GeoItems inside a Prognoz MetaInfo element as a direct child of the <svg> element at the root of your document.

<MetaInfo xmlns="http://www.prognoz.ru"><Geo>
  <GeoItem X="-595.30" Y="-142.88" Latitude="37.375593" Longitude="-121.977795"/>
  <GeoItem X="1388.66" Y=" 622.34" Latitude="37.369930" Longitude="-121.959404"/>
</Geo></MetaInfo>

These map opposing X/Y corners in your SVG coordinate space to Longitude/Latitude coordinates on the world. Note that the SVG coordinate space has Y increasing down (toward the south), while Latitude increases upwards (towards the north).

Usage

Running the binary from the command line:

$ npm install -g svg2geojson
$ svg2geojson file.svg          # Writes file.geojson
$ svg2geojson file.svg --layers # Writes file.geojson, file-layer1Name.geojson, …
# See svg2geojson --help for more parameters

Running as a Node.js library:

const { geoFromSVGFile, geoFromSVGXML } = require('svg2geojson.js');

// …reading from file on disk
geoFromSVGFile( 'my.svg', layers => {
	layers.forEach( layer => {
		let json = JSON.stringify(layer.geo); // Turn JS object into JSON string
		console.log(`Layer Named: "${layer.name}"`);
		console.log(json);
	});
}, {layers:true, tolerance:0.5} );

// …processing SVG code as a string
const svg = `<svg xmlns="http://www.w3.org/2000/svg"><!-- ... --></svg>`;
geoFromSVGXML( svg, layer => {
	let json = JSON.stringify(layer.geo); // Turn JS object into JSON string
	console.log(json);
} );

See the output of svg2geojson --help for the options you can pass to the functions, and their default values.

Preparing Paths

SVG allows <path> elements with an arbitrary number of overlapping subpaths, with some of them being 'positive' space and some 'negative' space. In SVG these subpaths may be oriented clockwise or counter-clockwise, and added in any order.

GeoJSON only allows a Polygon to have a single 'positive' subpath (and an arbitrary number of additional 'hole' subpaths). To make it easier for the code to detect which subpath is the 'positive' subpath you must currently:

  1. Have only one positive subpath per <path>.
  2. Ensure that the positive subpath is the first subpath in a <path>.

TODO (AKA Known Limitations)

  • Support modes of projection unmapping
  • Support non-rectangular, inverse bilinear unmappings
  • Add more command-line options to control JSON formatting.
  • Treat <g> as MultiPolygon, GeometryCollection, or MultiLineString as appropriate. Currently items within a group are flattened as individual Feature items in the GeoJSON.
  • Treat <path> with multiple positive subpaths as a MultiPolygon. (This requires figuring out which holes apply to which positive subpaths.)