Merge branch 'master' into bigint

This commit is contained in:
artemp 2012-12-03 13:14:31 +00:00
commit 8fa88a71b6
29 changed files with 256 additions and 29 deletions

View file

@ -8,6 +8,8 @@ For a complete change history, see the git log.
## Future
- Added support for DBF `Logical` type: #1614
- Added serialization of `line-offset` to save_map (#1562)
- Enabled default input plugin directory and fonts path to be set inherited from environment settings in

View file

@ -39,13 +39,15 @@ test:
@python tests/run_tests.py -q
test-local:
@echo "*** boostrapping local test environment..."
export ${LINK_FIX}=`pwd`/src:${${LINK_FIX}} && \
@echo "*** Boostrapping local test environment..."
@export ${LINK_FIX}=`pwd`/src:${${LINK_FIX}} && \
export PYTHONPATH=`pwd`/bindings/python/:${PYTHONPATH} && \
export MAPNIK_FONT_DIRECTORY=`pwd`/fonts/dejavu-fonts-ttf-2.33/ttf/ && \
export MAPNIK_INPUT_PLUGINS_DIRECTORY=`pwd`/plugins/input/ && \
make test
check: test-local
demo:
@echo "*** Running rundemo.cpp…"
cd demo/c++; ./rundemo `mapnik-config --prefix`/lib/mapnik

View file

@ -51,5 +51,8 @@ void export_palette ()
// "Creates a new color palette from a file\n"
// )
.def( "__init__", boost::python::make_constructor(make_palette))
.def("to_string", &mapnik::rgba_palette::to_string,
"Returns the palette as a string.\n"
)
;
}

View file

@ -78,11 +78,17 @@ struct raster_markers_rasterizer_dispatch_grid
{
marker_placement_e placement_method = sym_.get_marker_placement();
box2d<double> bbox_(0,0, src_.width(),src_.height());
if (placement_method != MARKER_LINE_PLACEMENT)
if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == Point)
{
double x = 0;
double y = 0;
if (placement_method == MARKER_INTERIOR_PLACEMENT)
if (path.type() == LineString)
{
if (!label::middle_point(path, x, y))
return;
}
else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{
if (!label::interior_position(path, x, y))
return;
@ -209,11 +215,17 @@ struct vector_markers_rasterizer_dispatch_grid
void add_path(T & path)
{
marker_placement_e placement_method = sym_.get_marker_placement();
if (placement_method != MARKER_LINE_PLACEMENT)
if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == Point)
{
double x = 0;
double y = 0;
if (placement_method == MARKER_INTERIOR_PLACEMENT)
if (path.type() == LineString)
{
if (!label::middle_point(path, x, y))
return;
}
else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{
if (!label::interior_position(path, x, y))
return;

View file

@ -87,7 +87,8 @@ struct vector_markers_rasterizer_dispatch
{
marker_placement_e placement_method = sym_.get_marker_placement();
if (placement_method != MARKER_LINE_PLACEMENT)
if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == Point)
{
double x = 0;
double y = 0;
@ -188,7 +189,8 @@ struct raster_markers_rasterizer_dispatch
marker_placement_e placement_method = sym_.get_marker_placement();
box2d<double> bbox_(0,0, src_.width(),src_.height());
if (placement_method != MARKER_LINE_PLACEMENT)
if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == Point)
{
double x = 0;
double y = 0;

View file

@ -151,6 +151,7 @@ public:
}
bool valid() const;
std::string to_string() const;
private:
void parse(std::string const& pal, palette_type type);

View file

@ -134,8 +134,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature & f)
switch (fields_[col].type_)
{
case 'C':
case 'D'://todo handle date?
case 'M':
case 'D':
{
// FIXME - avoid constructing std::string on stack
std::string str(record_+fields_[col].offset_,fields_[col].length_);
@ -152,6 +151,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature & f)
}
else
{
// NOTE: null logical fields use '?'
f.put(name,false);
}
break;

View file

@ -50,6 +50,7 @@ DATASOURCE_PLUGIN(shape_datasource)
using mapnik::String;
using mapnik::Double;
using mapnik::Integer;
using mapnik::Boolean;
using mapnik::datasource_exception;
using mapnik::filter_in_box;
using mapnik::filter_at_point;
@ -121,10 +122,12 @@ void shape_datasource::bind() const
case 'C': // character
case 'D': // Date
case 'M': // Memo, a string
case 'L': // logical
case '@': // timestamp
desc_.add_descriptor(attribute_descriptor(fld_name, String));
break;
case 'L': // logical
desc_.add_descriptor(attribute_descriptor(fld_name, Boolean));
break;
case 'N':
case 'O': // double
case 'F': // float
@ -153,7 +156,7 @@ void shape_datasource::bind() const
}
}
catch (const datasource_exception& ex)
catch (datasource_exception const& ex)
{
MAPNIK_LOG_ERROR(shape) << "Shape Plugin: error processing field attributes, " << ex.what();
throw;

View file

@ -272,8 +272,11 @@ void agg_renderer<T>::end_style_processing(feature_type_style const& st)
}
template <typename T>
void agg_renderer<T>::render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr,
double opacity, composite_mode_e comp_op)
void agg_renderer<T>::render_marker(pixel_position const& pos,
marker const& marker,
agg::trans_affine const& tr,
double opacity,
composite_mode_e comp_op)
{
typedef agg::rgba8 color_type;
typedef agg::order_rgba order_type;

View file

@ -393,5 +393,13 @@ else:
env['create_uninstall_target'](env, target1)
env['create_uninstall_target'](env, target)
# to enable local testing
lib_major_minor = "%s.%d.%d" % (os.path.basename(env.subst(env['MAPNIK_LIB_NAME'])), int(major), int(minor))
local_lib = os.path.basename(env.subst(env['MAPNIK_LIB_NAME']))
if os.path.islink(lib_major_minor) or os.path.exists(lib_major_minor):
os.remove(lib_major_minor)
os.symlink(local_lib,lib_major_minor)
Clean(mapnik,lib_major_minor);
if not env['RUNTIME_LINK'] == 'static':
Depends(mapnik, env.subst('../deps/agg/libagg.a'))

View file

@ -54,6 +54,7 @@
// boost
#include <boost/utility.hpp>
#include <boost/make_shared.hpp>
#include <boost/math/special_functions/round.hpp>
// agg
#include "agg_conv_clip_polyline.h"
@ -1212,7 +1213,13 @@ void cairo_renderer_base::render_marker(pixel_position const& pos, marker const&
else if (marker.is_bitmap())
{
agg::trans_affine matrix = tr;
matrix *= agg::trans_affine_translation(pos.x, pos.y);
double width = (*marker.get_bitmap_data())->width();
double height = (*marker.get_bitmap_data())->height();
double cx = 0.5 * width;
double cy = 0.5 * height;
matrix *= agg::trans_affine_translation(
boost::math::iround(pos.x - cx),
boost::math::iround(pos.y - cy));
context.add_image(matrix, **marker.get_bitmap_data(), opacity);
}
}
@ -1294,14 +1301,16 @@ void cairo_renderer_base::process(shield_symbolizer const& sym,
placements_type const& placements = helper.placements();
for (unsigned int ii = 0; ii < placements.size(); ++ii)
{
pixel_position marker_pos = helper.get_marker_position(placements[ii]);
pixel_position pos = helper.get_marker_position(placements[ii]);
pos.x += 0.5 * helper.get_marker_width();
pos.y += 0.5 * helper.get_marker_height();
double dx = 0.5 * helper.get_marker_width();
double dy = 0.5 * helper.get_marker_height();
agg::trans_affine marker_tr = agg::trans_affine_translation(-dx,-dy);
marker_tr *= agg::trans_affine_scaling(scale_factor_);
marker_tr *= agg::trans_affine_translation(dx,dy);
marker_tr *= helper.get_image_transform();
render_marker(marker_pos,
render_marker(pos,
helper.get_marker(),
marker_tr,
sym.get_opacity());
@ -1550,11 +1559,17 @@ struct markers_dispatch
{
marker_placement_e placement_method = sym_.get_marker_placement();
if (placement_method != MARKER_LINE_PLACEMENT)
if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == Point)
{
double x = 0;
double y = 0;
if (placement_method == MARKER_INTERIOR_PLACEMENT)
if (path.type() == LineString)
{
if (!label::middle_point(path, x, y))
return;
}
else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{
if (!label::interior_position(path, x, y))
return;
@ -1633,11 +1648,17 @@ struct markers_dispatch_2
{
marker_placement_e placement_method = sym_.get_marker_placement();
if (placement_method != MARKER_LINE_PLACEMENT)
if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == Point)
{
double x = 0;
double y = 0;
if (placement_method == MARKER_INTERIOR_PLACEMENT)
if (path.type() == LineString)
{
if (!label::middle_point(path, x, y))
return;
}
else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{
if (!label::interior_position(path, x, y))
return;

View file

@ -60,14 +60,10 @@ logger::severity_type logger::severity_level_ =
#if MAPNIK_DEFAULT_LOG_SEVERITY == 0
logger::debug
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 1
logger::info
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 2
logger::warn
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 3
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 2
logger::error
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 4
logger::fatal
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 5
#elif MAPNIK_DEFAULT_LOG_SEVERITY == 3
logger::none
#else
#error "Wrong default log severity level specified!"

View file

@ -23,6 +23,10 @@
#include <mapnik/palette.hpp>
#include <mapnik/config_error.hpp>
// stl
#include <iostream>
#include <iomanip>
namespace mapnik
{
@ -74,6 +78,32 @@ bool rgba_palette::valid() const
return colors_ > 0;
}
std::string rgba_palette::to_string() const
{
unsigned length = rgb_pal_.size();
unsigned alphaLength = alpha_pal_.size();
std::ostringstream str("");
str << "[Palette " << length;
if (length == 1)
{
str << " color";
}
else
{
str << " colors";
}
str << std::hex << std::setfill('0');
for (unsigned i = 0; i < length; i++) {
str << " #";
str << std::setw(2) << (unsigned)rgb_pal_[i].r;
str << std::setw(2) << (unsigned)rgb_pal_[i].g;
str << std::setw(2) << (unsigned)rgb_pal_[i].b;
if (i < alphaLength) str << std::setw(2) << alpha_pal_[i];
}
str << "]";
return str.str();
}
// return color index in returned earlier palette
unsigned char rgba_palette::quantize(rgba const& c) const
{

View file

@ -1,6 +1,6 @@
<OGRVRTDataSource>
<OGRVRTLayer name="long_lat">
<SrcDataSource>long_lat.csv</SrcDataSource>
<SrcDataSource relativeToVRT="1">long_lat.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
<GeometryField encoding="PointFromColumns" x="long" y="lat"/>

Binary file not shown.

Binary file not shown.

BIN
tests/data/shp/long_lat.dbf Normal file

Binary file not shown.

BIN
tests/data/shp/long_lat.dbt Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

BIN
tests/data/shp/long_lat.shp Normal file

Binary file not shown.

BIN
tests/data/shp/long_lat.shx Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,49 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from nose.tools import *
from utilities import execution_path
import os, mapnik
def setup():
# All of the paths used are relative, if we run the tests
# from another directory we need to chdir()
os.chdir(execution_path('.'))
expected_64 = '[Palette 64 colors #494746 #c37631 #89827c #d1955c #7397b9 #fc9237 #a09f9c #fbc147 #9bb3ce #b7c9a1 #b5d29c #c4b9aa #cdc4a5 #d5c8a3 #c1d7aa #ccc4b6 #dbd19c #b2c4d5 #eae487 #c9c8c6 #e4db99 #c9dcb5 #dfd3ac #cbd2c2 #d6cdbc #dbd2b6 #c0ceda #ece597 #f7ef86 #d7d3c3 #dfcbc3 #d1d0cd #d1e2bf #d3dec1 #dbd3c4 #e6d8b6 #f4ef91 #d3d3cf #cad5de #ded7c9 #dfdbce #fcf993 #ffff8a #dbd9d7 #dbe7cd #d4dce2 #e4ded3 #ebe3c9 #e0e2e2 #f4edc3 #fdfcae #e9e5dc #f4edda #eeebe4 #fefdc5 #e7edf2 #edf4e5 #f2efe9 #f6ede7 #fefedd #f6f4f0 #f1f5f8 #fbfaf8 #ffffff]'
expected_256 = '[Palette 256 colors #272727 #3c3c3c #484847 #564b41 #605243 #6a523e #555555 #785941 #5d5d5d #746856 #676767 #956740 #ba712e #787777 #cb752a #c27c3d #b68049 #dc8030 #df9e10 #878685 #e1a214 #928b82 #a88a70 #ea8834 #e7a81d #cb8d55 #909090 #94938c #e18f48 #f68d36 #6f94b7 #e1ab2e #8e959b #c79666 #999897 #ff9238 #ef9447 #a99a88 #f1b32c #919ca6 #a1a09f #f0b04b #8aa4bf #f8bc39 #b3ac8f #d1a67a #e3b857 #a8a8a7 #ffc345 #a2adb9 #afaeab #f9ab69 #afbba4 #c4c48a #b4b2af #dec177 #9ab2cf #a3bebb #d7b491 #b6cd9e #b5d29c #b9c8a2 #f1c969 #c5c79e #bbbab9 #cabdaa #a6bcd1 #cec4a7 #e7cc89 #dad98a #d5c9a3 #fabd8a #c1d7aa #cec5b4 #d1d1a5 #d9cf9f #c5c4c3 #d3c7b5 #ddd59d #b4c6d6 #d1cbb4 #d1c7ba #d7d1aa #e1c6ab #cbc7c2 #dbd0a9 #e8e58a #fee178 #d3cbba #dfd7a3 #d2cfb9 #c9ddb5 #d2cbbe #c3cbce #d7cbba #dcceb2 #dfd3aa #e5dd9a #dbd3b1 #ceccc6 #d7cbbe #d7cfba #dfc3be #dfd3ae #cbcbcb #cbd3c3 #d3cfc0 #e0d8aa #d7cfbe #dbd3b8 #ebe596 #dfd8b0 #c0ceda #f1ee89 #decfbc #d7cfc4 #d7d3c3 #d1d0cd #d2dfc0 #dbd3c3 #e7c7c3 #e7d7b3 #f2ed92 #d1e2bf #dad7c3 #fef383 #d3d3cf #dbd3c7 #e0d3c2 #dfd7c0 #ebe4a8 #dbd7c7 #dfd3c7 #f7f38f #c9d4de #dcdcc5 #dfd7c7 #e7d5c2 #d6d5d4 #faf78e #d7dfca #fbfb8a #fffb86 #dfd7cb #e5ddc0 #dad7d2 #ecd6c1 #cfd7de #e8d0cc #fbfb8e #fffb8a #eae3b8 #e3d7cd #dfdbce #fffb8e #ffff8a #f5efa6 #dae6cc #e3dbcf #edddc3 #dddbd6 #d5dbdf #ffff91 #e3dbd3 #fefc99 #e7dbd2 #eaddcd #e3dfd3 #ebd7d3 #dddddd #d4dee6 #e2dfd7 #fcdcc0 #e7dbd7 #e7dfd3 #ebe4cb #f4eeb8 #e3dfdb #e7dfd7 #ebded5 #e7e3d7 #fefea6 #e1ecd6 #ece5d3 #e7e3db #dee3e5 #ebe3db #efdfdb #efe3d8 #f4efc9 #e6ecdb #ebe3df #ebe7db #f0ecd3 #e5e6e5 #efe7da #ebe7df #efe3df #fefeb8 #dfe7ef #ebe7e3 #edebde #efe7e0 #e8efe0 #e7f3df #ebebe3 #e7ebe8 #f5edd9 #efebe3 #e3ebf1 #e9efe7 #ebebea #efebe7 #f0efe2 #ecf3e5 #fefdc9 #efefe7 #f3efe7 #f5f3e1 #f2efe9 #e9eef4 #ffeddf #efefef #f3efeb #f3f3eb #f0f7eb #fbf7e1 #fefed8 #f3f3ef #f7f3eb #eef3f7 #f7f7ea #f3f3f3 #f3f7ef #f7f3ef #f3f3f7 #f7f3f3 #f7f7ef #fffee3 #f3f7f7 #f7f7f3 #fcf7ee #f7f7f7 #f7fbf4 #f5f7fb #fbf7f6 #fffeef #f7fbfb #fbfbf7 #fbfbfb #fbfbff #fbfffb #fffbfb #fbffff #fffffb #ffffff]'
expected_rgb = '[Palette 2 colors #ff00ff #ffffff]'
def test_reading_palettes():
act = open('../data/palettes/palette64.act','rb')
palette = mapnik.Palette(act.read(),'act')
eq_(palette.to_string(),expected_64);
act = open('../data/palettes/palette256.act','rb')
palette = mapnik.Palette(act.read(),'act')
eq_(palette.to_string(),expected_256);
palette = mapnik.Palette('\xff\x00\xff\xff\xff\xff', 'rgb')
eq_(palette.to_string(),expected_rgb);
def test_render_with_palette():
m = mapnik.Map(600,400)
mapnik.load_map(m,'../data/good_maps/agg_poly_gamma_map.xml')
m.zoom_all()
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
act = open('../data/palettes/palette256.act','rb')
palette = mapnik.Palette(act.read(),'act')
# test saving directly to filesystem
im.save('/tmp/mapnik-palette-test.png','png',palette)
# test saving to a string
open('/tmp/mapnik-palette-test2.png','wb').write(im.tostring('png',palette));
# compare the two methods
eq_(mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(),mapnik.Image.open('/tmp/mapnik-palette-test2.png').tostring())
# compare to expected
eq_(mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(),mapnik.Image.open('./images/support/mapnik-palette-test.png').tostring())
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]

View file

@ -52,6 +52,23 @@ if 'shape' in mapnik.DatasourceCache.plugin_names():
query.add_property_name('bogus')
fs = ds.features(query)
def test_dbf_logical_field_is_boolean():
ds = mapnik.Shapefile(file='../data/shp/long_lat')
eq_(len(ds.fields()),7)
eq_(ds.fields(),['LONG', 'LAT', 'LOGICAL_TR', 'LOGICAL_FA', 'CHARACTER', 'NUMERIC', 'DATE'])
eq_(ds.field_types(),['str', 'str', 'bool', 'bool', 'str', 'float', 'str'])
query = mapnik.Query(ds.envelope())
for fld in ds.fields():
query.add_property_name(fld)
feat = ds.all_features()[0]
eq_(feat.id(),1)
eq_(feat['LONG'],'0')
eq_(feat['LAT'],'0')
eq_(feat['LOGICAL_TR'],True)
eq_(feat['LOGICAL_FA'],False)
eq_(feat['CHARACTER'],'254')
eq_(feat['NUMERIC'],32)
eq_(feat['DATE'],'20121202')
if __name__ == "__main__":
setup()

View file

@ -85,7 +85,7 @@ def summary(generate=False):
global passed
if len(errors) != 0:
msg = "Visual text rendering: %s failures" % len(errors)
msg = "Visual text rendering: %s failed / %s passed" % (len(errors),passed)
print "-"*len(msg)
print msg
print "-"*len(msg)

View file

@ -0,0 +1,40 @@
{
"keys": [
"",
"4",
"3",
"6",
"5",
"7",
"1",
"2"
],
"data": {},
"grid": [
" !!!!!! ###### ",
" !!!!! ##### ",
" !! ## ",
" ",
" ",
" ",
" ",
" ",
" $$$$ ",
" $$$$$$ ",
" $$$$$$$ ",
" $$$$$$ ",
" %%%$$%% ",
" %%&&&&% ",
" &&&&&& ",
" &&&&&&& ",
" &&&&&& ",
" && ",
" ",
" ",
" ",
" ",
" ",
" ''' ((( ",
" ''''' ((((( "
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,36 @@
<!DOCTYPE Map>
<Map background-color="white" srs="+init=epsg:4326" minimum-version="0.7.2">
<Style name="1">
<Rule>
<Filter>[id]=1</Filter>
<MarkersSymbolizer fill="darkgreen" opacity=".7" width="15" height="10" stroke="green" stroke-width="7" stroke-opacity=".2" placement="line" marker-type="ellipse"/>
</Rule>
<Rule>
<Filter>[id]=2</Filter>
<MarkersSymbolizer fill="darkorange" opacity=".7" width="20" height="10" stroke="orange" stroke-width="7" stroke-opacity=".2" placement="line" marker-type="ellipse"/>
</Rule>
<Rule>
<Filter>[id]=3</Filter>
<MarkersSymbolizer fill="darkred" opacity=".7" width="20" height="10" stroke="orange" stroke-width="7" stroke-opacity=".2" placement="line" marker-type="ellipse"/>
</Rule>
</Style>
<Layer name="point" srs="+init=epsg:4326">
<StyleName>1</StyleName>
<Datasource>
<Parameter name="type">csv</Parameter>
<Parameter name="inline">
x,y,id
0,0,1
5,0,1
5,5,1
0,5,1
2.5,2.5,2
2.5,3,3
2.5,2,3
3,2.5,3
2,2.5,3
</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -38,6 +38,7 @@ files = [
{'name': "lines-3", 'sizes': sizes_few_square,'bbox':default_text_box},
{'name': "lines-shield", 'sizes': sizes_few_square,'bbox':default_text_box},
{'name': "marker-multi-policy", 'sizes':[(600,400)]},
{'name': "marker_line_placement_on_points"},
{'name': "whole-centroid", 'sizes':[(600,400)],
'bbox': mapnik.Box2d(736908, 4390316, 2060771, 5942346)},
{'name': "simple-E", 'bbox':mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)},