mirror of
https://github.com/mapnik/mapnik.git
synced 2025-12-08 20:13:09 +00:00
1. refactored proj stuff into separate files
2. added is_geographic property 3. added basic support for text_symbolizer in load_map
This commit is contained in:
parent
f76079f15b
commit
110016fe78
@ -56,6 +56,7 @@ void export_projection ()
|
||||
.def ("inverse",&projection::inverse)
|
||||
.def ("params", make_function(&projection::params,
|
||||
return_value_policy<copy_const_reference>()))
|
||||
.add_property ("geographic",&projection::is_geographic)
|
||||
;
|
||||
|
||||
def("forward",&forward);
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
#include <mapnik/envelope.hpp>
|
||||
#include <mapnik/coord_array.hpp>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
|
||||
namespace mapnik {
|
||||
typedef coord_array<coord2d> CoordinateArray;
|
||||
|
||||
52
include/mapnik/proj_transform.hpp
Normal file
52
include/mapnik/proj_transform.hpp
Normal file
@ -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 <boost/utility.hpp>
|
||||
// mapnik
|
||||
#include <mapnik/projection.hpp>
|
||||
|
||||
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
|
||||
@ -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 <string>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/envelope.hpp>
|
||||
#include <proj_api.h>
|
||||
|
||||
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<double> & ext) const
|
||||
{
|
||||
if (is_source_latlong_)
|
||||
{
|
||||
ext = ext.intersect(Envelope<double>(-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_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -56,6 +56,8 @@ source = Split(
|
||||
text_symbolizer.cpp
|
||||
tiff_reader.cpp
|
||||
wkb.cpp
|
||||
projection.cpp
|
||||
proj_transform.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<std::string>("<xmlattr>.name");
|
||||
unsigned size =
|
||||
sym.second.get<unsigned>("<xmlattr>.size",10);
|
||||
std::string color_str =
|
||||
sym.second.get<std::string>("<xmlattr>.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<std::string>("<xmlattr>.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();
|
||||
|
||||
85
src/proj_transform.cpp
Normal file
85
src/proj_transform.cpp
Normal file
@ -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 <proj_api.h>
|
||||
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
101
src/projection.cpp
Normal file
101
src/projection.cpp
Normal file
@ -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 <proj_api.h>
|
||||
// mapnik
|
||||
#include <mapnik/projection.hpp>
|
||||
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user