goclipmaps

package module
v0.0.0-...-18e1b99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2021 License: MIT Imports: 18 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clipper

type Clipper struct{ MapboxAccessToken string }

Clipper ...

func (Clipper) ClipAndSave

func (c Clipper) ClipAndSave(mask Mask, img image.Image, filename string) error

ClipAndSave ...

func (Clipper) GetImage

func (c Clipper) GetImage(mask Mask) (image.Image, error)

GetImage ...

func (Clipper) NewMask

func (c Clipper) NewMask(feature *geojson.Feature) Mask

NewMask ...

func (Clipper) ReadFeature

func (c Clipper) ReadFeature(r io.Reader) (*geojson.Feature, error)

ReadFeature ...

type Mask

type Mask struct {
	Feature *geojson.Feature
	W, H    float64
	Bounds  []float64
	Opt2x   bool
}

Mask ...

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL