"Fossies" - the Fresh Open Source Software Archive

Member "fimex-1.4.1/src/coordSys/PolarStereographicProjection.cc" (30 Oct 2019, 2532 Bytes) of package /linux/privat/fimex-1.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PolarStereographicProjection.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Fimex, PolarStereographicProjection.cc
    3  *
    4  * (C) Copyright 2010, met.no
    5  *
    6  * Project Info:  https://wiki.met.no/fimex/start
    7  *
    8  * This library is free software; you can redistribute it and/or modify it
    9  * under the terms of the GNU Lesser General Public License as published by
   10  * the Free Software Foundation; either version 2.1 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This library is distributed in the hope that it will be useful, but
   14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
   16  * License for more details.
   17  *
   18  * You should have received a copy of the GNU Lesser General Public
   19  * License along with this library; if not, write to the Free Software
   20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
   21  * USA.
   22  *
   23  *  Created on: Apr 29, 2010
   24  *      Author: Heiko Klein
   25  */
   26 
   27 #include "fimex/coordSys/PolarStereographicProjection.h"
   28 #include "fimex/Data.h"
   29 #include "fimex/String2Type.h"
   30 
   31 #include <cassert>
   32 #include <cmath>
   33 #include <regex>
   34 
   35 namespace MetNoFimex
   36 {
   37 
   38 using namespace std;
   39 
   40 bool PolarStereographicProjection::acceptsProj4(const std::string& proj4Str)
   41 {
   42     if (proj4ProjectionMatchesName(proj4Str, "stere")) {
   43         std::smatch what;
   44         if (std::regex_search(proj4Str, what, std::regex("\\+lat_0=(\\S+)"))) {
   45             double lat0 = string2type<double>(what[1].str());
   46             if (fabs(fabs(lat0)-90) < 1e-4) {
   47                 return true; // +90/-90
   48             }
   49         }
   50     }
   51     return false;
   52 }
   53 
   54 std::vector<CDMAttribute> PolarStereographicProjection::parametersFromProj4(const std::string& proj4Str)
   55 {
   56     vector<CDMAttribute> attrs;
   57     if (!acceptsProj4(proj4Str)) return attrs;
   58 
   59     // get Stereographic attributes
   60     attrs = StereographicProjection::parametersFromProj4(proj4Str);
   61     // switch grid_mapping_name to polar_stereographic
   62     vector<CDMAttribute>::iterator found = find_if(attrs.begin(), attrs.end(), CDMNameEqual("grid_mapping_name"));
   63     assert(found != attrs.end());
   64     *found = CDMAttribute("grid_mapping_name", "polar_stereographic");
   65     // switch longitude_of_projection_origin to straight_vertical_longitude_from_pole
   66     found = find_if(attrs.begin(), attrs.end(), CDMNameEqual("longitude_of_projection_origin"));
   67     assert(found != attrs.end());
   68     double lonVal = found->getData()->asDouble()[0];
   69     *found = CDMAttribute("straight_vertical_longitude_from_pole", lonVal);
   70     return attrs;
   71 }
   72 
   73 }