Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (42 sloc) 1.52 KB
/*=============================
Visualize a grid dataset as a SliceGraph (AKA LineGraph)
=============================*/
DATA_SCALE = .008;
TextReader t file: "world_pop_lores.grid";
//--- convert grid file to individual data cell rows [ x y data ]
RE_DEC_NUM = \"[\d\.]+"; // matches a decimal number
t = select y: rowNum(), line from t;
t = select y, x: splitIndex, data: Val.toDouble(splitValue) from t split by RegEx.splitByMatch(line, RE_DEC_NUM);
//--- scale x,y,data to image size; raise non-zero data by a small amount for appearance
t = select y: 10 * (172 - y) ,
x: 6 * x ,
data: ( data > 0 ? 2.0 + data * DATA_SCALE : 0.0 )
from t;
//--- create slice lines
t = select y, x, geomConnect( Geom.createPoint( x, y + data ) ) line from t group by y;
//--- create mask polygon, data and water lines for rendering
//--- include symbolization for the graphic elements
//--- sort all geometry for rendering
t = select y,
styleStroke,
styleStrokeWidth: 2,
styleFill: #ffffff,
geom: case element
when #mask then Geom.createPolygon ( Geom.collect ( line, LINESTRING( 2000 1, 1 1) ) )
when #line then Geom.difference( line, baseline )
when #water then Geom.intersection( line, baseline )
end
let
baseline = Geom.createLine(0, y, 3000, y )
from t
join [ tt( element, styleStroke )
[ #mask, null ]
[ #line, #222222 ]
[ #water, #EEEEEE ] ] tt
order by y desc;
//Print t;
Plot data: t
width: 1800
height: 1450
extent: LINESTRING (0 0, 2540 1800 )
file: "world_pop_slicegraph.png";