"Fossies" - the Fresh Open Source Software Archive

Member "fimex-1.4.1/src/coordSys/LambertConformalConicProjection.cc" (30 Oct 2019, 3754 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 "LambertConformalConicProjection.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Fimex, LambertConformalConicProjection.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/LambertConformalConicProjection.h"
   28 #include "fimex/Data.h"
   29 #include "fimex/String2Type.h"
   30 #include <regex>
   31 
   32 namespace MetNoFimex
   33 {
   34 
   35 using namespace std;
   36 
   37 LambertConformalConicProjection::LambertConformalConicProjection()
   38 : ProjectionImpl("lambert_conformal_conic", false)
   39 {
   40 }
   41 
   42 bool LambertConformalConicProjection::acceptsProj4(const std::string& proj4Str)
   43 {
   44     return proj4ProjectionMatchesName(proj4Str, "lcc");
   45 }
   46 
   47 std::vector<CDMAttribute> LambertConformalConicProjection::parametersFromProj4(const std::string& proj4Str)
   48 {
   49     vector<CDMAttribute> attrs;
   50     if (!acceptsProj4(proj4Str)) return attrs;
   51 
   52     attrs.push_back(CDMAttribute("grid_mapping_name", "lambert_conformal_conic"));
   53 
   54     std::smatch what;
   55     if (std::regex_search(proj4Str, what, std::regex("\\+lat_1=(\\S+)"))) {
   56         double lat1 = string2type<double>(what[1].str());
   57         if (std::regex_search(proj4Str, what, std::regex("\\+lat_2=(\\S+)"))) {
   58             double lat2 = string2type<double>(what[1].str());
   59 
   60             DataPtr stdParallels = createData(CDM_DOUBLE, 2);
   61             stdParallels->setValue(0, lat1);
   62             stdParallels->setValue(1, lat2);
   63             attrs.push_back(CDMAttribute("standard_parallel", stdParallels));
   64         } else {
   65             attrs.push_back(CDMAttribute("standard_parallel", lat1));
   66         }
   67     }
   68 
   69     double lon0 = 0.;
   70     if (std::regex_search(proj4Str, what, std::regex("\\+lon_0=(\\S+)"))) {
   71         lon0 = string2type<double>(what[1].str());
   72     }
   73     attrs.push_back(CDMAttribute("longitude_of_central_meridian", lon0));
   74 
   75     double lat0 = 0.;
   76     if (std::regex_search(proj4Str, what, std::regex("\\+lat_0=(\\S+)"))) {
   77         lat0 = string2type<double>(what[1].str());
   78     }
   79     attrs.push_back(CDMAttribute("latitude_of_projection_origin", lat0));
   80 
   81     proj4GetEarthAttributes(proj4Str, attrs);
   82     attrs.push_back(CDMAttribute("proj4", proj4Str));
   83     return attrs;
   84 }
   85 
   86 std::ostream& LambertConformalConicProjection::getProj4ProjectionPart(std::ostream& oproj) const
   87 {
   88     oproj << "+proj=lcc";
   89     std::vector<CDMAttribute>::const_iterator foundAttr = std::find_if(params_.begin(), params_.end(), CDMNameEqual("standard_parallel"));
   90     if (foundAttr != params_.end()) {
   91         // standard_parallel - There may be 1 or 2 values.
   92         DataPtr spData = foundAttr->getData();
   93         oproj << " +lat_1=" << spData->asDouble()[0];
   94         if (spData->size() > 2) {
   95             oproj << " +lat_2=" << spData->asDouble()[1];
   96         } else {
   97             oproj << " +lat_2=" << spData->asDouble()[0];
   98         }
   99     } else {
  100         oproj << " +lat_1=0 +lat_2=0";
  101     }
  102     addParameterToStream(oproj, "longitude_of_central_meridian", " +lon_0=");
  103     addParameterToStream(oproj, "latitude_of_projection_origin", " +lat_0=");
  104 
  105     return oproj;
  106 }
  107 
  108 }