Merge branch 'master' into grouped-rendering
Conflicts: include/mapnik/feature_type_style.hpp src/feature_type_style.cpp
This commit is contained in:
commit
ac8b4c6d2d
550 changed files with 15151 additions and 10654 deletions
19
.gitignore
vendored
19
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
.DS_Store
|
||||
*~
|
||||
*.o
|
||||
*.pyc
|
||||
*.os
|
||||
|
@ -19,7 +21,24 @@ tests/python_tests/raster_colorizer_test_save.xml
|
|||
utils/mapnik-config/mapnik-config
|
||||
utils/mapnik-config/mapnik2.pc
|
||||
utils/shapeindex/shapeindex
|
||||
utils/ogrindex/ogrindex
|
||||
utils/pgsql2sqlite/pgsql2sqlite
|
||||
utils/svg2png/svg2png
|
||||
demo/python/demo*
|
||||
demo/python/map.xml
|
||||
tests/cpp_tests/svg_renderer_tests/background_color_test
|
||||
tests/cpp_tests/svg_renderer_tests/combined_test
|
||||
tests/cpp_tests/svg_renderer_tests/compilation_test
|
||||
tests/cpp_tests/svg_renderer_tests/file_output_test
|
||||
tests/cpp_tests/svg_renderer_tests/file_output_test_case.svg
|
||||
tests/cpp_tests/svg_renderer_tests/path_element_test
|
||||
tests/cpp_tests/svg_renderer_tests/path_element_test_case_1.svg
|
||||
tests/cpp_tests/svg_renderer_tests/root_element_test
|
||||
tests/data/sqlite/*index
|
||||
demo/c++/cairo-demo.pdf
|
||||
demo/c++/cairo-demo.png
|
||||
demo/c++/cairo-demo256.png
|
||||
demo/c++/demo.jpg
|
||||
demo/c++/demo.png
|
||||
demo/c++/demo256.png
|
||||
|
||||
|
|
64
CHANGELOG
64
CHANGELOG
|
@ -11,7 +11,19 @@ Developers: Please commit along with changes.
|
|||
For a complete change history, see the SVN log.
|
||||
|
||||
|
||||
Mapnik Trunk
|
||||
Mapnik 2.1.0
|
||||
------------
|
||||
|
||||
- New CSV plugin - reads tabular files - autodetecting geo columns, newlines, and delimiters. Uses in-memory featureset for fast rendering and is not designed for large files (#902)
|
||||
|
||||
- Fixed bug in shield line placement when dx/dy are used to shift the label relative to the placement point (Matt Amos) (#908)
|
||||
|
||||
- Added <layer_by_sql> parameter in OGR plugin to select a layer by SQL query (besides name or index): see http://www.gdal.org/ogr/ogr_sql.html for specifications (kunitoki) (#472)
|
||||
|
||||
- Added suppport for output maps as tiff files (addresses #967 partially)
|
||||
|
||||
|
||||
Mapnik 2.0.0
|
||||
------------
|
||||
|
||||
- Add minimum-path-length property to text_symbolizer to allow labels to be placed only on lines of a certain length (#865)
|
||||
|
@ -101,6 +113,50 @@ Mapnik Trunk
|
|||
- Implement MarkersSymbolizer in Cairo render and improve the markers placement finder. (#553)
|
||||
|
||||
|
||||
Mapnik 0.7.2 Release
|
||||
--------------------
|
||||
|
||||
- Added forward compatibility for Mapnik 2.0 XML syntax (https://trac.mapnik.org/wiki/Mapnik2/Changes)
|
||||
|
||||
- Build fixes to ensure boost_threads are not used unless THREADING=multi build option is used
|
||||
|
||||
- Fixes for the clang compiler
|
||||
|
||||
- Support for latest libpng (>= 1.5.x) (r2999)
|
||||
|
||||
- Fixes to the postgres pool
|
||||
|
||||
- Fix for correct transparency levels in png256/png8 output (#540)
|
||||
|
||||
- Various build system fixes, especially for gcc compiler on open solaris.
|
||||
|
||||
- When plugins are not found, report the searched directories (#568)
|
||||
|
||||
- Improved font loading support (#559)
|
||||
|
||||
- Fix to shapeindex for allowing indexing of directory of shapefiles like `shapeindex dir/*shp`
|
||||
|
||||
- Fixed handling of null and multipatch shapes in shapefile driver - avoiding inf loop (#573)
|
||||
|
||||
- Fixed raster alpha blending (#589,#674)
|
||||
|
||||
- Enhanced support for faster reprojection if proj >= 4.8 is used (#575)
|
||||
|
||||
- Allow for late-binding of datasources (#622)
|
||||
|
||||
- Fix to OSM plugin to avoid over-caching of data (#542)
|
||||
|
||||
- Various fixes to sqlite, ogr, and occi driver backported from trunk.
|
||||
|
||||
- Ensured that '\n' triggers linebreaks in text rendering (#584)
|
||||
|
||||
- Support for boost filesystem v3
|
||||
|
||||
- Fixes to cairo renderer to avoid missing images (r2526)
|
||||
|
||||
- Fixed reading of label_position_tolerance on text_symbolizer and height for building_symbolizer
|
||||
|
||||
|
||||
Mapnik 0.7.0 Release
|
||||
--------------------
|
||||
|
||||
|
@ -218,8 +274,6 @@ Mapnik 0.7.0 Release
|
|||
|
||||
- Python: Fixed potential crash if pycairo support is enabled but python-cairo module is missing (#392)
|
||||
|
||||
- Python: Added 'mapnik.mapnik_svn_revision()' function to svn revision of Mapnik was compiled at.
|
||||
|
||||
- Python: Added 'mapnik.has_pycairo()' function to test for pycairo support (r1278) (#284)
|
||||
|
||||
- Python: Added 'mapnik.register_plugins()' and 'mapnik.register_fonts()' functions (r1256)
|
||||
|
@ -353,10 +407,6 @@ Mapnik 0.6.0 Release
|
|||
|
||||
- Python: Added further pickling/copy support to Map, Layers, Datasources, Styles,and Rules (r907,r913,r921)
|
||||
|
||||
- OGCServer: Added support for load_map(), allowing reading of XML styles and layers (r901)
|
||||
|
||||
- OGCServer: Enabled friendly html output when in debug mode (debug=1 in ogcserver.conf) (r899)
|
||||
|
||||
- Plugins: Added Sqlite driver for reading sqlite databases (r881)
|
||||
|
||||
- Python: Exposed a number of properties for the Text Symbolizer (r869)
|
||||
|
|
286
SConstruct
286
SConstruct
|
@ -102,6 +102,7 @@ PLUGINS = { # plugins with external dependencies
|
|||
|
||||
# plugins without external dependencies requiring CheckLibWithHeader...
|
||||
'shape': {'default':True,'path':None,'inc':None,'lib':None,'lang':'C++'},
|
||||
'csv': {'default':True,'path':None,'inc':None,'lib':None,'lang':'C++'},
|
||||
'raster': {'default':True,'path':None,'inc':None,'lib':None,'lang':'C++'},
|
||||
'kismet': {'default':False,'path':None,'inc':None,'lib':None,'lang':'C++'},
|
||||
}
|
||||
|
@ -139,34 +140,6 @@ def strip_first(string,find,replace=''):
|
|||
return string.replace(find,replace,1)
|
||||
return string
|
||||
|
||||
def get_libtool_major_version():
|
||||
"""libtool >= 2.1b support lt_dlopenadvise and the previous
|
||||
release appears to be 1.9f (based on NEWS) so checking for
|
||||
>= 2 seems adequate.
|
||||
"""
|
||||
cmd = 'libtool'
|
||||
if platform.uname()[0] == "Darwin":
|
||||
cmd = 'glibtool'
|
||||
version = None
|
||||
fallback_version = 2
|
||||
pattern = r'(.*[^\S])(\d{1}\.\d+\.?\d?)(.*[^\S])'
|
||||
ret = os.popen('%s --version' % cmd).read()
|
||||
match = re.match(pattern,ret)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
if len(groups):
|
||||
version_string = groups[1]
|
||||
if version_string:
|
||||
version_string = version_string.split('.')[0]
|
||||
try:
|
||||
version = int(version_string)
|
||||
except ValueError:
|
||||
pass
|
||||
if not version:
|
||||
color_print(1,'Could not detect libtool --version, assuming major version 2')
|
||||
return fallback_version
|
||||
return version
|
||||
|
||||
# http://www.scons.org/wiki/InstallTargets
|
||||
def create_uninstall_target(env, path, is_glob=False):
|
||||
if 'uninstall' in COMMAND_LINE_TARGETS:
|
||||
|
@ -230,7 +203,7 @@ def sort_paths(items,priority):
|
|||
else:
|
||||
path_types['user'].append(i)
|
||||
# key system libs (likely others will fall into 'other')
|
||||
elif '/usr/' in i or '/System' in i or '/lib' in i:
|
||||
elif '/usr/' in i or '/System' in i or i.startswith('/lib'):
|
||||
path_types['system'].append(i)
|
||||
# anything not yet matched...
|
||||
# likely a combo of rare system lib paths and
|
||||
|
@ -301,6 +274,7 @@ opts.AddVariables(
|
|||
EnumVariable('OPTIMIZATION','Set g++ optimization level','3', ['0','1','2','3','4','s']),
|
||||
# Note: setting DEBUG=True will override any custom OPTIMIZATION level
|
||||
BoolVariable('DEBUG', 'Compile a debug version of Mapnik', 'False'),
|
||||
BoolVariable('DEBUG_UNDEFINED', 'Compile a version of Mapnik using clang/llvm undefined behavior asserts', 'False'),
|
||||
ListVariable('INPUT_PLUGINS','Input drivers to include',DEFAULT_PLUGINS,PLUGINS.keys()),
|
||||
('WARNING_CXXFLAGS', 'Compiler flags you can set to reduce warning levels which are placed after -Wall.', ''),
|
||||
|
||||
|
@ -317,7 +291,9 @@ opts.AddVariables(
|
|||
('PREFIX', 'The install path "prefix"', '/usr/local'),
|
||||
('PYTHON_PREFIX','Custom install path "prefix" for python bindings (default of no prefix)',''),
|
||||
('DESTDIR', 'The root directory to install into. Useful mainly for binary package building', '/'),
|
||||
('PATH_INSERT', 'A custom path to append to the $PATH env to prioritize usage of shell programs like pkg-config will be used if multiple are present on the system', ''),
|
||||
('PATH', 'A custom path (or multiple paths divided by ":") to append to the $PATH env to prioritize usage of command line programs (if multiple are present on the system)', ''),
|
||||
('PATH_REMOVE', 'A path prefix to exclude from all known command and compile paths', ''),
|
||||
('PATH_REPLACE', 'Two path prefixes (divided with a :) to search/replace from all known command and compile paths', ''),
|
||||
|
||||
# Boost variables
|
||||
# default is '/usr/include', see FindBoost method below
|
||||
|
@ -327,7 +303,7 @@ opts.AddVariables(
|
|||
('BOOST_TOOLKIT','Specify boost toolkit, e.g., gcc41.','',False),
|
||||
('BOOST_ABI', 'Specify boost ABI, e.g., d.','',False),
|
||||
('BOOST_VERSION','Specify boost version, e.g., 1_35.','',False),
|
||||
('BOOST_PYTHON_LIB','Specify library name or full path to boost_python lib (e.g. "boost_python-py26" or "/usr/lib/libboost_python.dylib")',''),
|
||||
('BOOST_PYTHON_LIB','Specify library name to specific Boost Python lib (e.g. "boost_python-py26")',''),
|
||||
|
||||
# Variables for required dependencies
|
||||
('FREETYPE_CONFIG', 'The path to the freetype-config executable.', 'freetype-config'),
|
||||
|
@ -373,7 +349,7 @@ opts.AddVariables(
|
|||
# Other variables
|
||||
BoolVariable('SHAPE_MEMORY_MAPPED_FILE', 'Utilize memory-mapped files in Shapefile Plugin (higher memory usage, better performance)', 'True'),
|
||||
('SYSTEM_FONTS','Provide location for python bindings to register fonts (if given aborts installation of bundled DejaVu fonts)',''),
|
||||
('LIB_DIR_NAME','Name to use for the subfolder beside libmapnik where fonts and plugins are installed','mapnik2'),
|
||||
('LIB_DIR_NAME','Name to use for the subfolder beside libmapnik where fonts and plugins are installed','mapnik'),
|
||||
PathVariable('PYTHON','Full path to Python executable used to build bindings', sys.executable),
|
||||
BoolVariable('FRAMEWORK_PYTHON', 'Link against Framework Python on Mac OS X', 'True'),
|
||||
BoolVariable('PYTHON_DYNAMIC_LOOKUP', 'On OSX, do not directly link python lib, but rather dynamically lookup symbols', 'True'),
|
||||
|
@ -423,16 +399,15 @@ pickle_store = [# Scons internal variables
|
|||
'PYTHON_INSTALL_LOCATION',
|
||||
'PYTHON_SYS_PREFIX',
|
||||
'COLOR_PRINT',
|
||||
'HAS_BOOST_SYSTEM',
|
||||
'SVN_REVISION',
|
||||
'HAS_CAIRO',
|
||||
'HAS_PYCAIRO',
|
||||
'HAS_LIBXML2',
|
||||
'LIBTOOL_SUPPORTS_ADVISE',
|
||||
'PYTHON_IS_64BIT',
|
||||
'SAMPLE_INPUT_PLUGINS',
|
||||
'PKG_CONFIG_PATH',
|
||||
'PATH_INSERT',
|
||||
'PATH',
|
||||
'PATH_REMOVE',
|
||||
'PATH_REPLACE',
|
||||
'MAPNIK_LIB_DIR',
|
||||
'MAPNIK_LIB_DIR_DEST',
|
||||
'INSTALL_PREFIX',
|
||||
|
@ -448,6 +423,8 @@ pickle_store = [# Scons internal variables
|
|||
'CAIROMM_LIBPATHS',
|
||||
'CAIROMM_LINKFLAGS',
|
||||
'CAIROMM_CPPPATHS',
|
||||
'SVG_RENDERER',
|
||||
'SQLITE_LINKFLAGS'
|
||||
]
|
||||
|
||||
# Add all other user configurable options to pickle pickle_store
|
||||
|
@ -522,19 +499,13 @@ if sys.platform == "win32":
|
|||
|
||||
color_print(4,'\nWelcome to Mapnik...\n')
|
||||
|
||||
color_print(1,'*'*45)
|
||||
color_print(1,'You are compiling Mapnik trunk (aka Mapnik2)')
|
||||
color_print(1,'See important details at:\nhttp://trac.mapnik.org/wiki/Mapnik2')
|
||||
color_print(1,('*'*45)+'\n')
|
||||
|
||||
|
||||
#### Custom Configure Checks ###
|
||||
|
||||
def prioritize_paths(context,silent=True):
|
||||
env = context.env
|
||||
prefs = env['LINK_PRIORITY'].split(',')
|
||||
if not silent:
|
||||
context.Message( 'Sorting lib and inc compiler paths by priority... %s' % ','.join(prefs) )
|
||||
context.Message( 'Sorting lib and inc compiler paths...')
|
||||
env['LIBPATH'] = sort_paths(env['LIBPATH'],prefs)
|
||||
env['CPPPATH'] = sort_paths(env['CPPPATH'],prefs)
|
||||
if silent:
|
||||
|
@ -835,10 +806,10 @@ int main()
|
|||
|
||||
major, minor = map(int,result.split('.'))
|
||||
if major >= 4 and minor >= 0:
|
||||
color_print(4,'\nFound icu version... %s\n' % result)
|
||||
color_print(4,'found: icu %s' % result)
|
||||
return True
|
||||
|
||||
color_print(1,'\nFound insufficient icu version... %s\n' % result)
|
||||
color_print(1,'\nFound insufficient icu version... %s' % result)
|
||||
return False
|
||||
|
||||
def boost_regex_has_icu(context):
|
||||
|
@ -877,18 +848,34 @@ def sqlite_has_rtree(context):
|
|||
|
||||
ret = context.TryRun("""
|
||||
|
||||
extern "C" {
|
||||
#include <sqlite3.h>
|
||||
}
|
||||
#include <sqlite3.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
sqlite3_rtree_geometry *p;
|
||||
//sqlite3_compileoption_used("ENABLE_RTREE");
|
||||
return 0;
|
||||
sqlite3* db;
|
||||
int rc;
|
||||
rc = sqlite3_open(":memory:", &db);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
printf("error 1: %s\\n", sqlite3_errmsg(db));
|
||||
}
|
||||
const char * sql = "create virtual table foo using rtree(pkid, xmin, xmax, ymin, ymax)";
|
||||
rc = sqlite3_exec(db, sql, 0, 0, 0);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
printf("error 2: %s\\n", sqlite3_errmsg(db));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("yes, has rtree!\\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
""", '.cpp')
|
||||
""", '.c')
|
||||
context.Message('Checking if SQLite supports RTREE... ')
|
||||
context.Result(ret[0])
|
||||
if ret[0]:
|
||||
|
@ -933,7 +920,7 @@ if not preconfigured:
|
|||
opts.files.append(conf)
|
||||
color_print(4,"SCons CONFIG found: '%s', variables will be inherited..." % conf)
|
||||
optfile = file(conf)
|
||||
print optfile.read().replace("\n", " ").replace("'","").replace(" = ","=")
|
||||
#print optfile.read().replace("\n", " ").replace("'","").replace(" = ","=")
|
||||
optfile.close()
|
||||
|
||||
elif not conf == SCONS_LOCAL_CONFIG:
|
||||
|
@ -956,8 +943,6 @@ if not preconfigured:
|
|||
env['PLATFORM'] = platform.uname()[0]
|
||||
color_print(4,"Configuring on %s in *%s*..." % (env['PLATFORM'],mode))
|
||||
|
||||
env['LIBTOOL_SUPPORTS_ADVISE'] = get_libtool_major_version() >= 2
|
||||
|
||||
env['MISSING_DEPS'] = []
|
||||
env['SKIPPED_DEPS'] = []
|
||||
env['HAS_CAIRO'] = False
|
||||
|
@ -966,14 +951,13 @@ if not preconfigured:
|
|||
env['CAIROMM_CPPPATHS'] = []
|
||||
env['HAS_PYCAIRO'] = False
|
||||
env['HAS_LIBXML2'] = False
|
||||
env['SVN_REVISION'] = None
|
||||
env['LIBMAPNIK_LIBS'] = []
|
||||
env['LIBMAPNIK_CPPATHS'] = []
|
||||
env['LIBMAPNIK_CXXFLAGS'] = []
|
||||
env['LIBDIR_SCHEMA'] = LIBDIR_SCHEMA
|
||||
env['PLUGINS'] = PLUGINS
|
||||
env['EXTRA_FREETYPE_LIBS'] = []
|
||||
|
||||
env['SQLITE_LINKFLAGS'] = []
|
||||
# previously a leading / was expected for LIB_DIR_NAME
|
||||
# now strip it to ensure expected behavior
|
||||
if env['LIB_DIR_NAME'].startswith(os.path.sep):
|
||||
|
@ -1007,15 +991,16 @@ if not preconfigured:
|
|||
env['MAPNIK_FONTS_DEST'] = os.path.join(env['MAPNIK_LIB_DIR_DEST'],'fonts')
|
||||
|
||||
if env['LINKING'] == 'static':
|
||||
env['MAPNIK_LIB_NAME'] = '${LIBPREFIX}mapnik2${LIBSUFFIX}'
|
||||
env['MAPNIK_LIB_NAME'] = '${LIBPREFIX}mapnik${LIBSUFFIX}'
|
||||
else:
|
||||
env['MAPNIK_LIB_NAME'] = '${SHLIBPREFIX}mapnik2${SHLIBSUFFIX}'
|
||||
env['MAPNIK_LIB_NAME'] = '${SHLIBPREFIX}mapnik${SHLIBSUFFIX}'
|
||||
|
||||
if env['PKG_CONFIG_PATH']:
|
||||
env['ENV']['PKG_CONFIG_PATH'] = os.path.realpath(env['PKG_CONFIG_PATH'])
|
||||
# otherwise this variable == os.environ["PKG_CONFIG_PATH"]
|
||||
if env['PATH_INSERT']:
|
||||
env['ENV']['PATH'] = os.path.realpath(env['PATH_INSERT']) + ':' + env['ENV']['PATH']
|
||||
|
||||
if env['PATH']:
|
||||
env['ENV']['PATH'] = os.path.realpath(env['PATH']) + ':' + env['ENV']['PATH']
|
||||
|
||||
if env['SYSTEM_FONTS']:
|
||||
if not os.path.isdir(env['SYSTEM_FONTS']):
|
||||
|
@ -1072,15 +1057,17 @@ if not preconfigured:
|
|||
env.AppendUnique(CPPPATH = os.path.realpath(inc_path))
|
||||
env.AppendUnique(LIBPATH = os.path.realpath(lib_path))
|
||||
|
||||
conf.parse_config('FREETYPE_CONFIG')
|
||||
|
||||
# check if freetype links to bz2
|
||||
if env['RUNTIME_LINK'] == 'static':
|
||||
temp_env = env.Clone()
|
||||
temp_env['LIBS'] = []
|
||||
temp_env.ParseConfig('%s --libs' % env['FREETYPE_CONFIG'])
|
||||
if 'bz2' in temp_env['LIBS']:
|
||||
env['EXTRA_FREETYPE_LIBS'].append('bz2')
|
||||
if conf.parse_config('FREETYPE_CONFIG'):
|
||||
# check if freetype links to bz2
|
||||
if env['RUNTIME_LINK'] == 'static':
|
||||
temp_env = env.Clone()
|
||||
temp_env['LIBS'] = []
|
||||
try:
|
||||
temp_env.ParseConfig('%s --libs' % env['FREETYPE_CONFIG'])
|
||||
if 'bz2' in temp_env['LIBS']:
|
||||
env['EXTRA_FREETYPE_LIBS'].append('bz2')
|
||||
except OSError,e:
|
||||
pass
|
||||
|
||||
# libxml2 should be optional but is currently not
|
||||
# https://github.com/mapnik/mapnik/issues/913
|
||||
|
@ -1107,14 +1094,14 @@ if not preconfigured:
|
|||
if env['PRIORITIZE_LINKING']:
|
||||
conf.prioritize_paths(silent=False)
|
||||
|
||||
for libinfo in LIBSHEADERS:
|
||||
if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], libinfo[3]):
|
||||
if libinfo[2]:
|
||||
color_print(1,'Could not find required header or shared library for %s' % libinfo[0])
|
||||
env['MISSING_DEPS'].append(libinfo[0])
|
||||
for libname, headers, required, lang in LIBSHEADERS:
|
||||
if not conf.CheckLibWithHeader(libname, headers, lang):
|
||||
if required:
|
||||
color_print(1, 'Could not find required header or shared library for %s' % libname)
|
||||
env['MISSING_DEPS'].append(libname)
|
||||
else:
|
||||
color_print(4,'Could not find optional header or shared library for %s' % libinfo[0])
|
||||
env['SKIPPED_DEPS'].append(libinfo[0])
|
||||
color_print(4, 'Could not find optional header or shared library for %s' % libname)
|
||||
env['SKIPPED_DEPS'].append(libname)
|
||||
|
||||
if env['ICU_LIB_NAME'] not in env['MISSING_DEPS']:
|
||||
if not conf.icu_at_least_four_two():
|
||||
|
@ -1128,18 +1115,14 @@ if not preconfigured:
|
|||
|
||||
conf.FindBoost(BOOST_SEARCH_PREFIXES,thread_flag)
|
||||
|
||||
# boost system is used in boost 1.35 and greater
|
||||
env['HAS_BOOST_SYSTEM'] = False
|
||||
boost_lib_version_from_header = conf.GetBoostLibVersion()
|
||||
if boost_lib_version_from_header:
|
||||
boost_version_from_header = int(boost_lib_version_from_header.split('_')[1])
|
||||
if boost_version_from_header >= 35:
|
||||
env['HAS_BOOST_SYSTEM'] = True
|
||||
|
||||
|
||||
# The other required boost headers.
|
||||
BOOST_LIBSHEADERS = [
|
||||
['system', 'boost/system/system_error.hpp', env['HAS_BOOST_SYSTEM']],
|
||||
['system', 'boost/system/system_error.hpp', True],
|
||||
['filesystem', 'boost/filesystem/operations.hpp', True],
|
||||
['regex', 'boost/regex.hpp', True],
|
||||
['program_options', 'boost/program_options.hpp', False]
|
||||
|
@ -1222,12 +1205,30 @@ if not preconfigured:
|
|||
if not conf.CheckLibWithHeader(details['lib'], details['inc'], details['lang']):
|
||||
env.Replace(**backup)
|
||||
env['SKIPPED_DEPS'].append(details['lib'])
|
||||
#if plugin == 'sqlite':
|
||||
# if not conf.sqlite_has_rtree():
|
||||
# env.Replace(**backup)
|
||||
# if details['lib'] in env['LIBS']:
|
||||
# env['LIBS'].remove(details['lib'])
|
||||
# env['SKIPPED_DEPS'].append('sqlite_rtree')
|
||||
if plugin == 'sqlite':
|
||||
sqlite_backup = env.Clone().Dictionary()
|
||||
|
||||
# if statically linking, on linux we likely
|
||||
# need to link sqlite to pthreads and dl
|
||||
if env['RUNTIME_LINK'] == 'static':
|
||||
if conf.CheckPKGConfig('0.15.0') and conf.CheckPKG('sqlite3'):
|
||||
sqlite_env = env.Clone()
|
||||
try:
|
||||
sqlite_env.ParseConfig('pkg-config --static --libs sqlite3')
|
||||
for lib in sqlite_env['LIBS']:
|
||||
if not lib in env['LIBS']:
|
||||
env["SQLITE_LINKFLAGS"].append(lib)
|
||||
env.Append(LIBS=lib)
|
||||
except OSError,e:
|
||||
pass
|
||||
|
||||
if not conf.sqlite_has_rtree():
|
||||
env.Replace(**sqlite_backup)
|
||||
if details['lib'] in env['LIBS']:
|
||||
env['LIBS'].remove(details['lib'])
|
||||
env['SKIPPED_DEPS'].append('sqlite_rtree')
|
||||
else:
|
||||
env.Replace(**sqlite_backup)
|
||||
|
||||
elif details['lib'] and details['inc']:
|
||||
if not conf.CheckLibWithHeader(details['lib'], details['inc'], details['lang']):
|
||||
|
@ -1239,10 +1240,10 @@ if not preconfigured:
|
|||
env.PrependUnique(CPPPATH = '#', delete_existing=True)
|
||||
env.PrependUnique(LIBPATH = '#src', delete_existing=True)
|
||||
|
||||
#if env['PGSQL2SQLITE']:
|
||||
# if not conf.sqlite_has_rtree():
|
||||
# env['SKIPPED_DEPS'].append('pgsql2sqlite_rtree')
|
||||
# env['PGSQL2SQLITE'] = False
|
||||
if env['PGSQL2SQLITE']:
|
||||
if not conf.sqlite_has_rtree():
|
||||
env['SKIPPED_DEPS'].append('pgsql2sqlite_rtree')
|
||||
env['PGSQL2SQLITE'] = False
|
||||
|
||||
# Decide which libagg to use
|
||||
# if we are using internal agg, then prepend to make sure
|
||||
|
@ -1300,21 +1301,29 @@ if not preconfigured:
|
|||
env['HAS_CAIRO'] = False
|
||||
env['SKIPPED_DEPS'].append('cairomm-version')
|
||||
else:
|
||||
print 'Checking for cairo/cairomm lib and include paths... ',
|
||||
cmd = 'pkg-config --libs --cflags cairomm-1.0'
|
||||
if env['RUNTIME_LINK'] == 'static':
|
||||
cmd += ' --static'
|
||||
cairo_env = env.Clone()
|
||||
cairo_env.ParseConfig(cmd)
|
||||
for lib in cairo_env['LIBS']:
|
||||
if not lib in env['LIBS']:
|
||||
env["CAIROMM_LINKFLAGS"].append(lib)
|
||||
for lpath in cairo_env['LIBPATH']:
|
||||
if not lpath in env['LIBPATH']:
|
||||
env["CAIROMM_LIBPATHS"].append(lpath)
|
||||
for inc in cairo_env['CPPPATH']:
|
||||
if not inc in env['CPPPATH']:
|
||||
env["CAIROMM_CPPPATHS"].append(inc)
|
||||
env['HAS_CAIRO'] = True
|
||||
try:
|
||||
cairo_env.ParseConfig(cmd)
|
||||
for lib in cairo_env['LIBS']:
|
||||
if not lib in env['LIBS']:
|
||||
env["CAIROMM_LINKFLAGS"].append(lib)
|
||||
for lpath in cairo_env['LIBPATH']:
|
||||
if not lpath in env['LIBPATH']:
|
||||
env["CAIROMM_LIBPATHS"].append(lpath)
|
||||
for inc in cairo_env['CPPPATH']:
|
||||
if not inc in env['CPPPATH']:
|
||||
env["CAIROMM_CPPPATHS"].append(inc)
|
||||
env['HAS_CAIRO'] = True
|
||||
print 'yes'
|
||||
except OSError,e:
|
||||
color_print(1,'no')
|
||||
env['SKIPPED_DEPS'].append('cairo')
|
||||
env['SKIPPED_DEPS'].append('cairomm')
|
||||
color_print(1,'pkg-config reported: %s' % e)
|
||||
|
||||
else:
|
||||
color_print(4,'Not building with cairo support, pass CAIRO=True to enable')
|
||||
|
@ -1390,13 +1399,6 @@ if not preconfigured:
|
|||
else :
|
||||
common_cxx_flags = '-D%s ' % env['PLATFORM'].upper()
|
||||
|
||||
svn_version = call('svnversion')
|
||||
if not svn_version == 'exported':
|
||||
pattern = r'(\d+)(.*)'
|
||||
try:
|
||||
env['SVN_REVISION'] = re.match(pattern,svn_version).groups()[0]
|
||||
except: pass
|
||||
|
||||
# Mac OSX (Darwin) special settings
|
||||
if env['PLATFORM'] == 'Darwin':
|
||||
pthread = ''
|
||||
|
@ -1414,6 +1416,7 @@ if not preconfigured:
|
|||
debug_flags = '-g -DDEBUG -DMAPNIK_DEBUG'
|
||||
ndebug_flags = '-DNDEBUG'
|
||||
|
||||
|
||||
# Customizing the C++ compiler flags depending on:
|
||||
# (1) the C++ compiler used; and
|
||||
# (2) whether debug binaries are requested.
|
||||
|
@ -1428,7 +1431,9 @@ if not preconfigured:
|
|||
if env['DEBUG']:
|
||||
env.Append(CXXFLAGS = gcc_cxx_flags + '-O0 -fno-inline %s' % debug_flags)
|
||||
else:
|
||||
env.Append(CXXFLAGS = gcc_cxx_flags + '-O%s -finline-functions -Wno-inline %s' % (env['OPTIMIZATION'],ndebug_flags))
|
||||
env.Append(CXXFLAGS = gcc_cxx_flags + '-O%s -finline-functions -Wno-inline -Wno-parentheses -Wno-char-subscripts %s' % (env['OPTIMIZATION'],ndebug_flags))
|
||||
if env['DEBUG_UNDEFINED']:
|
||||
env.Append(CXXFLAGS = '-fcatch-undefined-behavior') #-ftrapv -fwrapv
|
||||
|
||||
if 'python' in env['BINDINGS']:
|
||||
if not os.access(env['PYTHON'], os.X_OK):
|
||||
|
@ -1496,7 +1501,7 @@ if not preconfigured:
|
|||
if not conf.CheckHeader(header='Python.h',language='C'):
|
||||
color_print(1,'Could not find required header files for the Python language (version %s)' % env['PYTHON_VERSION'])
|
||||
env.Replace(**backup)
|
||||
env['MISSING_DEPS'].append('python %s development headers' % env['PYTHON_VERSION'])
|
||||
Exit(1)
|
||||
else:
|
||||
env.Replace(**backup)
|
||||
|
||||
|
@ -1504,6 +1509,15 @@ if not preconfigured:
|
|||
color_print(1,"Python version 2.2 or greater required")
|
||||
Exit(1)
|
||||
|
||||
if env['BOOST_PYTHON_LIB']:
|
||||
env.Append(LIBS='python%s' % env['PYTHON_VERSION'])
|
||||
if not conf.CheckLibWithHeader(libs=[env['BOOST_PYTHON_LIB']], header='boost/python/detail/config.hpp', language='C++'):
|
||||
color_print(1, 'Could not find library %s for boost python' % env['BOOST_PYTHON_LIB'])
|
||||
env.Replace(**backup)
|
||||
Exit(1)
|
||||
else:
|
||||
env.Replace(**backup)
|
||||
|
||||
color_print(4,'Bindings Python version... %s' % env['PYTHON_VERSION'])
|
||||
color_print(4,'Python %s prefix... %s' % (env['PYTHON_VERSION'], env['PYTHON_SYS_PREFIX']))
|
||||
color_print(4,'Python bindings will install in... %s' % os.path.normpath(env['PYTHON_INSTALL_LOCATION']))
|
||||
|
@ -1543,7 +1557,7 @@ if not preconfigured:
|
|||
except: pass
|
||||
|
||||
if 'configure' in command_line_args:
|
||||
color_print(4,'\n*Configure complete*\nNow run "python scons/scons.py" to build or "python scons/scons.py install" to install')
|
||||
color_print(4,'\nConfigure completed: run `make` to build or `make install`')
|
||||
if not HELP_REQUESTED:
|
||||
Exit(0)
|
||||
|
||||
|
@ -1562,17 +1576,57 @@ if not HELP_REQUESTED:
|
|||
env['ENV']['PKG_CONFIG_PATH'] = os.path.realpath(env['PKG_CONFIG_PATH'])
|
||||
# otherwise this variable == os.environ["PKG_CONFIG_PATH"]
|
||||
|
||||
if env['PATH_INSERT']:
|
||||
env['ENV']['PATH'] = os.path.realpath(env['PATH_INSERT']) + ':' + env['ENV']['PATH']
|
||||
if env['PATH']:
|
||||
env['ENV']['PATH'] = os.path.realpath(env['PATH']) + ':' + env['ENV']['PATH']
|
||||
|
||||
if env['PATH_REMOVE']:
|
||||
p = env['PATH_REMOVE']
|
||||
if p in env['ENV']['PATH']:
|
||||
env['ENV']['PATH'].replace(p,'')
|
||||
def rm_path(set):
|
||||
for i in env[set]:
|
||||
if p in i:
|
||||
env[set].remove(i)
|
||||
rm_path('LIBPATH')
|
||||
rm_path('CPPPATH')
|
||||
rm_path('CXXFLAGS')
|
||||
rm_path('CAIROMM_LIBPATHS')
|
||||
rm_path('CAIROMM_CPPPATHS')
|
||||
|
||||
if env['PATH_REPLACE']:
|
||||
searches,replace = env['PATH_REPLACE'].split(':')
|
||||
for search in searches.split(','):
|
||||
if search in env['ENV']['PATH']:
|
||||
env['ENV']['PATH'] = os.path.abspath(env['ENV']['PATH'].replace(search,replace))
|
||||
def replace_path(set,s,r):
|
||||
idx = 0
|
||||
for i in env[set]:
|
||||
if s in i:
|
||||
env[set][idx] = os.path.abspath(env[set][idx].replace(s,r))
|
||||
idx +=1
|
||||
replace_path('LIBPATH',search,replace)
|
||||
replace_path('CPPPATH',search,replace)
|
||||
replace_path('CXXFLAGS',search,replace)
|
||||
replace_path('CAIROMM_LIBPATHS',search,replace)
|
||||
replace_path('CAIROMM_CPPPATHS',search,replace)
|
||||
|
||||
# export env so it is available in build.py files
|
||||
Export('env')
|
||||
|
||||
plugin_base = env.Clone()
|
||||
# for this to work you need:
|
||||
# if __GNUC__ >= 4
|
||||
# define MAPNIK_EXP __attribute__ ((visibility ("default")))
|
||||
#plugin_base.Append(CXXFLAGS='-fvisibility=hidden')
|
||||
#plugin_base.Append(CXXFLAGS='-fvisibility-inlines-hidden')
|
||||
|
||||
Export('plugin_base')
|
||||
|
||||
# clear the '_CPPDEFFLAGS' variable
|
||||
# for unknown reasons this variable puts -DNone
|
||||
# in the g++ args prompting unnecessary recompiles
|
||||
env['_CPPDEFFLAGS'] = None
|
||||
plugin_base['_CPPDEFFLAGS'] = None
|
||||
|
||||
|
||||
if env['FAST']:
|
||||
|
@ -1658,7 +1712,7 @@ if not HELP_REQUESTED:
|
|||
# Install the python speed testing scripts if python bindings will be available
|
||||
SConscript('utils/performance/build.py')
|
||||
|
||||
# Install the mapnik2 upgrade script
|
||||
# Install the mapnik upgrade script
|
||||
SConscript('utils/upgrade_map_xml/build.py')
|
||||
|
||||
# Configure fonts and if requested install the bundled DejaVu fonts
|
||||
|
|
|
@ -40,21 +40,15 @@ def is_py3():
|
|||
|
||||
|
||||
prefix = env['PREFIX']
|
||||
target_path = os.path.normpath(env['PYTHON_INSTALL_LOCATION'] + os.path.sep + 'mapnik2')
|
||||
target_path = os.path.normpath(env['PYTHON_INSTALL_LOCATION'] + os.path.sep + 'mapnik')
|
||||
|
||||
libraries = ['mapnik2','png']
|
||||
libraries = ['mapnik','png']
|
||||
|
||||
if env['JPEG']:
|
||||
libraries.append('jpeg')
|
||||
|
||||
if env['BOOST_PYTHON_LIB']:
|
||||
if os.path.sep in env['BOOST_PYTHON_LIB']:
|
||||
pylib_dir = os.path.dirname(env['BOOST_PYTHON_LIB'])
|
||||
env.Prepend(LIBPATH = pylib_dir)
|
||||
pylib_name = os.path.splitext(os.path.basename(env['BOOST_PYTHON_LIB']))[0].replace('lib','',1)
|
||||
libraries.append(pylib_name)
|
||||
else:
|
||||
libraries.append(env['BOOST_PYTHON_LIB'].replace('lib','',1))
|
||||
libraries.append(env['BOOST_PYTHON_LIB'])
|
||||
else:
|
||||
if is_py3():
|
||||
libraries.append('boost_python3%s' % env['BOOST_APPEND'])
|
||||
|
@ -157,6 +151,10 @@ if 'install' in COMMAND_LINE_TARGETS:
|
|||
init_files.remove('mapnik/paths.py')
|
||||
init_module = env.Install(target_path, init_files)
|
||||
env.Alias(target='install', source=init_module)
|
||||
# install mapnik2 module which redirects to mapnik and issues DeprecatedWarning
|
||||
path = os.path.normpath(env['PYTHON_INSTALL_LOCATION'] + os.path.sep + 'mapnik2')
|
||||
init_mapnik2 = env.Install(path, 'mapnik2/__init__.py')
|
||||
env.Alias(target='install', source=init_mapnik2)
|
||||
|
||||
# fix perms and install the custom generated 'paths.py'
|
||||
if 'install' in COMMAND_LINE_TARGETS:
|
||||
|
@ -170,17 +168,10 @@ if 'install' in COMMAND_LINE_TARGETS:
|
|||
Chmod("$TARGET", 0644),
|
||||
])
|
||||
|
||||
# install the ogcserver module code
|
||||
if 'install' in COMMAND_LINE_TARGETS:
|
||||
ogcserver_files = glob.glob('mapnik/ogcserver/*.py')
|
||||
ogcserver_module = env.Install(target_path + '/ogcserver', ogcserver_files)
|
||||
env.Alias(target='install', source=ogcserver_module)
|
||||
|
||||
|
||||
# install the shared object beside the module directory
|
||||
sources = glob.glob('*.cpp')
|
||||
|
||||
|
||||
py_env = env.Clone()
|
||||
py_env.Append(CPPPATH = env['PYTHON_INCLUDES'])
|
||||
|
||||
|
@ -194,13 +185,7 @@ if env['HAS_PYCAIRO']:
|
|||
py_env.ParseConfig('pkg-config --cflags pycairo')
|
||||
py_env.Append(CXXFLAGS = '-DHAVE_PYCAIRO')
|
||||
|
||||
if env['SVN_REVISION']:
|
||||
sources.remove('mapnik_python.cpp')
|
||||
env2 = py_env.Clone()
|
||||
env2.Append(CXXFLAGS='-DSVN_REVISION=%s' % env['SVN_REVISION'])
|
||||
sources.insert(0,env2.SharedObject('mapnik_python.cpp'))
|
||||
|
||||
_mapnik = py_env.LoadableModule('mapnik/_mapnik2', sources, LIBS=libraries, LDMODULEPREFIX='', LDMODULESUFFIX='.so',LINKFLAGS=linkflags)
|
||||
_mapnik = py_env.LoadableModule('mapnik/_mapnik', sources, LIBS=libraries, LDMODULEPREFIX='', LDMODULESUFFIX='.so',LINKFLAGS=linkflags)
|
||||
|
||||
Depends(_mapnik, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ import os
|
|||
import sys
|
||||
import warnings
|
||||
|
||||
from _mapnik2 import *
|
||||
from _mapnik import *
|
||||
from paths import inputpluginspath, fontscollectionpath
|
||||
|
||||
import printing
|
||||
|
@ -410,6 +410,13 @@ def Raster(**keywords):
|
|||
|
||||
Optional keyword arguments:
|
||||
base -- path prefix (default None)
|
||||
multi -- whether the image is in tiles on disk (default False)
|
||||
|
||||
Multi-tiled keyword arguments:
|
||||
x_width -- virtual image number of tiles in X direction (required)
|
||||
y_width -- virtual image number of tiles in Y direction (required)
|
||||
tile_size -- if an image is in tiles, how large are the tiles (default 256)
|
||||
tile_stride -- if an image is in tiles, what's the increment between rows/cols (default 1)
|
||||
|
||||
>>> from mapnik import Raster, Layer
|
||||
>>> raster = Raster(base='/home/mapnik/data',file='elevation.tif',lox=-122.8,loy=48.5,hix=-122.7,hiy=48.6)
|
||||
|
@ -478,10 +485,11 @@ def Ogr(**keywords):
|
|||
|
||||
Required keyword arguments:
|
||||
file -- path to OGR supported dataset
|
||||
layer -- name of layer to use within datasource (optional if layer_by_index is used)
|
||||
layer -- name of layer to use within datasource (optional if layer_by_index or layer_by_sql is used)
|
||||
|
||||
Optional keyword arguments:
|
||||
layer_by_index -- choose layer by index number instead of by layer name.
|
||||
layer_by_index -- choose layer by index number instead of by layer name or sql.
|
||||
layer_by_sql -- choose layer by sql query number instead of by layer name or index.
|
||||
base -- path prefix (default None)
|
||||
encoding -- file encoding (default 'utf-8')
|
||||
multiple_geometries -- boolean, direct the Mapnik wkb reader to interpret as multigeometries (default False)
|
||||
|
@ -710,7 +718,6 @@ __all__ = [
|
|||
# version and environment
|
||||
'mapnik_version_string',
|
||||
'mapnik_version',
|
||||
'mapnik_svn_revision',
|
||||
'has_cairo',
|
||||
'has_pycairo',
|
||||
# factory methods
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""Interface for registering map styles and layers for availability in WMS Requests."""
|
||||
|
||||
from common import Version, copy_style, copy_layer
|
||||
from exceptions import OGCException, ServerConfigurationError
|
||||
from wms111 import ServiceHandler as ServiceHandler111
|
||||
from wms130 import ServiceHandler as ServiceHandler130
|
||||
from mapnik2 import Style, Map, load_map
|
||||
import re
|
||||
import sys
|
||||
|
||||
def ServiceHandlerFactory(conf, mapfactory, onlineresource, version):
|
||||
|
||||
if not version:
|
||||
version = Version('1.3.0')
|
||||
else:
|
||||
version = Version(version)
|
||||
if version >= '1.3.0':
|
||||
return ServiceHandler130(conf, mapfactory, onlineresource)
|
||||
else:
|
||||
return ServiceHandler111(conf, mapfactory, onlineresource)
|
||||
|
||||
class BaseWMSFactory:
|
||||
def __init__(self):
|
||||
self.layers = {}
|
||||
self.ordered_layers = []
|
||||
self.styles = {}
|
||||
self.aggregatestyles = {}
|
||||
|
||||
def loadXML(self, xmlfile, strict=False):
|
||||
tmp_map = Map(0,0)
|
||||
load_map (tmp_map, xmlfile, strict)
|
||||
for lyr in tmp_map.layers:
|
||||
style_count = len(lyr.styles)
|
||||
if style_count == 0:
|
||||
raise ServerConfigurationError("Cannot register Layer '%s' without a style" % lyr.name)
|
||||
elif style_count == 1:
|
||||
style_obj = tmp_map.find_style(lyr.styles[0])
|
||||
style_obj = copy_style(style_obj)
|
||||
style_name = lyr.styles[0]
|
||||
if style_name not in self.aggregatestyles.keys() and style_name not in self.styles.keys():
|
||||
self.register_style(style_name, style_obj)
|
||||
self.register_layer(copy_layer(lyr), style_name, extrastyles=(style_name,))
|
||||
elif style_count > 1:
|
||||
for style_name in lyr.styles:
|
||||
style_obj = tmp_map.find_style(style_name)
|
||||
style_obj = copy_style(style_obj)
|
||||
if style_name not in self.aggregatestyles.keys() and style_name not in self.styles.keys():
|
||||
self.register_style(style_name, style_obj)
|
||||
aggregates = tuple([sty for sty in lyr.styles])
|
||||
aggregates_name = '%s_aggregates' % lyr.name
|
||||
self.register_aggregate_style(aggregates_name,aggregates)
|
||||
self.register_layer(copy_layer(lyr), aggregates_name, extrastyles=aggregates)
|
||||
|
||||
def register_layer(self, layer, defaultstyle, extrastyles=()):
|
||||
layername = layer.name
|
||||
if not layername:
|
||||
raise ServerConfigurationError('Attempted to register an unnamed layer.')
|
||||
if not re.match('^\+init=epsg:\d+$', layer.srs) and not re.match('^\+proj=.*$', layer.srs):
|
||||
raise ServerConfigurationError('Attempted to register a layer without an epsg projection defined.')
|
||||
if defaultstyle not in self.styles.keys() + self.aggregatestyles.keys():
|
||||
raise ServerConfigurationError('Attempted to register a layer with an non-existent default style.')
|
||||
layer.wmsdefaultstyle = defaultstyle
|
||||
if isinstance(extrastyles, tuple):
|
||||
for stylename in extrastyles:
|
||||
if type(stylename) == type(''):
|
||||
if stylename not in self.styles.keys() + self.aggregatestyles.keys():
|
||||
raise ServerConfigurationError('Attempted to register a layer with an non-existent extra style.')
|
||||
else:
|
||||
ServerConfigurationError('Attempted to register a layer with an invalid extra style name.')
|
||||
layer.wmsextrastyles = extrastyles
|
||||
else:
|
||||
raise ServerConfigurationError('Layer "%s" was passed an invalid list of extra styles. List must be a tuple of strings.' % layername)
|
||||
self.ordered_layers.append(layer)
|
||||
self.layers[layername] = layer
|
||||
|
||||
def register_style(self, name, style):
|
||||
if not name:
|
||||
raise ServerConfigurationError('Attempted to register a style without providing a name.')
|
||||
if name in self.aggregatestyles.keys() or name in self.styles.keys():
|
||||
raise ServerConfigurationError("Attempted to register a style with a name already in use: '%s'" % name)
|
||||
if not isinstance(style, Style):
|
||||
raise ServerConfigurationError('Bad style object passed to register_style() for style "%s".' % name)
|
||||
self.styles[name] = style
|
||||
|
||||
def register_aggregate_style(self, name, stylenames):
|
||||
if not name:
|
||||
raise ServerConfigurationError('Attempted to register an aggregate style without providing a name.')
|
||||
if name in self.aggregatestyles.keys() or name in self.styles.keys():
|
||||
raise ServerConfigurationError('Attempted to register an aggregate style with a name already in use.')
|
||||
self.aggregatestyles[name] = []
|
||||
for stylename in stylenames:
|
||||
if stylename not in self.styles.keys():
|
||||
raise ServerConfigurationError('Attempted to register an aggregate style containing a style that does not exist.')
|
||||
self.aggregatestyles[name].append(stylename)
|
||||
|
||||
def finalize(self):
|
||||
if len(self.layers) == 0:
|
||||
raise ServerConfigurationError('No layers defined!')
|
||||
if len(self.styles) == 0:
|
||||
raise ServerConfigurationError('No styles defined!')
|
||||
for layer in self.layers.values():
|
||||
for style in list(layer.styles) + list(layer.wmsextrastyles):
|
||||
if style not in self.styles.keys() + self.aggregatestyles.keys():
|
||||
raise ServerConfigurationError('Layer "%s" refers to undefined style "%s".' % (layer.name, style))
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""Mapnik OGC WMS Server."""
|
||||
|
||||
import os
|
||||
import warnings
|
||||
|
||||
warnings.warn("ogcserver module development has moved to https://github.com/mapnik/OGCServer.\n This code will function fine with this version, but will be removed in Mapnik 2.1.0. Disable this warning by editing this file: %s" % os.path.realpath(__file__), DeprecationWarning, 2)
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""CGI/FastCGI handler for Mapnik OGC WMS Server.
|
||||
|
||||
Requires 'jon' module.
|
||||
|
||||
"""
|
||||
|
||||
from os import environ
|
||||
from tempfile import gettempdir
|
||||
environ['PYTHON_EGG_CACHE'] = gettempdir()
|
||||
|
||||
import sys
|
||||
from jon import cgi
|
||||
from exceptions import OGCException, ServerConfigurationError
|
||||
from wms111 import ExceptionHandler as ExceptionHandler111
|
||||
from wms130 import ExceptionHandler as ExceptionHandler130
|
||||
from configparser import SafeConfigParser
|
||||
from common import Version
|
||||
|
||||
class Handler(cgi.DebugHandler):
|
||||
|
||||
def __init__(self):
|
||||
conf = SafeConfigParser()
|
||||
conf.readfp(open(self.configpath))
|
||||
self.conf = conf
|
||||
if not conf.has_option_with_value('server', 'module'):
|
||||
raise ServerConfigurationError('The factory module is not defined in the configuration file.')
|
||||
try:
|
||||
mapfactorymodule = __import__(conf.get('server', 'module'))
|
||||
except ImportError:
|
||||
raise ServerConfigurationError('The factory module could not be loaded.')
|
||||
if hasattr(mapfactorymodule, 'WMSFactory'):
|
||||
self.mapfactory = getattr(mapfactorymodule, 'WMSFactory')()
|
||||
else:
|
||||
raise ServerConfigurationError('The factory module does not have a WMSFactory class.')
|
||||
if conf.has_option('server', 'debug'):
|
||||
self.debug = int(conf.get('server', 'debug'))
|
||||
else:
|
||||
self.debug = 0
|
||||
|
||||
def process(self, req):
|
||||
reqparams = lowerparams(req.params)
|
||||
onlineresource = 'http://%s:%s%s?' % (req.environ['SERVER_NAME'], req.environ['SERVER_PORT'], req.environ['SCRIPT_NAME'])
|
||||
if not reqparams.has_key('request'):
|
||||
raise OGCException('Missing request parameter.')
|
||||
request = reqparams['request']
|
||||
del reqparams['request']
|
||||
if request == 'GetCapabilities' and not reqparams.has_key('service'):
|
||||
raise OGCException('Missing service parameter.')
|
||||
if request in ['GetMap', 'GetFeatureInfo']:
|
||||
service = 'WMS'
|
||||
else:
|
||||
service = reqparams['service']
|
||||
if reqparams.has_key('service'):
|
||||
del reqparams['service']
|
||||
try:
|
||||
mapnikmodule = __import__('mapnik2.ogcserver.' + service)
|
||||
except:
|
||||
raise OGCException('Unsupported service "%s".' % service)
|
||||
ServiceHandlerFactory = getattr(mapnikmodule.ogcserver, service).ServiceHandlerFactory
|
||||
servicehandler = ServiceHandlerFactory(self.conf, self.mapfactory, onlineresource, reqparams.get('version', None))
|
||||
if reqparams.has_key('version'):
|
||||
del reqparams['version']
|
||||
if request not in servicehandler.SERVICE_PARAMS.keys():
|
||||
raise OGCException('Operation "%s" not supported.' % request, 'OperationNotSupported')
|
||||
ogcparams = servicehandler.processParameters(request, reqparams)
|
||||
try:
|
||||
requesthandler = getattr(servicehandler, request)
|
||||
except:
|
||||
raise OGCException('Operation "%s" not supported.' % request, 'OperationNotSupported')
|
||||
response = requesthandler(ogcparams)
|
||||
req.set_header('Content-Type', response.content_type)
|
||||
req.set_header('Content-Length', str(len(response.content)))
|
||||
req.write(response.content)
|
||||
|
||||
def traceback(self, req):
|
||||
reqparams = lowerparams(req.params)
|
||||
version = reqparams.get('version', None)
|
||||
if not version:
|
||||
version = Version('1.3.0')
|
||||
else:
|
||||
version = Version(version)
|
||||
if version >= '1.3.0':
|
||||
eh = ExceptionHandler130(self.debug)
|
||||
else:
|
||||
eh = ExceptionHandler111(self.debug)
|
||||
response = eh.getresponse(reqparams)
|
||||
req.set_header('Content-Type', response.content_type)
|
||||
req.set_header('Content-Length', str(len(response.content)))
|
||||
req.write(response.content)
|
||||
|
||||
def lowerparams(params):
|
||||
reqparams = {}
|
||||
for key, value in params.items():
|
||||
reqparams[key.lower()] = value
|
||||
return reqparams
|
|
@ -1,539 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""Core OGCServer classes and functions."""
|
||||
|
||||
from exceptions import OGCException, ServerConfigurationError
|
||||
from mapnik2 import Map, Color, Box2d, render, Image, Layer, Style, Projection as MapnikProjection, Coord
|
||||
from PIL.Image import new
|
||||
from PIL.ImageDraw import Draw
|
||||
from StringIO import StringIO
|
||||
from copy import deepcopy
|
||||
from traceback import format_exception, format_exception_only
|
||||
from sys import exc_info
|
||||
import re
|
||||
import sys
|
||||
|
||||
try:
|
||||
from lxml import etree as ElementTree
|
||||
except ImportError:
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
except ImportError:
|
||||
import elementtree.ElementTree as ElementTree
|
||||
|
||||
# from elementtree import ElementTree
|
||||
# ElementTree._namespace_map.update({'http://www.opengis.net/wms': 'wms',
|
||||
# 'http://www.opengis.net/ogc': 'ogc',
|
||||
# 'http://www.w3.org/1999/xlink': 'xlink',
|
||||
# 'http://www.w3.org/2001/XMLSchema-instance': 'xsi'
|
||||
# })
|
||||
|
||||
PIL_TYPE_MAPPING = {'image/jpeg': 'jpeg', 'image/png': 'png'}
|
||||
|
||||
class ParameterDefinition:
|
||||
|
||||
def __init__(self, mandatory, cast, default=None, allowedvalues=None, fallback=False):
|
||||
""" An OGC request parameter definition. Used to describe a
|
||||
parameter's characteristics.
|
||||
|
||||
@param mandatory: Is this parameter required by the request?
|
||||
@type mandatory: Boolean.
|
||||
|
||||
@param default: Default value to use if one is not provided
|
||||
and the parameter is optional.
|
||||
@type default: None or any valid value.
|
||||
|
||||
@param allowedvalues: A list of allowed values for the parameter.
|
||||
If a value is provided that is not in this
|
||||
list, an error is raised.
|
||||
@type allowedvalues: A python tuple of values.
|
||||
|
||||
@param fallback: Whether the value of the parameter should fall
|
||||
back to the default should an illegal value be
|
||||
provided.
|
||||
@type fallback: Boolean.
|
||||
|
||||
@return: A L{ParameterDefinition} instance.
|
||||
"""
|
||||
if mandatory not in [True, False]:
|
||||
raise ServerConfigurationError("Bad value for 'mandatory' parameter, must be True or False.")
|
||||
self.mandatory = mandatory
|
||||
if not callable(cast):
|
||||
raise ServerConfigurationError('Cast parameter definition must be callable.')
|
||||
self.cast = cast
|
||||
self.default = default
|
||||
if allowedvalues and type(allowedvalues) != type(()):
|
||||
raise ServerConfigurationError("Bad value for 'allowedvalues' parameter, must be a tuple.")
|
||||
self.allowedvalues = allowedvalues
|
||||
if fallback not in [True, False]:
|
||||
raise ServerConfigurationError("Bad value for 'fallback' parameter, must be True or False.")
|
||||
self.fallback = fallback
|
||||
|
||||
class BaseServiceHandler:
|
||||
|
||||
CONF_CONTACT_PERSON_PRIMARY = [
|
||||
['contactperson', 'ContactPerson', str],
|
||||
['contactorganization', 'ContactOrganization', str]
|
||||
]
|
||||
|
||||
CONF_CONTACT_ADDRESS = [
|
||||
['addresstype', 'AddressType', str],
|
||||
['address', 'Address', str],
|
||||
['city', 'City', str],
|
||||
['stateorprovince', 'StateOrProvince', str],
|
||||
['postcode', 'PostCode', str],
|
||||
['country', 'Country', str]
|
||||
]
|
||||
|
||||
CONF_CONTACT = [
|
||||
['contactposition', 'ContactPosition', str],
|
||||
['contactvoicetelephone', 'ContactVoiceTelephone', str],
|
||||
['contactelectronicmailaddress', 'ContactElectronicMailAddress', str]
|
||||
]
|
||||
|
||||
def processParameters(self, requestname, params):
|
||||
finalparams = {}
|
||||
for paramname, paramdef in self.SERVICE_PARAMS[requestname].items():
|
||||
if paramname not in params.keys() and paramdef.mandatory:
|
||||
raise OGCException('Mandatory parameter "%s" missing from request.' % paramname)
|
||||
elif paramname in params.keys():
|
||||
try:
|
||||
params[paramname] = paramdef.cast(params[paramname])
|
||||
except OGCException:
|
||||
raise
|
||||
except:
|
||||
raise OGCException('Invalid value "%s" for parameter "%s".' % (params[paramname], paramname))
|
||||
if paramdef.allowedvalues and params[paramname] not in paramdef.allowedvalues:
|
||||
if not paramdef.fallback:
|
||||
raise OGCException('Parameter "%s" has an illegal value.' % paramname)
|
||||
else:
|
||||
finalparams[paramname] = paramdef.default
|
||||
else:
|
||||
finalparams[paramname] = params[paramname]
|
||||
elif not paramdef.mandatory and paramdef.default:
|
||||
finalparams[paramname] = paramdef.default
|
||||
return finalparams
|
||||
|
||||
def processServiceCapabilities(self, capetree):
|
||||
if len(self.conf.items('service')) > 0:
|
||||
servicee = capetree.find('{http://www.opengis.net/wms}Service')
|
||||
for item in self.CONF_SERVICE:
|
||||
if self.conf.has_option_with_value('service', item[0]):
|
||||
value = self.conf.get('service', item[0]).strip()
|
||||
try:
|
||||
item[2](value)
|
||||
except:
|
||||
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
|
||||
if item[0] == 'onlineresource':
|
||||
element = ElementTree.Element('%s' % item[1])
|
||||
servicee.append(element)
|
||||
element.set('{http://www.w3.org/1999/xlink}href', value)
|
||||
element.set('{http://www.w3.org/1999/xlink}type', 'simple')
|
||||
elif item[0] == 'keywordlist':
|
||||
element = ElementTree.Element('%s' % item[1])
|
||||
servicee.append(element)
|
||||
keywords = value.split(',')
|
||||
keywords = map(str.strip, keywords)
|
||||
for keyword in keywords:
|
||||
kelement = ElementTree.Element('Keyword')
|
||||
kelement.text = keyword
|
||||
element.append(kelement)
|
||||
else:
|
||||
element = ElementTree.Element('%s' % item[1])
|
||||
element.text = value
|
||||
servicee.append(element)
|
||||
if len(self.conf.items_with_value('contact')) > 0:
|
||||
element = ElementTree.Element('ContactInformation')
|
||||
servicee.append(element)
|
||||
for item in self.CONF_CONTACT:
|
||||
if self.conf.has_option_with_value('contact', item[0]):
|
||||
value = self.conf.get('contact', item[0]).strip()
|
||||
try:
|
||||
item[2](value)
|
||||
except:
|
||||
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
|
||||
celement = ElementTree.Element('%s' % item[1])
|
||||
celement.text = value
|
||||
element.append(celement)
|
||||
for item in self.CONF_CONTACT_PERSON_PRIMARY + self.CONF_CONTACT_ADDRESS:
|
||||
if item in self.CONF_CONTACT_PERSON_PRIMARY:
|
||||
tagname = 'ContactPersonPrimary'
|
||||
else:
|
||||
tagname = 'ContactAddress'
|
||||
if self.conf.has_option_with_value('contact', item[0]):
|
||||
if element.find(tagname) == None:
|
||||
subelement = ElementTree.Element(tagname)
|
||||
element.append(subelement)
|
||||
value = self.conf.get('contact', item[0]).strip()
|
||||
try:
|
||||
item[2](value)
|
||||
except:
|
||||
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
|
||||
celement = ElementTree.Element('%s' % item[1])
|
||||
celement.text = value
|
||||
subelement.append(celement)
|
||||
|
||||
class Response:
|
||||
|
||||
def __init__(self, content_type, content):
|
||||
self.content_type = content_type
|
||||
self.content = content
|
||||
|
||||
class Version:
|
||||
|
||||
def __init__(self, version):
|
||||
version = version.split('.')
|
||||
if len(version) != 3:
|
||||
raise OGCException('Badly formatted version number.')
|
||||
try:
|
||||
version = map(int, version)
|
||||
except:
|
||||
raise OGCException('Badly formatted version number.')
|
||||
self.version = version
|
||||
|
||||
def __repr__(self):
|
||||
return '%s.%s.%s' % (self.version[0], self.version[1], self.version[2])
|
||||
|
||||
def __cmp__(self, other):
|
||||
if isinstance(other, str):
|
||||
other = Version(other)
|
||||
if self.version[0] < other.version[0]:
|
||||
return -1
|
||||
elif self.version[0] > other.version[0]:
|
||||
return 1
|
||||
else:
|
||||
if self.version[1] < other.version[1]:
|
||||
return -1
|
||||
elif self.version[1] > other.version[1]:
|
||||
return 1
|
||||
else:
|
||||
if self.version[2] < other.version[2]:
|
||||
return -1
|
||||
elif self.version[2] > other.version[2]:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
class ListFactory:
|
||||
|
||||
def __init__(self, cast):
|
||||
self.cast = cast
|
||||
|
||||
def __call__(self, string):
|
||||
seq = string.split(',')
|
||||
return map(self.cast, seq)
|
||||
|
||||
def ColorFactory(colorstring):
|
||||
if re.match('^0x[a-fA-F0-9]{6}$', colorstring):
|
||||
return Color(eval('0x' + colorstring[2:4]), eval('0x' + colorstring[4:6]), eval('0x' + colorstring[6:8]))
|
||||
else:
|
||||
raise OGCException('Invalid color value. Must be of format "0xFFFFFF".')
|
||||
|
||||
class CRS:
|
||||
|
||||
def __init__(self, namespace, code):
|
||||
self.namespace = namespace.lower()
|
||||
self.code = int(code)
|
||||
self.proj = None
|
||||
|
||||
def __repr__(self):
|
||||
return '%s:%s' % (self.namespace, self.code)
|
||||
|
||||
def __eq__(self, other):
|
||||
if str(other) == str(self):
|
||||
return True
|
||||
return False
|
||||
|
||||
def inverse(self, x, y):
|
||||
if not self.proj:
|
||||
self.proj = Projection('+init=%s:%s' % (self.namespace, self.code))
|
||||
return self.proj.inverse(Coord(x, y))
|
||||
|
||||
def forward(self, x, y):
|
||||
if not self.proj:
|
||||
self.proj = Projection('+init=%s:%s' % (self.namespace, self.code))
|
||||
return self.proj.forward(Coord(x, y))
|
||||
|
||||
class CRSFactory:
|
||||
|
||||
def __init__(self, allowednamespaces):
|
||||
self.allowednamespaces = allowednamespaces
|
||||
|
||||
def __call__(self, crsstring):
|
||||
if not re.match('^[A-Z]{3,5}:\d+$', crsstring):
|
||||
raise OGCException('Invalid format for the CRS parameter: %s' % crsstring, 'InvalidCRS')
|
||||
crsparts = crsstring.split(':')
|
||||
if crsparts[0] in self.allowednamespaces:
|
||||
return CRS(crsparts[0], crsparts[1])
|
||||
else:
|
||||
raise OGCException('Invalid CRS Namespace: %s' % crsparts[0], 'InvalidCRS')
|
||||
|
||||
def copy_layer(obj):
|
||||
lyr = Layer(obj.name)
|
||||
lyr.abstract = obj.abstract
|
||||
lyr.active = obj.active
|
||||
lyr.clear_label_cache = obj.clear_label_cache
|
||||
lyr.datasource = obj.datasource
|
||||
#lyr.maxzoom = obj.maxzoom
|
||||
#lyr.minzoom = obj.minzoom
|
||||
lyr.queryable = obj.queryable
|
||||
lyr.srs = obj.srs
|
||||
lyr.title = obj.title
|
||||
if hasattr(obj,'wmsdefaultstyle'):
|
||||
lyr.wmsdefaultstyle = obj.wmsdefaultstyle
|
||||
if hasattr(obj,'wmsextrastyles'):
|
||||
lyr.wmsextrastyles = obj.wmsextrastyles
|
||||
return lyr
|
||||
|
||||
def copy_style(obj):
|
||||
sty = Style()
|
||||
for rule in obj.rules:
|
||||
sty.rules.append(rule)
|
||||
return sty
|
||||
|
||||
class WMSBaseServiceHandler(BaseServiceHandler):
|
||||
|
||||
def GetMap(self, params):
|
||||
m = self._buildMap(params)
|
||||
im = Image(params['width'], params['height'])
|
||||
render(m, im)
|
||||
return Response(params['format'], im.tostring(PIL_TYPE_MAPPING[params['format']]))
|
||||
|
||||
def GetFeatureInfo(self, params, querymethodname='query_point'):
|
||||
m = self._buildMap(params)
|
||||
if params['info_format'] == 'text/plain':
|
||||
writer = TextFeatureInfo()
|
||||
elif params['info_format'] == 'text/xml':
|
||||
writer = XMLFeatureInfo()
|
||||
if params['query_layers'] and params['query_layers'][0] == '__all__':
|
||||
for layerindex, layer in enumerate(m.layers):
|
||||
featureset = getattr(m, querymethodname)(layerindex, params['i'], params['j'])
|
||||
features = featureset.features
|
||||
if features:
|
||||
writer.addlayer(layer.name)
|
||||
for feat in features:
|
||||
writer.addfeature()
|
||||
for prop in feat.properties:
|
||||
writer.addattribute(prop[0], prop[1])
|
||||
else:
|
||||
for layerindex, layername in enumerate(params['query_layers']):
|
||||
if layername in params['layers']:
|
||||
if m.layers[layerindex].queryable:
|
||||
featureset = getattr(m, querymethodname)(layerindex, params['i'], params['j'])
|
||||
features = featureset.features
|
||||
if features:
|
||||
writer.addlayer(m.layers[layerindex].name)
|
||||
for feat in features:
|
||||
writer.addfeature()
|
||||
for prop in feat.properties:
|
||||
writer.addattribute(prop[0], prop[1])
|
||||
else:
|
||||
raise OGCException('Requested query layer "%s" is not marked queryable.' % layername, 'LayerNotQueryable')
|
||||
else:
|
||||
raise OGCException('Requested query layer "%s" not in the LAYERS parameter.' % layername)
|
||||
return Response(params['info_format'], str(writer))
|
||||
|
||||
def _buildMap(self, params):
|
||||
if str(params['crs']) not in self.allowedepsgcodes:
|
||||
raise OGCException('Unsupported CRS "%s" requested.' % str(params['crs']).upper(), 'InvalidCRS')
|
||||
if params['bbox'][0] >= params['bbox'][2]:
|
||||
raise OGCException("BBOX values don't make sense. minx is greater than maxx.")
|
||||
if params['bbox'][1] >= params['bbox'][3]:
|
||||
raise OGCException("BBOX values don't make sense. miny is greater than maxy.")
|
||||
if params.has_key('styles') and len(params['styles']) != len(params['layers']):
|
||||
raise OGCException('STYLES length does not match LAYERS length.')
|
||||
m = Map(params['width'], params['height'], '+init=%s' % params['crs'])
|
||||
if params.has_key('transparent') and params['transparent'] == 'FALSE':
|
||||
if params['bgcolor']:
|
||||
m.background = params['bgcolor']
|
||||
else:
|
||||
m.background = Color(0, 0, 0, 0)
|
||||
maplayers = self.mapfactory.layers
|
||||
orderedmaplayers = self.mapfactory.ordered_layers
|
||||
mapstyles = self.mapfactory.styles
|
||||
mapaggregatestyles = self.mapfactory.aggregatestyles
|
||||
# a non WMS spec way of requesting all layers
|
||||
if params['layers'] and params['layers'][0] == '__all__':
|
||||
for layername in orderedmaplayers:
|
||||
layer = copy_layer(layername)
|
||||
reqstyle = layer.wmsdefaultstyle
|
||||
if reqstyle in mapaggregatestyles.keys():
|
||||
for stylename in mapaggregatestyles[reqstyle]:
|
||||
layer.styles.append(stylename)
|
||||
else:
|
||||
layer.styles.append(reqstyle)
|
||||
for stylename in layer.styles:
|
||||
if stylename in mapstyles.keys():
|
||||
m.append_style(stylename, mapstyles[stylename])
|
||||
m.layers.append(layer)
|
||||
else:
|
||||
for layerindex, layername in enumerate(params['layers']):
|
||||
try:
|
||||
layer = copy_layer(maplayers[layername])
|
||||
except KeyError:
|
||||
raise OGCException('Layer "%s" not defined.' % layername, 'LayerNotDefined')
|
||||
try:
|
||||
reqstyle = params['styles'][layerindex]
|
||||
except IndexError:
|
||||
reqstyle = ''
|
||||
if reqstyle and reqstyle not in layer.wmsextrastyles:
|
||||
raise OGCException('Invalid style "%s" requested for layer "%s".' % (reqstyle, layername), 'StyleNotDefined')
|
||||
if not reqstyle:
|
||||
reqstyle = layer.wmsdefaultstyle
|
||||
if reqstyle in mapaggregatestyles.keys():
|
||||
for stylename in mapaggregatestyles[reqstyle]:
|
||||
layer.styles.append(stylename)
|
||||
else:
|
||||
layer.styles.append(reqstyle)
|
||||
for stylename in layer.styles:
|
||||
if stylename in mapstyles.keys():
|
||||
m.append_style(stylename, mapstyles[stylename])
|
||||
else:
|
||||
raise ServerConfigurationError('Layer "%s" refers to non-existent style "%s".' % (layername, stylename))
|
||||
m.layers.append(layer)
|
||||
m.zoom_to_box(Box2d(params['bbox'][0], params['bbox'][1], params['bbox'][2], params['bbox'][3]))
|
||||
return m
|
||||
|
||||
class BaseExceptionHandler:
|
||||
|
||||
def __init__(self, debug):
|
||||
self.debug = debug
|
||||
|
||||
def getresponse(self, params):
|
||||
code = ''
|
||||
message = '\n'
|
||||
if not params:
|
||||
message = '''
|
||||
<h2>Welcome to the Mapnik OGCServer.</h2>
|
||||
<h3>Ready to accept map requests...</h5>
|
||||
<h4>For more info see: <a href="http://trac.mapnik.org/wiki/OgcServer">trac.mapnik.org</a></h4>
|
||||
'''
|
||||
return self.htmlhandler('', message)
|
||||
excinfo = exc_info()
|
||||
if self.debug:
|
||||
messagelist = format_exception(excinfo[0], excinfo[1], excinfo[2])
|
||||
else:
|
||||
messagelist = format_exception_only(excinfo[0], excinfo[1])
|
||||
message += ''.join(messagelist)
|
||||
if isinstance(excinfo[1], OGCException) and len(excinfo[1].args) > 1:
|
||||
code = excinfo[1].args[1]
|
||||
exceptions = params.get('exceptions', None)
|
||||
if self.debug:
|
||||
return self.htmlhandler(code, message)
|
||||
if not exceptions or not self.handlers.has_key(exceptions):
|
||||
exceptions = self.defaulthandler
|
||||
return self.handlers[exceptions](self, code, message, params)
|
||||
|
||||
def htmlhandler(self,code,message):
|
||||
if code:
|
||||
resp_text = '<h2>OGCServer Error:</h2><pre>%s</pre>\n<h3>Traceback:</h3><pre>%s</pre>\n' % (message, code)
|
||||
else:
|
||||
resp_text = message
|
||||
return Response('text/html', resp_text)
|
||||
|
||||
def xmlhandler(self, code, message, params):
|
||||
ogcexcetree = deepcopy(self.xmltemplate)
|
||||
e = ogcexcetree.find(self.xpath)
|
||||
e.text = message
|
||||
if code:
|
||||
e.set('code', code)
|
||||
return Response(self.xmlmimetype, ElementTree.tostring(ogcexcetree))
|
||||
|
||||
def inimagehandler(self, code, message, params):
|
||||
im = new('RGBA', (int(params['width']), int(params['height'])))
|
||||
im.putalpha(new('1', (int(params['width']), int(params['height']))))
|
||||
draw = Draw(im)
|
||||
for count, line in enumerate(message.strip().split('\n')):
|
||||
draw.text((12,15*(count+1)), line, fill='#000000')
|
||||
fh = StringIO()
|
||||
im.save(fh, PIL_TYPE_MAPPING[params['format']])
|
||||
fh.seek(0)
|
||||
return Response(params['format'], fh.read())
|
||||
|
||||
def blankhandler(self, code, message, params):
|
||||
bgcolor = params.get('bgcolor', '#FFFFFF')
|
||||
bgcolor = bgcolor.replace('0x', '#')
|
||||
transparent = params.get('transparent', 'FALSE')
|
||||
if transparent == 'TRUE':
|
||||
im = new('RGBA', (int(params['width']), int(params['height'])))
|
||||
im.putalpha(new('1', (int(params['width']), int(params['height']))))
|
||||
else:
|
||||
im = new('RGBA', (int(params['width']), int(params['height'])), bgcolor)
|
||||
fh = StringIO()
|
||||
im.save(fh, PIL_TYPE_MAPPING[params['format']])
|
||||
fh.seek(0)
|
||||
return Response(params['format'], fh.read())
|
||||
|
||||
class Projection(MapnikProjection):
|
||||
|
||||
def epsgstring(self):
|
||||
return self.params().split('=')[1].upper()
|
||||
|
||||
class TextFeatureInfo:
|
||||
|
||||
def __init__(self):
|
||||
self.buffer = ''
|
||||
|
||||
def addlayer(self, name):
|
||||
self.buffer += '\n[%s]\n' % name
|
||||
|
||||
def addfeature(self):
|
||||
pass#self.buffer += '\n'
|
||||
|
||||
def addattribute(self, name, value):
|
||||
self.buffer += '%s=%s\n' % (name, str(value))
|
||||
|
||||
def __str__(self):
|
||||
return self.buffer
|
||||
|
||||
class XMLFeatureInfo:
|
||||
|
||||
basexml = """<?xml version="1.0"?>
|
||||
<resultset>
|
||||
</resultset>
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.rootelement = ElementTree.fromstring(self.basexml)
|
||||
|
||||
def addlayer(self, name):
|
||||
layer = ElementTree.Element('layer')
|
||||
layer.set('name', name)
|
||||
self.rootelement.append(layer)
|
||||
self.currentlayer = layer
|
||||
|
||||
def addfeature(self):
|
||||
feature = ElementTree.Element('feature')
|
||||
self.currentlayer.append(feature)
|
||||
self.currentfeature = feature
|
||||
|
||||
def addattribute(self, name, value):
|
||||
attribute = ElementTree.Element('attribute')
|
||||
attname = ElementTree.Element('name')
|
||||
attname.text = name
|
||||
attvalue = ElementTree.Element('value')
|
||||
attvalue.text = unicode(value)
|
||||
attribute.append(attname)
|
||||
attribute.append(attvalue)
|
||||
self.currentfeature.append(attribute)
|
||||
|
||||
def __str__(self):
|
||||
return '<?xml version="1.0"?>\n' + ElementTree.tostring(self.rootelement)
|
|
@ -1,44 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
""" Change SafeConfigParser behavior to treat options without values as
|
||||
non-existent.
|
||||
"""
|
||||
|
||||
from ConfigParser import SafeConfigParser as OrigSafeConfigParser
|
||||
|
||||
class SafeConfigParser(OrigSafeConfigParser):
|
||||
|
||||
def items_with_value(self, section):
|
||||
finallist = []
|
||||
items = self.items(section)
|
||||
for item in items:
|
||||
if item[1] != '':
|
||||
finallist.append(item)
|
||||
return finallist
|
||||
|
||||
def has_option_with_value(self, section, option):
|
||||
if self.has_option(section, option):
|
||||
if self.get(section, option) == '':
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
return True
|
|
@ -1,28 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""Custom OGCServer Exceptions"""
|
||||
|
||||
class OGCException(Exception):
|
||||
pass
|
||||
|
||||
class ServerConfigurationError(Exception):
|
||||
pass
|
|
@ -1,133 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id: modserver.py 283 2006-07-22 18:54:53Z jdoyon $
|
||||
|
||||
"""Mod_python handler for Mapnik OGC WMS Server."""
|
||||
|
||||
import sys
|
||||
from mod_python import apache, util
|
||||
from exceptions import OGCException, ServerConfigurationError
|
||||
from wms111 import ExceptionHandler as ExceptionHandler111
|
||||
from wms130 import ExceptionHandler as ExceptionHandler130
|
||||
from configparser import SafeConfigParser
|
||||
from common import Version
|
||||
|
||||
|
||||
class ModHandler(object):
|
||||
def __init__(self, configpath):
|
||||
conf = SafeConfigParser()
|
||||
conf.readfp(open(configpath))
|
||||
self.conf = conf
|
||||
if not conf.has_option_with_value('server', 'module'):
|
||||
raise ServerConfigurationError('The factory module is not defined in the configuration file.')
|
||||
try:
|
||||
mapfactorymodule = __import__(conf.get('server', 'module'))
|
||||
except ImportError:
|
||||
raise ServerConfigurationError('The factory module could not be loaded.')
|
||||
if hasattr(mapfactorymodule, 'WMSFactory'):
|
||||
self.mapfactory = getattr(mapfactorymodule, 'WMSFactory')()
|
||||
else:
|
||||
raise ServerConfigurationError('The factory module does not have a WMSFactory class.')
|
||||
if conf.has_option('server', 'debug'):
|
||||
self.debug = int(conf.get('server', 'debug'))
|
||||
else:
|
||||
self.debug = 0
|
||||
if self.conf.has_option_with_value('server', 'maxage'):
|
||||
self.max_age = 'max-age=%d' % self.conf.get('server', 'maxage')
|
||||
else:
|
||||
self.max_age = None
|
||||
|
||||
def __call__(self, apacheReq):
|
||||
try:
|
||||
reqparams = util.FieldStorage(apacheReq,keep_blank_values=1)
|
||||
if not reqparams:
|
||||
eh = ExceptionHandler130(self.debug)
|
||||
response = eh.getresponse(reqparams)
|
||||
apacheReq.content_type = response.content_type
|
||||
else:
|
||||
reqparams = lowerparams(reqparams)
|
||||
port = apacheReq.connection.local_addr[1]
|
||||
onlineresource = 'http://%s:%s%s?' % (apacheReq.hostname, port, apacheReq.subprocess_env['SCRIPT_NAME'])
|
||||
if not reqparams.has_key('request'):
|
||||
raise OGCException('Missing Request parameter.')
|
||||
request = reqparams['request']
|
||||
del reqparams['request']
|
||||
if request == 'GetCapabilities' and not reqparams.has_key('service'):
|
||||
raise OGCException('Missing service parameter.')
|
||||
if request in ['GetMap', 'GetFeatureInfo']:
|
||||
service = 'WMS'
|
||||
else:
|
||||
service = reqparams['service']
|
||||
if reqparams.has_key('service'):
|
||||
del reqparams['service']
|
||||
try:
|
||||
mapnikmodule = __import__('mapnik2.ogcserver.' + service)
|
||||
except:
|
||||
raise OGCException('Unsupported service "%s".' % service)
|
||||
ServiceHandlerFactory = getattr(mapnikmodule.ogcserver, service).ServiceHandlerFactory
|
||||
servicehandler = ServiceHandlerFactory(self.conf, self.mapfactory, onlineresource, reqparams.get('version', None))
|
||||
if reqparams.has_key('version'):
|
||||
del reqparams['version']
|
||||
if request not in servicehandler.SERVICE_PARAMS.keys():
|
||||
raise OGCException('Operation "%s" not supported.' % request, 'OperationNotSupported')
|
||||
|
||||
# Get parameters and pass to WMSFactory in custom "setup" method
|
||||
ogcparams = servicehandler.processParameters(request, reqparams)
|
||||
try:
|
||||
requesthandler = getattr(servicehandler, request)
|
||||
except:
|
||||
raise OGCException('Operation "%s" not supported.' % request, 'OperationNotSupported')
|
||||
|
||||
response = requesthandler(ogcparams)
|
||||
apacheReq.content_type = response.content_type
|
||||
apacheReq.status = apache.HTTP_OK
|
||||
except Exception, E:
|
||||
return self.traceback(apacheReq,E)
|
||||
|
||||
if self.max_age:
|
||||
apacheReq.headers_out.add('Cache-Control', max_age)
|
||||
apacheReq.headers_out.add('Content-Length', str(len(response.content)))
|
||||
apacheReq.send_http_header()
|
||||
apacheReq.write(response.content)
|
||||
return apache.OK
|
||||
|
||||
def traceback(self, apacheReq,E):
|
||||
reqparams = lowerparams(util.FieldStorage(apacheReq))
|
||||
version = reqparams.get('version', None)
|
||||
if not version:
|
||||
version = Version('1.3.0')
|
||||
else:
|
||||
version = Version(version)
|
||||
if version >= '1.3.0':
|
||||
eh = ExceptionHandler130(self.debug)
|
||||
else:
|
||||
eh = ExceptionHandler111(self.debug)
|
||||
response = eh.getresponse(reqparams)
|
||||
apacheReq.content_type = response.content_type
|
||||
apacheReq.headers_out.add('Content-Length', str(len(response.content)))
|
||||
apacheReq.send_http_header()
|
||||
apacheReq.write(response.content)
|
||||
return apache.OK
|
||||
|
||||
def lowerparams(params):
|
||||
reqparams = {}
|
||||
for key, value in params.items():
|
||||
reqparams[key.lower()] = value
|
||||
return reqparams
|
|
@ -1,238 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""WMS 1.1.1 compliant GetCapabilities, GetMap, GetFeatureInfo, and Exceptions interface."""
|
||||
|
||||
from common import ParameterDefinition, Response, Version, ListFactory, \
|
||||
ColorFactory, CRSFactory, WMSBaseServiceHandler, CRS, \
|
||||
BaseExceptionHandler, Projection
|
||||
from exceptions import OGCException, ServerConfigurationError
|
||||
from mapnik2 import Coord
|
||||
|
||||
try:
|
||||
from lxml import etree as ElementTree
|
||||
except ImportError:
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
except ImportError:
|
||||
import elementtree.ElementTree as ElementTree
|
||||
|
||||
class ServiceHandler(WMSBaseServiceHandler):
|
||||
|
||||
SERVICE_PARAMS = {
|
||||
'GetCapabilities': {
|
||||
'updatesequence': ParameterDefinition(False, str)
|
||||
},
|
||||
'GetMap': {
|
||||
'layers': ParameterDefinition(True, ListFactory(str)),
|
||||
'styles': ParameterDefinition(True, ListFactory(str)),
|
||||
'srs': ParameterDefinition(True, CRSFactory(['EPSG'])),
|
||||
'bbox': ParameterDefinition(True, ListFactory(float)),
|
||||
'width': ParameterDefinition(True, int),
|
||||
'height': ParameterDefinition(True, int),
|
||||
'format': ParameterDefinition(True, str, allowedvalues=('image/png', 'image/jpeg')),
|
||||
'transparent': ParameterDefinition(False, str, 'FALSE', ('TRUE', 'FALSE')),
|
||||
'bgcolor': ParameterDefinition(False, ColorFactory, ColorFactory('0xFFFFFF')),
|
||||
'exceptions': ParameterDefinition(False, str, 'application/vnd.ogc.se_xml', ('application/vnd.ogc.se_xml', 'application/vnd.ogc.se_inimage', 'application/vnd.ogc.se_blank','text/html'))
|
||||
},
|
||||
'GetFeatureInfo': {
|
||||
'layers': ParameterDefinition(True, ListFactory(str)),
|
||||
'styles': ParameterDefinition(False, ListFactory(str)),
|
||||
'srs': ParameterDefinition(True, CRSFactory(['EPSG'])),
|
||||
'bbox': ParameterDefinition(True, ListFactory(float)),
|
||||
'width': ParameterDefinition(True, int),
|
||||
'height': ParameterDefinition(True, int),
|
||||
'format': ParameterDefinition(False, str, allowedvalues=('image/png', 'image/jpeg')),
|
||||
'transparent': ParameterDefinition(False, str, 'FALSE', ('TRUE', 'FALSE')),
|
||||
'bgcolor': ParameterDefinition(False, ColorFactory, ColorFactory('0xFFFFFF')),
|
||||
'exceptions': ParameterDefinition(False, str, 'application/vnd.ogc.se_xml', ('application/vnd.ogc.se_xml', 'application/vnd.ogc.se_inimage', 'application/vnd.ogc.se_blank','text/html')),
|
||||
'query_layers': ParameterDefinition(True, ListFactory(str)),
|
||||
'info_format': ParameterDefinition(True, str, allowedvalues=('text/plain', 'text/xml')),
|
||||
'feature_count': ParameterDefinition(False, int, 1),
|
||||
'x': ParameterDefinition(True, int),
|
||||
'y': ParameterDefinition(True, int)
|
||||
}
|
||||
}
|
||||
|
||||
CONF_SERVICE = [
|
||||
['title', 'Title', str],
|
||||
['abstract', 'Abstract', str],
|
||||
['onlineresource', 'OnlineResource', str],
|
||||
['fees', 'Fees', str],
|
||||
['accessconstraints', 'AccessConstraints', str],
|
||||
['keywordlist', 'KeywordList', str]
|
||||
]
|
||||
|
||||
capabilitiesxmltemplate = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://www.digitalearth.gov/wmt/xml/capabilities_1_1_1.dtd">
|
||||
<WMT_MS_Capabilities version="1.1.1" updateSequence="0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.opengis.net/wms">
|
||||
<Service>
|
||||
<Name>WMS</Name>
|
||||
</Service>
|
||||
<Capability>
|
||||
<Request>
|
||||
<GetCapabilities>
|
||||
<Format>application/vnd.ogc.wms_xml</Format>
|
||||
<DCPType>
|
||||
<HTTP>
|
||||
<Get>
|
||||
<OnlineResource xlink:type="simple"/>
|
||||
</Get>
|
||||
</HTTP>
|
||||
</DCPType>
|
||||
</GetCapabilities>
|
||||
<GetMap>
|
||||
<Format>image/png</Format>
|
||||
<Format>image/jpeg</Format>
|
||||
<DCPType>
|
||||
<HTTP>
|
||||
<Get>
|
||||
<OnlineResource xlink:type="simple"/>
|
||||
</Get>
|
||||
</HTTP>
|
||||
</DCPType>
|
||||
</GetMap>
|
||||
<GetFeatureInfo>
|
||||
<Format>text/plain</Format>
|
||||
<DCPType>
|
||||
<HTTP>
|
||||
<Get>
|
||||
<OnlineResource xlink:type="simple"/>
|
||||
</Get>
|
||||
</HTTP>
|
||||
</DCPType>
|
||||
</GetFeatureInfo>
|
||||
</Request>
|
||||
<Exception>
|
||||
<Format>application/vnd.ogc.se_xml</Format>
|
||||
<Format>application/vnd.ogc.se_inimage</Format>
|
||||
<Format>application/vnd.ogc.se_blank</Format>
|
||||
</Exception>
|
||||
<Layer>
|
||||
<Title>A Mapnik WMS Server</Title>
|
||||
<Abstract>A Mapnik WMS Server</Abstract>
|
||||
</Layer>
|
||||
</Capability>
|
||||
</WMT_MS_Capabilities>
|
||||
"""
|
||||
|
||||
def __init__(self, conf, mapfactory, opsonlineresource):
|
||||
self.conf = conf
|
||||
self.mapfactory = mapfactory
|
||||
self.opsonlineresource = opsonlineresource
|
||||
if self.conf.has_option('service', 'allowedepsgcodes'):
|
||||
self.allowedepsgcodes = map(lambda code: 'epsg:%s' % code, self.conf.get('service', 'allowedepsgcodes').split(','))
|
||||
else:
|
||||
raise ServerConfigurationError('Allowed EPSG codes not properly configured.')
|
||||
self.capabilities = None
|
||||
|
||||
def GetCapabilities(self, params):
|
||||
if not self.capabilities:
|
||||
capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)
|
||||
|
||||
elements = capetree.findall('Capability//OnlineResource')
|
||||
for element in elements:
|
||||
element.set('{http://www.w3.org/1999/xlink}href', self.opsonlineresource)
|
||||
|
||||
self.processServiceCapabilities(capetree)
|
||||
|
||||
rootlayerelem = capetree.find('{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer')
|
||||
|
||||
for epsgcode in self.allowedepsgcodes:
|
||||
rootlayercrs = ElementTree.Element('SRS')
|
||||
rootlayercrs.text = epsgcode.upper()
|
||||
rootlayerelem.append(rootlayercrs)
|
||||
|
||||
for layer in self.mapfactory.ordered_layers:
|
||||
layerproj = Projection(layer.srs)
|
||||
layername = ElementTree.Element('Name')
|
||||
layername.text = layer.name
|
||||
env = layer.envelope()
|
||||
llp = layerproj.inverse(Coord(env.minx, env.miny))
|
||||
urp = layerproj.inverse(Coord(env.maxx, env.maxy))
|
||||
latlonbb = ElementTree.Element('LatLonBoundingBox')
|
||||
latlonbb.set('minx', str(llp.x))
|
||||
latlonbb.set('miny', str(llp.y))
|
||||
latlonbb.set('maxx', str(urp.x))
|
||||
latlonbb.set('maxy', str(urp.y))
|
||||
layerbbox = ElementTree.Element('BoundingBox')
|
||||
layerbbox.set('SRS', layerproj.epsgstring())
|
||||
layerbbox.set('minx', str(env.minx))
|
||||
layerbbox.set('miny', str(env.miny))
|
||||
layerbbox.set('maxx', str(env.maxx))
|
||||
layerbbox.set('maxy', str(env.maxy))
|
||||
layere = ElementTree.Element('Layer')
|
||||
layere.append(layername)
|
||||
if layer.title:
|
||||
layertitle = ElementTree.Element('Title')
|
||||
layertitle.text = layer.title
|
||||
layere.append(layertitle)
|
||||
if layer.abstract:
|
||||
layerabstract = ElementTree.Element('Abstract')
|
||||
layerabstract.text = layer.abstract
|
||||
layere.append(layerabstract)
|
||||
if layer.queryable:
|
||||
layere.set('queryable', '1')
|
||||
layere.append(latlonbb)
|
||||
layere.append(layerbbox)
|
||||
if len(layer.wmsextrastyles) > 0:
|
||||
for extrastyle in [layer.wmsdefaultstyle] + list(layer.wmsextrastyles):
|
||||
style = ElementTree.Element('Style')
|
||||
stylename = ElementTree.Element('Name')
|
||||
stylename.text = extrastyle
|
||||
styletitle = ElementTree.Element('Title')
|
||||
styletitle.text = extrastyle
|
||||
style.append(stylename)
|
||||
style.append(styletitle)
|
||||
layere.append(style)
|
||||
rootlayerelem.append(layere)
|
||||
self.capabilities = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + ElementTree.tostring(capetree)
|
||||
response = Response('application/vnd.ogc.wms_xml', self.capabilities)
|
||||
return response
|
||||
|
||||
def GetMap(self, params):
|
||||
params['crs'] = params['srs']
|
||||
return WMSBaseServiceHandler.GetMap(self, params)
|
||||
|
||||
def GetFeatureInfo(self, params):
|
||||
params['crs'] = params['srs']
|
||||
params['i'] = params['x']
|
||||
params['j'] = params['y']
|
||||
return WMSBaseServiceHandler.GetFeatureInfo(self, params, 'query_map_point')
|
||||
|
||||
class ExceptionHandler(BaseExceptionHandler):
|
||||
|
||||
xmlmimetype = "application/vnd.ogc.se_xml"
|
||||
|
||||
xmltemplate = ElementTree.fromstring("""<?xml version='1.0' encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE ServiceExceptionReport SYSTEM "http://www.digitalearth.gov/wmt/xml/exception_1_1_1.dtd">
|
||||
<ServiceExceptionReport version="1.1.1">
|
||||
<ServiceException />
|
||||
</ServiceExceptionReport>
|
||||
""")
|
||||
|
||||
xpath = 'ServiceException'
|
||||
|
||||
handlers = {'application/vnd.ogc.se_xml': BaseExceptionHandler.xmlhandler,
|
||||
'application/vnd.ogc.se_inimage': BaseExceptionHandler.inimagehandler,
|
||||
'application/vnd.ogc.se_blank': BaseExceptionHandler.blankhandler,
|
||||
'text/html': BaseExceptionHandler.htmlhandler}
|
||||
|
||||
defaulthandler = 'application/vnd.ogc.se_xml'
|
|
@ -1,264 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""WMS 1.3.0 compliant GetCapabilities, GetMap, GetFeatureInfo, and Exceptions interface."""
|
||||
|
||||
from common import ParameterDefinition, Response, Version, ListFactory, \
|
||||
ColorFactory, CRSFactory, CRS, WMSBaseServiceHandler, \
|
||||
BaseExceptionHandler, Projection, Box2d
|
||||
from exceptions import OGCException, ServerConfigurationError
|
||||
from mapnik2 import Coord
|
||||
|
||||
try:
|
||||
from lxml import etree as ElementTree
|
||||
except ImportError:
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
except ImportError:
|
||||
import elementtree.ElementTree as ElementTree
|
||||
|
||||
class ServiceHandler(WMSBaseServiceHandler):
|
||||
|
||||
SERVICE_PARAMS = {
|
||||
'GetCapabilities': {
|
||||
'format': ParameterDefinition(False, str, 'text/xml', ('text/xml',), True),
|
||||
'updatesequence': ParameterDefinition(False, str)
|
||||
},
|
||||
'GetMap': {
|
||||
'layers': ParameterDefinition(True, ListFactory(str)),
|
||||
'styles': ParameterDefinition(True, ListFactory(str)),
|
||||
'crs': ParameterDefinition(True, CRSFactory(['EPSG'])),
|
||||
'bbox': ParameterDefinition(True, ListFactory(float)),
|
||||
'width': ParameterDefinition(True, int),
|
||||
'height': ParameterDefinition(True, int),
|
||||
'format': ParameterDefinition(True, str, allowedvalues=('image/png', 'image/jpeg')),
|
||||
'transparent': ParameterDefinition(False, str, 'FALSE', ('TRUE', 'FALSE')),
|
||||
'bgcolor': ParameterDefinition(False, ColorFactory, ColorFactory('0xFFFFFF')),
|
||||
'exceptions': ParameterDefinition(False, str, 'XML', ('XML', 'INIMAGE', 'BLANK','HTML')),
|
||||
},
|
||||
'GetFeatureInfo': {
|
||||
'layers': ParameterDefinition(True, ListFactory(str)),
|
||||
'styles': ParameterDefinition(False, ListFactory(str)),
|
||||
'crs': ParameterDefinition(True, CRSFactory(['EPSG'])),
|
||||
'bbox': ParameterDefinition(True, ListFactory(float)),
|
||||
'width': ParameterDefinition(True, int),
|
||||
'height': ParameterDefinition(True, int),
|
||||
'format': ParameterDefinition(False, str, allowedvalues=('image/png', 'image/jpeg')),
|
||||
'transparent': ParameterDefinition(False, str, 'FALSE', ('TRUE', 'FALSE')),
|
||||
'bgcolor': ParameterDefinition(False, ColorFactory, ColorFactory('0xFFFFFF')),
|
||||
'exceptions': ParameterDefinition(False, str, 'XML', ('XML', 'INIMAGE', 'BLANK','HTML')),
|
||||
'query_layers': ParameterDefinition(True, ListFactory(str)),
|
||||
'info_format': ParameterDefinition(True, str, allowedvalues=('text/plain', 'text/xml')),
|
||||
'feature_count': ParameterDefinition(False, int, 1),
|
||||
'i': ParameterDefinition(True, float),
|
||||
'j': ParameterDefinition(True, float)
|
||||
}
|
||||
}
|
||||
|
||||
CONF_SERVICE = [
|
||||
['title', 'Title', str],
|
||||
['abstract', 'Abstract', str],
|
||||
['onlineresource', 'OnlineResource', str],
|
||||
['fees', 'Fees', str],
|
||||
['accessconstraints', 'AccessConstraints', str],
|
||||
['layerlimit', 'LayerLimit', int],
|
||||
['maxwidth', 'MaxWidth', int],
|
||||
['maxheight', 'MaxHeight', int],
|
||||
['keywordlist', 'KeywordList', str]
|
||||
]
|
||||
|
||||
capabilitiesxmltemplate = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<WMS_Capabilities version="1.3.0" xmlns="http://www.opengis.net/wms"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd">
|
||||
<Service>
|
||||
<Name>WMS</Name>
|
||||
</Service>
|
||||
<Capability>
|
||||
<Request>
|
||||
<GetCapabilities>
|
||||
<Format>text/xml</Format>
|
||||
<DCPType>
|
||||
<HTTP>
|
||||
<Get>
|
||||
<OnlineResource xlink:type="simple"/>
|
||||
</Get>
|
||||
</HTTP>
|
||||
</DCPType>
|
||||
</GetCapabilities>
|
||||
<GetMap>
|
||||
<Format>image/png</Format>
|
||||
<Format>image/jpeg</Format>
|
||||
<DCPType>
|
||||
<HTTP>
|
||||
<Get>
|
||||
<OnlineResource xlink:type="simple"/>
|
||||
</Get>
|
||||
</HTTP>
|
||||
</DCPType>
|
||||
</GetMap>
|
||||
<GetFeatureInfo>
|
||||
<Format>text/plain</Format>
|
||||
<DCPType>
|
||||
<HTTP>
|
||||
<Get>
|
||||
<OnlineResource xlink:type="simple"/>
|
||||
</Get>
|
||||
</HTTP>
|
||||
</DCPType>
|
||||
</GetFeatureInfo>
|
||||
</Request>
|
||||
<Exception>
|
||||
<Format>XML</Format>
|
||||
<Format>INIMAGE</Format>
|
||||
<Format>BLANK</Format>
|
||||
</Exception>
|
||||
<Layer>
|
||||
<Title>A Mapnik WMS Server</Title>
|
||||
<Abstract>A Mapnik WMS Server</Abstract>
|
||||
</Layer>
|
||||
</Capability>
|
||||
</WMS_Capabilities>
|
||||
"""
|
||||
|
||||
def __init__(self, conf, mapfactory, opsonlineresource):
|
||||
self.conf = conf
|
||||
self.mapfactory = mapfactory
|
||||
self.opsonlineresource = opsonlineresource
|
||||
if self.conf.has_option('service', 'allowedepsgcodes'):
|
||||
self.allowedepsgcodes = map(lambda code: 'epsg:%s' % code, self.conf.get('service', 'allowedepsgcodes').split(','))
|
||||
else:
|
||||
raise ServerConfigurationError('Allowed EPSG codes not properly configured.')
|
||||
self.capabilities = None
|
||||
|
||||
def GetCapabilities(self, params):
|
||||
if not self.capabilities:
|
||||
capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)
|
||||
|
||||
elements = capetree.findall('{http://www.opengis.net/wms}Capability//{http://www.opengis.net/wms}OnlineResource')
|
||||
for element in elements:
|
||||
element.set('{http://www.w3.org/1999/xlink}href', self.opsonlineresource)
|
||||
|
||||
self.processServiceCapabilities(capetree)
|
||||
|
||||
rootlayerelem = capetree.find('{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer')
|
||||
|
||||
for epsgcode in self.allowedepsgcodes:
|
||||
rootlayercrs = ElementTree.Element('CRS')
|
||||
rootlayercrs.text = epsgcode.upper()
|
||||
rootlayerelem.append(rootlayercrs)
|
||||
|
||||
for layer in self.mapfactory.ordered_layers:
|
||||
layerproj = Projection(layer.srs)
|
||||
layername = ElementTree.Element('Name')
|
||||
layername.text = layer.name
|
||||
env = layer.envelope()
|
||||
layerexgbb = ElementTree.Element('EX_GeographicBoundingBox')
|
||||
ll = layerproj.inverse(Coord(env.minx, env.miny))
|
||||
ur = layerproj.inverse(Coord(env.maxx, env.maxy))
|
||||
exgbb_wbl = ElementTree.Element('westBoundLongitude')
|
||||
exgbb_wbl.text = str(ll.x)
|
||||
layerexgbb.append(exgbb_wbl)
|
||||
exgbb_ebl = ElementTree.Element('eastBoundLongitude')
|
||||
exgbb_ebl.text = str(ur.x)
|
||||
layerexgbb.append(exgbb_ebl)
|
||||
exgbb_sbl = ElementTree.Element('southBoundLatitude')
|
||||
exgbb_sbl.text = str(ll.y)
|
||||
layerexgbb.append(exgbb_sbl)
|
||||
exgbb_nbl = ElementTree.Element('northBoundLatitude')
|
||||
exgbb_nbl.text = str(ur.y)
|
||||
layerexgbb.append(exgbb_nbl)
|
||||
layerbbox = ElementTree.Element('BoundingBox')
|
||||
layerbbox.set('CRS', layerproj.epsgstring())
|
||||
layerbbox.set('minx', str(env.minx))
|
||||
layerbbox.set('miny', str(env.miny))
|
||||
layerbbox.set('maxx', str(env.maxx))
|
||||
layerbbox.set('maxy', str(env.maxy))
|
||||
layere = ElementTree.Element('Layer')
|
||||
layere.append(layername)
|
||||
if layer.title:
|
||||
layertitle = ElementTree.Element('Title')
|
||||
layertitle.text = layer.title
|
||||
layere.append(layertitle)
|
||||
if layer.abstract:
|
||||
layerabstract = ElementTree.Element('Abstract')
|
||||
layerabstract.text = layer.abstract
|
||||
layere.append(layerabstract)
|
||||
if layer.queryable:
|
||||
layere.set('queryable', '1')
|
||||
layere.append(layerexgbb)
|
||||
layere.append(layerbbox)
|
||||
if len(layer.wmsextrastyles) > 0:
|
||||
for extrastyle in [layer.wmsdefaultstyle] + list(layer.wmsextrastyles):
|
||||
style = ElementTree.Element('Style')
|
||||
stylename = ElementTree.Element('Name')
|
||||
stylename.text = extrastyle
|
||||
styletitle = ElementTree.Element('Title')
|
||||
styletitle.text = extrastyle
|
||||
style.append(stylename)
|
||||
style.append(styletitle)
|
||||
layere.append(style)
|
||||
rootlayerelem.append(layere)
|
||||
self.capabilities = '<?xml version="1.0" encoding="UTF-8"?>' + ElementTree.tostring(capetree)
|
||||
response = Response('text/xml', self.capabilities)
|
||||
return response
|
||||
|
||||
def GetMap(self, params):
|
||||
if params['width'] > int(self.conf.get('service', 'maxwidth')) or params['height'] > int(self.conf.get('service', 'maxheight')):
|
||||
raise OGCException('Requested map size exceeds limits set by this server.')
|
||||
return WMSBaseServiceHandler.GetMap(self, params)
|
||||
|
||||
def _buildMap(self, params):
|
||||
""" Override _buildMap method to handle reverse axis ordering in WMS 1.3.0.
|
||||
|
||||
More info: http://mapserver.org/development/rfc/ms-rfc-30.html
|
||||
|
||||
'when using epsg code >=4000 and <5000 will be assumed to have a reversed axes.'
|
||||
|
||||
"""
|
||||
# Call superclass method
|
||||
m = WMSBaseServiceHandler._buildMap(self, params)
|
||||
# for range of epsg codes reverse axis
|
||||
if params['crs'].code >= 4000 and params['crs'].code < 5000:
|
||||
m.zoom_to_box(Box2d(params['bbox'][1], params['bbox'][0], params['bbox'][3], params['bbox'][2]))
|
||||
return m
|
||||
|
||||
class ExceptionHandler(BaseExceptionHandler):
|
||||
|
||||
xmlmimetype = "text/xml"
|
||||
|
||||
xmltemplate = ElementTree.fromstring("""<?xml version='1.0' encoding="UTF-8"?>
|
||||
<ServiceExceptionReport version="1.3.0"
|
||||
xmlns="http://www.opengis.net/ogc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">
|
||||
<ServiceException/>
|
||||
</ServiceExceptionReport>
|
||||
""")
|
||||
|
||||
xpath = '{http://www.opengis.net/ogc}ServiceException'
|
||||
|
||||
handlers = {'XML': BaseExceptionHandler.xmlhandler,
|
||||
'INIMAGE': BaseExceptionHandler.inimagehandler,
|
||||
'BLANK': BaseExceptionHandler.blankhandler,
|
||||
'HTML': BaseExceptionHandler.htmlhandler}
|
||||
|
||||
defaulthandler = 'XML'
|
|
@ -1,106 +0,0 @@
|
|||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
#
|
||||
# Copyright (C) 2006 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik 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
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""WSGI application wrapper for Mapnik OGC WMS Server."""
|
||||
|
||||
from exceptions import OGCException, ServerConfigurationError
|
||||
from configparser import SafeConfigParser
|
||||
from cgi import parse_qs
|
||||
from wms111 import ExceptionHandler as ExceptionHandler111
|
||||
from wms130 import ExceptionHandler as ExceptionHandler130
|
||||
from common import Version
|
||||
|
||||
class WSGIApp:
|
||||
|
||||
def __init__(self, configpath):
|
||||
conf = SafeConfigParser()
|
||||
conf.readfp(open(configpath))
|
||||
self.conf = conf
|
||||
if not conf.has_option_with_value('server', 'module'):
|
||||
raise ServerConfigurationError('The factory module is not defined in the configuration file.')
|
||||
try:
|
||||
mapfactorymodule = __import__(conf.get('server', 'module'))
|
||||
except ImportError:
|
||||
raise ServerConfigurationError('The factory module could not be loaded.')
|
||||
if hasattr(mapfactorymodule, 'WMSFactory'):
|
||||
self.mapfactory = getattr(mapfactorymodule, 'WMSFactory')()
|
||||
else:
|
||||
raise ServerConfigurationError('The factory module does not have a WMSFactory class.')
|
||||
if conf.has_option('server', 'debug'):
|
||||
self.debug = int(conf.get('server', 'debug'))
|
||||
else:
|
||||
self.debug = 0
|
||||
if self.conf.has_option_with_value('server', 'maxage'):
|
||||
self.max_age = 'max-age=%d' % self.conf.get('server', 'maxage')
|
||||
else:
|
||||
self.max_age = None
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
reqparams = {}
|
||||
for key, value in parse_qs(environ['QUERY_STRING'], True).items():
|
||||
reqparams[key.lower()] = value[0]
|
||||
onlineresource = 'http://%s:%s%s?' % (environ['SERVER_NAME'], environ['SERVER_PORT'], environ['PATH_INFO'])
|
||||
try:
|
||||
if not reqparams.has_key('request'):
|
||||
raise OGCException('Missing request parameter.')
|
||||
request = reqparams['request']
|
||||
del reqparams['request']
|
||||
if request == 'GetCapabilities' and not reqparams.has_key('service'):
|
||||
raise OGCException('Missing service parameter.')
|
||||
if request in ['GetMap', 'GetFeatureInfo']:
|
||||
service = 'WMS'
|
||||
else:
|
||||
service = reqparams['service']
|
||||
if reqparams.has_key('service'):
|
||||
del reqparams['service']
|
||||
try:
|
||||
mapnikmodule = __import__('mapnik2.ogcserver.' + service)
|
||||
except:
|
||||
raise OGCException('Unsupported service "%s".' % service)
|
||||
ServiceHandlerFactory = getattr(mapnikmodule.ogcserver, service).ServiceHandlerFactory
|
||||
servicehandler = ServiceHandlerFactory(self.conf, self.mapfactory, onlineresource, reqparams.get('version', None))
|
||||
if reqparams.has_key('version'):
|
||||
del reqparams['version']
|
||||
if request not in servicehandler.SERVICE_PARAMS.keys():
|
||||
raise OGCException('Operation "%s" not supported.' % request, 'OperationNotSupported')
|
||||
ogcparams = servicehandler.processParameters(request, reqparams)
|
||||
try:
|
||||
requesthandler = getattr(servicehandler, request)
|
||||
except:
|
||||
raise OGCException('Operation "%s" not supported.' % request, 'OperationNotSupported')
|
||||
response = requesthandler(ogcparams)
|
||||
except:
|
||||
version = reqparams.get('version', None)
|
||||
if not version:
|
||||
version = Version('1.3.0')
|
||||
else:
|
||||
version = Version(version)
|
||||
if version >= '1.3.0':
|
||||
eh = ExceptionHandler130(self.debug)
|
||||
else:
|
||||
eh = ExceptionHandler111(self.debug)
|
||||
response = eh.getresponse(reqparams)
|
||||
response_headers = [('Content-Type', response.content_type),('Content-Length', str(len(response.content)))]
|
||||
if self.max_age:
|
||||
response_headers.append(('Cache-Control', max_age))
|
||||
start_response('200 OK', response_headers)
|
||||
yield response.content
|
||||
|
|
@ -4,17 +4,18 @@
|
|||
|
||||
basic usage is along the lines of
|
||||
|
||||
import mapnik2
|
||||
import mapnik
|
||||
|
||||
page = mapnik2.printing.PDFPrinter()
|
||||
m = mapnik2.Map(100,100)
|
||||
mapnik2.load_map(m, "my_xml_map_description", True)
|
||||
page = mapnik.printing.PDFPrinter()
|
||||
m = mapnik.Map(100,100)
|
||||
mapnik.load_map(m, "my_xml_map_description", True)
|
||||
m.zoom_all()
|
||||
page.render_map(m,"my_output_file.pdf")
|
||||
|
||||
see the documentation of mapnik2.printing.PDFPrinter() for options
|
||||
see the documentation of mapnik.printing.PDFPrinter() for options
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from . import render, Map, Box2d, MemoryDatasource, Layer, Feature, Projection, ProjTransform, Coord, Style, Rule, Geometry2d
|
||||
import math
|
||||
|
|
27
bindings/python/mapnik2/__init__.py
Normal file
27
bindings/python/mapnik2/__init__.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# This file is part of Mapnik (C++/Python mapping toolkit)
|
||||
# Copyright (C) 2011 Artem Pavlenko
|
||||
#
|
||||
# Mapnik is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or any later version.
|
||||
#
|
||||
# This program 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 General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
|
||||
# mapnik2 module (Deprecated)
|
||||
|
||||
import warnings
|
||||
from mapnik import *
|
||||
warnings.simplefilter("default")
|
||||
msg=""" mapnik2 module has been deprecated,
|
||||
please use 'import mapnik' """
|
||||
warnings.warn(msg, DeprecationWarning)
|
|
@ -46,7 +46,7 @@ public:
|
|||
enumeration_(const char * python_alias, const char * doc) :
|
||||
base_type( python_alias, doc )
|
||||
#else
|
||||
enumeration_(const char * python_alias, const char * /*doc*/) :
|
||||
enumeration_(const char * python_alias, const char * /*doc*/) :
|
||||
// Boost.Python < 1.35.0 doesn't support
|
||||
// docstrings for enums so we ignore it.
|
||||
base_type( python_alias )
|
||||
|
|
|
@ -264,7 +264,6 @@ void export_envelope()
|
|||
.def(self == self) // __eq__
|
||||
.def(self != self) // __neq__
|
||||
.def(self + self) // __add__
|
||||
//.def(self - self) // __sub__
|
||||
.def(self * float()) // __mult__
|
||||
.def(float() * self)
|
||||
.def(self / float()) // __div__
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
#include "mapnik_value_converter.hpp"
|
||||
|
||||
mapnik::geometry_type & (mapnik::Feature::*get_geom1)(unsigned) = &mapnik::Feature::get_geometry;
|
||||
|
||||
|
@ -59,7 +58,7 @@ void feature_add_geometries_from_wkt(Feature &feature, std::string wkt)
|
|||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// Forward declaration
|
||||
// Forward declaration
|
||||
template <class Container, bool NoProxy, class DerivedPolicies>
|
||||
class map_indexing_suite2;
|
||||
|
||||
|
@ -95,9 +94,11 @@ namespace boost { namespace python {
|
|||
|
||||
template <class Class>
|
||||
static void
|
||||
extension_def(Class& /*cl*/)
|
||||
extension_def(Class& cl)
|
||||
{
|
||||
|
||||
cl
|
||||
.def("get", &get)
|
||||
;
|
||||
}
|
||||
|
||||
static data_type&
|
||||
|
@ -106,12 +107,25 @@ namespace boost { namespace python {
|
|||
typename Container::iterator i = container.props().find(i_);
|
||||
if (i == container.end())
|
||||
{
|
||||
PyErr_SetString(PyExc_KeyError, "Invalid key");
|
||||
PyErr_SetString(PyExc_KeyError, i_.c_str());
|
||||
throw_error_already_set();
|
||||
}
|
||||
// will be auto-converted to proper python type by `mapnik_value_to_python`
|
||||
return i->second;
|
||||
}
|
||||
|
||||
static data_type
|
||||
get(Container& container, index_type i_)
|
||||
{
|
||||
typename Container::iterator i = container.props().find(i_);
|
||||
if (i != container.end())
|
||||
{
|
||||
// will be auto-converted to proper python type by `mapnik_value_to_python`
|
||||
return i->second;
|
||||
}
|
||||
return mapnik::value_null();
|
||||
}
|
||||
|
||||
static void
|
||||
set_item(Container& container, index_type i, data_type const& v)
|
||||
{
|
||||
|
|
|
@ -71,15 +71,15 @@ void export_featureset()
|
|||
.def("__iter__",pass_through)
|
||||
.def("next",next)
|
||||
.add_property("features",features,
|
||||
"The list of features.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> m.query_map_point(0, 10, 10)\n"
|
||||
"<mapnik2._mapnik2.Featureset object at 0x1004d2938>\n"
|
||||
">>> fs = m.query_map_point(0, 10, 10)\n"
|
||||
">>> for f in fs.features:\n"
|
||||
">>> print f\n"
|
||||
"<mapnik2.Feature object at 0x105e64140>\n"
|
||||
"The list of features.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> m.query_map_point(0, 10, 10)\n"
|
||||
"<mapnik._mapnik.Featureset object at 0x1004d2938>\n"
|
||||
">>> fs = m.query_map_point(0, 10, 10)\n"
|
||||
">>> for f in fs.features:\n"
|
||||
">>> print f\n"
|
||||
"<mapnik.Feature object at 0x105e64140>\n"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/util/geometry_to_wkb.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -47,19 +48,47 @@ geometry_type const& getitem_impl(path_type & p, int key)
|
|||
throw boost::python::error_already_set();
|
||||
}
|
||||
|
||||
void from_wkt_impl(path_type& p, std::string const& wkt)
|
||||
void add_wkt_impl(path_type& p, std::string const& wkt)
|
||||
{
|
||||
bool result = mapnik::from_wkt(wkt, p);
|
||||
bool result = mapnik::from_wkt(wkt , p);
|
||||
if (!result) throw std::runtime_error("Failed to parse WKT");
|
||||
}
|
||||
|
||||
void from_wkb_impl(path_type& p, std::string const& wkb)
|
||||
void add_wkb_impl(path_type& p, std::string const& wkb)
|
||||
{
|
||||
mapnik::geometry_utils::from_wkb(p, wkb.c_str(), wkb.size(), true);
|
||||
}
|
||||
|
||||
boost::shared_ptr<path_type> from_wkt_impl(std::string const& wkt)
|
||||
{
|
||||
boost::shared_ptr<path_type> paths = boost::make_shared<path_type>();
|
||||
bool result = mapnik::from_wkt(wkt, *paths);
|
||||
if (!result) throw std::runtime_error("Failed to parse WKT");
|
||||
return paths;
|
||||
}
|
||||
|
||||
boost::shared_ptr<path_type> from_wkb_impl(std::string const& wkb)
|
||||
{
|
||||
boost::shared_ptr<path_type> paths = boost::make_shared<path_type>();
|
||||
mapnik::geometry_utils::from_wkb(*paths, wkb.c_str(), wkb.size(), true);
|
||||
return paths;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PyObject* to_wkb( geometry_type const& geom)
|
||||
{
|
||||
mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,mapnik::util::wkbXDR);
|
||||
return
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
::PyBytes_FromStringAndSize
|
||||
#else
|
||||
::PyString_FromStringAndSize
|
||||
#endif
|
||||
((const char*)wkb->buffer(),wkb->size());
|
||||
}
|
||||
|
||||
|
||||
void export_geometry()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
@ -74,19 +103,23 @@ void export_geometry()
|
|||
;
|
||||
|
||||
using mapnik::geometry_type;
|
||||
class_<geometry_type, std::auto_ptr<geometry_type>,boost::noncopyable>("Geometry2d",no_init)
|
||||
class_<geometry_type, std::auto_ptr<geometry_type>, boost::noncopyable>("Geometry2d",no_init)
|
||||
.def("envelope",&geometry_type::envelope)
|
||||
// .def("__str__",&geometry_type::to_string)
|
||||
.def("type",&geometry_type::type)
|
||||
.def("area",&geometry_type::area)
|
||||
.def("to_wkb",&to_wkb)
|
||||
// TODO add other geometry_type methods
|
||||
;
|
||||
|
||||
class_<path_type,boost::noncopyable>("Path")
|
||||
class_<path_type, boost::shared_ptr<path_type>, boost::noncopyable>("Path")
|
||||
.def("__getitem__", getitem_impl,return_value_policy<reference_existing_object>())
|
||||
.def("__len__", &path_type::size)
|
||||
.def("add_wkt",add_wkt_impl)
|
||||
.def("add_wkb",add_wkb_impl)
|
||||
.def("from_wkt",from_wkt_impl)
|
||||
.def("from_wkb",from_wkb_impl)
|
||||
.staticmethod("from_wkt")
|
||||
.staticmethod("from_wkb")
|
||||
;
|
||||
|
||||
}
|
||||
|
|
|
@ -43,10 +43,10 @@ bool painted(mapnik::grid const& grid)
|
|||
void export_grid()
|
||||
{
|
||||
class_<mapnik::grid,boost::shared_ptr<mapnik::grid> >(
|
||||
"Grid",
|
||||
"This class represents a feature hitgrid.",
|
||||
init<int,int,std::string,unsigned>(
|
||||
( arg("width"),arg("height"),arg("key")="__id__",arg("resolution")=1 ),
|
||||
"Grid",
|
||||
"This class represents a feature hitgrid.",
|
||||
init<int,int,std::string,unsigned>(
|
||||
( boost::python::arg("width"), boost::python::arg("height"),boost::python::arg("key")="__id__", boost::python::arg("resolution")=1 ),
|
||||
"Create a mapnik.Grid object\n"
|
||||
))
|
||||
.def("painted",&painted)
|
||||
|
@ -54,16 +54,16 @@ void export_grid()
|
|||
.def("height",&mapnik::grid::height)
|
||||
.def("view",&mapnik::grid::get_view)
|
||||
.def("encode",encode,
|
||||
( arg("encoding")="utf",arg("features")=true,arg("resolution")=4 ),
|
||||
"Encode the grid as as optimized json\n"
|
||||
( boost::python::arg("encoding")="utf", boost::python::arg("features")=true,boost::python::arg("resolution")=4 ),
|
||||
"Encode the grid as as optimized json\n"
|
||||
)
|
||||
.add_property("key",
|
||||
make_function(&mapnik::grid::get_key,return_value_policy<copy_const_reference>()),
|
||||
&mapnik::grid::set_key,
|
||||
"Get/Set key to be used as unique indentifier for features\n"
|
||||
"The value should either be __id__ to refer to the feature.id()\n"
|
||||
"or some globally unique integer or string attribute field\n"
|
||||
)
|
||||
make_function(&mapnik::grid::get_key,return_value_policy<copy_const_reference>()),
|
||||
&mapnik::grid::set_key,
|
||||
"Get/Set key to be used as unique indentifier for features\n"
|
||||
"The value should either be __id__ to refer to the feature.id()\n"
|
||||
"or some globally unique integer or string attribute field\n"
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
|
|
|
@ -40,13 +40,13 @@ static dict (*encode)( mapnik::grid_view const&, std::string, bool, unsigned int
|
|||
void export_grid_view()
|
||||
{
|
||||
class_<mapnik::grid_view,
|
||||
boost::shared_ptr<mapnik::grid_view> >("GridView",
|
||||
"This class represents a feature hitgrid subset.",no_init)
|
||||
boost::shared_ptr<mapnik::grid_view> >("GridView",
|
||||
"This class represents a feature hitgrid subset.",no_init)
|
||||
.def("width",&mapnik::grid_view::width)
|
||||
.def("height",&mapnik::grid_view::height)
|
||||
.def("encode",encode,
|
||||
( arg("encoding")="utf",arg("add_features")=true,arg("resolution")=4 ),
|
||||
"Encode the grid as as optimized json\n"
|
||||
( boost::python::arg("encoding")="utf",boost::python::arg("add_features")=true,boost::python::arg("resolution")=4 ),
|
||||
"Encode the grid as as optimized json\n"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ PyObject* tostring2(image_32 const & im, std::string const& format)
|
|||
#else
|
||||
::PyString_FromStringAndSize
|
||||
#endif
|
||||
(s.data(),s.size());
|
||||
(s.data(),s.size());
|
||||
}
|
||||
|
||||
PyObject* tostring3(image_32 const & im, std::string const& format, mapnik::rgba_palette const& pal)
|
||||
|
@ -98,7 +98,7 @@ PyObject* tostring3(image_32 const & im, std::string const& format, mapnik::rgba
|
|||
#else
|
||||
::PyString_FromStringAndSize
|
||||
#endif
|
||||
(s.data(),s.size());
|
||||
(s.data(),s.size());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,34 +35,34 @@ using mapnik::metawriter_inmem_ptr;
|
|||
namespace {
|
||||
std::map<std::string, mapnik::value>::const_iterator
|
||||
mapnik_value_map_begin(const std::map<std::string, mapnik::value> &m) {
|
||||
return m.begin();
|
||||
return m.begin();
|
||||
}
|
||||
|
||||
std::map<std::string, mapnik::value>::const_iterator
|
||||
mapnik_value_map_end(const std::map<std::string, mapnik::value> &m) {
|
||||
return m.end();
|
||||
return m.end();
|
||||
}
|
||||
}
|
||||
|
||||
void export_inmem_metawriter() {
|
||||
using namespace boost::python;
|
||||
using namespace boost::python;
|
||||
|
||||
class_<std::map<std::string, mapnik::value> >
|
||||
("MapnikProperties", "Retarded.", init<>())
|
||||
.def("__iter__", range(&mapnik_value_map_begin, &mapnik_value_map_end))
|
||||
;
|
||||
class_<std::map<std::string, mapnik::value> >
|
||||
("MapnikProperties", "Retarded.", init<>())
|
||||
.def("__iter__", range(&mapnik_value_map_begin, &mapnik_value_map_end))
|
||||
;
|
||||
|
||||
class_<metawriter_inmem::meta_instance>
|
||||
("MetaInstance", "Single rendered instance of meta-information.", no_init)
|
||||
.def_readonly("box", &metawriter_inmem::meta_instance::box)
|
||||
.def_readonly("properties", &metawriter_inmem::meta_instance::properties)
|
||||
;
|
||||
class_<metawriter_inmem::meta_instance>
|
||||
("MetaInstance", "Single rendered instance of meta-information.", no_init)
|
||||
.def_readonly("box", &metawriter_inmem::meta_instance::box)
|
||||
.def_readonly("properties", &metawriter_inmem::meta_instance::properties)
|
||||
;
|
||||
|
||||
class_<metawriter_inmem, metawriter_inmem_ptr, boost::noncopyable>
|
||||
("MetaWriterInMem",
|
||||
"Collects meta-information about elements rendered.",
|
||||
no_init)
|
||||
.def("__iter__", range(&metawriter_inmem::inst_begin,
|
||||
&metawriter_inmem::inst_end))
|
||||
;
|
||||
class_<metawriter_inmem, metawriter_inmem_ptr, boost::noncopyable>
|
||||
("MetaWriterInMem",
|
||||
"Collects meta-information about elements rendered.",
|
||||
no_init)
|
||||
.def("__iter__", range(&metawriter_inmem::inst_begin,
|
||||
&metawriter_inmem::inst_end))
|
||||
;
|
||||
}
|
||||
|
|
123
bindings/python/mapnik_label_collision_detector.cpp
Normal file
123
bindings/python/mapnik_label_collision_detector.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <mapnik/label_collision_detector.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
|
||||
#include <list>
|
||||
|
||||
using mapnik::label_collision_detector4;
|
||||
using mapnik::box2d;
|
||||
using mapnik::Map;
|
||||
using boost::make_shared;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
boost::shared_ptr<label_collision_detector4>
|
||||
create_label_collision_detector_from_extent(box2d<double> const &extent)
|
||||
{
|
||||
return make_shared<label_collision_detector4>(extent);
|
||||
}
|
||||
|
||||
boost::shared_ptr<label_collision_detector4>
|
||||
create_label_collision_detector_from_map(Map const &m)
|
||||
{
|
||||
double buffer = m.buffer_size();
|
||||
box2d<double> extent(-buffer, -buffer, m.width() + buffer, m.height() + buffer);
|
||||
return make_shared<label_collision_detector4>(extent);
|
||||
}
|
||||
|
||||
boost::python::list
|
||||
make_label_boxes(boost::shared_ptr<label_collision_detector4> det)
|
||||
{
|
||||
boost::python::list boxes;
|
||||
|
||||
for (label_collision_detector4::query_iterator jtr = det->begin();
|
||||
jtr != det->end(); ++jtr)
|
||||
{
|
||||
boxes.append<box2d<double> >(jtr->box);
|
||||
}
|
||||
|
||||
return boxes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void export_label_collision_detector()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
// for overload resolution
|
||||
void (label_collision_detector4::*insert_box)(box2d<double> const &) = &label_collision_detector4::insert;
|
||||
|
||||
class_<label_collision_detector4, boost::shared_ptr<label_collision_detector4>, boost::noncopyable>
|
||||
("LabelCollisionDetector",
|
||||
"Object to detect collisions between labels, used in the rendering process.",
|
||||
no_init)
|
||||
|
||||
.def("__init__", make_constructor(create_label_collision_detector_from_extent),
|
||||
"Creates an empty collision detection object with a given extent. Note "
|
||||
"that the constructor from Map objects is a sensible default and usually "
|
||||
"what you want to do.\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
">>> m = Map(size_x, size_y)\n"
|
||||
">>> buf_sz = m.buffer_size\n"
|
||||
">>> extent = mapnik.Box2d(-buf_sz, -buf_sz, m.width + buf_sz, m.height + buf_sz)\n"
|
||||
">>> detector = mapnik.LabelCollisionDetector(extent)")
|
||||
|
||||
.def("__init__", make_constructor(create_label_collision_detector_from_map),
|
||||
"Creates an empty collision detection object matching the given Map object. "
|
||||
"The created detector will have the same size, including the buffer, as the "
|
||||
"map object. This is usually what you want to do.\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
">>> m = Map(size_x, size_y)\n"
|
||||
">>> detector = mapnik.LabelCollisionDetector(m)")
|
||||
|
||||
.def("extent", &label_collision_detector4::extent, return_value_policy<copy_const_reference>(),
|
||||
"Returns the total extent (bounding box) of all labels inside the detector.\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
">>> detector.extent()\n"
|
||||
"Box2d(573.252589209,494.789179821,584.261023823,496.83610261)")
|
||||
|
||||
.def("boxes", &make_label_boxes,
|
||||
"Returns a list of all the label boxes inside the detector.")
|
||||
|
||||
.def("insert", insert_box,
|
||||
"Insert a 2d box into the collision detector. This can be used to ensure that "
|
||||
"some space is left clear on the map for later overdrawing, for example by "
|
||||
"non-Mapnik processes.\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
">>> m = Map(size_x, size_y)\n"
|
||||
">>> detector = mapnik.LabelCollisionDetector(m)"
|
||||
">>> detector.insert(mapnik.Box2d(196, 254, 291, 389))")
|
||||
;
|
||||
}
|
|
@ -70,8 +70,8 @@ void export_line_pattern_symbolizer()
|
|||
("<image file expression>"))
|
||||
//.def_pickle(line_pattern_symbolizer_pickle_suite())
|
||||
.add_property("transform",
|
||||
mapnik::get_svg_transform<line_pattern_symbolizer>,
|
||||
mapnik::set_svg_transform<line_pattern_symbolizer>)
|
||||
mapnik::get_svg_transform<line_pattern_symbolizer>,
|
||||
mapnik::set_svg_transform<line_pattern_symbolizer>)
|
||||
.add_property("filename",
|
||||
&get_filename,
|
||||
&set_filename)
|
||||
|
|
|
@ -119,6 +119,8 @@ struct map_pickle_suite : boost::python::pickle_suite
|
|||
std::vector<layer>& (Map::*layers_nonconst)() = &Map::layers;
|
||||
std::vector<layer> const& (Map::*layers_const)() const = &Map::layers;
|
||||
|
||||
mapnik::parameters& (Map::*attr_nonconst)() = &Map::get_extra_attributes;
|
||||
mapnik::parameters& (Map::*params_nonconst)() = &Map::get_extra_parameters;
|
||||
|
||||
mapnik::feature_type_style find_style (mapnik::Map const& m, std::string const& name)
|
||||
{
|
||||
|
@ -141,14 +143,14 @@ bool has_metawriter(mapnik::Map const& m)
|
|||
// returns empty shared_ptr when the metawriter isn't found, or is
|
||||
// of the wrong type. empty pointers make it back to Python as a None.
|
||||
mapnik::metawriter_inmem_ptr find_inmem_metawriter(const mapnik::Map &m, const std::string &name) {
|
||||
mapnik::metawriter_ptr metawriter = m.find_metawriter(name);
|
||||
mapnik::metawriter_inmem_ptr inmem;
|
||||
mapnik::metawriter_ptr metawriter = m.find_metawriter(name);
|
||||
mapnik::metawriter_inmem_ptr inmem;
|
||||
|
||||
if (metawriter) {
|
||||
inmem = boost::dynamic_pointer_cast<mapnik::metawriter_inmem>(metawriter);
|
||||
}
|
||||
if (metawriter) {
|
||||
inmem = boost::dynamic_pointer_cast<mapnik::metawriter_inmem>(metawriter);
|
||||
}
|
||||
|
||||
return inmem;
|
||||
return inmem;
|
||||
}
|
||||
|
||||
// TODO - we likely should allow indexing by negative number from python
|
||||
|
@ -173,6 +175,7 @@ mapnik::featureset_ptr query_map_point(mapnik::Map const& m, int index, double x
|
|||
return m.query_map_point(idx, x, y);
|
||||
}
|
||||
|
||||
|
||||
void export_map()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
@ -418,38 +421,39 @@ void export_map()
|
|||
">>> m.zoom_to_box(extent)\n"
|
||||
)
|
||||
.def("get_metawriter_property", &Map::get_metawriter_property,
|
||||
(arg("name")),
|
||||
"Reads a metawriter property.\n"
|
||||
"These properties are completely user-defined and can be used to"
|
||||
"create filenames, etc.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> map.set_metawriter_property(\"x\", \"10\")\n"
|
||||
">>> map.get_metawriter_property(\"x\")\n"
|
||||
"10\n"
|
||||
)
|
||||
(arg("name")),
|
||||
"Reads a metawriter property.\n"
|
||||
"These properties are completely user-defined and can be used to"
|
||||
"create filenames, etc.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> map.set_metawriter_property(\"x\", \"10\")\n"
|
||||
">>> map.get_metawriter_property(\"x\")\n"
|
||||
"10\n"
|
||||
)
|
||||
.def("set_metawriter_property", &Map::set_metawriter_property,
|
||||
(arg("name"),arg("value")),
|
||||
"Sets a metawriter property.\n"
|
||||
"These properties are completely user-defined and can be used to"
|
||||
"create filenames, etc.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> map.set_metawriter_property(\"x\", str(x))\n"
|
||||
">>> map.set_metawriter_property(\"y\", str(y))\n"
|
||||
">>> map.set_metawriter_property(\"z\", str(z))\n"
|
||||
"\n"
|
||||
"Use a path like \"[z]/[x]/[y].json\" to create filenames.\n"
|
||||
)
|
||||
(arg("name"),arg("value")),
|
||||
"Sets a metawriter property.\n"
|
||||
"These properties are completely user-defined and can be used to"
|
||||
"create filenames, etc.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> map.set_metawriter_property(\"x\", str(x))\n"
|
||||
">>> map.set_metawriter_property(\"y\", str(y))\n"
|
||||
">>> map.set_metawriter_property(\"z\", str(z))\n"
|
||||
"\n"
|
||||
"Use a path like \"[z]/[x]/[y].json\" to create filenames.\n"
|
||||
)
|
||||
.def("find_inmem_metawriter", find_inmem_metawriter,
|
||||
(arg("name")),
|
||||
"Gets an inmem metawriter, or None if no such metawriter "
|
||||
"exists.\n"
|
||||
"Use this after the map has been rendered to retrieve information "
|
||||
"about the hit areas rendered on the map.\n"
|
||||
)
|
||||
(arg("name")),
|
||||
"Gets an inmem metawriter, or None if no such metawriter "
|
||||
"exists.\n"
|
||||
"Use this after the map has been rendered to retrieve information "
|
||||
"about the hit areas rendered on the map.\n"
|
||||
)
|
||||
|
||||
.def("extra_attributes",&Map::get_extra_attributes,return_value_policy<copy_const_reference>(),"TODO")
|
||||
.add_property("extra_attributes",make_function(attr_nonconst,return_value_policy<reference_existing_object>()),"TODO")
|
||||
.add_property("parameters",make_function(params_nonconst,return_value_policy<reference_existing_object>()),"TODO")
|
||||
|
||||
.add_property("aspect_fix_mode",
|
||||
&Map::get_aspect_fix_mode,
|
||||
|
|
|
@ -89,7 +89,7 @@ void export_markers_symbolizer()
|
|||
using namespace boost::python;
|
||||
|
||||
class_<markers_symbolizer>("MarkersSymbolizer",
|
||||
init<>("Default Markers Symbolizer - blue arrow"))
|
||||
init<>("Default Markers Symbolizer - blue arrow"))
|
||||
.def (init<mapnik::path_expression_ptr>("<path expression ptr>"))
|
||||
//.def_pickle(markers_symbolizer_pickle_suite())
|
||||
.add_property("filename",
|
||||
|
|
|
@ -44,10 +44,10 @@ void export_palette ()
|
|||
{
|
||||
using namespace boost::python;
|
||||
class_<boost::shared_ptr<mapnik::rgba_palette> >("Palette",no_init)
|
||||
/*, init<std::string,std::string>(
|
||||
( arg("palette"), arg("type")),
|
||||
"Creates a new color palette from a file\n"
|
||||
)*/
|
||||
.def( "__init__", boost::python::make_constructor( &make_palette))
|
||||
;
|
||||
/*, init<std::string,std::string>(
|
||||
( arg("palette"), arg("type")),
|
||||
"Creates a new color palette from a file\n"
|
||||
)*/
|
||||
.def( "__init__", boost::python::make_constructor(make_palette))
|
||||
;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -19,50 +19,26 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
//$Id: mapnik_parameters.cpp 17 2005-03-08 23:58:43Z pavlenko $
|
||||
|
||||
// boost
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/params.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/value.hpp>
|
||||
|
||||
using mapnik::parameter;
|
||||
using mapnik::parameters;
|
||||
|
||||
struct pickle_value : public boost::static_visitor<>
|
||||
{
|
||||
public:
|
||||
pickle_value( boost::python::list vals):
|
||||
vals_(vals) {}
|
||||
|
||||
void operator () ( int val )
|
||||
{
|
||||
vals_.append(val);
|
||||
}
|
||||
|
||||
void operator () ( double val )
|
||||
{
|
||||
vals_.append(val);
|
||||
}
|
||||
|
||||
void operator () ( std::string val )
|
||||
{
|
||||
vals_.append(val);
|
||||
}
|
||||
|
||||
private:
|
||||
boost::python::list vals_;
|
||||
|
||||
};
|
||||
|
||||
struct parameter_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static boost::python::tuple
|
||||
getinitargs(const parameter& p)
|
||||
{
|
||||
using namespace boost::python;
|
||||
return boost::python::make_tuple(p.first,boost::get<std::string>(p.second));
|
||||
return boost::python::make_tuple(p.first,p.second);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -76,11 +52,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite
|
|||
parameters::const_iterator pos=p.begin();
|
||||
while(pos!=p.end())
|
||||
{
|
||||
boost::python::list vals;
|
||||
pickle_value serializer( vals );
|
||||
mapnik::value_holder val = pos->second;
|
||||
boost::apply_visitor( serializer, val );
|
||||
d[pos->first] = vals[0];
|
||||
d[pos->first] = pos->second;
|
||||
++pos;
|
||||
}
|
||||
return boost::python::make_tuple(d);
|
||||
|
@ -107,7 +79,9 @@ struct parameters_pickle_suite : boost::python::pickle_suite
|
|||
extract<std::string> ex0(obj);
|
||||
extract<int> ex1(obj);
|
||||
extract<double> ex2(obj);
|
||||
extract<UnicodeString> ex3(obj);
|
||||
|
||||
// TODO - this is never hit - we need proper python string -> std::string to get invoked here
|
||||
if (ex0.check())
|
||||
{
|
||||
p[key] = ex0();
|
||||
|
@ -120,72 +94,131 @@ struct parameters_pickle_suite : boost::python::pickle_suite
|
|||
{
|
||||
p[key] = ex2();
|
||||
}
|
||||
|
||||
/*
|
||||
extract_value serializer( p, key );
|
||||
mapnik::value_holder val = extract<mapnik::value_holder>(d[key]);
|
||||
boost::apply_visitor( serializer, val );
|
||||
*/
|
||||
else if (ex3.check())
|
||||
{
|
||||
std::string buffer;
|
||||
mapnik::to_utf8(ex3(),buffer);
|
||||
p[key] = buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::clog << "could not unpickle key: " << key << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
boost::python::dict dict_params(parameters& p)
|
||||
|
||||
mapnik::value_holder get_params_by_key1(mapnik::parameters const& p, std::string const& key)
|
||||
{
|
||||
boost::python::dict d;
|
||||
parameters::const_iterator pos=p.begin();
|
||||
while(pos!=p.end())
|
||||
parameters::const_iterator pos = p.find(key);
|
||||
if (pos != p.end())
|
||||
{
|
||||
boost::python::list vals;
|
||||
pickle_value serializer( vals );
|
||||
mapnik::value_holder val = pos->second;
|
||||
boost::apply_visitor( serializer, val );
|
||||
d[pos->first] = vals[0];
|
||||
++pos;
|
||||
// will be auto-converted to proper python type by `mapnik_params_to_python`
|
||||
return pos->second;
|
||||
}
|
||||
return d;
|
||||
return mapnik::value_null();
|
||||
}
|
||||
|
||||
boost::python::list list_params(parameters& p)
|
||||
mapnik::value_holder get_params_by_key2(mapnik::parameters const& p, std::string const& key)
|
||||
{
|
||||
boost::python::list l;
|
||||
parameters::const_iterator pos=p.begin();
|
||||
while(pos!=p.end())
|
||||
parameters::const_iterator pos = p.find(key);
|
||||
if (pos == p.end())
|
||||
{
|
||||
boost::python::list vals;
|
||||
pickle_value serializer( vals );
|
||||
mapnik::value_holder val = pos->second;
|
||||
boost::apply_visitor( serializer, val );
|
||||
l.append(boost::python::make_tuple(pos->first,vals[0]));
|
||||
++pos;
|
||||
PyErr_SetString(PyExc_KeyError, key.c_str());
|
||||
boost::python::throw_error_already_set();
|
||||
}
|
||||
return l;
|
||||
// will be auto-converted to proper python type by `mapnik_params_to_python`
|
||||
return pos->second;
|
||||
}
|
||||
|
||||
boost::python::dict dict_param(parameter& p)
|
||||
mapnik::parameter get_params_by_index(mapnik::parameters const& p, int index)
|
||||
{
|
||||
boost::python::dict d;
|
||||
d[p.first] = boost::get<std::string>(p.second);
|
||||
return d;
|
||||
if (index < 0 || index > p.size())
|
||||
{
|
||||
PyErr_SetString(PyExc_IndexError, "Index is out of range");
|
||||
throw boost::python::error_already_set();
|
||||
}
|
||||
|
||||
parameters::const_iterator itr = p.begin();
|
||||
parameters::const_iterator end = p.end();
|
||||
|
||||
unsigned idx = 0;
|
||||
while (itr != p.end())
|
||||
{
|
||||
if (idx == index)
|
||||
{
|
||||
return *itr;
|
||||
}
|
||||
++idx;
|
||||
++itr;
|
||||
}
|
||||
PyErr_SetString(PyExc_IndexError, "Index is out of range");
|
||||
throw boost::python::error_already_set();
|
||||
}
|
||||
|
||||
boost::python::tuple tuple_param(parameter& p)
|
||||
void add_parameter(mapnik::parameters & p, mapnik::parameter const& param)
|
||||
{
|
||||
return boost::python::make_tuple(p.first,boost::get<std::string>(p.second));
|
||||
p[param.first] = param.second;
|
||||
}
|
||||
|
||||
mapnik::value_holder get_param(mapnik::parameter const& p, int index)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
return p.first;
|
||||
}
|
||||
else if (index == 1)
|
||||
{
|
||||
return p.second;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_IndexError, "Index is out of range");
|
||||
throw boost::python::error_already_set();
|
||||
}
|
||||
}
|
||||
|
||||
boost::shared_ptr<mapnik::parameter> create_parameter_from_string(std::string const& key, std::string const& value)
|
||||
{
|
||||
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
|
||||
}
|
||||
|
||||
boost::shared_ptr<mapnik::parameter> create_parameter_from_int(std::string const& key, int value)
|
||||
{
|
||||
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
|
||||
}
|
||||
|
||||
boost::shared_ptr<mapnik::parameter> create_parameter_from_float(std::string const& key, double value)
|
||||
{
|
||||
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
|
||||
}
|
||||
|
||||
|
||||
void export_parameters()
|
||||
{
|
||||
using namespace boost::python;
|
||||
class_<parameter>("Parameter",init<std::string,std::string>())
|
||||
class_<parameter,boost::shared_ptr<parameter> >("Parameter",no_init)
|
||||
.def("__init__", make_constructor(create_parameter_from_string),
|
||||
"Create a mapnik.Parameter from a pair of values, the first being a string\n"
|
||||
"and the second being either a string, and integer, or a float")
|
||||
.def("__init__", make_constructor(create_parameter_from_int),
|
||||
"Create a mapnik.Parameter from a pair of values, the first being a string\n"
|
||||
"and the second being either a string, and integer, or a float")
|
||||
.def("__init__", make_constructor(create_parameter_from_float),
|
||||
"Create a mapnik.Parameter from a pair of values, the first being a string\n"
|
||||
"and the second being either a string, and integer, or a float")
|
||||
.def_pickle(parameter_pickle_suite())
|
||||
.def("as_dict",dict_param)
|
||||
.def("as_tuple",tuple_param)
|
||||
.def("__getitem__",get_param)
|
||||
;
|
||||
|
||||
class_<parameters>("Parameters",init<>())
|
||||
.def_pickle(parameters_pickle_suite())
|
||||
.def("as_dict",dict_params)
|
||||
.def("as_list",list_params)
|
||||
.def("get",get_params_by_key1)
|
||||
.def("__getitem__",get_params_by_key2)
|
||||
.def("__getitem__",get_params_by_index)
|
||||
.def("__len__",¶meters::size)
|
||||
.def("append",add_parameter)
|
||||
.def("iteritems",iterator<parameters>())
|
||||
;
|
||||
}
|
||||
|
|
|
@ -97,12 +97,12 @@ void export_polygon_pattern_symbolizer()
|
|||
init<path_expression_ptr>("<path_expression_ptr>"))
|
||||
.def_pickle(polygon_pattern_symbolizer_pickle_suite())
|
||||
.add_property("alignment",
|
||||
&polygon_pattern_symbolizer::get_alignment,
|
||||
&polygon_pattern_symbolizer::set_alignment,
|
||||
"Set/get the alignment of the pattern")
|
||||
&polygon_pattern_symbolizer::get_alignment,
|
||||
&polygon_pattern_symbolizer::set_alignment,
|
||||
"Set/get the alignment of the pattern")
|
||||
.add_property("transform",
|
||||
mapnik::get_svg_transform<polygon_pattern_symbolizer>,
|
||||
mapnik::set_svg_transform<polygon_pattern_symbolizer>)
|
||||
mapnik::get_svg_transform<polygon_pattern_symbolizer>,
|
||||
mapnik::set_svg_transform<polygon_pattern_symbolizer>)
|
||||
.add_property("filename",
|
||||
&get_filename,
|
||||
&set_filename)
|
||||
|
|
|
@ -66,6 +66,7 @@ void export_view_transform();
|
|||
void export_raster_colorizer();
|
||||
void export_glyph_symbolizer();
|
||||
void export_inmem_metawriter();
|
||||
void export_label_collision_detector();
|
||||
|
||||
#include <mapnik/version.hpp>
|
||||
#include <mapnik/value_error.hpp>
|
||||
|
@ -82,47 +83,58 @@ void export_inmem_metawriter();
|
|||
#include <mapnik/value_error.hpp>
|
||||
#include <mapnik/save_map.hpp>
|
||||
#include "python_grid_utils.hpp"
|
||||
#include "mapnik_value_converter.hpp"
|
||||
|
||||
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
||||
#include <pycairo.h>
|
||||
static Pycairo_CAPI_t *Pycairo_CAPI;
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct mapnik_value_to_python
|
||||
{
|
||||
static PyObject* convert(mapnik::value const& v)
|
||||
{
|
||||
return boost::apply_visitor(value_converter(),v.base());
|
||||
}
|
||||
};
|
||||
}}
|
||||
|
||||
void render(const mapnik::Map& map,
|
||||
mapnik::image_32& image,
|
||||
mapnik::image_32& image,
|
||||
double scale_factor = 1.0,
|
||||
unsigned offset_x = 0u,
|
||||
unsigned offset_y = 0u)
|
||||
{
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
try
|
||||
{
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(map,image,scale_factor,offset_x, offset_y);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
|
||||
void render_with_detector(
|
||||
const mapnik::Map &map,
|
||||
mapnik::image_32 &image,
|
||||
boost::shared_ptr<mapnik::label_collision_detector4> detector,
|
||||
double scale_factor = 1.0,
|
||||
unsigned offset_x = 0u,
|
||||
unsigned offset_y = 0u)
|
||||
{
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
try
|
||||
{
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(map,image,scale_factor,offset_x, offset_y);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(map,image,detector);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
}
|
||||
|
||||
void render_layer2(const mapnik::Map& map,
|
||||
mapnik::image_32& image,
|
||||
unsigned layer_idx)
|
||||
mapnik::image_32& image,
|
||||
unsigned layer_idx)
|
||||
{
|
||||
std::vector<mapnik::layer> const& layers = map.layers();
|
||||
std::size_t layer_num = layers.size();
|
||||
|
@ -134,96 +146,96 @@ void render_layer2(const mapnik::Map& map,
|
|||
}
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
try
|
||||
{
|
||||
mapnik::layer const& layer = layers[layer_idx];
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(map,image,1.0,0,0);
|
||||
std::set<std::string> names;
|
||||
ren.apply(layer,names);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
mapnik::layer const& layer = layers[layer_idx];
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(map,image,1.0,0,0);
|
||||
std::set<std::string> names;
|
||||
ren.apply(layer,names);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
||||
|
||||
void render3(const mapnik::Map& map,
|
||||
PycairoSurface* surface,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0)
|
||||
PycairoSurface* surface,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0)
|
||||
{
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
|
||||
mapnik::cairo_renderer<Cairo::Surface> ren(map,s,offset_x, offset_y);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
|
||||
mapnik::cairo_renderer<Cairo::Surface> ren(map,s,offset_x, offset_y);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
}
|
||||
|
||||
void render4(const mapnik::Map& map, PycairoSurface* surface)
|
||||
{
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
|
||||
mapnik::cairo_renderer<Cairo::Surface> ren(map,s);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
|
||||
mapnik::cairo_renderer<Cairo::Surface> ren(map,s);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
}
|
||||
|
||||
void render5(const mapnik::Map& map,
|
||||
PycairoContext* context,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0)
|
||||
PycairoContext* context,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0)
|
||||
{
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx));
|
||||
mapnik::cairo_renderer<Cairo::Context> ren(map,c,offset_x, offset_y);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx));
|
||||
mapnik::cairo_renderer<Cairo::Context> ren(map,c,offset_x, offset_y);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
}
|
||||
|
||||
void render6(const mapnik::Map& map, PycairoContext* context)
|
||||
{
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx));
|
||||
mapnik::cairo_renderer<Cairo::Context> ren(map,c);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx));
|
||||
mapnik::cairo_renderer<Cairo::Context> ren(map,c);
|
||||
ren.apply();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Py_BLOCK_THREADS
|
||||
throw;
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -282,7 +294,7 @@ void render_to_file3(const mapnik::Map& map,
|
|||
const std::string& filename,
|
||||
const std::string& format,
|
||||
double scale_factor = 1.0
|
||||
)
|
||||
)
|
||||
{
|
||||
if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24")
|
||||
{
|
||||
|
@ -319,22 +331,13 @@ unsigned mapnik_version()
|
|||
return MAPNIK_VERSION;
|
||||
}
|
||||
|
||||
unsigned mapnik_svn_revision()
|
||||
{
|
||||
#if defined(SVN_REVISION)
|
||||
return SVN_REVISION;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// indicator for jpeg read/write support within libmapnik
|
||||
bool has_jpeg()
|
||||
{
|
||||
#if defined(HAVE_JPEG)
|
||||
return true;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -374,8 +377,9 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(load_map_string_overloads, load_map_string, 2, 4
|
|||
BOOST_PYTHON_FUNCTION_OVERLOADS(save_map_overloads, save_map, 2, 3)
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(save_map_to_string_overloads, save_map_to_string, 1, 2)
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(render_overloads, render, 2, 5)
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(render_with_detector_overloads, render_with_detector, 3, 6)
|
||||
|
||||
BOOST_PYTHON_MODULE(_mapnik2)
|
||||
BOOST_PYTHON_MODULE(_mapnik)
|
||||
{
|
||||
|
||||
using namespace boost::python;
|
||||
|
@ -427,15 +431,16 @@ BOOST_PYTHON_MODULE(_mapnik2)
|
|||
export_raster_colorizer();
|
||||
export_glyph_symbolizer();
|
||||
export_inmem_metawriter();
|
||||
export_label_collision_detector();
|
||||
|
||||
def("render_grid",&render_grid,
|
||||
( arg("map"),
|
||||
arg("layer"),
|
||||
args("key")="__id__",
|
||||
arg("resolution")=4,
|
||||
arg("fields")=boost::python::list()
|
||||
)
|
||||
);
|
||||
( arg("map"),
|
||||
arg("layer"),
|
||||
args("key")="__id__",
|
||||
arg("resolution")=4,
|
||||
arg("fields")=boost::python::list()
|
||||
)
|
||||
);
|
||||
|
||||
def("render_to_file",&render_to_file1,
|
||||
"\n"
|
||||
|
@ -503,13 +508,26 @@ BOOST_PYTHON_MODULE(_mapnik2)
|
|||
"\n"
|
||||
));
|
||||
|
||||
def("render_with_detector", &render_with_detector, render_with_detector_overloads(
|
||||
"\n"
|
||||
"Render Map to an AGG image_32 using a pre-constructed detector.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> from mapnik import Map, Image, LabelCollisionDetector, render_with_detector, load_map\n"
|
||||
">>> m = Map(256,256)\n"
|
||||
">>> load_map(m,'mapfile.xml')\n"
|
||||
">>> im = Image(m.width,m.height)\n"
|
||||
">>> detector = LabelCollisionDetector(m)\n"
|
||||
">>> render_with_detector(m, im, detector)\n"
|
||||
));
|
||||
|
||||
def("render_layer", &render_layer2,
|
||||
(arg("map"),arg("image"),args("layer"))
|
||||
);
|
||||
(arg("map"),arg("image"),args("layer"))
|
||||
);
|
||||
|
||||
def("render_layer", &mapnik::render_layer_for_grid,
|
||||
(arg("map"),arg("grid"),args("layer"),arg("fields")=boost::python::list())
|
||||
);
|
||||
(arg("map"),arg("grid"),args("layer"),arg("fields")=boost::python::list())
|
||||
);
|
||||
|
||||
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
||||
def("render",&render3,
|
||||
|
@ -606,12 +624,12 @@ BOOST_PYTHON_MODULE(_mapnik2)
|
|||
|
||||
def("save_map_to_string", &save_map_to_string, save_map_to_string_overloads());
|
||||
def("mapnik_version", &mapnik_version,"Get the Mapnik version number");
|
||||
def("mapnik_svn_revision", &mapnik_svn_revision,"Get the Mapnik svn revision");
|
||||
def("has_jpeg", &has_jpeg, "Get jpeg read/write support status");
|
||||
def("has_cairo", &has_cairo, "Get cairo library status");
|
||||
def("has_pycairo", &has_pycairo, "Get pycairo module status");
|
||||
|
||||
register_ptr_to_python<mapnik::expression_ptr>();
|
||||
register_ptr_to_python<mapnik::path_expression_ptr>();
|
||||
to_python_converter<mapnik::value_holder,mapnik_param_to_python>();
|
||||
to_python_converter<mapnik::value,mapnik_value_to_python>();
|
||||
}
|
||||
|
|
|
@ -69,98 +69,98 @@ void export_raster_colorizer()
|
|||
using namespace boost::python;
|
||||
|
||||
class_<raster_colorizer,raster_colorizer_ptr>("RasterColorizer",
|
||||
"A Raster Colorizer object.",
|
||||
init<colorizer_mode_enum, color>(args("default_mode","default_color"))
|
||||
)
|
||||
"A Raster Colorizer object.",
|
||||
init<colorizer_mode_enum, color>(args("default_mode","default_color"))
|
||||
)
|
||||
.def(init<>())
|
||||
.add_property("default_color",
|
||||
make_function(&raster_colorizer::get_default_color, return_value_policy<reference_existing_object>()),
|
||||
&raster_colorizer::set_default_color,
|
||||
"The default color for stops added without a color (mapnik.Color).\n")
|
||||
make_function(&raster_colorizer::get_default_color, return_value_policy<reference_existing_object>()),
|
||||
&raster_colorizer::set_default_color,
|
||||
"The default color for stops added without a color (mapnik.Color).\n")
|
||||
.add_property("default_mode",
|
||||
&raster_colorizer::get_default_mode_enum,
|
||||
&raster_colorizer::set_default_mode_enum,
|
||||
"The default mode (mapnik.ColorizerMode).\n"
|
||||
"\n"
|
||||
"If a stop is added without a mode, then it will inherit this default mode\n")
|
||||
&raster_colorizer::get_default_mode_enum,
|
||||
&raster_colorizer::set_default_mode_enum,
|
||||
"The default mode (mapnik.ColorizerMode).\n"
|
||||
"\n"
|
||||
"If a stop is added without a mode, then it will inherit this default mode\n")
|
||||
.add_property("stops",
|
||||
make_function(get_stops,return_value_policy<reference_existing_object>()),
|
||||
"The list of stops this RasterColorizer contains\n")
|
||||
make_function(get_stops,return_value_policy<reference_existing_object>()),
|
||||
"The list of stops this RasterColorizer contains\n")
|
||||
.add_property("epsilon",
|
||||
&raster_colorizer::get_epsilon,
|
||||
&raster_colorizer::set_epsilon,
|
||||
"Comparison epsilon value for exact mode\n"
|
||||
"\n"
|
||||
"When comparing values in exact mode, values need only be within epsilon to match.\n")
|
||||
&raster_colorizer::get_epsilon,
|
||||
&raster_colorizer::set_epsilon,
|
||||
"Comparison epsilon value for exact mode\n"
|
||||
"\n"
|
||||
"When comparing values in exact mode, values need only be within epsilon to match.\n")
|
||||
|
||||
|
||||
.def("add_stop", add_stop,
|
||||
(arg("ColorizerStop")),
|
||||
"Add a colorizer stop to the raster colorizer.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> colorizer = mapnik.RasterColorizer()\n"
|
||||
">>> color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> stop = mapnik.ColorizerStop(3, mapnik.COLORIZER_INHERIT, color)\n"
|
||||
">>> colorizer.add_stop(stop)\n"
|
||||
(arg("ColorizerStop")),
|
||||
"Add a colorizer stop to the raster colorizer.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> colorizer = mapnik.RasterColorizer()\n"
|
||||
">>> color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> stop = mapnik.ColorizerStop(3, mapnik.COLORIZER_INHERIT, color)\n"
|
||||
">>> colorizer.add_stop(stop)\n"
|
||||
)
|
||||
.def("add_stop", add_stop2,
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer, using the default mode and color.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100)\n"
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer, using the default mode and color.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100)\n"
|
||||
)
|
||||
.def("add_stop", add_stop3,
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer, using the default mode.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100, mapnik.Color(\"#123456\"))\n"
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer, using the default mode.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100, mapnik.Color(\"#123456\"))\n"
|
||||
)
|
||||
.def("add_stop", add_stop4,
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer, using the default color.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100, mapnik2.COLORIZER_EXACT)\n"
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer, using the default color.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100, mapnik.COLORIZER_EXACT)\n"
|
||||
)
|
||||
.def("add_stop", add_stop5,
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100, mapnik.COLORIZER_DISCRETE, mapnik.Color(\"#112233\"))\n"
|
||||
(arg("value")),
|
||||
"Add a colorizer stop to the raster colorizer.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> default_color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer = mapnik.RasterColorizer(mapnik.COLORIZER_LINEAR, default_color)\n"
|
||||
">>> colorizer.add_stop(100, mapnik.COLORIZER_DISCRETE, mapnik.Color(\"#112233\"))\n"
|
||||
)
|
||||
.def("get_color", &raster_colorizer::get_color,
|
||||
"Get the color assigned to a certain value in raster data.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> colorizer = mapnik.RasterColorizer()\n"
|
||||
">>> color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer.add_stop(0, mapnik2.COLORIZER_DISCRETE, mapnik.Color(\"#000000\"))\n"
|
||||
">>> colorizer.add_stop(100, mapnik2.COLORIZER_DISCRETE, mapnik.Color(\"#0E0A06\"))\n"
|
||||
">>> colorizer.get_color(50)\n"
|
||||
"Color('#070503')\n"
|
||||
"Get the color assigned to a certain value in raster data.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
">>> colorizer = mapnik.RasterColorizer()\n"
|
||||
">>> color = mapnik.Color(\"#0044cc\")\n"
|
||||
">>> colorizer.add_stop(0, mapnik.COLORIZER_DISCRETE, mapnik.Color(\"#000000\"))\n"
|
||||
">>> colorizer.add_stop(100, mapnik.COLORIZER_DISCRETE, mapnik.Color(\"#0E0A06\"))\n"
|
||||
">>> colorizer.get_color(50)\n"
|
||||
"Color('#070503')\n"
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
|
||||
class_<colorizer_stops>("ColorizerStops",
|
||||
"A RasterColorizer's collection of ordered color stops.\n"
|
||||
"This class is not meant to be instantiated from python. However, "
|
||||
"it can be accessed at a RasterColorizer's \"stops\" attribute for "
|
||||
"introspection purposes",
|
||||
no_init)
|
||||
"A RasterColorizer's collection of ordered color stops.\n"
|
||||
"This class is not meant to be instantiated from python. However, "
|
||||
"it can be accessed at a RasterColorizer's \"stops\" attribute for "
|
||||
"introspection purposes",
|
||||
no_init)
|
||||
.def(vector_indexing_suite<colorizer_stops>())
|
||||
;
|
||||
|
||||
|
@ -174,32 +174,32 @@ void export_raster_colorizer()
|
|||
|
||||
|
||||
class_<colorizer_stop>("ColorizerStop",init<float, colorizer_mode_enum, color const&>(
|
||||
"A Colorizer Stop object.\n"
|
||||
"Create with a value, ColorizerMode, and Color\n"
|
||||
"\n"
|
||||
"Usage:"
|
||||
">>> color = mapnik.Color(\"#fff000\")\n"
|
||||
">>> stop= mapnik.ColorizerStop(42.42, mapnik.COLORIZER_LINEAR, color)\n"
|
||||
))
|
||||
"A Colorizer Stop object.\n"
|
||||
"Create with a value, ColorizerMode, and Color\n"
|
||||
"\n"
|
||||
"Usage:"
|
||||
">>> color = mapnik.Color(\"#fff000\")\n"
|
||||
">>> stop= mapnik.ColorizerStop(42.42, mapnik.COLORIZER_LINEAR, color)\n"
|
||||
))
|
||||
.add_property("color",
|
||||
make_function(&colorizer_stop::get_color, return_value_policy<reference_existing_object>()),
|
||||
&colorizer_stop::set_color,
|
||||
"The stop color (mapnik.Color).\n")
|
||||
make_function(&colorizer_stop::get_color, return_value_policy<reference_existing_object>()),
|
||||
&colorizer_stop::set_color,
|
||||
"The stop color (mapnik.Color).\n")
|
||||
.add_property("value",
|
||||
&colorizer_stop::get_value,
|
||||
&colorizer_stop::set_value,
|
||||
"The stop value.\n")
|
||||
&colorizer_stop::get_value,
|
||||
&colorizer_stop::set_value,
|
||||
"The stop value.\n")
|
||||
.add_property("label",
|
||||
make_function(&colorizer_stop::get_label, return_value_policy<copy_const_reference>()),
|
||||
&colorizer_stop::set_label,
|
||||
"The stop label.\n")
|
||||
make_function(&colorizer_stop::get_label, return_value_policy<copy_const_reference>()),
|
||||
&colorizer_stop::set_label,
|
||||
"The stop label.\n")
|
||||
.add_property("mode",
|
||||
&colorizer_stop::get_mode_enum,
|
||||
&colorizer_stop::set_mode_enum,
|
||||
"The stop mode (mapnik.ColorizerMode).\n"
|
||||
"\n"
|
||||
"If this is COLORIZER_INHERIT then it will inherit the default mode\n"
|
||||
" from the RasterColorizer it is added to.\n")
|
||||
&colorizer_stop::get_mode_enum,
|
||||
&colorizer_stop::set_mode_enum,
|
||||
"The stop mode (mapnik.ColorizerMode).\n"
|
||||
"\n"
|
||||
"If this is COLORIZER_INHERIT then it will inherit the default mode\n"
|
||||
" from the RasterColorizer it is added to.\n")
|
||||
.def(self == self)
|
||||
.def("__str__",&colorizer_stop::to_string)
|
||||
;
|
||||
|
|
|
@ -148,8 +148,8 @@ struct rule_pickle_suite : boost::python::pickle_suite
|
|||
extract_symbolizer serializer( r );
|
||||
for (int i=0;i<len(syms);++i)
|
||||
{
|
||||
symbolizer symbol = extract<symbolizer>(syms[i]);
|
||||
boost::apply_visitor( serializer, symbol );
|
||||
//symbolizer symbol = extract<symbolizer>(syms[i]);
|
||||
//boost::apply_visitor( serializer, symbol );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -131,10 +131,10 @@ void export_shield_symbolizer()
|
|||
{
|
||||
using namespace boost::python;
|
||||
class_< shield_symbolizer, bases<text_symbolizer> >("ShieldSymbolizer",
|
||||
init<expression_ptr,
|
||||
std::string const&,
|
||||
unsigned, mapnik::color const&,
|
||||
path_expression_ptr>("TODO")
|
||||
init<expression_ptr,
|
||||
std::string const&,
|
||||
unsigned, mapnik::color const&,
|
||||
path_expression_ptr>("TODO")
|
||||
)
|
||||
//.def_pickle(shield_symbolizer_pickle_suite())
|
||||
.add_property("anchor",
|
||||
|
|
|
@ -95,9 +95,9 @@ void export_style()
|
|||
"Usage:\n"
|
||||
">>> for r in m.find_style('style 1').rules:\n"
|
||||
">>> print r\n"
|
||||
"<mapnik2._mapnik2.Rule object at 0x100549910>\n"
|
||||
"<mapnik2._mapnik2.Rule object at 0x100549980>\n"
|
||||
)
|
||||
"<mapnik._mapnik.Rule object at 0x100549910>\n"
|
||||
"<mapnik._mapnik.Rule object at 0x100549980>\n"
|
||||
)
|
||||
.add_property("filter_mode",
|
||||
&feature_type_style::get_filter_mode,
|
||||
&feature_type_style::set_filter_mode,
|
||||
|
|
|
@ -43,7 +43,7 @@ template <class T>
|
|||
void set_svg_transform(T& symbolizer, std::string const& transform_wkt)
|
||||
{
|
||||
agg::trans_affine tr;
|
||||
if (!mapnik::svg::parse_transform(transform_wkt, tr))
|
||||
if (!mapnik::svg::parse_transform(transform_wkt.c_str(), tr))
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'";
|
||||
|
|
|
@ -93,9 +93,9 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
extras.append(t.get_minimum_path_length());
|
||||
|
||||
return boost::python::make_tuple(disp,t.get_label_placement(),
|
||||
t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(),
|
||||
t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(),
|
||||
anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras
|
||||
t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(),
|
||||
t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(),
|
||||
anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -196,19 +196,19 @@ void export_text_symbolizer()
|
|||
;
|
||||
|
||||
class_<text_symbolizer>("TextSymbolizer",init<expression_ptr,std::string const&, unsigned,color const&>())
|
||||
/*
|
||||
// todo - all python classes can have kwargs and default constructors
|
||||
class_<text_symbolizer>("TextSymbolizer",
|
||||
/*
|
||||
// todo - all python classes can have kwargs and default constructors
|
||||
class_<text_symbolizer>("TextSymbolizer",
|
||||
init<expression_ptr,std::string const&, unsigned,color const&>(
|
||||
(
|
||||
arg("name"),
|
||||
arg("font_face")="DejaVu Sans Book",
|
||||
arg("size")=10,
|
||||
arg("color")=color("black")
|
||||
),
|
||||
(
|
||||
arg("name"),
|
||||
arg("font_face")="DejaVu Sans Book",
|
||||
arg("size")=10,
|
||||
arg("color")=color("black")
|
||||
),
|
||||
"Create a TextSymbolizer\n"
|
||||
))
|
||||
*/
|
||||
*/
|
||||
|
||||
//.def_pickle(text_symbolizer_pickle_suite())
|
||||
.add_property("anchor",
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <boost/implicit_cast.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct value_converter : public boost::static_visitor<PyObject*>
|
||||
{
|
||||
PyObject * operator() (int val) const
|
||||
|
@ -48,6 +49,13 @@ namespace boost { namespace python {
|
|||
return ::PyBool_FromLong(val);
|
||||
}
|
||||
|
||||
PyObject * operator() (std::string const& s) const
|
||||
{
|
||||
PyObject *obj = Py_None;
|
||||
obj = ::PyUnicode_DecodeUTF8(s.c_str(),implicit_cast<ssize_t>(s.length()),0);
|
||||
return obj;
|
||||
}
|
||||
|
||||
PyObject * operator() (UnicodeString const& s) const
|
||||
{
|
||||
std::string buffer;
|
||||
|
@ -63,7 +71,26 @@ namespace boost { namespace python {
|
|||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct mapnik_value_to_python
|
||||
{
|
||||
static PyObject* convert(mapnik::value const& v)
|
||||
{
|
||||
return boost::apply_visitor(value_converter(),v.base());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct mapnik_param_to_python
|
||||
{
|
||||
static PyObject* convert(mapnik::value_holder const& v)
|
||||
{
|
||||
return boost::apply_visitor(value_converter(),v);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MAPNIK_PYTHON_BINDING_VALUE_CONVERTER_INCLUDED
|
||||
|
|
|
@ -41,8 +41,8 @@ namespace mapnik {
|
|||
|
||||
template <typename T>
|
||||
static void grid2utf(T const& grid_type,
|
||||
boost::python::list& l,
|
||||
std::vector<grid::lookup_type>& key_order)
|
||||
boost::python::list& l,
|
||||
std::vector<grid::lookup_type>& key_order)
|
||||
{
|
||||
typename T::data_type const& data = grid_type.data();
|
||||
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
|
||||
|
@ -50,12 +50,12 @@ static void grid2utf(T const& grid_type,
|
|||
typename T::key_type::const_iterator key_pos;
|
||||
typename T::feature_key_type::const_iterator feature_pos;
|
||||
// start counting at utf8 codepoint 32, aka space character
|
||||
uint16_t codepoint = 32;
|
||||
boost::uint16_t codepoint = 32;
|
||||
|
||||
unsigned array_size = data.width();
|
||||
for (unsigned y = 0; y < data.height(); ++y)
|
||||
{
|
||||
uint16_t idx = 0;
|
||||
boost::uint16_t idx = 0;
|
||||
boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]);
|
||||
typename T::value_type const* row = data.getRow(y);
|
||||
for (unsigned x = 0; x < data.width(); ++x)
|
||||
|
@ -85,17 +85,17 @@ static void grid2utf(T const& grid_type,
|
|||
// else, shouldn't get here...
|
||||
}
|
||||
l.append(boost::python::object(
|
||||
boost::python::handle<>(
|
||||
PyUnicode_FromUnicode(line.get(), array_size))));
|
||||
boost::python::handle<>(
|
||||
PyUnicode_FromUnicode(line.get(), array_size))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static void grid2utf(T const& grid_type,
|
||||
boost::python::list& l,
|
||||
std::vector<typename T::lookup_type>& key_order,
|
||||
unsigned int resolution)
|
||||
boost::python::list& l,
|
||||
std::vector<typename T::lookup_type>& key_order,
|
||||
unsigned int resolution)
|
||||
{
|
||||
//typename T::data_type const& data = grid_type.data();
|
||||
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
|
||||
|
@ -103,13 +103,13 @@ static void grid2utf(T const& grid_type,
|
|||
typename T::key_type::const_iterator key_pos;
|
||||
typename T::feature_key_type::const_iterator feature_pos;
|
||||
// start counting at utf8 codepoint 32, aka space character
|
||||
uint16_t codepoint = 32;
|
||||
boost::uint16_t codepoint = 32;
|
||||
|
||||
// TODO - use double?
|
||||
unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution);
|
||||
for (unsigned y = 0; y < grid_type.height(); y=y+resolution)
|
||||
{
|
||||
uint16_t idx = 0;
|
||||
boost::uint16_t idx = 0;
|
||||
boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]);
|
||||
mapnik::grid::value_type const* row = grid_type.getRow(y);
|
||||
for (unsigned x = 0; x < grid_type.width(); x=x+resolution)
|
||||
|
@ -138,17 +138,17 @@ static void grid2utf(T const& grid_type,
|
|||
// else, shouldn't get here...
|
||||
}
|
||||
l.append(boost::python::object(
|
||||
boost::python::handle<>(
|
||||
PyUnicode_FromUnicode(line.get(), array_size))));
|
||||
boost::python::handle<>(
|
||||
PyUnicode_FromUnicode(line.get(), array_size))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static void grid2utf2(T const& grid_type,
|
||||
boost::python::list& l,
|
||||
std::vector<typename T::lookup_type>& key_order,
|
||||
unsigned int resolution)
|
||||
boost::python::list& l,
|
||||
std::vector<typename T::lookup_type>& key_order,
|
||||
unsigned int resolution)
|
||||
{
|
||||
typename T::data_type const& data = grid_type.data();
|
||||
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
|
||||
|
@ -194,16 +194,16 @@ static void grid2utf2(T const& grid_type,
|
|||
// else, shouldn't get here...
|
||||
}
|
||||
l.append(boost::python::object(
|
||||
boost::python::handle<>(
|
||||
PyUnicode_FromUnicode(line.get(), array_size))));
|
||||
boost::python::handle<>(
|
||||
PyUnicode_FromUnicode(line.get(), array_size))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static void write_features(T const& grid_type,
|
||||
boost::python::dict& feature_data,
|
||||
std::vector<typename T::lookup_type> const& key_order)
|
||||
boost::python::dict& feature_data,
|
||||
std::vector<typename T::lookup_type> const& key_order)
|
||||
{
|
||||
std::string const& key = grid_type.get_key();
|
||||
std::set<std::string> const& attributes = grid_type.property_names();
|
||||
|
@ -236,7 +236,7 @@ static void write_features(T const& grid_type,
|
|||
boost::python::handle<>(
|
||||
boost::apply_visitor(
|
||||
boost::python::value_converter(),
|
||||
it->second.base())));
|
||||
it->second.base())));
|
||||
}
|
||||
}
|
||||
else if ( (attributes.find(key_name) != attributes.end()) )
|
||||
|
@ -246,7 +246,7 @@ static void write_features(T const& grid_type,
|
|||
boost::python::handle<>(
|
||||
boost::apply_visitor(
|
||||
boost::python::value_converter(),
|
||||
it->second.base())));
|
||||
it->second.base())));
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
|
@ -264,9 +264,9 @@ static void write_features(T const& grid_type,
|
|||
|
||||
template <typename T>
|
||||
static void grid_encode_utf(T const& grid_type,
|
||||
boost::python::dict & json,
|
||||
bool add_features,
|
||||
unsigned int resolution)
|
||||
boost::python::dict & json,
|
||||
bool add_features,
|
||||
unsigned int resolution)
|
||||
{
|
||||
// convert buffer to utf and gather key order
|
||||
boost::python::list l;
|
||||
|
@ -325,9 +325,9 @@ static boost::python::dict grid_encode( T const& grid, std::string format, bool
|
|||
* whether features are dumped is determined by argument not 'fields'
|
||||
*/
|
||||
static void render_layer_for_grid(const mapnik::Map& map,
|
||||
mapnik::grid& grid,
|
||||
unsigned layer_idx, // TODO - layer by name or index
|
||||
boost::python::list const& fields)
|
||||
mapnik::grid& grid,
|
||||
unsigned layer_idx, // TODO - layer by name or index
|
||||
boost::python::list const& fields)
|
||||
{
|
||||
std::vector<mapnik::layer> const& layers = map.layers();
|
||||
std::size_t layer_num = layers.size();
|
||||
|
@ -347,9 +347,9 @@ static void render_layer_for_grid(const mapnik::Map& map,
|
|||
}
|
||||
else
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "list of field names must be strings";
|
||||
throw mapnik::value_error(s.str());
|
||||
std::stringstream s;
|
||||
s << "list of field names must be strings";
|
||||
throw mapnik::value_error(s.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,10 +385,10 @@ static void render_layer_for_grid(const mapnik::Map& map,
|
|||
* grid object is created on the fly at potentially reduced size
|
||||
*/
|
||||
static boost::python::dict render_grid(const mapnik::Map& map,
|
||||
unsigned layer_idx, // layer
|
||||
std::string const& key, // key_name
|
||||
unsigned int step, // resolution
|
||||
boost::python::list const& fields)
|
||||
unsigned layer_idx, // layer
|
||||
std::string const& key, // key_name
|
||||
unsigned int step, // resolution
|
||||
boost::python::list const& fields)
|
||||
{
|
||||
|
||||
std::vector<mapnik::layer> const& layers = map.layers();
|
||||
|
@ -415,9 +415,9 @@ static boost::python::dict render_grid(const mapnik::Map& map,
|
|||
}
|
||||
else
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "list of field names must be strings";
|
||||
throw mapnik::value_error(s.str());
|
||||
std::stringstream s;
|
||||
s << "list of field names must be strings";
|
||||
throw mapnik::value_error(s.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ if env['HAS_CAIRO']:
|
|||
|
||||
libraries = copy(env['LIBMAPNIK_LIBS'])
|
||||
boost_program_options = 'boost_program_options%s' % env['BOOST_APPEND']
|
||||
libraries.extend([boost_program_options,'mapnik2'])
|
||||
libraries.extend([boost_program_options,'mapnik'])
|
||||
|
||||
rundemo = demo_env.Program('rundemo', source, LIBS=libraries, LINKFLAGS=env["CUSTOM_LDFLAGS"])
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -43,7 +43,7 @@ int main ( int argc , char** argv)
|
|||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cout << "usage: ./rundemo <mapnik_install_dir>\nUsually /usr/local/lib/mapnik2\n";
|
||||
std::cout << "usage: ./rundemo <mapnik_install_dir>\nUsually /usr/local/lib/mapnik\n";
|
||||
std::cout << "Warning: ./rundemo looks for data in ../data/,\nTherefore must be run from within the demo/c++ folder.\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ int main ( int argc , char** argv)
|
|||
provpoly_style.add_rule(provpoly_rule_on);
|
||||
|
||||
rule provpoly_rule_qc;
|
||||
provpoly_rule_qc.set_filter(parse_expression("[NOM_FR] = 'Québec'"));
|
||||
provpoly_rule_qc.set_filter(parse_expression("[NOM_FR] = 'Québec'"));
|
||||
provpoly_rule_qc.append(polygon_symbolizer(color(217, 235, 203)));
|
||||
provpoly_style.add_rule(provpoly_rule_qc);
|
||||
|
||||
|
@ -244,7 +244,7 @@ int main ( int argc , char** argv)
|
|||
}
|
||||
|
||||
m.zoom_to_box(box2d<double>(1405120.04127408,-247003.813399447,
|
||||
1706357.31328276,-25098.593149577));
|
||||
1706357.31328276,-25098.593149577));
|
||||
|
||||
image_32 buf(m.width(),m.height());
|
||||
agg_renderer<image_32> ren(m,buf);
|
||||
|
@ -253,13 +253,16 @@ int main ( int argc , char** argv)
|
|||
save_to_file<image_data_32>(buf.data(),"demo.jpg","jpeg");
|
||||
save_to_file<image_data_32>(buf.data(),"demo.png","png");
|
||||
save_to_file<image_data_32>(buf.data(),"demo256.png","png256");
|
||||
std::cout << "Three maps have been rendered using AGG in the current directory:\n"
|
||||
"- demo.jpg\n"
|
||||
"- demo.png\n"
|
||||
"- demo256.png\n"
|
||||
"Have a look!\n";
|
||||
save_to_file<image_data_32>(buf.data(),"demo.tif","tiff");
|
||||
|
||||
#if defined(HAVE_CAIRO)
|
||||
std::cout << "Three maps have been rendered using AGG in the current directory:\n"
|
||||
"- demo.jpg\n"
|
||||
"- demo.png\n"
|
||||
"- demo256.png\n"
|
||||
"- demo.tif\n"
|
||||
"Have a look!\n";
|
||||
|
||||
#if defined(HAVE_CAIRO)
|
||||
Cairo::RefPtr<Cairo::ImageSurface> image_surface;
|
||||
|
||||
image_surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, m.width(),m.height());
|
||||
|
@ -280,12 +283,12 @@ int main ( int argc , char** argv)
|
|||
svg_render.apply();
|
||||
|
||||
std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
|
||||
"- cairo-demo.png\n"
|
||||
"- cairo-demo256.png\n"
|
||||
"- cairo-demo.pdf\n"
|
||||
"- cairo-demo.svg\n"
|
||||
"Have a look!\n";
|
||||
#endif
|
||||
"- cairo-demo.png\n"
|
||||
"- cairo-demo256.png\n"
|
||||
"- cairo-demo.pdf\n"
|
||||
"- cairo-demo.svg\n"
|
||||
"Have a look!\n";
|
||||
#endif
|
||||
|
||||
}
|
||||
catch ( const mapnik::config_error & ex )
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
import sys
|
||||
|
||||
try:
|
||||
import mapnik2
|
||||
import mapnik
|
||||
except:
|
||||
print '\n\nThe mapnik library and python bindings must have been compiled and \
|
||||
installed successfully before running this script.\n\n'
|
||||
|
@ -41,11 +41,11 @@ except ImportError:
|
|||
# Instanciate a map, giving it a width and height. Remember: the word "map" is
|
||||
# reserved in Python! :)
|
||||
|
||||
m = mapnik2.Map(800,600,"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs")
|
||||
m = mapnik.Map(800,600,"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs")
|
||||
|
||||
# Set its background colour. More on colours later ...
|
||||
|
||||
m.background = mapnik2.Color('white')
|
||||
m.background = mapnik.Color('white')
|
||||
|
||||
# Now we can start adding layers, in stacking order (i.e. bottom layer first)
|
||||
|
||||
|
@ -66,9 +66,9 @@ m.background = mapnik2.Color('white')
|
|||
# password='mypassword'
|
||||
# table= TODO
|
||||
|
||||
provpoly_lyr = mapnik2.Layer('Provinces')
|
||||
provpoly_lyr = mapnik.Layer('Provinces')
|
||||
provpoly_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
provpoly_lyr.datasource = mapnik2.Shapefile(file='../data/boundaries', encoding='latin1')
|
||||
provpoly_lyr.datasource = mapnik.Shapefile(file='../data/boundaries', encoding='latin1')
|
||||
|
||||
# We then define a style for the layer. A layer can have one or many styles.
|
||||
# Styles are named, so they can be shared across different layers.
|
||||
|
@ -78,18 +78,18 @@ provpoly_lyr.datasource = mapnik2.Shapefile(file='../data/boundaries', encoding=
|
|||
# multiple styles in one layer is the same has having multiple layers.
|
||||
# The paradigm is useful mostly as a convenience.
|
||||
|
||||
provpoly_style = mapnik2.Style()
|
||||
provpoly_style = mapnik.Style()
|
||||
|
||||
# A Style needs one or more rules. A rule will normally consist of a filter
|
||||
# for feature selection, and one or more symbolizers.
|
||||
|
||||
provpoly_rule_on = mapnik2.Rule()
|
||||
provpoly_rule_on = mapnik.Rule()
|
||||
|
||||
# A Expression() allows the selection of features to which the symbology will
|
||||
# be applied. More on Mapnik expressions can be found in Tutorial #2.
|
||||
# A given feature can only match one filter per rule per style.
|
||||
|
||||
provpoly_rule_on.filter = mapnik2.Expression("[NAME_EN] = 'Ontario'")
|
||||
provpoly_rule_on.filter = mapnik.Expression("[NAME_EN] = 'Ontario'")
|
||||
|
||||
# Here a symbolizer is defined. Available are:
|
||||
# - LineSymbolizer(Color(),<width>)
|
||||
|
@ -103,12 +103,12 @@ provpoly_rule_on.filter = mapnik2.Expression("[NAME_EN] = 'Ontario'")
|
|||
# - Color(<string>) where <string> will be something like '#00FF00'
|
||||
# or '#0f0' or 'green'
|
||||
|
||||
provpoly_rule_on.symbols.append(mapnik2.PolygonSymbolizer(mapnik2.Color(250, 190, 183)))
|
||||
provpoly_rule_on.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(250, 190, 183)))
|
||||
provpoly_style.rules.append(provpoly_rule_on)
|
||||
|
||||
provpoly_rule_qc = mapnik2.Rule()
|
||||
provpoly_rule_qc.filter = mapnik2.Expression("[NOM_FR] = 'Québec'")
|
||||
provpoly_rule_qc.symbols.append(mapnik2.PolygonSymbolizer(mapnik2.Color(217, 235, 203)))
|
||||
provpoly_rule_qc = mapnik.Rule()
|
||||
provpoly_rule_qc.filter = mapnik.Expression("[NOM_FR] = 'Québec'")
|
||||
provpoly_rule_qc.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(217, 235, 203)))
|
||||
provpoly_style.rules.append(provpoly_rule_qc)
|
||||
|
||||
# Add the style to the map, giving it a name. This is the name that will be
|
||||
|
@ -131,14 +131,14 @@ m.layers.append(provpoly_lyr)
|
|||
|
||||
# A simple example ...
|
||||
|
||||
qcdrain_lyr = mapnik2.Layer('Quebec Hydrography')
|
||||
qcdrain_lyr = mapnik.Layer('Quebec Hydrography')
|
||||
qcdrain_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
qcdrain_lyr.datasource = mapnik2.Shapefile(file='../data/qcdrainage')
|
||||
qcdrain_lyr.datasource = mapnik.Shapefile(file='../data/qcdrainage')
|
||||
|
||||
qcdrain_style = mapnik2.Style()
|
||||
qcdrain_rule = mapnik2.Rule()
|
||||
qcdrain_rule.filter = mapnik2.Expression('[HYC] = 8')
|
||||
qcdrain_rule.symbols.append(mapnik2.PolygonSymbolizer(mapnik2.Color(153, 204, 255)))
|
||||
qcdrain_style = mapnik.Style()
|
||||
qcdrain_rule = mapnik.Rule()
|
||||
qcdrain_rule.filter = mapnik.Expression('[HYC] = 8')
|
||||
qcdrain_rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(153, 204, 255)))
|
||||
qcdrain_style.rules.append(qcdrain_rule)
|
||||
|
||||
m.append_style('drainage', qcdrain_style)
|
||||
|
@ -149,31 +149,31 @@ m.layers.append(qcdrain_lyr)
|
|||
# attributes, and same desired style), so we're going to
|
||||
# re-use the style defined in the above layer for the next one.
|
||||
|
||||
ondrain_lyr = mapnik2.Layer('Ontario Hydrography')
|
||||
ondrain_lyr = mapnik.Layer('Ontario Hydrography')
|
||||
ondrain_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
ondrain_lyr.datasource = mapnik2.Shapefile(file='../data/ontdrainage')
|
||||
ondrain_lyr.datasource = mapnik.Shapefile(file='../data/ontdrainage')
|
||||
|
||||
ondrain_lyr.styles.append('drainage')
|
||||
m.layers.append(ondrain_lyr)
|
||||
|
||||
# Provincial boundaries
|
||||
|
||||
provlines_lyr = mapnik2.Layer('Provincial borders')
|
||||
provlines_lyr = mapnik.Layer('Provincial borders')
|
||||
provlines_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
provlines_lyr.datasource = mapnik2.Shapefile(file='../data/boundaries_l')
|
||||
provlines_lyr.datasource = mapnik.Shapefile(file='../data/boundaries_l')
|
||||
|
||||
# Here we define a "dash dot dot dash" pattern for the provincial boundaries.
|
||||
|
||||
provlines_stk = mapnik2.Stroke()
|
||||
provlines_stk = mapnik.Stroke()
|
||||
provlines_stk.add_dash(8, 4)
|
||||
provlines_stk.add_dash(2, 2)
|
||||
provlines_stk.add_dash(2, 2)
|
||||
provlines_stk.color = mapnik2.Color('black')
|
||||
provlines_stk.color = mapnik.Color('black')
|
||||
provlines_stk.width = 1.0
|
||||
|
||||
provlines_style = mapnik2.Style()
|
||||
provlines_rule = mapnik2.Rule()
|
||||
provlines_rule.symbols.append(mapnik2.LineSymbolizer(provlines_stk))
|
||||
provlines_style = mapnik.Style()
|
||||
provlines_rule = mapnik.Rule()
|
||||
provlines_rule.symbols.append(mapnik.LineSymbolizer(provlines_stk))
|
||||
provlines_style.rules.append(provlines_rule)
|
||||
|
||||
m.append_style('provlines', provlines_style)
|
||||
|
@ -182,22 +182,22 @@ m.layers.append(provlines_lyr)
|
|||
|
||||
# Roads 3 and 4 (The "grey" roads)
|
||||
|
||||
roads34_lyr = mapnik2.Layer('Roads')
|
||||
roads34_lyr = mapnik.Layer('Roads')
|
||||
roads34_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
# create roads datasource (we're going to re-use it later)
|
||||
|
||||
roads34_lyr.datasource = mapnik2.Shapefile(file='../data/roads')
|
||||
roads34_lyr.datasource = mapnik.Shapefile(file='../data/roads')
|
||||
|
||||
roads34_style = mapnik2.Style()
|
||||
roads34_rule = mapnik2.Rule()
|
||||
roads34_rule.filter = mapnik2.Expression('([CLASS] = 3) or ([CLASS] = 4)')
|
||||
roads34_style = mapnik.Style()
|
||||
roads34_rule = mapnik.Rule()
|
||||
roads34_rule.filter = mapnik.Expression('([CLASS] = 3) or ([CLASS] = 4)')
|
||||
|
||||
# With lines of a certain width, you can control how the ends
|
||||
# are closed off using line_cap as below.
|
||||
|
||||
roads34_rule_stk = mapnik2.Stroke()
|
||||
roads34_rule_stk.color = mapnik2.Color(171,158,137)
|
||||
roads34_rule_stk.line_cap = mapnik2.line_cap.ROUND_CAP
|
||||
roads34_rule_stk = mapnik.Stroke()
|
||||
roads34_rule_stk.color = mapnik.Color(171,158,137)
|
||||
roads34_rule_stk.line_cap = mapnik.line_cap.ROUND_CAP
|
||||
|
||||
# Available options are:
|
||||
# line_cap: BUTT_CAP, SQUARE_CAP, ROUND_CAP
|
||||
|
@ -207,7 +207,7 @@ roads34_rule_stk.line_cap = mapnik2.line_cap.ROUND_CAP
|
|||
# can be set to a numerical value.
|
||||
|
||||
roads34_rule_stk.width = 2.0
|
||||
roads34_rule.symbols.append(mapnik2.LineSymbolizer(roads34_rule_stk))
|
||||
roads34_rule.symbols.append(mapnik.LineSymbolizer(roads34_rule_stk))
|
||||
roads34_style.rules.append(roads34_rule)
|
||||
|
||||
m.append_style('smallroads', roads34_style)
|
||||
|
@ -216,31 +216,31 @@ m.layers.append(roads34_lyr)
|
|||
|
||||
# Roads 2 (The thin yellow ones)
|
||||
|
||||
roads2_lyr = mapnik2.Layer('Roads')
|
||||
roads2_lyr = mapnik.Layer('Roads')
|
||||
roads2_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
# Just get a copy from roads34_lyr
|
||||
roads2_lyr.datasource = roads34_lyr.datasource
|
||||
|
||||
roads2_style_1 = mapnik2.Style()
|
||||
roads2_rule_1 = mapnik2.Rule()
|
||||
roads2_rule_1.filter = mapnik2.Expression('[CLASS] = 2')
|
||||
roads2_rule_stk_1 = mapnik2.Stroke()
|
||||
roads2_rule_stk_1.color = mapnik2.Color(171,158,137)
|
||||
roads2_rule_stk_1.line_cap = mapnik2.line_cap.ROUND_CAP
|
||||
roads2_style_1 = mapnik.Style()
|
||||
roads2_rule_1 = mapnik.Rule()
|
||||
roads2_rule_1.filter = mapnik.Expression('[CLASS] = 2')
|
||||
roads2_rule_stk_1 = mapnik.Stroke()
|
||||
roads2_rule_stk_1.color = mapnik.Color(171,158,137)
|
||||
roads2_rule_stk_1.line_cap = mapnik.line_cap.ROUND_CAP
|
||||
roads2_rule_stk_1.width = 4.0
|
||||
roads2_rule_1.symbols.append(mapnik2.LineSymbolizer(roads2_rule_stk_1))
|
||||
roads2_rule_1.symbols.append(mapnik.LineSymbolizer(roads2_rule_stk_1))
|
||||
roads2_style_1.rules.append(roads2_rule_1)
|
||||
|
||||
m.append_style('road-border', roads2_style_1)
|
||||
|
||||
roads2_style_2 = mapnik2.Style()
|
||||
roads2_rule_2 = mapnik2.Rule()
|
||||
roads2_rule_2.filter = mapnik2.Expression('[CLASS] = 2')
|
||||
roads2_rule_stk_2 = mapnik2.Stroke()
|
||||
roads2_rule_stk_2.color = mapnik2.Color(255,250,115)
|
||||
roads2_rule_stk_2.line_cap = mapnik2.line_cap.ROUND_CAP
|
||||
roads2_style_2 = mapnik.Style()
|
||||
roads2_rule_2 = mapnik.Rule()
|
||||
roads2_rule_2.filter = mapnik.Expression('[CLASS] = 2')
|
||||
roads2_rule_stk_2 = mapnik.Stroke()
|
||||
roads2_rule_stk_2.color = mapnik.Color(255,250,115)
|
||||
roads2_rule_stk_2.line_cap = mapnik.line_cap.ROUND_CAP
|
||||
roads2_rule_stk_2.width = 2.0
|
||||
roads2_rule_2.symbols.append(mapnik2.LineSymbolizer(roads2_rule_stk_2))
|
||||
roads2_rule_2.symbols.append(mapnik.LineSymbolizer(roads2_rule_stk_2))
|
||||
roads2_style_2.rules.append(roads2_rule_2)
|
||||
|
||||
m.append_style('road-fill', roads2_style_2)
|
||||
|
@ -252,29 +252,29 @@ m.layers.append(roads2_lyr)
|
|||
|
||||
# Roads 1 (The big orange ones, the highways)
|
||||
|
||||
roads1_lyr = mapnik2.Layer('Roads')
|
||||
roads1_lyr = mapnik.Layer('Roads')
|
||||
roads1_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
roads1_lyr.datasource = roads34_lyr.datasource
|
||||
|
||||
roads1_style_1 = mapnik2.Style()
|
||||
roads1_rule_1 = mapnik2.Rule()
|
||||
roads1_rule_1.filter = mapnik2.Expression('[CLASS] = 1')
|
||||
roads1_rule_stk_1 = mapnik2.Stroke()
|
||||
roads1_rule_stk_1.color = mapnik2.Color(188,149,28)
|
||||
roads1_rule_stk_1.line_cap = mapnik2.line_cap.ROUND_CAP
|
||||
roads1_style_1 = mapnik.Style()
|
||||
roads1_rule_1 = mapnik.Rule()
|
||||
roads1_rule_1.filter = mapnik.Expression('[CLASS] = 1')
|
||||
roads1_rule_stk_1 = mapnik.Stroke()
|
||||
roads1_rule_stk_1.color = mapnik.Color(188,149,28)
|
||||
roads1_rule_stk_1.line_cap = mapnik.line_cap.ROUND_CAP
|
||||
roads1_rule_stk_1.width = 7.0
|
||||
roads1_rule_1.symbols.append(mapnik2.LineSymbolizer(roads1_rule_stk_1))
|
||||
roads1_rule_1.symbols.append(mapnik.LineSymbolizer(roads1_rule_stk_1))
|
||||
roads1_style_1.rules.append(roads1_rule_1)
|
||||
m.append_style('highway-border', roads1_style_1)
|
||||
|
||||
roads1_style_2 = mapnik2.Style()
|
||||
roads1_rule_2 = mapnik2.Rule()
|
||||
roads1_rule_2.filter = mapnik2.Expression('[CLASS] = 1')
|
||||
roads1_rule_stk_2 = mapnik2.Stroke()
|
||||
roads1_rule_stk_2.color = mapnik2.Color(242,191,36)
|
||||
roads1_rule_stk_2.line_cap = mapnik2.line_cap.ROUND_CAP
|
||||
roads1_style_2 = mapnik.Style()
|
||||
roads1_rule_2 = mapnik.Rule()
|
||||
roads1_rule_2.filter = mapnik.Expression('[CLASS] = 1')
|
||||
roads1_rule_stk_2 = mapnik.Stroke()
|
||||
roads1_rule_stk_2.color = mapnik.Color(242,191,36)
|
||||
roads1_rule_stk_2.line_cap = mapnik.line_cap.ROUND_CAP
|
||||
roads1_rule_stk_2.width = 5.0
|
||||
roads1_rule_2.symbols.append(mapnik2.LineSymbolizer(roads1_rule_stk_2))
|
||||
roads1_rule_2.symbols.append(mapnik.LineSymbolizer(roads1_rule_stk_2))
|
||||
roads1_style_2.rules.append(roads1_rule_2)
|
||||
|
||||
m.append_style('highway-fill', roads1_style_2)
|
||||
|
@ -286,25 +286,25 @@ m.layers.append(roads1_lyr)
|
|||
|
||||
# Populated Places
|
||||
|
||||
popplaces_lyr = mapnik2.Layer('Populated Places')
|
||||
popplaces_lyr = mapnik.Layer('Populated Places')
|
||||
popplaces_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
|
||||
popplaces_lyr.datasource = mapnik2.Shapefile(file='../data/popplaces',encoding='latin1')
|
||||
popplaces_lyr.datasource = mapnik.Shapefile(file='../data/popplaces',encoding='latin1')
|
||||
|
||||
popplaces_style = mapnik2.Style()
|
||||
popplaces_rule = mapnik2.Rule()
|
||||
popplaces_style = mapnik.Style()
|
||||
popplaces_rule = mapnik.Rule()
|
||||
|
||||
# And here we have a TextSymbolizer, used for labeling.
|
||||
# The first parameter is the name of the attribute to use as the source of the
|
||||
# text to label with. Then there is font size in points (I think?), and colour.
|
||||
|
||||
popplaces_text_symbolizer = mapnik2.TextSymbolizer(mapnik2.Expression("[GEONAME]"),
|
||||
popplaces_text_symbolizer = mapnik.TextSymbolizer(mapnik.Expression("[GEONAME]"),
|
||||
'DejaVu Sans Book',
|
||||
10, mapnik2.Color('black'))
|
||||
10, mapnik.Color('black'))
|
||||
|
||||
# We set a "halo" around the text, which looks like an outline if thin enough,
|
||||
# or an outright background if large enough.
|
||||
popplaces_text_symbolizer.label_placement= mapnik2.label_placement.POINT_PLACEMENT
|
||||
popplaces_text_symbolizer.halo_fill = mapnik2.Color('white')
|
||||
popplaces_text_symbolizer.label_placement= mapnik.label_placement.POINT_PLACEMENT
|
||||
popplaces_text_symbolizer.halo_fill = mapnik.Color('white')
|
||||
popplaces_text_symbolizer.halo_radius = 1
|
||||
popplaces_text_symbolizer.avoid_edges = True
|
||||
#popplaces_text_symbolizer.minimum_padding = 30
|
||||
|
@ -320,11 +320,11 @@ m.layers.append(popplaces_lyr)
|
|||
# Draw map
|
||||
|
||||
# Set the initial extent of the map in 'master' spherical Mercator projection
|
||||
m.zoom_to_box(mapnik2.Box2d(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855))
|
||||
m.zoom_to_box(mapnik.Box2d(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855))
|
||||
|
||||
# Render two maps, two PNGs, one JPEG.
|
||||
im = mapnik2.Image(m.width,m.height)
|
||||
mapnik2.render(m, im)
|
||||
# Render map
|
||||
im = mapnik.Image(m.width,m.height)
|
||||
mapnik.render(m, im)
|
||||
|
||||
# Save image to files
|
||||
images_ = []
|
||||
|
@ -347,38 +347,41 @@ images_.append('demo_high.jpg')
|
|||
im.save('demo_low.jpg', 'jpeg50')
|
||||
images_.append('demo_low.jpg')
|
||||
|
||||
im.save('demo.tif', 'tiff')
|
||||
images_.append('demo.tif')
|
||||
|
||||
# Render cairo examples
|
||||
if HAS_PYCAIRO_MODULE and mapnik2.has_pycairo():
|
||||
if HAS_PYCAIRO_MODULE and mapnik.has_pycairo():
|
||||
|
||||
svg_surface = cairo.SVGSurface('demo.svg', m.width,m.height)
|
||||
mapnik2.render(m, svg_surface)
|
||||
mapnik.render(m, svg_surface)
|
||||
svg_surface.finish()
|
||||
images_.append('demo.svg')
|
||||
|
||||
pdf_surface = cairo.PDFSurface('demo.pdf', m.width,m.height)
|
||||
mapnik2.render(m, pdf_surface)
|
||||
mapnik.render(m, pdf_surface)
|
||||
images_.append('demo.pdf')
|
||||
pdf_surface.finish()
|
||||
|
||||
postscript_surface = cairo.PSSurface('demo.ps', m.width,m.height)
|
||||
mapnik2.render(m, postscript_surface)
|
||||
mapnik.render(m, postscript_surface)
|
||||
images_.append('demo.ps')
|
||||
postscript_surface.finish()
|
||||
|
||||
else:
|
||||
print '\n\nPycairo not available...',
|
||||
if mapnik2.has_cairo():
|
||||
if mapnik.has_cairo():
|
||||
print ' will render Cairo formats using alternative method'
|
||||
|
||||
mapnik2.render_to_file(m,'demo.pdf')
|
||||
mapnik.render_to_file(m,'demo.pdf')
|
||||
images_.append('demo.pdf')
|
||||
mapnik2.render_to_file(m,'demo.ps')
|
||||
mapnik.render_to_file(m,'demo.ps')
|
||||
images_.append('demo.ps')
|
||||
mapnik2.render_to_file(m,'demo.svg')
|
||||
mapnik.render_to_file(m,'demo.svg')
|
||||
images_.append('demo.svg')
|
||||
mapnik2.render_to_file(m,'demo_cairo_rgb.png','RGB24')
|
||||
mapnik.render_to_file(m,'demo_cairo_rgb.png','RGB24')
|
||||
images_.append('demo_cairo_rgb.png')
|
||||
mapnik2.render_to_file(m,'demo_cairo_argb.png','ARGB32')
|
||||
mapnik.render_to_file(m,'demo_cairo_argb.png','ARGB32')
|
||||
images_.append('demo_cairo_argb.png')
|
||||
|
||||
print "\n\n", len(images_), "maps have been rendered in the current directory:"
|
||||
|
@ -388,4 +391,4 @@ for im_ in images_:
|
|||
|
||||
print "\n\nHave a look!\n\n"
|
||||
|
||||
mapnik2.save_map(m,"map.xml")
|
||||
mapnik.save_map(m,"map.xml")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -23,7 +23,7 @@ Import ('env')
|
|||
import os
|
||||
import platform
|
||||
|
||||
lib_dir = os.path.normpath(env['DESTDIR'] + '/' + env['PREFIX'] + '/' + env['LIBDIR_SCHEMA'] + '/mapnik2')
|
||||
lib_dir = os.path.normpath(env['DESTDIR'] + '/' + env['PREFIX'] + '/' + env['LIBDIR_SCHEMA'] + '/mapnik')
|
||||
|
||||
fonts = 1
|
||||
ini_template = '''
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -43,7 +44,7 @@ int main( int argc, char **argv )
|
|||
|
||||
// register input plug-ins
|
||||
QString plugins_dir = settings.value("mapnik/plugins_dir",
|
||||
QVariant("/usr/local/lib/mapnik2/input/")).toString();
|
||||
QVariant("/usr/local/lib/mapnik/input/")).toString();
|
||||
datasource_cache::instance()->register_datasources(plugins_dir.toStdString());
|
||||
// register fonts
|
||||
int count = settings.beginReadArray("mapnik/fonts");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
|
|
@ -11,7 +11,7 @@ INCLUDEPATH += /usr/X11/include/freetype2
|
|||
INCLUDEPATH += .
|
||||
|
||||
QMAKE_CXXFLAGS +=' -DDARWIN -Wno-missing-field-initializers -ansi'
|
||||
unix:LIBS = -L/usr/local/lib -L/usr/X11/lib -lmapnik2 -lfreetype
|
||||
unix:LIBS = -L/usr/local/lib -L/usr/X11/lib -lmapnik -lfreetype
|
||||
unix:LIBS += -lboost_system -licuuc -lboost_filesystem -lboost_regex
|
||||
|
||||
# Input
|
||||
|
|
2
deps/agg/include/agg_path_storage.h
vendored
2
deps/agg/include/agg_path_storage.h
vendored
|
@ -736,7 +736,7 @@ namespace agg
|
|||
template<class VertexSource>
|
||||
void join_path(VertexSource& vs, unsigned path_id = 0)
|
||||
{
|
||||
double x, y;
|
||||
double x=0.0, y=0.0;
|
||||
unsigned cmd;
|
||||
vs.rewind(path_id);
|
||||
cmd = vs.vertex(&x, &y);
|
||||
|
|
111
deps/agg/include/agg_rasterizer_outline_aa.h
vendored
111
deps/agg/include/agg_rasterizer_outline_aa.h
vendored
|
@ -323,68 +323,65 @@ namespace agg
|
|||
int y2;
|
||||
int lprev;
|
||||
|
||||
if(close_polygon)
|
||||
if(close_polygon && (m_src_vertices.size() >= 3))
|
||||
{
|
||||
if(m_src_vertices.size() >= 3)
|
||||
dv.idx = 2;
|
||||
|
||||
v = &m_src_vertices[m_src_vertices.size() - 1];
|
||||
x1 = v->x;
|
||||
y1 = v->y;
|
||||
lprev = v->len;
|
||||
|
||||
v = &m_src_vertices[0];
|
||||
x2 = v->x;
|
||||
y2 = v->y;
|
||||
dv.lcurr = v->len;
|
||||
line_parameters prev(x1, y1, x2, y2, lprev);
|
||||
|
||||
v = &m_src_vertices[1];
|
||||
dv.x1 = v->x;
|
||||
dv.y1 = v->y;
|
||||
dv.lnext = v->len;
|
||||
dv.curr = line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr);
|
||||
|
||||
v = &m_src_vertices[dv.idx];
|
||||
dv.x2 = v->x;
|
||||
dv.y2 = v->y;
|
||||
dv.next = line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext);
|
||||
|
||||
dv.xb1 = 0;
|
||||
dv.yb1 = 0;
|
||||
dv.xb2 = 0;
|
||||
dv.yb2 = 0;
|
||||
|
||||
switch(m_line_join)
|
||||
{
|
||||
dv.idx = 2;
|
||||
case outline_no_join:
|
||||
dv.flags = 3;
|
||||
break;
|
||||
|
||||
v = &m_src_vertices[m_src_vertices.size() - 1];
|
||||
x1 = v->x;
|
||||
y1 = v->y;
|
||||
lprev = v->len;
|
||||
case outline_miter_join:
|
||||
case outline_round_join:
|
||||
dv.flags =
|
||||
(prev.diagonal_quadrant() == dv.curr.diagonal_quadrant()) |
|
||||
((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant()) << 1);
|
||||
break;
|
||||
|
||||
v = &m_src_vertices[0];
|
||||
x2 = v->x;
|
||||
y2 = v->y;
|
||||
dv.lcurr = v->len;
|
||||
line_parameters prev(x1, y1, x2, y2, lprev);
|
||||
|
||||
v = &m_src_vertices[1];
|
||||
dv.x1 = v->x;
|
||||
dv.y1 = v->y;
|
||||
dv.lnext = v->len;
|
||||
dv.curr = line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr);
|
||||
|
||||
v = &m_src_vertices[dv.idx];
|
||||
dv.x2 = v->x;
|
||||
dv.y2 = v->y;
|
||||
dv.next = line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext);
|
||||
|
||||
dv.xb1 = 0;
|
||||
dv.yb1 = 0;
|
||||
dv.xb2 = 0;
|
||||
dv.yb2 = 0;
|
||||
|
||||
switch(m_line_join)
|
||||
{
|
||||
case outline_no_join:
|
||||
dv.flags = 3;
|
||||
break;
|
||||
|
||||
case outline_miter_join:
|
||||
case outline_round_join:
|
||||
dv.flags =
|
||||
(prev.diagonal_quadrant() == dv.curr.diagonal_quadrant()) |
|
||||
((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant()) << 1);
|
||||
break;
|
||||
|
||||
case outline_miter_accurate_join:
|
||||
dv.flags = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if((dv.flags & 1) == 0 && m_line_join != outline_round_join)
|
||||
{
|
||||
bisectrix(prev, dv.curr, &dv.xb1, &dv.yb1);
|
||||
}
|
||||
|
||||
if((dv.flags & 2) == 0 && m_line_join != outline_round_join)
|
||||
{
|
||||
bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2);
|
||||
}
|
||||
draw(dv, 0, m_src_vertices.size());
|
||||
case outline_miter_accurate_join:
|
||||
dv.flags = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if((dv.flags & 1) == 0 && m_line_join != outline_round_join)
|
||||
{
|
||||
bisectrix(prev, dv.curr, &dv.xb1, &dv.yb1);
|
||||
}
|
||||
|
||||
if((dv.flags & 2) == 0 && m_line_join != outline_round_join)
|
||||
{
|
||||
bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2);
|
||||
}
|
||||
draw(dv, 0, m_src_vertices.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
4
deps/agg/src/agg_rounded_rect.cpp
vendored
4
deps/agg/src/agg_rounded_rect.cpp
vendored
|
@ -78,8 +78,8 @@ namespace agg
|
|||
//--------------------------------------------------------------------
|
||||
void rounded_rect::normalize_radius()
|
||||
{
|
||||
double dx = fabs(m_y2 - m_y1);
|
||||
double dy = fabs(m_x2 - m_x1);
|
||||
double dx = fabs(m_x2 - m_x1);
|
||||
double dy = fabs(m_y2 - m_y1);
|
||||
|
||||
double k = 1.0;
|
||||
double t;
|
||||
|
|
|
@ -15,11 +15,33 @@ Look through the code to get an idea, and do not hesitate to ask questions.
|
|||
|
||||
Also read the design philosophy page for the motivations that lead to code decisions.
|
||||
|
||||
Templates are good, within reason. We seek to use templates were possible for flexible code, but not in cases where functional
|
||||
patterns would be just as concise and clear.
|
||||
|
||||
In general we use Boost, it makes more possible in C++. It is a big build time dependency (as in time to compile against and # of headers) but ultimately compiles to small object code and is very fast (particularly spirit). It also has no dependencies itself (it's really an extension to the C++ language) so requiring it is much easier than requiring a hard dependency that itself has other dependencies. This is a big reason that we prefer AGG to Cairo as our primary renderer. Also AGG, besides producing the best visual output, strikes an excellent balance between speed and thread safety by using very lightweight objects. Cairo not so much.
|
||||
|
||||
You will also notice that we don't use many of the standard geo libraries when we could. For instance we don't use GDAL, OGR, or GEOS anywhere in core, and only leverage them in optional plugins. We feel we can often write code that is faster and more thread safe than these libraries but that still does the job. If this ever changes we can adapt and start using these libraries or others as dependencies - nothing is nicer than standing on the shoulders of giants when it makes sense.
|
||||
|
||||
|
||||
## Code commits best practices.
|
||||
|
||||
#### Big changes - awesome as pull requests
|
||||
|
||||
We love big, aggressive refactoring - but ideally in branches. Even if the changes should go directly into the mainline code and are stable, very big changes are useful to see as a group and branches are cheap. So, branch and commit then create a pull request against master so that other developers can take a quick look. This is a great way for informal code review when a full issue is not warrented.
|
||||
|
||||
#### Commits that fix issues should note the issue #
|
||||
|
||||
git commit plugins/input/ogr/ -m "implemented sql query in OGR plugin (closes #472)"
|
||||
|
||||
#### Commits that relate to issues should reference them:
|
||||
|
||||
git commit tests/python_tests/sqlite_test.py -m "more robust sqlite tests - refs #928"
|
||||
|
||||
#### Commits that add a new feature or fix should be added to the CHANGELOG
|
||||
|
||||
Ideally the CHANGELOG can be a very concise place to look for the most important recent development and should not read like a full commit log. So, some developers may prefer to weekly or monthly look back over their commits and summarize all at once with additions to the CHANGELOG. Other developers may prefer to add as they go.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Mapnik is licensed LGPL, which means that you are a free to use the code in any of your applications whether they be open source or not. It also means that if you contribute code to Mapnik that others are free to continue using Mapnik in the same way, even with your new additions. If you choose to redistribute an application using Mapnik just make sure to provide any source code modifications you make back to the community. For the actual details see the full LGPL license in the COPYING doc.
|
||||
|
@ -67,13 +89,19 @@ If you see bits of code around that do not follow these please don't hesitate to
|
|||
|
||||
#### Indentation is four spaces
|
||||
|
||||
#### Use C++ style casts
|
||||
|
||||
static_cast<int>(value); // yes
|
||||
|
||||
(int)value; // no
|
||||
|
||||
#### Shared pointers should be created with [boost::make_shared](http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/make_shared.html) where possible
|
||||
|
||||
#### Function definitions should not be separated from their arguments:
|
||||
|
||||
void foo(int a) { ... } // please
|
||||
void foo(int a) // please
|
||||
|
||||
void foo (int a) { ... } // no
|
||||
void foo (int a) // no
|
||||
|
||||
#### Separate arguments by a single space:
|
||||
|
||||
|
@ -87,7 +115,18 @@ If you see bits of code around that do not follow these please don't hesitate to
|
|||
|
||||
if(a==b) // no
|
||||
|
||||
#### Braces should ideally be on a separate line:
|
||||
#### 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)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2010 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -19,15 +19,16 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_AGG_PATTERN_SOURCE_HPP
|
||||
#define MAPNIK_AGG_PATTERN_SOURCE_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/image_data.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
// agg
|
||||
#include "agg_color_rgba.h"
|
||||
|
||||
|
@ -61,4 +62,4 @@ private:
|
|||
};
|
||||
}
|
||||
|
||||
#endif //MAPNIK_AGG_PATTERN_SOURCE_HPP
|
||||
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2010 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -19,12 +19,14 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_AGG_RASTERIZER_HPP
|
||||
#define MAPNIK_AGG_RASTERIZER_HPP
|
||||
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
// agg
|
||||
#include "agg_rasterizer_scanline_aa.h"
|
||||
|
||||
namespace mapnik {
|
||||
|
@ -33,4 +35,4 @@ struct rasterizer : agg::rasterizer_scanline_aa<>, boost::noncopyable {};
|
|||
|
||||
}
|
||||
|
||||
#endif //MAPNIK_AGG_RASTERIZER_HPP
|
||||
#endif // MAPNIK_AGG_RASTERIZER_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef AGG_RENDERER_HPP
|
||||
#define AGG_RENDERER_HPP
|
||||
#ifndef MAPNIK_AGG_RENDERER_HPP
|
||||
#define MAPNIK_AGG_RENDERER_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
|
@ -40,6 +38,7 @@
|
|||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// FIXME
|
||||
// forward declare so that
|
||||
|
@ -61,7 +60,11 @@ class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T>
|
|||
{
|
||||
|
||||
public:
|
||||
// create with default, empty placement detector
|
||||
agg_renderer(Map const& m, T & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
||||
// create with external placement detector, possibly non-empty
|
||||
agg_renderer(Map const &m, T & pixmap, boost::shared_ptr<label_collision_detector4> detector,
|
||||
double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
||||
~agg_renderer();
|
||||
void start_map_processing(Map const& map);
|
||||
void end_map_processing(Map const& map);
|
||||
|
@ -122,9 +125,11 @@ private:
|
|||
CoordTransform t_;
|
||||
freetype_engine font_engine_;
|
||||
face_manager<freetype_engine> font_manager_;
|
||||
label_collision_detector4 detector_;
|
||||
boost::shared_ptr<label_collision_detector4> detector_;
|
||||
boost::scoped_ptr<rasterizer> ras_ptr;
|
||||
|
||||
void setup(Map const &m);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //AGG_RENDERER_HPP
|
||||
#endif // MAPNIK_AGG_RENDERER_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef ARROW_HPP
|
||||
#define ARROW_HPP
|
||||
#ifndef MAPNIK_ARROW_HPP
|
||||
#define MAPNIK_ARROW_HPP
|
||||
|
||||
#include <mapnik/box2d.hpp>
|
||||
|
||||
|
@ -44,4 +42,4 @@ private:
|
|||
};
|
||||
}
|
||||
|
||||
#endif // ARROW_HPP
|
||||
#endif // MAPNIK_ARROW_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2010 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,15 +20,18 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_ATTRIBUTE_HPP
|
||||
#define MAPNIK_ATTRIBUTE_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/value.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
static mapnik::value _null_value;
|
||||
|
||||
struct attribute
|
||||
{
|
||||
std::string name_;
|
||||
|
@ -38,7 +41,13 @@ struct attribute
|
|||
template <typename V ,typename F>
|
||||
V value(F const& f) const
|
||||
{
|
||||
return f[name_];
|
||||
typedef typename F::const_iterator const_iterator;
|
||||
const_iterator itr = f.find(name_);
|
||||
if (itr != f.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
return _null_value;
|
||||
}
|
||||
std::string const& name() const { return name_;}
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,20 +20,20 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef ATTRIBUTE_COLLECTOR_HPP
|
||||
#define ATTRIBUTE_COLLECTOR_HPP
|
||||
#ifndef MAPNIK_ATTRIBUTE_COLLECTOR_HPP
|
||||
#define MAPNIK_ATTRIBUTE_COLLECTOR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/feature_layer_desc.hpp>
|
||||
#include <mapnik/rule.hpp>
|
||||
#include <mapnik/path_expression_grammar.hpp>
|
||||
#include <mapnik/parse_path.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
// stl
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
|
@ -271,4 +271,4 @@ private:
|
|||
|
||||
} // namespace mapnik
|
||||
|
||||
#endif //ATTRIBUTE_COLLECTOR_HPP
|
||||
#endif // MAPNIK_ATTRIBUTE_COLLECTOR_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef ATTRIBUTE_DESCRIPTOR
|
||||
#define ATTRIBUTE_DESCRIPTOR
|
||||
#ifndef MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
||||
#define MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -118,4 +116,4 @@ operator << (std::basic_ostream<charT,traits>& out,
|
|||
|
||||
}
|
||||
|
||||
#endif // ATTRIBUTE_DESCRIPTOR_HPP
|
||||
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2010 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,16 +20,16 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: box2d.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef MAPNIK_BOX2D_HPP
|
||||
#define MAPNIK_BOX2D_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/coord.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
// stl
|
||||
#include <iomanip>
|
||||
|
||||
|
@ -41,9 +41,8 @@ namespace mapnik {
|
|||
template <typename T> class MAPNIK_DECL box2d
|
||||
: boost::equality_comparable<box2d<T> ,
|
||||
boost::addable<box2d<T>,
|
||||
boost::subtractable<box2d<T>,
|
||||
boost::dividable2<box2d<T>, T,
|
||||
boost::multipliable2<box2d<T>, T > > > > >
|
||||
boost::dividable2<box2d<T>, T,
|
||||
boost::multipliable2<box2d<T>, T > > > >
|
||||
{
|
||||
public:
|
||||
typedef box2d<T> box2d_type;
|
||||
|
@ -86,7 +85,6 @@ public:
|
|||
|
||||
// define some operators
|
||||
box2d_type& operator+=(box2d_type const& other);
|
||||
box2d_type& operator-=(box2d_type const& other);
|
||||
box2d_type& operator*=(T);
|
||||
box2d_type& operator/=(T);
|
||||
T operator[](int index) const;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2008 Tom Hughes
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,14 +20,10 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#if defined(HAVE_CAIRO)
|
||||
|
||||
#ifndef CAIRO_RENDERER_HPP
|
||||
#define CAIRO_RENDERER_HPP
|
||||
|
||||
|
||||
#ifndef MAPNIK_CAIRO_RENDERER_HPP
|
||||
#define MAPNIK_CAIRO_RENDERER_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
|
@ -152,6 +148,6 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // MAPNIK_CAIRO_RENDERER_HPP
|
||||
|
||||
#endif //CAIRO_RENDERER_HPP
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: color.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef COLOR_HPP
|
||||
#define COLOR_HPP
|
||||
#ifndef MAPNIK_COLOR_HPP
|
||||
#define MAPNIK_COLOR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
|
@ -32,6 +30,7 @@
|
|||
//boost
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
// stl
|
||||
#include <sstream>
|
||||
|
||||
|
@ -141,4 +140,4 @@ public:
|
|||
|
||||
}
|
||||
|
||||
#endif //COLOR_HPP
|
||||
#endif // MAPNIK_COLOR_HPP
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_COLOR_FACTORY_HPP
|
||||
#define MAPNIK_COLOR_FACTORY_HPP
|
||||
|
||||
|
@ -120,4 +118,4 @@ public:
|
|||
|
||||
#endif
|
||||
|
||||
#endif //MAPNIK_COLOR_FACTORY_HPP
|
||||
#endif // MAPNIK_COLOR_FACTORY_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,8 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_HPP
|
||||
#define CONFIG_HPP
|
||||
#ifndef MAPNIK_CONFIG_HPP
|
||||
#define MAPNIK_CONFIG_HPP
|
||||
|
||||
// Windows DLL support
|
||||
|
||||
|
@ -47,4 +47,5 @@
|
|||
#endif
|
||||
|
||||
#define PROJ_ENVELOPE_POINTS 20
|
||||
#endif // CONFIG_HPP
|
||||
|
||||
#endif // MAPNIK_CONFIG_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,8 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_CONFIG_ERROR_INCLUDED
|
||||
#define MAPNIK_CONFIG_ERROR_INCLUDED
|
||||
#ifndef MAPNIK_CONFIG_ERROR_HPP
|
||||
#define MAPNIK_CONFIG_ERROR_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
@ -54,4 +54,4 @@ protected:
|
|||
};
|
||||
}
|
||||
|
||||
#endif // MAPNIK_CONFIG_ERROR_INCLUDED
|
||||
#endif // MAPNIK_CONFIG_ERROR_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,12 +20,13 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: coord.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef COORD_HPP
|
||||
#define COORD_HPP
|
||||
#ifndef MAPNIK_COORD_HPP
|
||||
#define MAPNIK_COORD_HPP
|
||||
|
||||
// boost
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
// stl
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -187,4 +188,4 @@ operator << (std::basic_ostream<charT,traits>& out,
|
|||
}
|
||||
}
|
||||
|
||||
#endif // COORD_HPP
|
||||
#endif // MAPNIK_COORD_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,13 +20,12 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: coord_array.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef COORD_ARRAY_HPP
|
||||
#define COORD_ARRAY_HPP
|
||||
#ifndef MAPNIK_COORD_ARRAY_HPP
|
||||
#define MAPNIK_COORD_ARRAY_HPP
|
||||
|
||||
//mapnik
|
||||
#include <mapnik/coord.hpp>
|
||||
|
||||
// stl
|
||||
#include <cassert>
|
||||
|
||||
|
@ -89,4 +88,4 @@ private:
|
|||
}
|
||||
|
||||
|
||||
#endif //COORD_ARRAY_HPP
|
||||
#endif // MAPNIK_COORD_ARRAY_HPP
|
||||
|
|
|
@ -20,22 +20,23 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_CSS_COLOR_GRAMMAR_HPP
|
||||
#define MAPNIK_CSS_COLOR_GRAMMAR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/color.hpp>
|
||||
|
||||
// spirit2
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
|
||||
// phoenix
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_fusion.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
|
||||
// fusion
|
||||
#include <boost/fusion/include/adapt_struct.hpp>
|
||||
#include <boost/fusion/include/adapt_adt.hpp>
|
||||
|
@ -387,4 +388,4 @@ struct css_color_grammar : qi::grammar<Iterator, color(), ascii_space_type>
|
|||
|
||||
}
|
||||
|
||||
#endif //MAPNIK_CSS_COLOR_GRAMMAR_HPP
|
||||
#endif // MAPNIK_CSS_COLOR_GRAMMAR_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2009 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,22 +20,23 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_CSS_COLOR_GRAMMAR_HPP
|
||||
#define MAPNIK_CSS_COLOR_GRAMMAR_HPP
|
||||
#ifndef MAPNIK_CSS_COLOR_GRAMMAR_DEPRECATED_HPP
|
||||
#define MAPNIK_CSS_COLOR_GRAMMAR_DEPRECATED_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/color.hpp>
|
||||
|
||||
// spirit2
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
|
||||
// phoenix
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_fusion.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
|
||||
// fusion
|
||||
#include <boost/fusion/include/adapt_struct.hpp>
|
||||
|
||||
|
@ -45,7 +46,6 @@
|
|||
// stl
|
||||
#include <string>
|
||||
|
||||
|
||||
//BOOST_FUSION_ADAPT_CLASS(
|
||||
// mapnik::color,
|
||||
// (unsigned, unsigned, obj.red(), obj.set_red(val))
|
||||
|
@ -417,4 +417,4 @@ struct css_color_grammar : qi::grammar<Iterator, css(), ascii_space_type>
|
|||
|
||||
}
|
||||
|
||||
#endif //MAPNIK_CSS_COLOR_GRAMMAR_HPP
|
||||
#endif // MAPNIK_CSS_COLOR_GRAMMAR_DEPRECATED_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,35 +20,44 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: ctrans.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef CTRANS_HPP
|
||||
#define CTRANS_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#ifndef MAPNIK_CTRANS_HPP
|
||||
#define MAPNIK_CTRANS_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/vertex.hpp>
|
||||
#include <mapnik/coord_array.hpp>
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
|
||||
namespace mapnik {
|
||||
// boost
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
// stl
|
||||
#include <algorithm>
|
||||
|
||||
const double pi = boost::math::constants::pi<double>();
|
||||
const double pi_by_2 = pi/2.0;
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
typedef coord_array<coord2d> CoordinateArray;
|
||||
|
||||
template <typename Transform,typename Geometry>
|
||||
|
||||
template <typename Transform, typename Geometry>
|
||||
struct MAPNIK_DECL coord_transform
|
||||
{
|
||||
coord_transform(Transform const& t, Geometry& geom)
|
||||
: t_(t), geom_(geom) {}
|
||||
|
||||
unsigned vertex(double *x , double *y) const
|
||||
unsigned vertex(double *x, double *y) const
|
||||
{
|
||||
unsigned command = geom_.vertex(x,y);
|
||||
t_.forward(x,y);
|
||||
unsigned command = geom_.vertex(x, y);
|
||||
t_.forward(x, y);
|
||||
return command;
|
||||
}
|
||||
|
||||
void rewind (unsigned pos)
|
||||
void rewind(unsigned pos)
|
||||
{
|
||||
geom_.rewind(pos);
|
||||
}
|
||||
|
@ -58,7 +67,8 @@ private:
|
|||
Geometry& geom_;
|
||||
};
|
||||
|
||||
template <typename Transform,typename Geometry>
|
||||
|
||||
template <typename Transform, typename Geometry>
|
||||
struct MAPNIK_DECL coord_transform2
|
||||
{
|
||||
typedef std::size_t size_type;
|
||||
|
@ -71,39 +81,29 @@ struct MAPNIK_DECL coord_transform2
|
|||
geom_(geom),
|
||||
prj_trans_(prj_trans) {}
|
||||
|
||||
unsigned vertex(double * x , double * y) const
|
||||
unsigned vertex(double *x, double *y) const
|
||||
{
|
||||
unsigned command(SEG_MOVETO);
|
||||
unsigned command = SEG_MOVETO;
|
||||
bool ok = false;
|
||||
bool skipped_points = false;
|
||||
while (!ok)
|
||||
double z = 0;
|
||||
while (!ok && command != SEG_END)
|
||||
{
|
||||
command = geom_.vertex(x,y);
|
||||
double z=0;
|
||||
ok = prj_trans_.backward(*x,*y,z);
|
||||
command = geom_.vertex(x, y);
|
||||
ok = prj_trans_.backward(*x, *y, z);
|
||||
if (!ok) {
|
||||
skipped_points = true;
|
||||
}
|
||||
ok = ok || (command == SEG_END);
|
||||
}
|
||||
if (skipped_points && (command == SEG_LINETO))
|
||||
{
|
||||
command = SEG_MOVETO;
|
||||
}
|
||||
t_.forward(x,y);
|
||||
t_.forward(x, y);
|
||||
return command;
|
||||
}
|
||||
|
||||
/*unsigned vertex(double * x , double * y) const
|
||||
{
|
||||
unsigned command = geom_.vertex(x,y);
|
||||
double z=0;
|
||||
prj_trans_.backward(*x,*y,z);
|
||||
t_.forward(x,y);
|
||||
return command;
|
||||
}*/
|
||||
|
||||
void rewind (unsigned pos)
|
||||
void rewind(unsigned pos)
|
||||
{
|
||||
geom_.rewind(pos);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ private:
|
|||
};
|
||||
|
||||
|
||||
template <typename Transform,typename Geometry>
|
||||
template <typename Transform, typename Geometry>
|
||||
struct MAPNIK_DECL coord_transform3
|
||||
{
|
||||
coord_transform3(Transform const& t,
|
||||
|
@ -132,18 +132,18 @@ struct MAPNIK_DECL coord_transform3
|
|||
prj_trans_(prj_trans),
|
||||
dx_(dx), dy_(dy) {}
|
||||
|
||||
unsigned vertex(double * x , double * y) const
|
||||
unsigned vertex(double *x, double *y) const
|
||||
{
|
||||
unsigned command = geom_.vertex(x,y);
|
||||
double z=0;
|
||||
prj_trans_.backward(*x,*y,z);
|
||||
t_.forward(x,y);
|
||||
*x+=dx_;
|
||||
*y+=dy_;
|
||||
unsigned command = geom_.vertex(x, y);
|
||||
double z = 0;
|
||||
prj_trans_.backward(*x, *y, z);
|
||||
t_.forward(x, y);
|
||||
*x += dx_;
|
||||
*y += dy_;
|
||||
return command;
|
||||
}
|
||||
|
||||
void rewind (unsigned pos)
|
||||
void rewind(unsigned pos)
|
||||
{
|
||||
geom_.rewind(pos);
|
||||
}
|
||||
|
@ -156,6 +156,225 @@ private:
|
|||
int dy_;
|
||||
};
|
||||
|
||||
|
||||
// TODO - expose this and make chainable
|
||||
template <typename Transform,typename Geometry>
|
||||
struct MAPNIK_DECL coord_transform_parallel
|
||||
{
|
||||
typedef std::size_t size_type;
|
||||
typedef typename Geometry::value_type value_type;
|
||||
|
||||
coord_transform_parallel(Transform const& t,
|
||||
Geometry const& geom,
|
||||
proj_transform const& prj_trans )
|
||||
: t_(t),
|
||||
geom_(geom),
|
||||
prj_trans_(prj_trans),
|
||||
offset_(0.0),
|
||||
threshold_(10),
|
||||
m_status(initial) {}
|
||||
|
||||
enum status
|
||||
{
|
||||
initial,
|
||||
start,
|
||||
first,
|
||||
process,
|
||||
last_vertex,
|
||||
angle_joint,
|
||||
end
|
||||
};
|
||||
|
||||
double get_offset() const
|
||||
{
|
||||
return offset_;
|
||||
}
|
||||
|
||||
void set_offset(double offset)
|
||||
{
|
||||
offset_ = offset;
|
||||
}
|
||||
|
||||
unsigned int get_threshold() const
|
||||
{
|
||||
return threshold_;
|
||||
}
|
||||
|
||||
void set_threshold(unsigned int t)
|
||||
{
|
||||
threshold_ = t;
|
||||
}
|
||||
|
||||
unsigned vertex(double * x , double * y)
|
||||
{
|
||||
double z=0;
|
||||
|
||||
if (offset_==0.0)
|
||||
{
|
||||
unsigned command = geom_.vertex(x,y);
|
||||
prj_trans_.backward(*x,*y,z);
|
||||
t_.forward(x,y);
|
||||
return command;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(true){
|
||||
switch(m_status)
|
||||
{
|
||||
case end:
|
||||
return SEG_END;
|
||||
break;
|
||||
case initial:
|
||||
m_pre_cmd = geom_.vertex(x,y);
|
||||
prj_trans_.backward(*x,*y,z);
|
||||
t_.forward(x,y);
|
||||
m_pre_x = *x;
|
||||
m_pre_y = *y;
|
||||
//m_status = (m_pre_cmd!=SEG_END)?start:end; //
|
||||
case start:
|
||||
m_cur_cmd = geom_.vertex(&m_cur_x, &m_cur_y);
|
||||
prj_trans_.backward(m_cur_x,m_cur_y,z);
|
||||
t_.forward(&m_cur_x,&m_cur_y);
|
||||
case first:
|
||||
angle_a = atan2((m_pre_y-m_cur_y),(m_pre_x-m_cur_x));
|
||||
dx_pre = cos(angle_a + pi_by_2);
|
||||
dy_pre = sin(angle_a + pi_by_2);
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "offsetting line by: " << offset_ << "\n";
|
||||
std::clog << "initial dx=" << (dx_pre * offset_) << " dy=" << (dy_pre * offset_) << "\n";
|
||||
#endif
|
||||
*x = m_pre_x + (dx_pre * offset_);
|
||||
*y = m_pre_y + (dy_pre * offset_);
|
||||
m_status = process;
|
||||
return SEG_MOVETO;
|
||||
case process:
|
||||
switch(m_cur_cmd)
|
||||
{
|
||||
case SEG_LINETO:
|
||||
m_next_cmd = geom_.vertex(&m_next_x, &m_next_y);
|
||||
prj_trans_.backward(m_next_x,m_next_y,z);
|
||||
t_.forward(&m_next_x,&m_next_y);
|
||||
switch(m_next_cmd)
|
||||
{
|
||||
case SEG_LINETO:
|
||||
m_status = angle_joint;
|
||||
break;
|
||||
default:
|
||||
m_status = last_vertex;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SEG_END:
|
||||
m_status = end;
|
||||
return SEG_END;
|
||||
}
|
||||
break;
|
||||
case last_vertex:
|
||||
dx_curr = cos(angle_a + pi_by_2);
|
||||
dy_curr = sin(angle_a + pi_by_2);
|
||||
*x = m_cur_x + (dx_curr * offset_);
|
||||
*y = m_cur_y + (dy_curr * offset_);
|
||||
m_status = end;
|
||||
return m_cur_cmd;
|
||||
case angle_joint:
|
||||
angle_b = atan2((m_cur_y-m_next_y),(m_cur_x-m_next_x));
|
||||
h = tan((angle_b - angle_a)/2.0);
|
||||
|
||||
if (fabs(h) < threshold_)
|
||||
{
|
||||
dx_curr = cos(angle_a + pi_by_2);
|
||||
dy_curr = sin(angle_a + pi_by_2);
|
||||
*x = m_cur_x + (dx_curr * offset_) - h * (dy_curr * offset_);
|
||||
*y = m_cur_y + (dy_curr * offset_) + h * (dx_curr * offset_);
|
||||
}
|
||||
else // skip sharp spikes
|
||||
{
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
dx_curr = cos(angle_a + pi_by_2);
|
||||
dy_curr = sin(angle_a + pi_by_2);
|
||||
sin_curve = dx_curr*dy_pre-dy_curr*dx_pre;
|
||||
std::clog << "angle a: " << angle_a << "\n";
|
||||
std::clog << "angle b: " << angle_b << "\n";
|
||||
std::clog << "h: " << h << "\n";
|
||||
std::clog << "sin_curve: " << sin_curve << "\n";
|
||||
#endif
|
||||
m_status = process;
|
||||
break;
|
||||
}
|
||||
|
||||
// alternate sharp spike fix, but suboptimal...
|
||||
|
||||
/*
|
||||
sin_curve = dx_curr*dy_pre-dy_curr*dx_pre;
|
||||
cos_curve = -dx_pre*dx_curr-dy_pre*dy_curr;
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "sin_curve value: " << sin_curve << "\n";
|
||||
#endif
|
||||
if(sin_curve > -0.3 && sin_curve < 0.3) {
|
||||
angle_b = atan2((m_cur_y-m_next_y),(m_cur_x-m_next_x));
|
||||
h = tan((angle_b - angle_a)/2.0);
|
||||
*x = m_cur_x + (dx_curr * offset_) - h * (dy_curr * offset_);
|
||||
*y = m_cur_y + (dy_curr * offset_) + h * (dx_curr * offset_);
|
||||
} else {
|
||||
if (angle_b - angle_a > 0)
|
||||
h = -1.0*(1.0+cos_curve)/sin_curve;
|
||||
else
|
||||
h = (1.0+cos_curve)/sin_curve;
|
||||
*x = m_cur_x + (dx_curr + base_shift*dy_curr)*offset_;
|
||||
*y = m_cur_y + (dy_curr - base_shift*dx_curr)*offset_;
|
||||
}
|
||||
*/
|
||||
|
||||
m_pre_x = *x;
|
||||
m_pre_x = *y;
|
||||
m_cur_x = m_next_x;
|
||||
m_cur_y = m_next_y;
|
||||
angle_a = angle_b;
|
||||
m_pre_cmd = m_cur_cmd;
|
||||
m_cur_cmd = m_next_cmd;
|
||||
m_status = process;
|
||||
return m_pre_cmd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rewind (unsigned pos)
|
||||
{
|
||||
geom_.rewind(pos);
|
||||
m_status = initial;
|
||||
}
|
||||
|
||||
private:
|
||||
Transform const& t_;
|
||||
Geometry const& geom_;
|
||||
proj_transform const& prj_trans_;
|
||||
int offset_;
|
||||
unsigned int threshold_;
|
||||
status m_status;
|
||||
double dx_pre;
|
||||
double dy_pre;
|
||||
double dx_curr;
|
||||
double dy_curr;
|
||||
double sin_curve;
|
||||
double cos_curve;
|
||||
double angle_a;
|
||||
double angle_b;
|
||||
double h;
|
||||
unsigned m_pre_cmd;
|
||||
double m_pre_x;
|
||||
double m_pre_y;
|
||||
unsigned m_cur_cmd;
|
||||
double m_cur_x;
|
||||
double m_cur_y;
|
||||
unsigned m_next_cmd;
|
||||
double m_next_x;
|
||||
double m_next_y;
|
||||
};
|
||||
|
||||
|
||||
class CoordTransform
|
||||
{
|
||||
private:
|
||||
|
@ -166,13 +385,15 @@ private:
|
|||
box2d<double> extent_;
|
||||
double offset_x_;
|
||||
double offset_y_;
|
||||
|
||||
public:
|
||||
CoordTransform(int width,int height,const box2d<double>& extent,
|
||||
CoordTransform(int width, int height, const box2d<double>& extent,
|
||||
double offset_x = 0, double offset_y = 0)
|
||||
:width_(width),height_(height),extent_(extent),offset_x_(offset_x),offset_y_(offset_y)
|
||||
: width_(width), height_(height), extent_(extent),
|
||||
offset_x_(offset_x), offset_y_(offset_y)
|
||||
{
|
||||
sx_ = (double(width_))/extent_.width();
|
||||
sy_ = (double(height_))/extent_.height();
|
||||
sx_ = static_cast<double>(width_) / extent_.width();
|
||||
sy_ = static_cast<double>(height_) / extent_.height();
|
||||
}
|
||||
|
||||
inline int width() const
|
||||
|
@ -195,42 +416,43 @@ public:
|
|||
return sy_;
|
||||
}
|
||||
|
||||
inline void forward(double * x, double * y) const
|
||||
inline void forward(double *x, double *y) const
|
||||
{
|
||||
*x = (*x - extent_.minx()) * sx_ - offset_x_;
|
||||
*y = (extent_.maxy() - *y) * sy_ - offset_y_;
|
||||
}
|
||||
|
||||
inline void backward(double * x, double * y) const
|
||||
inline void backward(double *x, double *y) const
|
||||
{
|
||||
*x = extent_.minx() + (*x + offset_x_)/sx_;
|
||||
*y = extent_.maxy() - (*y + offset_y_)/sy_;
|
||||
*x = extent_.minx() + (*x + offset_x_) / sx_;
|
||||
*y = extent_.maxy() - (*y + offset_y_) / sy_;
|
||||
}
|
||||
|
||||
inline coord2d& forward(coord2d& c) const
|
||||
{
|
||||
forward(&c.x,&c.y);
|
||||
forward(&c.x, &c.y);
|
||||
return c;
|
||||
}
|
||||
|
||||
inline coord2d& backward(coord2d& c) const
|
||||
{
|
||||
backward(&c.x,&c.y);
|
||||
backward(&c.x, &c.y);
|
||||
return c;
|
||||
}
|
||||
|
||||
inline box2d<double> forward(const box2d<double>& e,proj_transform const& prj_trans) const
|
||||
inline box2d<double> forward(const box2d<double>& e,
|
||||
proj_transform const& prj_trans) const
|
||||
{
|
||||
double x0 = e.minx();
|
||||
double y0 = e.miny();
|
||||
double x1 = e.maxx();
|
||||
double y1 = e.maxy();
|
||||
double z = 0.0;
|
||||
prj_trans.backward(x0,y0,z);
|
||||
forward(&x0,&y0);
|
||||
prj_trans.backward(x1,y1,z);
|
||||
forward(&x1,&y1);
|
||||
return box2d<double>(x0,y0,x1,y1);
|
||||
prj_trans.backward(x0, y0, z);
|
||||
forward(&x0, &y0);
|
||||
prj_trans.backward(x1, y1, z);
|
||||
forward(&x1, &y1);
|
||||
return box2d<double>(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
inline box2d<double> forward(const box2d<double>& e) const
|
||||
|
@ -239,23 +461,24 @@ public:
|
|||
double y0 = e.miny();
|
||||
double x1 = e.maxx();
|
||||
double y1 = e.maxy();
|
||||
forward(&x0,&y0);
|
||||
forward(&x1,&y1);
|
||||
return box2d<double>(x0,y0,x1,y1);
|
||||
forward(&x0, &y0);
|
||||
forward(&x1, &y1);
|
||||
return box2d<double>(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
inline box2d<double> backward(const box2d<double>& e,proj_transform const& prj_trans) const
|
||||
inline box2d<double> backward(const box2d<double>& e,
|
||||
proj_transform const& prj_trans) const
|
||||
{
|
||||
double x0 = e.minx();
|
||||
double y0 = e.miny();
|
||||
double x1 = e.maxx();
|
||||
double y1 = e.maxy();
|
||||
double z = 0.0;
|
||||
backward(&x0,&y0);
|
||||
prj_trans.forward(x0,y0,z);
|
||||
backward(&x1,&y1);
|
||||
prj_trans.forward(x1,y1,z);
|
||||
return box2d<double>(x0,y0,x1,y1);
|
||||
backward(&x0, &y0);
|
||||
prj_trans.forward(x0, y0, z);
|
||||
backward(&x1, &y1);
|
||||
prj_trans.forward(x1, y1, z);
|
||||
return box2d<double>(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
inline box2d<double> backward(const box2d<double>& e) const
|
||||
|
@ -264,14 +487,14 @@ public:
|
|||
double y0 = e.miny();
|
||||
double x1 = e.maxx();
|
||||
double y1 = e.maxy();
|
||||
backward(&x0,&y0);
|
||||
backward(&x1,&y1);
|
||||
return box2d<double>(x0,y0,x1,y1);
|
||||
backward(&x0, &y0);
|
||||
backward(&x1, &y1);
|
||||
return box2d<double>(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
inline CoordinateArray& forward(CoordinateArray& coords) const
|
||||
{
|
||||
for (unsigned i=0;i<coords.size();++i)
|
||||
for (unsigned i = 0; i < coords.size(); ++i)
|
||||
{
|
||||
forward(coords[i]);
|
||||
}
|
||||
|
@ -280,12 +503,13 @@ public:
|
|||
|
||||
inline CoordinateArray& backward(CoordinateArray& coords) const
|
||||
{
|
||||
for (unsigned i=0;i<coords.size();++i)
|
||||
for (unsigned i = 0; i < coords.size(); ++i)
|
||||
{
|
||||
backward(coords[i]);
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
inline box2d<double> const& extent() const
|
||||
{
|
||||
return extent_;
|
||||
|
@ -293,4 +517,4 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
#endif //CTRANS_HPP
|
||||
#endif // MAPNIK_CTRANS_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,9 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: datasource.hpp 43 2005-04-22 18:52:47Z pavlenko $
|
||||
#ifndef MAPNIK_DATASOURCE_HPP
|
||||
#define MAPNIK_DATASOURCE_HPP
|
||||
|
||||
#ifndef DATASOURCE_HPP
|
||||
#define DATASOURCE_HPP
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/ctrans.hpp>
|
||||
|
@ -31,9 +30,11 @@
|
|||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/query.hpp>
|
||||
#include <mapnik/feature_layer_desc.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// stl
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
@ -142,6 +143,7 @@ typedef boost::shared_ptr<datasource> datasource_ptr;
|
|||
delete ds; \
|
||||
} \
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
#endif //DATASOURCE_HPP
|
||||
#endif // MAPNIK_DATASOURCE_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,24 +20,26 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: datasource_cache.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef DATASOURCE_CACHE_HPP
|
||||
#define DATASOURCE_CACHE_HPP
|
||||
#ifndef MAPNIK_DATASOURCE_CACHE_HPP
|
||||
#define MAPNIK_DATASOURCE_CACHE_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/utils.hpp>
|
||||
#include <mapnik/params.hpp>
|
||||
#include <mapnik/plugin.hpp>
|
||||
#include <mapnik/datasource.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// stl
|
||||
#include <map>
|
||||
|
||||
namespace mapnik {
|
||||
class MAPNIK_DECL datasource_cache :
|
||||
public singleton <datasource_cache,CreateStatic>
|
||||
public singleton <datasource_cache,CreateStatic>,
|
||||
private boost::noncopyable
|
||||
{
|
||||
friend class CreateStatic<datasource_cache>;
|
||||
private:
|
||||
|
@ -57,4 +59,4 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
#endif //DATASOURCE_CACHE_HPP
|
||||
#endif // MAPNIK_DATASOURCE_CACHE_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef DISTANCE_HPP
|
||||
#define DISTANCE_HPP
|
||||
#ifndef MAPNIK_DISTANCE_HPP
|
||||
#define MAPNIK_DISTANCE_HPP
|
||||
|
||||
#include <mapnik/coord.hpp>
|
||||
|
||||
|
@ -52,4 +50,4 @@ public:
|
|||
*/
|
||||
}
|
||||
|
||||
#endif // GEO_UTILS_HPP
|
||||
#endif // MAPNIK_DISTANCE_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,8 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_ELLIPSOID_HPP
|
||||
#define MAPNIK_ELLIPSOID_HPP
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,11 +20,13 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_ENUMERATION_INCLUDED
|
||||
#define MAPNIK_ENUMERATION_INCLUDED
|
||||
#ifndef MAPNIK_ENUMERATION_HPP
|
||||
#define MAPNIK_ENUMERATION_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
|
||||
// stl
|
||||
#include <vector>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
|
@ -325,4 +327,4 @@ operator>>(std::istream & is, mapnik::enumeration<ENUM, THE_MAX> & e)
|
|||
template <> std::string name ::our_name_ = #name; \
|
||||
template <> bool name ::our_verified_flag_( name ::verify(__FILE__, __LINE__));
|
||||
|
||||
#endif // MAPNIK_ENUMERATION_INCLUDED
|
||||
#endif // MAPNIK_ENUMERATION_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2009 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,14 +20,11 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_EXPRESSION_EVALUATOR_HPP
|
||||
#define MAPNIK_EXPRESSION_EVALUATOR_HPP
|
||||
|
||||
// boost
|
||||
#include <boost/regex.hpp>
|
||||
//#include <boost/regex/config.hpp>
|
||||
#if defined(BOOST_REGEX_HAS_ICU)
|
||||
#include <boost/regex/icu.hpp>
|
||||
#endif
|
||||
|
@ -43,7 +40,11 @@ struct evaluate : boost::static_visitor<T1>
|
|||
explicit evaluate(feature_type const& f)
|
||||
: feature_(f) {}
|
||||
|
||||
value_type operator() (value_type x) const { return x; }
|
||||
value_type operator() (value_type x) const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
value_type operator() (attribute const& attr) const
|
||||
{
|
||||
return attr.value<value_type,feature_type>(feature_);
|
||||
|
@ -104,4 +105,4 @@ struct evaluate : boost::static_visitor<T1>
|
|||
|
||||
}
|
||||
|
||||
#endif //MAPNIK_EXPRESSION_EVALUATOR_HPP
|
||||
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2009 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,8 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_EXPRESSIONS_GRAMMAR_HPP
|
||||
#define MAPNIK_EXPRESSIONS_GRAMMAR_HPP
|
||||
|
||||
|
@ -34,12 +32,15 @@
|
|||
#include <boost/variant.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
//spirit2
|
||||
|
||||
// spirit2
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
//fusion
|
||||
|
||||
// fusion
|
||||
#include <boost/fusion/include/adapt_struct.hpp>
|
||||
//phoenix
|
||||
|
||||
// phoenix
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_object.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
|
@ -50,6 +51,7 @@
|
|||
namespace mapnik
|
||||
{
|
||||
|
||||
using namespace boost;
|
||||
namespace qi = boost::spirit::qi;
|
||||
namespace standard_wide = boost::spirit::standard_wide;
|
||||
using standard_wide::space_type;
|
||||
|
@ -217,15 +219,17 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
|
|||
| lit("false") [_val = false]
|
||||
| lit("null") [_val = value_null() ]
|
||||
| ustring [_val = unicode_(_1) ]
|
||||
| attr [_val = construct<attribute>( _1 ) ]
|
||||
| attr [_val = construct<mapnik::attribute>( _1 ) ]
|
||||
| '(' >> expr [_val = _1 ] >> ')'
|
||||
;
|
||||
|
||||
attr %= '[' >> +(char_ - ']') >> ']';
|
||||
|
||||
#if BOOST_VERSION > 104200
|
||||
ustring %= '\'' >> no_skip[*~char_('\'')] >> '\'';
|
||||
attr %= '[' >> no_skip[+~char_(']')] >> ']';
|
||||
#else
|
||||
ustring %= '\'' >> lexeme[*(char_-'\'')] >> '\'';
|
||||
attr %= '[' >> lexeme[+(char_ - ']')] >> ']';
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2009 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,12 +20,13 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_EXPRESSION_NODE_HPP
|
||||
#define MAPNIK_EXPRESSION_NODE_HPP
|
||||
#ifndef MAPNIK_EXPRESSION_NODE_HPP
|
||||
#define MAPNIK_EXPRESSION_NODE_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/value.hpp>
|
||||
#include <mapnik/attribute.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2009 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,14 +20,13 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_EXPRESSION_STRING_HPP
|
||||
#define MAPNIK_EXPRESSION_STRING_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/expression_node.hpp>
|
||||
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,13 +20,12 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: factory.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef FACTORY_HPP
|
||||
#define FACTORY_HPP
|
||||
#ifndef MAPNIK_FACTORY_HPP
|
||||
#define MAPNIK_FACTORY_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/utils.hpp>
|
||||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
#include <map>
|
||||
|
@ -89,4 +88,4 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
#endif //FACTORY_HPP
|
||||
#endif // MAPNIK_FACTORY_HPP
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef FASTMATH_HPP
|
||||
#define FASTMATH_HPP
|
||||
#ifndef MAPNIK_FASTMATH_HPP
|
||||
#define MAPNIK_FASTMATH_HPP
|
||||
|
||||
/* Timings:
|
||||
* fast_sin(not inlined) 8.95s
|
||||
|
@ -109,4 +109,4 @@ static inline double fast_atan2(double y, double x)
|
|||
return result;
|
||||
}
|
||||
|
||||
#endif // FASTMATH_HPP
|
||||
#endif // MAPNIK_FASTMATH_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,9 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: feature.hpp 40 2005-04-13 20:20:46Z pavlenko $
|
||||
#ifndef MAPNIK_FEATURE_HPP
|
||||
#define MAPNIK_FEATURE_HPP
|
||||
|
||||
#ifndef FEATURE_HPP
|
||||
#define FEATURE_HPP
|
||||
// mapnik
|
||||
#include <mapnik/value.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
|
@ -36,9 +35,9 @@
|
|||
#else
|
||||
#include <boost/property_map.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// stl
|
||||
#include <map>
|
||||
|
||||
|
@ -66,6 +65,7 @@ private:
|
|||
std::map<std::string,value> props_;
|
||||
public:
|
||||
typedef std::map<std::string,value>::iterator iterator;
|
||||
typedef std::map<std::string,value>::const_iterator const_iterator;
|
||||
explicit feature(int id)
|
||||
: properties(props_),
|
||||
id_(id),
|
||||
|
@ -157,11 +157,26 @@ public:
|
|||
return props_.end();
|
||||
}
|
||||
|
||||
const_iterator begin() const
|
||||
{
|
||||
return props_.begin();
|
||||
}
|
||||
|
||||
const_iterator end() const
|
||||
{
|
||||
return props_.end();
|
||||
}
|
||||
|
||||
const_iterator find(std::string const& key) const
|
||||
{
|
||||
return props_.find(key);
|
||||
}
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "feature (" << std::endl;
|
||||
ss << " id:" << id_ << std::endl;
|
||||
ss << "feature "
|
||||
<< id_ << " (" << std::endl;
|
||||
for (std::map<std::string,value>::const_iterator itr=props_.begin();
|
||||
itr != props_.end();++itr)
|
||||
{
|
||||
|
@ -181,4 +196,4 @@ inline std::ostream& operator<< (std::ostream & out,Feature const& f)
|
|||
}
|
||||
}
|
||||
|
||||
#endif //FEATURE_HPP
|
||||
#endif // MAPNIK_FEATURE_HPP
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue