Hello to all, I have succesfully rendered a map through Postgres datasource using Python API. Now I am trying to do the same through C++ API.
The map doesn't get shown when through C++ program. The only major difference I found in compilation output was the "Scale" Here by I have attached the Python as well as C++ code as well as their respective outputs. Kindly help, Thanks! -- Regards, Anisha Kaul
#!/usr/bin/env python from mapnik import * m = Map (2600, 2300, "+proj=latlong +datum=WGS84") m.background = Color ('white') """ Defining rules and style for Layer 1 ________________________________________________________ """ r = Rule () # For showing roads r.symbols.append (LineSymbolizer (Color ('darkorange'), 2)) s1 = Style () s1.rules.append (r) m.append_style ('style1', s1) lyr = Layer ('roads') lyr.datasource = PostGIS (host='127.0.0.1',user='anisha',password='',dbname='gis',table='planet_osm_roads') lyr.styles.append ('style1') """ Defining rules and style for Layer 2 ________________________________________________________ """ r2 = Rule() # For showing text r2.symbols.append (TextSymbolizer ('name', 'DejaVu Sans Book', 30, Color('green'))) s2 = Style() s2.rules.append (r2) m.append_style ('style2', s2) lyr2 = Layer('places') lyr2.datasource = PostGIS (host='127.0.0.1',user='anisha',password='',dbname='gis',table='planet_osm_line') lyr2.styles.append ('style2') # Append the second, background layer first, since Mapnik uses the painter's model m.layers.append (lyr2) m.layers.append (lyr) m.zoom_all () render_to_file (m, 'postgis_geometry.png')
ani...@linux:~/mapnikCode/18Jan> python layersPostgres.py registered datasource : raster registered datasource : osm registered datasource : shape registered datasource : postgis registered datasource : sqlite size = 6 dbname=gis host=127.0.0.1 password= table=planet_osm_roads type=postgis user=anisha datasource=0x70b4c0 type=1 size = 6 dbname=gis host=127.0.0.1 password= table=planet_osm_line type=postgis user=anisha datasource=0x7099a0 type=1 layer1 - > Envelope(68.1872177124023,6.74739980697632,97.4028778076172,35.5042037963867) layer2 - > Envelope(68.1872177124023,6.74739980697632,97.4028778076172,35.5042037963867) layer1 - > Envelope(68.1872177124023,8.076608657836911,97.4028778076172,35.5038909912109) layer2 - > Envelope(68.1872177124023,8.076608657836911,97.4028778076172,35.5038909912109) scale=0.012503 start map processing bbox=Envelope(66.54120202686475,6.74739980697632,99.04889349315475,35.5042037963867) scale denominator = 4.9708e+06 start layer processing : places datasource = 0x7099a0 end layer processing start layer processing : roads datasource = 0x70b4c0 end layer processing end map processing 5.16 s ~font_face: Clean up face "DejaVu Sans Book" destroyed singleton destroyed singleton destroyed singleton
#include <mapnik/map.hpp> #include <mapnik/datasource_cache.hpp> #include <mapnik/font_engine_freetype.hpp> #include <mapnik/agg_renderer.hpp> #include <mapnik/filter_factory.hpp> #include <mapnik/color_factory.hpp> #include <mapnik/image_util.hpp> #include <mapnik/config_error.hpp> #include <iostream> int main (int argc ,char** argv) { using namespace mapnik; std::string mapnik_dir (argv[1]); datasource_cache::instance()->register_datasources (mapnik_dir + "/input/"); freetype_engine::register_font(mapnik_dir + "/fonts/DejaVuSans.ttf"); Map m (2600, 2300, "+proj=latlong +datum=WGS84"); m.set_background (color_factory::from_string ("white")); // Defining rules and style for Layer 1 ________________________________________________________ stroke line1 (color(0,0,0),1.0); line1.add_dash (8, 4); line1.add_dash (2, 2); line1.add_dash (2, 2); feature_type_style style1; rule_type rule1; rule1.append (line_symbolizer (line1)); style1.add_rule (rule1); m.insert_style ("roads", style1); parameters p1; p1["type"] ="postgis"; p1["host"] ="127.0.0.1"; p1["port"] ="5432"; p1["dbname"] ="gis"; p1["user"] ="anisha"; p1["password"] =""; p1["table"] ="planet_osm_roads"; Layer lyr1("roads"); lyr1.set_datasource(datasource_cache::instance()->create(p1)); lyr1.add_style("style1"); // Defining rules and style for Layer 2 ________________________________________________________ feature_type_style style2; rule_type rule2; rule2.append (text_symbolizer ("DejaVu Sans Book", 30, color(250, 190, 183))); style2.add_rule (rule2); m.insert_style ("places", style2); parameters p2; p2["type"] ="postgis"; p2["host"] ="127.0.0.1"; p2["port"] ="5432"; p2["dbname"] ="gis"; p2["user"] ="anisha"; p2["password"] =""; p2["table"] ="planet_osm_line"; Layer lyr2("places"); lyr2.set_datasource(datasource_cache::instance()->create (p2)); lyr2.add_style("style2"); // Append the second, background layer first, since Mapnik uses the painter's model m.addLayer (lyr2); m.addLayer (lyr1); m.zoom_all (); Image32 buf (m.getWidth(),m.getHeight()); agg_renderer<Image32> ren (m, buf); ren.apply(); save_to_file<ImageData32> (buf.data(), "demo.jpg", "jpeg"); }
ani...@linux:~/mapnik-0.6.0> demo/c++/./rundemo /usr/local/lib64/mapnik/ registered datasource : raster registered datasource : osm registered datasource : shape registered datasource : postgis registered datasource : sqlite size = 7 dbname=gis host=127.0.0.1 password= port=5432 table=planet_osm_roads type=postgis user=anisha datasource=0x80ca40 type=1 size = 7 dbname=gis host=127.0.0.1 password= port=5432 table=planet_osm_line type=postgis user=anisha datasource=0x7f94d0 type=1 layer1 - > Envelope(68.1872177124023,6.74739980697632,97.4028778076172,35.5042037963867) layer2 - > Envelope(68.1872177124023,6.74739980697632,97.4028778076172,35.5042037963867) layer1 - > Envelope(68.1872177124023,8.076608657836911,97.4028778076172,35.5038909912109) layer2 - > Envelope(68.1872177124023,8.076608657836911,97.4028778076172,35.5038909912109) scale=3.84282e-06 start map processing bbox=Envelope(66.54120202686475,6.74739980697632,99.04889349315475,35.5042037963867) scale denominator = 1527.79 start layer processing : places datasource = 0x7f94d0 end layer processing start layer processing : roads datasource = 0x80ca40 end layer processing end map processing 0.00 s destroyed singleton destroyed singleton
------------------------------------- Hi-Tech Gears Limited, Gurgaon, India
_______________________________________________ Mapnik-users mailing list Mapnik-users@lists.berlios.de https://lists.berlios.de/mailman/listinfo/mapnik-users