From 110016fe78d4521ae7eb640f068641b564be2274 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 17 Oct 2006 17:26:35 +0000 Subject: [PATCH] 1. refactored proj stuff into separate files 2. added is_geographic property 3. added basic support for text_symbolizer in load_map --- bindings/python/mapnik_projection.cpp | 1 + include/mapnik/ctrans.hpp | 2 +- include/mapnik/proj_transform.hpp | 52 +++++++ include/mapnik/projection.hpp | 186 ++++++-------------------- src/SConscript | 2 + src/load_map.cpp | 24 +++- src/proj_transform.cpp | 85 ++++++++++++ src/projection.cpp | 101 ++++++++++++++ utils/ogcserver/ogcserver | 58 ++++---- 9 files changed, 336 insertions(+), 175 deletions(-) create mode 100644 include/mapnik/proj_transform.hpp create mode 100644 src/proj_transform.cpp create mode 100644 src/projection.cpp diff --git a/bindings/python/mapnik_projection.cpp b/bindings/python/mapnik_projection.cpp index 301e94650..5e88bfef6 100644 --- a/bindings/python/mapnik_projection.cpp +++ b/bindings/python/mapnik_projection.cpp @@ -56,6 +56,7 @@ void export_projection () .def ("inverse",&projection::inverse) .def ("params", make_function(&projection::params, return_value_policy())) + .add_property ("geographic",&projection::is_geographic) ; def("forward",&forward); diff --git a/include/mapnik/ctrans.hpp b/include/mapnik/ctrans.hpp index bf9865e17..f4cd8cee4 100644 --- a/include/mapnik/ctrans.hpp +++ b/include/mapnik/ctrans.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include namespace mapnik { typedef coord_array CoordinateArray; diff --git a/include/mapnik/proj_transform.hpp b/include/mapnik/proj_transform.hpp new file mode 100644 index 000000000..5a5e92c13 --- /dev/null +++ b/include/mapnik/proj_transform.hpp @@ -0,0 +1,52 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2006 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 + * + *****************************************************************************/ + +//$Id$ + +#ifndef PROJ_TRANSFORM_HPP +#define PROJ_TRANSFORM_HPP + +// boost +#include +// mapnik +#include + +namespace mapnik { + + class proj_transform : private boost::noncopyable + { + public: + proj_transform(projection const& source, + projection const& dest); + + bool forward (double& x, double& y , double& z) const; + bool backward (double& x, double& y , double& z) const; + + private: + projection const& source_; + projection const& dest_; + bool is_source_latlong_; + bool is_dest_latlong_; + }; +} + +#endif // PROJ_TRANSFORM_HPP diff --git a/include/mapnik/projection.hpp b/include/mapnik/projection.hpp index 719fffafb..90e40819f 100644 --- a/include/mapnik/projection.hpp +++ b/include/mapnik/projection.hpp @@ -1,17 +1,41 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2006 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 + * + *****************************************************************************/ + +//$Id$ #ifndef PROJECTION_HPP #define PROJECTION_HPP +// stl #include #include #include +// boost #include - +// mapnik #include -#include -namespace mapnik -{ +namespace mapnik { + class proj_init_error : public std::runtime_error { public: @@ -23,151 +47,25 @@ namespace mapnik { friend class proj_transform; public: - explicit projection(std::string params = "+proj=latlong +ellps=WGS84") - : params_(params) - { - init(); // - } + explicit projection(std::string params = "+proj=latlong +ellps=WGS84"); + projection(projection const& rhs); + ~projection(); - projection(projection const& rhs) - : params_(rhs.params_) - { - init(); // - } + projection& operator=(projection const& rhs); + bool is_initialized() const; + bool is_geographic() const; + std::string const& params() const; + + void forward(double & x, double &y ) const; + void inverse(double & x,double & y) const; - projection& operator=(projection const& rhs) - { - projection tmp(rhs); - swap(tmp); - return *this; - } - - bool is_initialized() const - { - return proj_ ? true : false; - } - - std::string const& params() const - { - return params_; - } - - void forward(double & x, double &y ) const - { - projUV p; - p.u = x * DEG_TO_RAD; - p.v = y * DEG_TO_RAD; - p = pj_fwd(p,proj_); - x = p.u; - y = p.v; - } - - void inverse(double & x,double & y) const - { - projUV p; - p.u = x; - p.v = y; - p = pj_inv(p,proj_); - x = RAD_TO_DEG * p.u; - y = RAD_TO_DEG * p.v; - } - - ~projection() - { - if (proj_) pj_free(proj_); - } private: - - void init() - { - proj_=pj_init_plus(params_.c_str()); - if (!proj_) throw proj_init_error(params_); - } - - void swap (projection& rhs) - { - std::swap(params_,rhs.params_); - init (); - } - + void init(); + void swap (projection& rhs); + private: std::string params_; - projPJ proj_; - }; - - class proj_transform : private boost::noncopyable - { - public: - proj_transform(projection const& source, - projection const& dest) - : source_(source), - dest_(dest) - { - is_source_latlong_ = pj_is_latlong(source_.proj_); - is_dest_latlong_ = pj_is_latlong(dest_.proj_); - } - - bool forward (double & x, double & y , double & z) const - { - if (is_source_latlong_) - { - x *= DEG_TO_RAD; - y *= DEG_TO_RAD; - } - - if (pj_transform( source_.proj_, dest_.proj_, 1, - 0, &x,&y,&z) != 0) - { - return false; - } - - if (is_dest_latlong_) - { - x *= RAD_TO_DEG; - y *= RAD_TO_DEG; - } - - return true; - } - - bool forward (Envelope & ext) const - { - if (is_source_latlong_) - { - ext = ext.intersect(Envelope(-180,-90,180,90)); - } - // TODO - return true; - } - - bool backward (double & x, double & y , double & z) const - { - if (is_dest_latlong_) - { - x *= DEG_TO_RAD; - y *= DEG_TO_RAD; - } - - if (pj_transform( dest_.proj_, source_.proj_, 1, - 0, &x,&y,&z) != 0) - { - return false; - } - - if (is_source_latlong_) - { - x *= RAD_TO_DEG; - y *= RAD_TO_DEG; - } - - return true; - } - - private: - projection const& source_; - projection const& dest_; - bool is_source_latlong_; - bool is_dest_latlong_; + void * proj_; }; } diff --git a/src/SConscript b/src/SConscript index 8c68ea478..4dc1efc26 100644 --- a/src/SConscript +++ b/src/SConscript @@ -56,6 +56,8 @@ source = Split( text_symbolizer.cpp tiff_reader.cpp wkb.cpp + projection.cpp + proj_transform.cpp """ ) diff --git a/src/load_map.cpp b/src/load_map.cpp index 6458535e7..842e2117e 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -127,7 +127,29 @@ namespace mapnik { std::cout << sym.first << "\n"; } - else if ( sym.first == "LineSymbolizer") + else if ( sym.first == "TextSymbolizer") + { + std::string name = + sym.second.get(".name"); + unsigned size = + sym.second.get(".size",10); + std::string color_str = + sym.second.get(".fill","black"); + Color c = color_factory::from_string(color_str.c_str()); + + text_symbolizer text_symbol(name,size,c); + + std::string placement_str = + sym.second.get(".placement","point"); + + if (placement_str == "line") + { + text_symbol.set_label_placement(line_placement); + } + + rule.append(text_symbol); + } + else if ( sym.first == "LineSymbolizer") { stroke strk; ptree::const_iterator cssIter = sym.second.begin(); diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp new file mode 100644 index 000000000..40b438f2c --- /dev/null +++ b/src/proj_transform.cpp @@ -0,0 +1,85 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2006 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 + * + *****************************************************************************/ + +//$Id$ + +#include + +#include + +namespace mapnik { + + proj_transform::proj_transform(projection const& source, + projection const& dest) + : source_(source), + dest_(dest) + { + is_source_latlong_ = pj_is_latlong(source_.proj_); + is_dest_latlong_ = pj_is_latlong(dest_.proj_); + } + + bool proj_transform::forward (double & x, double & y , double & z) const + { + if (is_source_latlong_) + { + x *= DEG_TO_RAD; + y *= DEG_TO_RAD; + } + + if (pj_transform( source_.proj_, dest_.proj_, 1, + 0, &x,&y,&z) != 0) + { + return false; + } + + if (is_dest_latlong_) + { + x *= RAD_TO_DEG; + y *= RAD_TO_DEG; + } + + return true; + } + + bool proj_transform::backward (double & x, double & y , double & z) const + { + if (is_dest_latlong_) + { + x *= DEG_TO_RAD; + y *= DEG_TO_RAD; + } + + if (pj_transform( dest_.proj_, source_.proj_, 1, + 0, &x,&y,&z) != 0) + { + return false; + } + + if (is_source_latlong_) + { + x *= RAD_TO_DEG; + y *= RAD_TO_DEG; + } + + return true; + } +} diff --git a/src/projection.cpp b/src/projection.cpp new file mode 100644 index 000000000..a6660def3 --- /dev/null +++ b/src/projection.cpp @@ -0,0 +1,101 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2006 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 + * + *****************************************************************************/ + +//$Id$ + +// proj4 +#include +// mapnik +#include + +namespace mapnik { + projection::projection(std::string params) + : params_(params) + { + init(); // + } + + projection::projection(projection const& rhs) + : params_(rhs.params_) + { + init(); // + } + + projection& projection::operator=(projection const& rhs) + { + projection tmp(rhs); + swap(tmp); + return *this; + } + + bool projection::is_initialized() const + { + return proj_ ? true : false; + } + + bool projection::is_geographic() const + { + return pj_is_latlong(proj_); + } + + std::string const& projection::params() const + { + return params_; + } + + void projection::forward(double & x, double &y ) const + { + projUV p; + p.u = x * DEG_TO_RAD; + p.v = y * DEG_TO_RAD; + p = pj_fwd(p,proj_); + x = p.u; + y = p.v; + } + + void projection::inverse(double & x,double & y) const + { + projUV p; + p.u = x; + p.v = y; + p = pj_inv(p,proj_); + x = RAD_TO_DEG * p.u; + y = RAD_TO_DEG * p.v; + } + + projection::~projection() + { + if (proj_) pj_free(proj_); + } + + void projection::init() + { + proj_=pj_init_plus(params_.c_str()); + if (!proj_) throw proj_init_error(params_); + } + + void projection::swap (projection& rhs) + { + std::swap(params_,rhs.params_); + init (); + } +} diff --git a/utils/ogcserver/ogcserver b/utils/ogcserver/ogcserver index 52d67aea5..0f6a2250a 100644 --- a/utils/ogcserver/ogcserver +++ b/utils/ogcserver/ogcserver @@ -1,29 +1,29 @@ -#!/usr/bin/python2.3 -# -# 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$ - -from mapnik.ogcserver.cgiserver import Handler -from jon import fcgi - -class OGCServerHandler(Handler): - configpath = '/etc/ogcserver.conf' - -fcgi.Server({fcgi.FCGI_RESPONDER: OGCServerHandler}).run() +#!/usr/bin/python2.3 +# +# 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$ + +from mapnik.ogcserver.cgiserver import Handler +from jon import fcgi + +class OGCServerHandler(Handler): + configpath = '/etc/ogcserver.conf' + +fcgi.Server({fcgi.FCGI_RESPONDER: OGCServerHandler}).run()