Merge remote-tracking branch 'origin/master'

This commit is contained in:
Artem Pavlenko 2012-06-26 15:02:28 +01:00
commit f8a7d06034
8 changed files with 60 additions and 36 deletions

View file

@ -43,6 +43,28 @@ import os
import sys import sys
import warnings 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 _mapnik import *
from paths import inputpluginspath, fontscollectionpath from paths import inputpluginspath, fontscollectionpath

View file

@ -45,6 +45,7 @@
#include <string> #include <string>
#include <cassert> #include <cassert>
#include <vector> #include <vector>
#include <boost/integer_traits.hpp>
namespace mapnik namespace mapnik
{ {
@ -60,7 +61,7 @@ public:
typedef std::map<value_type, lookup_type> feature_key_type; typedef std::map<value_type, lookup_type> feature_key_type;
typedef std::map<lookup_type, value_type> key_type; typedef std::map<lookup_type, value_type> key_type;
typedef std::map<lookup_type, mapnik::feature_ptr> feature_type; typedef std::map<lookup_type, mapnik::feature_ptr> feature_type;
static const value_type base_mask; static const value_type base_mask = boost::integer_traits<value_type>::const_min;
private: private:
unsigned width_; unsigned width_;

View file

@ -173,7 +173,7 @@ struct gray32
typedef agg::int64 long_type; typedef agg::int64 long_type;
enum base_scale_e enum base_scale_e
{ {
base_shift = 32, base_shift = 16,
base_scale = 1 << base_shift, base_scale = 1 << base_shift,
base_mask = base_scale - 1 base_mask = base_scale - 1
}; };

View file

@ -298,6 +298,7 @@ void csv_datasource::parse_csv(T& stream,
} }
if (lower_val == "x" if (lower_val == "x"
|| lower_val == "lon" || lower_val == "lon"
|| lower_val == "lng"
|| lower_val == "long" || lower_val == "long"
|| (lower_val.find("longitude") != std::string::npos)) || (lower_val.find("longitude") != std::string::npos))
{ {
@ -370,6 +371,7 @@ void csv_datasource::parse_csv(T& stream,
} }
if (lower_val == "x" if (lower_val == "x"
|| lower_val == "lon" || lower_val == "lon"
|| lower_val == "lng"
|| lower_val == "long" || lower_val == "long"
|| (lower_val.find("longitude") != std::string::npos)) || (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) ) if (!has_wkt_field && (!has_lon_field || !has_lat_field) )
{ {
std::ostringstream s; 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()); throw mapnik::datasource_exception(s.str());
} }

View file

@ -260,7 +260,6 @@ if env['RUNTIME_LINK'] == "static":
# grid backend # grid backend
source += Split( source += Split(
""" """
grid/grid.cpp
grid/grid_renderer.cpp grid/grid_renderer.cpp
grid/process_building_symbolizer.cpp grid/process_building_symbolizer.cpp
grid/process_line_pattern_symbolizer.cpp grid/process_line_pattern_symbolizer.cpp

View file

@ -1,32 +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 <mapnik/grid/grid.hpp>
#include <mapnik/util/conversions.hpp>
namespace mapnik
{
template<> const grid::value_type grid::base_mask = std::numeric_limits<int>::min();
}

View file

@ -0,0 +1,2 @@
lng,lat
0,0
1 lng lat
2 0 0

View file

@ -45,6 +45,36 @@ if 'csv' in mapnik.DatasourceCache.instance().plugin_names():
except Exception: except Exception:
print '\x1b[33mfailed\x1b[0m',csv 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): def test_type_detection(**kwargs):
ds = get_csv_ds('nypd.csv') ds = get_csv_ds('nypd.csv')
eq_(ds.fields(),['Precinct','Phone','Address','City','geo_longitude','geo_latitude','geo_accuracy']) eq_(ds.fields(),['Precinct','Phone','Address','City','geo_longitude','geo_latitude','geo_accuracy'])