Giter Site home page Giter Site logo

svg-to-geojson's Introduction

SVG to GeoJson

Converts shapes from an SVG file present in the DOM, into a javascript GeoJSON Object.

Reference

svgtogeojson.svgToGeoJson(ArrayOfBounds, SVGNode, CurveComplexity)

ArrayOfBounds: An Array containing two items, each as Arrays of Lat/Lng points corresponding to North East and South West Lat/Lng points over which you want your SVG to be placed on a map. For example, [[51.60351870425863, 0.207366943359375], [51.342623007528246, -0.46829223632812494]] would be the (rough) bounds for projecting an SVG over Greater London. See on map

SVGNode: A DOM object for an SVG. This could be found somewhere on the page, or loaded via an async request, or raw SVG code e.g jQuery('<svg></svg>')[0]

CurveComplexity: An Integer corresponding to the number of straight-light segments a curve will be broken into. GeoJSON has no support for true circles, so svgToGeoJson converts curves into polygons with N straight sides. How many sides is controlled by CurveComplexity. Providing the value 3 would mean a curve is broken into 3 sections. Note that SVG Circles are defined as 4 joined curves, so a CurveComplexity of 3 would result in a circle that was in fact comprised of 12 facets.

Note that providing ArrayOfBounds with values that would change the native height/width of the SVG will result in the resulting GeoJSON points being stretched.

Usage

  1. Link svg-to-geojson.min.js as a <script> tag in your HTML
  2. Find the NE/SW points of your insertion area using a tool such as geojson.io
  3. Add an SVG from the DOM, or generate/insert one
  4. Run the following
var geoJson = svgtogeojson.svgToGeoJson(
  [[51.60351870425863, 0.207366943359375], [51.342623007528246, -0.46829223632812494]]
  document.getElementById('mysvg'),
  3
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.