add 'gamma' attribute to PolygonSymbolizer, along with tests against simplified world borders shapefile - setting gamma to .5-.7 can remove gaps in processed_p.shp depending on background color - closes #428

This commit is contained in:
Dane Springmeyer 2010-01-13 00:14:44 +00:00
parent 17b8eda5aa
commit b096852829
12 changed files with 183 additions and 5 deletions

View file

@ -81,6 +81,10 @@ Mapnik 0.7.0 Release
- PNG: Added support for semitransparency in png256 outpuy (#477,#202)
- PolygonSymbolizer: Added 'gamma' attribute to allow for dilation of polygon edges - a solution
to gap artifacts or "ghost lines" between adjacent polygons and allows for slight sharpening of
the edges of non overlapping polygons. Accepts any values but 0-1 is the recommended range.
- TextSymbolizer: Large set of new attributes: 'text_convert', 'line_spacing', 'character_spacing',
'wrap_character', 'wrap_before', 'horizontal_alignment', 'justify_alignment', and 'opacity'.

View file

@ -38,23 +38,24 @@ struct polygon_symbolizer_pickle_suite : boost::python::pickle_suite
static boost::python::tuple
getstate(const polygon_symbolizer& p)
{
return boost::python::make_tuple(p.get_opacity());
return boost::python::make_tuple(p.get_opacity(),p.get_gamma());
}
static void
setstate (polygon_symbolizer& p, boost::python::tuple state)
{
using namespace boost::python;
if (len(state) != 1)
if (len(state) != 2)
{
PyErr_SetObject(PyExc_ValueError,
("expected 1-item tuple in call to __setstate__; got %s"
("expected 2-item tuple in call to __setstate__; got %s"
% state).ptr()
);
throw_error_already_set();
}
p.set_opacity(extract<float>(state[0]));
p.set_gamma(extract<float>(state[1]));
}
};
@ -74,6 +75,9 @@ void export_polygon_symbolizer()
.add_property("fill_opacity",
&polygon_symbolizer::get_opacity,
&polygon_symbolizer::set_opacity)
.add_property("gamma",
&polygon_symbolizer::get_gamma,
&polygon_symbolizer::set_gamma)
;
}

View file

