This is an automated email from the git hooks/post-receive script. sebastic pushed a commit to branch master in repository python-mapnik.
commit e03ba5efb0b511001d4d5d2f8a7acb94696aee53 Author: Bas Couwenberg <sebas...@xs4all.nl> Date: Sat Oct 10 14:51:31 2015 +0200 Imported Upstream version 0.0~20151010-b223124 --- CONTRIBUTING.md | 125 +------------------------ mapnik/__init__.py | 10 +- mapnik/printing.py | 4 +- test/python_tests/image_encoding_speed_test.py | 2 +- test/python_tests/postgis_test.py | 49 ++++++++-- 5 files changed, 52 insertions(+), 138 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5dfb3ce..7f82239 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,130 +4,7 @@ General guidelines for contributing to python-mapnik ## Coding Conventions -Much of python Mapnik is written in C++, and we try to follow general coding guidelines. - -If you see bits of code around that do not follow these please don't hesitate to flag the issue or correct it yourself. - -### C++ Style Guide - -#### Prefix cmath functions with std:: - -The avoids ambiguity and potential bugs of using old C library math directly. - -So always do `std::abs()` instead of `abs()`. Here is a script to fix your code in one fell swoop: - - -```sh -DIR=./bindings -for i in {abs,fabs,tan,sin,cos,floor,ceil,atan2,acos,asin}; do - find $DIR -type f -name '*.cpp' -or -name '*.h' -or -name '*.hpp' | xargs perl -i -p -e "s/ $i\(/ std::$i\(/g;" - find $DIR -type f -name '*.cpp' -or -name '*.h' -or -name '*.hpp' | xargs perl -i -p -e "s/\($i\(/\(std::$i\(/g;" -done -``` - -#### Avoid boost::lexical_cast - -It's slow both to compile and at runtime. - -#### Avoid sstream objects if possible - -They should never be used in performance critical code because they trigger std::locale usage -which triggers locks - -#### Spaces not tabs, and avoid trailing whitespace - -#### Indentation is four spaces - -#### Use C++ style casts - - static_cast<int>(value); // yes - - (int)value; // no - - -#### Use const keyword after the type - - std::string const& variable_name // preferred, for consistency - - const std::string & variable_name // no - - -#### Pass built-in types by value, all others by const& - - void my_function(int double val); // if int, char, double, etc pass by value - - void my_function(std::string const& val); // if std::string or user type, pass by const& - -#### Use unique_ptr instead of new/delete - -#### Use std::copy instead of memcpy - -#### When to use shared_ptr and unique_ptr - -Sparingly, always prefer passing objects as const& except where using share_ptr or unique_ptr express more clearly your intent. See http://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/ for more details. - -#### Shared pointers should be created with std::make_shared. - -#### Use assignment operator for zero initialized numbers - - double num = 0; // please - - double num(0); // no - - -#### Function definitions should not be separated from their arguments: - - void foo(int a) // please - - void foo (int a) // no - - -#### Separate arguments by a single space: - - void foo(int a, float b) // please - - void foo(int a,float b) // no - - -#### Space between operators: - - if (a == b) // please - - if(a==b) // no - - -#### Braces should always be used: - - if (!file) - { - throw mapnik::datasource_exception("not found"); // please - } - - if (!file) - throw mapnik::datasource_exception("not found"); // no - - -#### Braces should be on a separate line: - - if (a == b) - { - int z = 5; - // more... - } - - -#### Prefer `empty()` over `size() == 0` if container supports it - -This avoids implicit conversions to bool and reduces compiler warnings. - - if (container.empty()) // please - - if (container.size() == 0) // no - - -### Other C++ style resources - -Many also follow the useful [Google style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml) which mostly fits our style. However, Google obviously has to maintain a lot of aging codebases. Mapnik can move faster, so we don't follow all of those style recommendations. +See the [Mapnik guide](https://github.com/mapnik/mapnik/blob/master/docs/contributing.md#coding-conventions). ### Python Style Guide diff --git a/mapnik/__init__.py b/mapnik/__init__.py index 25414c0..8c18496 100644 --- a/mapnik/__init__.py +++ b/mapnik/__init__.py @@ -193,7 +193,7 @@ class _Box2d(Box2d, _injector): Following operators are defined for Box2d: Addition: - e1 + e2 is equvalent to e1.expand_to_include(e2) but yields + e1 + e2 is equivalent to e1.expand_to_include(e2) but yields a new envelope instead of modifying e1 Subtraction: @@ -433,7 +433,7 @@ def PostGIS(**keywords): Optional db connection keyword arguments: user -- database user to connect as (default: see postgres docs) password -- password for database user (default: see postgres docs) - host -- portgres hostname (default: see postgres docs) + host -- postgres hostname (default: see postgres docs) port -- postgres port (default: see postgres docs) initial_size -- integer size of connection pool (default: 1) max_size -- integer max of connection pool (default: 10) @@ -476,7 +476,7 @@ def PgRaster(**keywords): Optional db connection keyword arguments: user -- database user to connect as (default: see postgres docs) password -- password for database user (default: see postgres docs) - host -- portgres hostname (default: see postgres docs) + host -- postgres hostname (default: see postgres docs) port -- postgres port (default: see postgres docs) initial_size -- integer size of connection pool (default: 1) max_size -- integer max of connection pool (default: 10) @@ -630,7 +630,7 @@ def SQLite(**keywords): base -- path prefix (default None) encoding -- file encoding (default 'utf-8') extent -- manually specified data extent (comma delimited string, default None) - metadata -- name of auxillary table containing record for table with xmin, ymin, xmax, ymax, and f_table_name + metadata -- name of auxiliary table containing record for table with xmin, ymin, xmax, ymax, and f_table_name geometry_field -- name of geometry field (default 'the_geom') key_field -- name of primary key field (default 'OGC_FID') row_offset -- specify a custom integer row offset (default 0) @@ -738,7 +738,7 @@ class PythonDatasource(object): return None def features_at_point(self, point): - """Rarely uses. Return an iterable which yields instances of Feature for the specified point.""" + """Rarely used. Return an iterable which yields instances of Feature for the specified point.""" return None @classmethod diff --git a/mapnik/printing.py b/mapnik/printing.py index 4519e79..e2f975d 100644 --- a/mapnik/printing.py +++ b/mapnik/printing.py @@ -1023,8 +1023,8 @@ class PDFPrinter: ctx: A cairo context to render the legend to. If this is None (the default) then automatically create a context and choose the best location for the legend. width: Width of area available to render legend in (in m) - page_break: move to next page if legen over flows this one - collumns: number of collumns available in legend box + page_break: move to next page if legend overflows this one + collumns: number of columns available in legend box attribution: additional text that will be rendered in gray under the layer name. keyed by layer name legend_item_box_size: two tuple with width and height of legend item box size in meters diff --git a/test/python_tests/image_encoding_speed_test.py b/test/python_tests/image_encoding_speed_test.py index 58f0785..13b824b 100644 --- a/test/python_tests/image_encoding_speed_test.py +++ b/test/python_tests/image_encoding_speed_test.py @@ -113,7 +113,7 @@ def do_encoding(): t = Timer(aerial_24) run(aerial_24, aerial_24_im, c, t) - for key, value in sorted(sortable.iteritems(), key=lambda k, v: (v, k)): + for key, value in sorted(sortable.items(), key=lambda i: (i[1], i[0])): s = results[key] min_ = str(s[0])[:6] avg = str(s[1])[:6] diff --git a/test/python_tests/postgis_test.py b/test/python_tests/postgis_test.py index d9a6f10..08dd5f7 100644 --- a/test/python_tests/postgis_test.py +++ b/test/python_tests/postgis_test.py @@ -433,7 +433,9 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \ geometry_field='geom', autodetect_key_field=True) fs = ds.featureset() - eq_(fs.next()['manual_id'], 0) + f = fs.next() + eq_(len(ds.fields()),len(f.attributes)) + eq_(f['manual_id'], 0) eq_(fs.next()['manual_id'], 1) eq_(fs.next()['manual_id'], 1000) eq_(fs.next()['manual_id'], -1000) @@ -452,6 +454,27 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \ eq_(meta.get('key_field'), u'manual_id') eq_(meta['geometry_type'], mapnik.DataGeometryType.Point) + def test_auto_detection_of_unique_feature_id_32_bit_no_attribute(): + ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME, table='test2', + geometry_field='geom', + autodetect_key_field=True, + key_field_as_attribute=False) + fs = ds.featureset() + f = fs.next() + eq_(len(ds.fields()),len(f.attributes)) + eq_(len(ds.fields()),0) + eq_(len(f.attributes),0) + eq_(f.id(), 0) + eq_(fs.next().id(), 1) + eq_(fs.next().id(), 1000) + eq_(fs.next().id(), -1000) + eq_(fs.next().id(), 2147483647) + eq_(fs.next().id(), -2147483648) + meta = ds.describe() + eq_(meta['srid'], 4326) + eq_(meta.get('key_field'), u'manual_id') + eq_(meta['geometry_type'], mapnik.DataGeometryType.Point) + def test_auto_detection_will_fail_since_no_primary_key(): ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME, table='test3', geometry_field='geom', @@ -459,8 +482,7 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \ fs = ds.featureset() feat = fs.next() eq_(feat['manual_id'], 0) - # will fail: https://github.com/mapnik/mapnik/issues/895 - # eq_(feat['non_id'],9223372036854775807) + eq_(feat['non_id'],9223372036854775807) eq_(fs.next()['manual_id'], 1) eq_(fs.next()['manual_id'], 1000) eq_(fs.next()['manual_id'], -1000) @@ -494,7 +516,9 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \ geometry_field='geom', autodetect_key_field=True) fs = ds.featureset() - eq_(fs.next()['manual_id'], 0) + f = fs.next() + eq_(len(ds.fields()),len(f.attributes)) + eq_(f['manual_id'], 0) eq_(fs.next()['manual_id'], 1) eq_(fs.next()['manual_id'], 1000) eq_(fs.next()['manual_id'], -1000) @@ -548,7 +572,9 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \ geometry_field='geom', autodetect_key_field=True) fs = ds.featureset() - eq_(fs.next()['manual_id'], 0) + f = fs.next() + eq_(len(ds.fields()),len(f.attributes)) + eq_(f['manual_id'], 0) eq_(fs.next()['manual_id'], 1) eq_(fs.next()['manual_id'], 1000) eq_(fs.next()['manual_id'], -1000) @@ -592,7 +618,9 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \ key_field='manual_id', autodetect_key_field=True) fs = ds.featureset() - eq_(fs.next()['manual_id'], 0) + f = fs.next() + eq_(len(ds.fields()),len(f.attributes)) + eq_(f['manual_id'], 0) eq_(fs.next()['manual_id'], 1) eq_(fs.next()['manual_id'], 1000) eq_(fs.next()['manual_id'], -1000) @@ -1211,6 +1239,15 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \ eq_(feat.geometry.to_wkt(), 'MULTIPOLYGON(((0 0,1 1,2 2,0 0)),((0 0,1 1,2 2,0 0)))') + def test_handling_of_discarded_key_field(): + ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME, + table='(select * from test12) as tmp', + key_field='gid', + key_field_as_attribute=False) + fs = ds.featureset() + feat = fs.next() + eq_(feat['name'],'Point') + def test_variable_in_subquery1(): ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME, table=''' (select * from test where @zoom = 30 ) as tmp''', -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-mapnik.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel