From 37c91425154bcf99a6494764dfc37d9cf0ac0eed Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 25 Jun 2012 10:18:09 -0700 Subject: [PATCH 1/6] csv plugin: also detect fields named 'lng' as longitude --- plugins/input/csv/csv_datasource.cpp | 4 +++- tests/python_tests/csv_test.py | 30 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 2bb26d1f2..3c5b4b439 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -298,6 +298,7 @@ void csv_datasource::parse_csv(T& stream, } if (lower_val == "x" || lower_val == "lon" + || lower_val == "lng" || lower_val == "long" || (lower_val.find("longitude") != std::string::npos)) { @@ -370,6 +371,7 @@ void csv_datasource::parse_csv(T& stream, } if (lower_val == "x" || lower_val == "lon" + || lower_val == "lng" || lower_val == "long" || (lower_val.find("longitude") != std::string::npos)) { @@ -402,7 +404,7 @@ void csv_datasource::parse_csv(T& stream, if (!has_wkt_field && (!has_lon_field || !has_lat_field) ) { std::ostringstream s; - s << "CSV Plugin: could not detect column headers with the name of wkt ,x/y, or latitude/longitude - this is required for reading geometry data"; + s << "CSV Plugin: could not detect column headers with the name of wkt, x/y, or latitude/longitude - this is required for reading geometry data"; throw mapnik::datasource_exception(s.str()); } diff --git a/tests/python_tests/csv_test.py b/tests/python_tests/csv_test.py index ae86d37ac..e7cfa3028 100644 --- a/tests/python_tests/csv_test.py +++ b/tests/python_tests/csv_test.py @@ -45,6 +45,36 @@ if 'csv' in mapnik.DatasourceCache.instance().plugin_names(): except Exception: print '\x1b[33mfailed\x1b[0m',csv + def test_lon_lat_detection(**kwargs): + ds = get_csv_ds('lon_lat.csv') + eq_(len(ds.fields()),2) + eq_(ds.fields(),['lon','lat']) + eq_(ds.field_types(),['int','int']) + query = mapnik.Query(ds.envelope()) + for fld in ds.fields(): + query.add_property_name(fld) + fs = ds.features(query) + desc = ds.describe() + eq_(desc['geometry_type'],mapnik.DataGeometryType.Point) + feat = fs.next() + attr = {'lon': 0, 'lat': 0} + eq_(feat.attributes,attr) + + def test_lon_lat_detection(**kwargs): + ds = get_csv_ds('lng_lat.csv') + eq_(len(ds.fields()),2) + eq_(ds.fields(),['lng','lat']) + eq_(ds.field_types(),['int','int']) + query = mapnik.Query(ds.envelope()) + for fld in ds.fields(): + query.add_property_name(fld) + fs = ds.features(query) + desc = ds.describe() + eq_(desc['geometry_type'],mapnik.DataGeometryType.Point) + feat = fs.next() + attr = {'lng': 0, 'lat': 0} + eq_(feat.attributes,attr) + def test_type_detection(**kwargs): ds = get_csv_ds('nypd.csv') eq_(ds.fields(),['Precinct','Phone','Address','City','geo_longitude','geo_latitude','geo_accuracy']) From 7b3e86b59f13966f9bdc277f99850903e43ccd0f Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 25 Jun 2012 14:58:38 -0700 Subject: [PATCH 2/6] add test csv file --- tests/data/csv/lng_lat.csv | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/data/csv/lng_lat.csv diff --git a/tests/data/csv/lng_lat.csv b/tests/data/csv/lng_lat.csv new file mode 100644 index 000000000..ea3002a7f --- /dev/null +++ b/tests/data/csv/lng_lat.csv @@ -0,0 +1,2 @@ +lng,lat +0,0 \ No newline at end of file From 5b873beafb0516b8010ee2f395627ecc0e45350c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 25 Jun 2012 15:37:49 -0700 Subject: [PATCH 3/6] add support for dynamically inheriting an optional settings file in python --- bindings/python/mapnik/__init__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index 129b90b59..78b618827 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -43,6 +43,28 @@ import os import sys import warnings +def bootstrap_env(): + """ + If an optional settings file exists, inherit its + environment settings before loading the mapnik library. + + This feature is intended for customized packages of mapnik. + + The settings file should be a python file with an 'env' variable + that declares a dictionary of key:value pairs to push into the + global process environment, if not already set, like: + + env = {'ICU_DATA':'/usr/local/share/icu/'} + """ + if os.path.exists(os.path.join(os.path.dirname(__file__),'mapnik_settings.py')): + from mapnik_settings import env + process_keys = os.environ.keys() + for key, value in env.items(): + if key not in process_keys: + os.environ[key] = value + +bootstrap_env() + from _mapnik import * from paths import inputpluginspath, fontscollectionpath From 18cf6b1bdd86a6167adcefb6cfdadc4777539a45 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 25 Jun 2012 17:28:01 -0700 Subject: [PATCH 4/6] remove unneeded header --- src/grid/grid.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/grid/grid.cpp b/src/grid/grid.cpp index 7550fbf39..ade783a7b 100644 --- a/src/grid/grid.cpp +++ b/src/grid/grid.cpp @@ -22,7 +22,6 @@ // mapnik #include -#include namespace mapnik { From b71553682bbeef7d6d68f1d6c7a3849384ce37c9 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 25 Jun 2012 17:31:43 -0700 Subject: [PATCH 5/6] grid_pixel does not need a 32bit base_shift since alpha is not used --- include/mapnik/grid/grid_pixel.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mapnik/grid/grid_pixel.hpp b/include/mapnik/grid/grid_pixel.hpp index 23588472f..409b50113 100644 --- a/include/mapnik/grid/grid_pixel.hpp +++ b/include/mapnik/grid/grid_pixel.hpp @@ -173,7 +173,7 @@ struct gray32 typedef agg::int64 long_type; enum base_scale_e { - base_shift = 32, + base_shift = 16, base_scale = 1 << base_shift, base_mask = base_scale - 1 }; From 98753db9fdc954f745801638496ff54cc699378e Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 25 Jun 2012 17:57:52 -0700 Subject: [PATCH 6/6] cleaner approach to a compile time magic alpha number for grid buffers --- include/mapnik/grid/grid.hpp | 3 ++- src/build.py | 1 - src/grid/grid.cpp | 31 ------------------------------- 3 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 src/grid/grid.cpp diff --git a/include/mapnik/grid/grid.hpp b/include/mapnik/grid/grid.hpp index 708f8bddc..1f838a2d3 100644 --- a/include/mapnik/grid/grid.hpp +++ b/include/mapnik/grid/grid.hpp @@ -45,6 +45,7 @@ #include #include #include +#include namespace mapnik { @@ -60,7 +61,7 @@ public: typedef std::map feature_key_type; typedef std::map key_type; typedef std::map feature_type; - static const value_type base_mask; + static const value_type base_mask = boost::integer_traits::const_min; private: unsigned width_; diff --git a/src/build.py b/src/build.py index f34a067d8..2e0e8183f 100644 --- a/src/build.py +++ b/src/build.py @@ -260,7 +260,6 @@ if env['RUNTIME_LINK'] == "static": # grid backend source += Split( """ - grid/grid.cpp grid/grid_renderer.cpp grid/process_building_symbolizer.cpp grid/process_line_pattern_symbolizer.cpp diff --git a/src/grid/grid.cpp b/src/grid/grid.cpp deleted file mode 100644 index ade783a7b..000000000 --- a/src/grid/grid.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2012 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// mapnik -#include - -namespace mapnik -{ - -template<> const grid::value_type grid::base_mask = std::numeric_limits::min(); - -}