Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor projection interface: 1. cleanup custom lonlat<->merc code. …
…2. centralize proj4 strings into constants, 3. tweak projection benchmarking to allocate objects in loop so we can test that specifically - refs #1703
- Loading branch information
Dane Springmeyer
committed
Jan 28, 2013
1 parent
95b29f8
commit f8b1520
Showing
11 changed files
with
326 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/***************************************************************************** | ||
* | ||
* This file is part of Mapnik (c++ mapping toolkit) | ||
* | ||
* Copyright (C) 2013 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 | ||
* | ||
*****************************************************************************/ | ||
|
||
#ifndef MAPNIK_WELL_KNOWN_SRS_HPP | ||
#define MAPNIK_WELL_KNOWN_SRS_HPP | ||
|
||
// mapnik | ||
#include <mapnik/enumeration.hpp> | ||
|
||
// boost | ||
#include <boost/optional.hpp> | ||
|
||
// stl | ||
#include <cmath> | ||
|
||
namespace mapnik { | ||
|
||
enum well_known_srs_enum { | ||
WGS_84, | ||
G_MERC, | ||
well_known_srs_enum_MAX | ||
}; | ||
|
||
DEFINE_ENUM( well_known_srs_e, well_known_srs_enum ); | ||
|
||
static const double EARTH_RADIUS = 6378137.0; | ||
static const double EARTH_DIAMETER = EARTH_RADIUS * 2.0; | ||
static const double EARTH_CIRCUMFERENCE = EARTH_DIAMETER * M_PI; | ||
static const double MAXEXTENT = EARTH_CIRCUMFERENCE / 2.0; | ||
static const double M_PI_by2 = M_PI / 2; | ||
static const double D2R = M_PI / 180; | ||
static const double R2D = 180 / M_PI; | ||
static const double M_PIby360 = M_PI / 360; | ||
static const double MAXEXTENTby180 = MAXEXTENT / 180; | ||
static const std::string MAPNIK_LONGLAT_PROJ = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"; | ||
static const std::string MAPNIK_GMERC_PROJ = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"; | ||
|
||
boost::optional<well_known_srs_e> is_well_known_srs(std::string const& srs); | ||
|
||
boost::optional<bool> is_known_geographic(std::string const& srs); | ||
|
||
static inline bool lonlat2merc(double * x, double * y , int point_count) | ||
{ | ||
int i; | ||
for(i=0; i<point_count; i++) { | ||
x[i] = x[i] * MAXEXTENTby180; | ||
y[i] = std::log(std::tan((90 + y[i]) * M_PIby360)) * R2D; | ||
y[i] = y[i] * MAXEXTENTby180; | ||
if (x[i] > MAXEXTENT) x[i] = MAXEXTENT; | ||
if (x[i] < -MAXEXTENT) x[i] = -MAXEXTENT; | ||
if (y[i] > MAXEXTENT) y[i] = MAXEXTENT; | ||
if (y[i] < -MAXEXTENT) y[i] = -MAXEXTENT; | ||
} | ||
return true; | ||
} | ||
|
||
static inline bool merc2lonlat(double * x, double * y , int point_count) | ||
{ | ||
int i; | ||
for(i=0; i<point_count; i++) | ||
{ | ||
x[i] = (x[i] / MAXEXTENT) * 180; | ||
y[i] = (y[i] / MAXEXTENT) * 180; | ||
y[i] = R2D * (2 * std::atan(std::exp(y[i] * D2R)) - M_PI_by2); | ||
if (x[i] > 180) x[i] = 180; | ||
if (x[i] < -180) x[i] = -180; | ||
if (y[i] > 85.0511) y[i] = 85.0511; | ||
if (y[i] < -85.0511) y[i] = -85.0511; | ||
} | ||
return true; | ||
} | ||
|
||
} | ||
|
||
#endif // MAPNIK_WELL_KNOWN_SRS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.