Ok, I've partially figured this out and am posting in case someone else
is trying to render a raster in C++. I'd suggest adding a raster
example to the demo program. I've added additional comments below that
may be obvious to the developers but the answers are quite amorphous
when looking at this fresh - for instance where to put the input
plugins.
It wasn't clear to me that a style and rule were required - I thought it
was optional, especially for a raster where it doesn't appear they do
much. The code below successfully displays a grayscale raster image.
Can anything be done with the style and rules? Now I've got to figure
out how to set my RGB bands - I'm assuming this is done through a
style....somehow, pointers would be greatly appreciated.
// Setup mapnik
// This should point to the directory containing the input
plugins (actually DLL's renamed as *.input)
mapnik::datasource_cache::instance()->register_datasources("../");
mapnik::freetype_engine::register_font("../DejaVuSans.ttf");
mapnik::Map map(vm["out_width"].as<int>(),
vm["out_height"].as<int>());
map.set_background(mapnik::color_factory::from_string("white"));
// Setup default style and rule in order to display raster
image
mapnik::feature_type_style raster_style;
mapnik::rule_type raster_rule;
raster_rule.append(mapnik::raster_symbolizer());
// Styles contain rules
raster_style.add_rule(raster_rule);
// Map contains styles for all layers
map.insert_style("raster",raster_style);
// The parameters define the input plugin to use and the
data filename
mapnik::parameters param;
param["type"]="gdal";
param["file"] = InputFile.string();
//param["lox"] = 0; param["loy"] = 0; param["hix"] = 6000;
param["hiy"] = 6000;
// Layer is made up of the input parameters and associated
with a style
mapnik::Layer layer("raster");
layer.set_datasource(mapnik::datasource_cache::instance()->create(param)
);
layer.add_style("raster");
map.addLayer(layer);
map.zoomToBox(layer.envelope());
mapnik::Image32 buf(map.getWidth(),map.getHeight());
mapnik::agg_renderer<mapnik::Image32> ren(map,buf);
ren.apply();
mapnik::save_to_file<mapnik::ImageData32>(buf.data(),fname.string(),"png
256");
************************************************************************
***
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Matt Hanson
Sent: Monday, June 09, 2008 10:44 AM
To: [email protected]
Subject: [Mapnik-users] reading rasters (c++)
I'm trying to read a raster file. In this particular test case I've
got a geotiff, but with no valid projection info - does it default to
using pixel space if no projection info? Here is my code for reading:
************************************************************************
******
// Setup mapnik
mapnik::datasource_cache::instance()->register_datasources("../");
mapnik::freetype_engine::register_font("../DejaVuSans.ttf");
mapnik::Map map(vm["out_width"].as<int>(),
vm["out_height"].as<int>());
map.set_background(mapnik::color_factory::from_string("white"));
mapnik::parameters param;
param["type"]="gdal";
param["file"] = InputFile.string();
mapnik::Layer layer("raster");
layer.set_datasource(mapnik::datasource_cache::instance()->create(param)
);
map.addLayer(layer);
//map.zoomToBox(mapnik::Envelope<double>(371440.5,
3693172.5, 371640.5, 3693372.5));
map.zoomToBox(mapnik::Envelope<double>(0,0,6000,6600));
mapnik::Image32 buf(map.getWidth(),map.getHeight());
mapnik::agg_renderer<mapnik::Image32> ren(map,buf);
ren.apply();
mapnik::save_to_file<mapnik::ImageData32>(buf.data(),fname.string(),"png
256");
************************************************************************
******
All I've been able to do is to get out a blank [white] image. I have
tried another image with projection info to no avail. In one of the
list messages I found reference to having to give parameters for
lox,loy,hix,hiy when reading the raster in a python script so I tried
giving additional parameters with those names like so:
param["lox"] = 0;
param["loy"] = 0;
param["hix"] = 6000;
param["hiy"] = 6000;
Can anyone point out what I may be doing wrong here? I've been unable
to find any C++ mapnik example for raster input, does it work? Does the
gdal plugin even work?
Thanks in advance,
matt
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users