Create linear color gradient in go

Go doesn’t have any builtin gradient functions to paint/fill the background of a raster, however it has all the required primitives one needs to create a very basic linear gradient. Here is a basic code which defines a 256 x 256 image, then calculates the value of each pixel in the raster based on a linear interpolation formula. import ( "image" "image/color" "image/png" "log" "os" "os/exec" ) var( colorB = [3]float64{248, 54, 0} colorA = [3]float64{254, 140, 0} ) var( width = 256 height = 256 max = float64(width) ) func linearGradient(x, y float64) (uint8, uint8, uint8) { d := x/max r := colorA[0] + d * (colorB[0] - colorA[0]) g := colorA[1] + d * (colorB[1] - colorA[1]) b := colorA[2] + d * (colorB[2] - colorA[2]) return uint8(r), uint8(g), uint8(b) } func main() { var w, h int = width, height dst := image.
Read more →

merge sort in python

Many useful algorithms are recursive in structure: to solve a given problem, they call themselves recursively one or more times to deal with closely related subproblems. These algorithms typically follow a divide-and-conquer approach: they break the problem into several subproblems that are similar to the original problem but smaller in size, solve the subproblems recursively, and then combine these solutions to create a solution to the original problem. The divide-and-conquer paradigm involves three steps at each level of the recursion:
Read more →

Using Geotiff as datasource via gdal

Recently, I have been working on algorithms which needs elevation data as well as Land Cover data, with world coverage. Google has an excellent elevation API however free usage comes with a limit. While searching, I came across a dataset in geotiff format for landcover as well as a processed version of world elevation. Elevation data comes in various resolution (250m,500m,1km), landcover is 500m . So how do we read it ?
Read more →

How to create fishnets or geospatial grids

There are many use cases in GIS world, where the information has to be aggregated, an easy way to achieve this is via gridding or binning, where the area of interest is divided into small sections called grids or bins. These sections are mostly of rectangular form (which can be easily converted into geotiffs), but in some cases even circles or hexagons are also used. You can read a good tutorial from mapbox using Qgis with a mmqgis plugin here.
Read more →

How to transform projections between Spherical Mercator and EPSG 4326

Projections in GIS are commonly referred to by their “EPSG” codes, these are identifiers managed by the European Petroleum Survey Group. One common identifier is “EPSG:4326”, which describes maps where latitude and longitude are treated as X/Y values. Spherical Mercator has an official designation of EPSG:3857. However, before this was established, a large amount of software used the identifier EPSG:900913. This is an unofficial code, but is still the commonly usedin many GIS systems.
Read more →