-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1] Colorize raster using pgraster mapnik plugin
- This code was possible thanks to a pairing session with @dlebrero - We found that there is no need to convert the raster to Byte type if we use the band number in the datasouce configuration https://github.com/mapnik/mapnik/wiki/PgRaster band - integer - request for a specific raster band index (1-based). 0 means to read all bands. Note that a band read from a single band raster gets interpreted as Grayscale if band=0 is specified while they retain their original value when explicitly referenced with the "band" parameter. This affects effectiveness of RasterColorizer: https://github.com/mapnik/mapnik/wiki/RasterColorizer - We still need to test if the same behavior applies to a raster that has been reprojected to Web mercator (EPSG:3857) with gdalwarp - We're using `pgraster` plugin. We need to double if this is the same plugin used in Windshaft or if it is `postgis`
- Loading branch information
Showing
6 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ services: | |
context: ./mapnik | ||
links: | ||
- postgres:postgres | ||
volumes: | ||
- ./src:/usr/local/src | ||
- ./rasters:/rasters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Map srs="+init=epsg:4326" background-color="white"> | ||
<Style name="style"> | ||
<Rule> | ||
<RasterSymbolizer opacity="1" scaling="bilinear"> | ||
<RasterColorizer default-mode="linear" default-color="black" epsilon="0.5"> | ||
<stop color="yellow" value="0" /> | ||
<stop color="green" value="240" /> | ||
</RasterColorizer> | ||
</RasterSymbolizer> | ||
</Rule> | ||
</Style> | ||
|
||
|
||
<Layer name="sierra_leone" srs="+init=epsg:4326"> | ||
<StyleName>style</StyleName> | ||
<Datasource> | ||
<Parameter name="type">pgraster</Parameter> | ||
<Parameter name="host">postgres</Parameter> | ||
<Parameter name="dbname">sierra_leone</Parameter> | ||
<Parameter name="user">postgres</Parameter> | ||
<Parameter name="password">sa</Parameter> | ||
<Parameter name="table">sle_pop</Parameter> | ||
<Parameter name="raster_table">sle_pop</Parameter> | ||
<Parameter name="raster_field">rast</Parameter> | ||
<Parameter name="estimate_extent">true</Parameter> | ||
<Parameter name="band">1</Parameter> | ||
<Parameter name="srid">4326</Parameter> | ||
</Datasource> | ||
</Layer> | ||
</Map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
|
||
cd /usr/local/src | ||
|
||
FILE=$(node "${1}") | ||
|
||
curl --upload-file "/tmp/${FILE}" "https://transfer.sh/${FILE}" && echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var mapnik = require('mapnik'); | ||
var fs = require('fs'); | ||
|
||
mapnik.Logger.setSeverity(mapnik.Logger.DEBUG); | ||
|
||
// register fonts and datasource plugins | ||
mapnik.register_default_fonts(); | ||
mapnik.register_default_input_plugins(); | ||
|
||
var map = new mapnik.Map(1000, 1000); | ||
var file = Date.now() + '.png' | ||
|
||
map.load('./pg.xml', function(err,map) { | ||
if (err) throw err; | ||
map.zoomAll(); | ||
var im = new mapnik.Image(1000, 1000); | ||
map.render(im, function(err,im) { | ||
if (err) throw err; | ||
im.encode('png', function(err,buffer) { | ||
if (err) throw err; | ||
fs.writeFile('/tmp/' + file, buffer, function(err) { | ||
if (err) throw err; | ||
console.log(file); | ||
}); | ||
}); | ||
}); | ||
}); |