@ -33,11 +33,13 @@ namespace mapnik
{
explicit polygon_symbolizer()
: fill_(color(128,128,128)),
opacity_(1.0) {}
opacity_(1.0),
gamma_(1.0) {}
polygon_symbolizer(color const& fill)
: fill_(fill),
opacity_(1.0) {}
opacity_(1.0),
gamma_(1.0) {}
color const& get_fill() const
{
@ -55,9 +57,19 @@ namespace mapnik
{
return opacity_;
}
void set_gamma(float gamma)
{
gamma_ = gamma;
}
float get_gamma() const
{
return gamma_;
}
private:
color fill_;
float opacity_;
float gamma_;
};
struct MAPNIK_DECL building_symbolizer

View file

@ -188,6 +188,8 @@ namespace mapnik
renderer ren(renb);
ras_ptr->reset();
ras_ptr->gamma(agg::gamma_linear(0.0, sym.get_gamma()));
for (unsigned i=0;i<feature.num_geometries();++i)
{

View file

@ -1487,6 +1487,11 @@ namespace mapnik
float opacity = get_css<float>(css, css_name);
poly_sym.set_opacity(opacity);
}
else if (css_name == "gamma")
{
float gamma = get_css<float>(css, css_name);
poly_sym.set_gamma(gamma);
}
else
{
throw config_error(std::string("Failed to parse unknown CSS ") +

View file

@ -128,6 +128,10 @@ namespace mapnik
{
set_css( sym_node, "fill-opacity", sym.get_opacity() );
}
if ( sym.get_gamma() != dfl.get_gamma() || explicit_defaults_ )
{
set_css( sym_node, "gamma", sym.get_gamma() );
}
}
void operator () ( const polygon_pattern_symbolizer & sym )

View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Map srs="+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs" bgcolor="steelblue">
<Style name="world_merc20090930161252883_style">
<!-- Asia - default dark color behind light polygon
leads to "ghost lines" show-through
-->
<Rule>
<Filter>([REGION]=142)</Filter>
<PolygonSymbolizer>
<CssParameter name="fill">yellow</CssParameter>
</PolygonSymbolizer>
</Rule>
<!-- Europe, using Opacity avoids "ghost lines"
-->
<Rule>
<Filter>([REGION]=150)</Filter>
<PolygonSymbolizer>
<CssParameter name="fill">rgb(176,151,238)</CssParameter>
<CssParameter name="fill-opacity">.3</CssParameter>
</PolygonSymbolizer>
</Rule>
<!-- Americas, using gamma of .65 to remove blue lines works as well..
-->
<Rule>
<Filter>([REGION]=19)</Filter>
<PolygonSymbolizer>
<CssParameter name="fill">rgb(136,172,2)</CssParameter>
<CssParameter name="gamma">.6</CssParameter>
</PolygonSymbolizer>
</Rule>
<!-- Africa, using gamma of .65 to remove blue lines works as well..
-->
<Rule>
<Filter>([REGION]=2)</Filter>
<PolygonSymbolizer>
<CssParameter name="fill">rgb(239,98,133)</CssParameter>
<CssParameter name="gamma">.65</CssParameter>
</PolygonSymbolizer>
</Rule>
<!-- Oceana, all disjunct polygons so it does not matter -->
<Rule>
<Filter>([REGION]=9)</Filter>
<PolygonSymbolizer>
<CssParameter name="fill">rgb(212,9,14)</CssParameter>
</PolygonSymbolizer>
</Rule>
</Style>
<Layer name="world_merc20090930161252883" srs="+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs" status="1" clear_label_cache="0" queryable="1">
<StyleName>world_merc20090930161252883_style</StyleName>
<Datasource>
<Parameter name="file">../../data/shp/world_merc</Parameter>
<Parameter name="type">shape</Parameter>
</Datasource>
</Layer>
</Map>

Binary file not shown.

View file

@ -0,0 +1 @@
PROJCS["Google Maps Global Mercator",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Mercator_2SP"],PARAMETER["standard_parallel_1",0],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1]]

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,85 @@
world_merc
==========
'world_merc.shp' is a version of TM_WORLD_BORDERS_SIMPL-0.3.shp
downloaded from http://thematicmapping.org/downloads/world_borders.php.
Coodinates near 180 degress longitude were clipped to faciliate reprojection
to Google mercator (EPSG:900913).
Details from original readme are below:
-------------
TM_WORLD_BORDERS-0.1.ZIP
Provided by Bjorn Sandvik, thematicmapping.org
Use this dataset with care, as several of the borders are disputed.
The original shapefile (world_borders.zip, 3.2 MB) was downloaded from the Mapping Hacks website:
http://www.mappinghacks.com/data/
The dataset was derived by Schuyler Erle from public domain sources.
Sean Gilles did some clean up and made some enhancements.
COLUMN TYPE DESCRIPTION
Shape Polygon Country/area border as polygon(s)
FIPS String(2) FIPS 10-4 Country Code
ISO2 String(2) ISO 3166-1 Alpha-2 Country Code
ISO3 String(3) ISO 3166-1 Alpha-3 Country Code
UN Short Integer(3) ISO 3166-1 Numeric-3 Country Code
NAME String(50) Name of country/area
AREA Long Integer(7) Land area, FAO Statistics (2002)
POP2005 Double(10,0) Population, World Polulation Prospects (2005)
REGION Short Integer(3) Macro geographical (continental region), UN Statistics
SUBREGION Short Integer(3) Geogrpahical sub-region, UN Statistics
LON FLOAT (7,3) Longitude
LAT FLOAT (6,3) Latitude
CHANGELOG VERSION 0.3 - 30 July 2008
- Corrected spelling mistake (United Arab Emirates)
- Corrected population number for Japan
- Adjusted long/lat values for India, Italy and United Kingdom
CHANGELOG VERSION 0.2 - 1 April 2008
- Made new ZIP archieves. No change in dataset.
CHANGELOG VERSION 0.1 - 13 March 2008
- Polygons representing each country were merged into one feature
- ≈land Islands was extracted from Finland
- Hong Kong was extracted from China
- Holy See (Vatican City) was added
- Gaza Strip and West Bank was merged into "Occupied Palestinean Territory"
- Saint-Barthelemy was extracted from Netherlands Antilles
- Saint-Martin (Frensh part) was extracted from Guadeloupe
- Svalbard and Jan Mayen was merged into "Svalbard and Jan Mayen Islands"
- Timor-Leste was extracted from Indonesia
- Juan De Nova Island was merged with "French Southern & Antarctic Land"
- Baker Island, Howland Island, Jarvis Island, Johnston Atoll, Midway Islands
and Wake Island was merged into "United States Minor Outlying Islands"
- Glorioso Islands, Parcel Islands, Spartly Islands was removed
(almost uninhabited and missing ISO-3611-1 code)
- Added ISO-3166-1 codes (alpha-2, alpha-3, numeric-3). Source:
https://www.cia.gov/library/publications/the-world-factbook/appendix/appendix-d.html
http://unstats.un.org/unsd/methods/m49/m49alpha.htm
http://www.fysh.org/~katie/development/geography.txt
- AREA column has been replaced with data from UNdata:
Land area, 1000 hectares, 2002, FAO Statistics
- POPULATION column (POP2005) has been replaced with data from UNdata:
Population, 2005, Medium variant, World Population Prospects: The 2006 Revision
- Added region and sub-region codes from UN Statistics Division. Source:
http://unstats.un.org/unsd/methods/m49/m49regin.htm
- Added LAT, LONG values for each country