Skip to content

Instantly share code, notes, and snippets.

@gagan-bansal
Created November 24, 2014 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagan-bansal/4d779c7d09a69345d96c to your computer and use it in GitHub Desktop.
Save gagan-bansal/4d779c7d09a69345d96c to your computer and use it in GitHub Desktop.
svg to geojson approach
// svg file detail
var width = 400;
var height = 400;
// svg file spatial extent, you should know these values for your file
var extent = {left: -180, bottom: 90, right: 180, top: 90};
var x_res = (extent.left - extent.right) / width;
var y_res = (extent.left - extent.right) / height;
// x_res and y_res should be same
// for each x,y value of svg element in svg file extract the path coordinate
long = extent.left + ele_x1 * x_res;
lat = extent.top - ele_y1 * y_res;
// these coordinates can be placed in geojson accirding to the svg element type
// svg line -> LineString
// svg rectangle -> Polygon
// svg polygon -> Polygon
// svg path (if closed) > Polygon
// circle -> Point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment