Coder Social home page Coder Social logo

goclipmaps's Introduction

goclipmaps

goclipmaps is an experiment in clipping Mapbox Static Map images to GeoJSON features using pure Go.

Inspired by the Twitter bot @everytract.

Census Tract 19, Mercer County, New Jersey (34021001900)

Install

go get github.com/engelsjk/goclipmaps/cmd/goclipmaps

Usage

goclipmaps -shape test/shapes/34021001900.geojson -o 34021001900.png

You'll need an access token for the Mapbox Static Images API. This needs to be set as an environmental variable, available in a .env file, or set inline while running the command.

What

A GeoJSON feature file is used as an input. The bounds of the feature are converted into a geoviewport in order to request a Mapbox Satellite image from the Mapbox Static Image API. That image is then drawn onto a virtal SVG canvas. Next, the GeoJSON feature is converted into SVG path strings which are then parsed into step-by-step path commands. Those path commands are fed into a vector rendering engine and the path is drawn onto a mask layer on the canvas above the image. Finally, the vector mask is clipped against the original raster image.

How

A couple of external packages were used in this experiment.

The package engelsjk/geoviewport is used to calculate the bounds of the Mapbox Static Image API request to geographically center the image to the GeoJSON Feature. It was ported to Go from the JavaScript library mapbox/geo-viewport.

Next, engelsjk/geojson2svg converts the GeoJSON Feature into SVG as an XML string. This package was forked from whosonfirst/go-geojson-svg to add additional functionality for extent and mercator options.

The package JoshVarga/svgparser helps to parse the XML string in order to isolate the specific SVG path string.

Finally, engelsjk/svgg takes in the SVG path string, parses out each command and uses the fogleman/gg rendering engine to draw the paths to a canvas. engelsjk/svgg was forked from the raster rendering engine srwiley/oksvg and modified to draw SVG to fogleman/gg instead of a raster image.

goclipmaps's People

Contributors

engelsjk avatar

Watchers

James Cloos avatar  avatar

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.