Skip to content

Commit

Permalink
Dispatch content of 4D_api.cpp into multiple .cpp files, and rename t…
Browse files Browse the repository at this point in the history
…he remainder as misc.cpp

No functional change, just moving code around.

4D_api.cpp has become quite large and a set of 'random' things, that
didn't correlate well with the '4D' naming. Some re-organization was needed.

Create following files:
- src/area.cpp: PJ_AREA related code
- src/coord_operation.cpp: PJCoordOperation methods
- src/create.cpp: pj_create_internal() related stuff
- src/crs_to_crs.cpp: proj_create_crs_to_crs() and the like
- src/dist.cpp: distance related functions
- src/info.cpp: proj_info() and proj_pj_info()
- src/trans.cpp: proj_trans(), proj_trans_array(), proj_trans_generic(), proj_roundtrip()
- src/trans_bounds.cpp: proj_trans_bounds()

Some other functions also moved to more relevant existing source files.
  • Loading branch information
rouault committed Feb 4, 2025
1 parent 8268efc commit 61da477
Show file tree
Hide file tree
Showing 17 changed files with 3,378 additions and 3,108 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = src/iso19111 src/iso19111/operation include/proj src/proj.h src/proj_experimental.h src/general_doc.dox src/filemanager.cpp src/networkfilemanager.cpp src/4D_api.cpp
INPUT = src/iso19111 src/iso19111/operation include/proj src/proj.h src/proj_experimental.h src/general_doc.dox src/filemanager.cpp src/networkfilemanager.cpp src/misc.cpp src/trans_bounds.cpp

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
3,096 changes: 0 additions & 3,096 deletions src/4D_api.cpp

This file was deleted.

52 changes: 52 additions & 0 deletions src/area.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/******************************************************************************
* Project: PROJ
* Purpose: PJ_AREA related code
*
* Author: Thomas Knudsen, thokn@sdfe.dk, 2016-06-09/2016-11-06
*
******************************************************************************
* Copyright (c) 2016, 2017 Thomas Knudsen/SDFE
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#define FROM_PROJ_CPP

#include "proj.h"
#include "proj_internal.h"

/** Create an area of use */
PJ_AREA *proj_area_create(void) { return new PJ_AREA(); }

/** Assign a bounding box to an area of use. */
void proj_area_set_bbox(PJ_AREA *area, double west_lon_degree,
double south_lat_degree, double east_lon_degree,
double north_lat_degree) {
area->bbox_set = TRUE;
area->west_lon_degree = west_lon_degree;
area->south_lat_degree = south_lat_degree;
area->east_lon_degree = east_lon_degree;
area->north_lat_degree = north_lat_degree;
}

/** Assign the name of an area of use. */
void proj_area_set_name(PJ_AREA *area, const char *name) { area->name = name; }

/** Free an area of use */
void proj_area_destroy(PJ_AREA *area) { delete area; }
30 changes: 30 additions & 0 deletions src/conversions/geoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@

PROJ_HEAD(geoc, "Geocentric Latitude");

/*************************************************************************************/
PJ_COORD pj_geocentric_latitude(const PJ *P, PJ_DIRECTION direction,
PJ_COORD coord) {
/**************************************************************************************
Convert geographical latitude to geocentric (or the other way round if
direction = PJ_INV)
The conversion involves a call to the tangent function, which goes
through the roof at the poles, so very close (the last centimeter) to the
poles no conversion takes place and the input latitude is copied directly to
the output.
Fortunately, the geocentric latitude converges to the geographical at
the poles, so the difference is negligible.
For the spherical case, the geographical latitude equals the geocentric,
and consequently, the input is copied directly to the output.
**************************************************************************************/
const double limit = M_HALFPI - 1e-9;
PJ_COORD res = coord;
if ((coord.lp.phi > limit) || (coord.lp.phi < -limit) || (P->es == 0))
return res;
if (direction == PJ_FWD)
res.lp.phi = atan(P->one_es * tan(coord.lp.phi));
else
res.lp.phi = atan(P->rone_es * tan(coord.lp.phi));

return res;
}

/* Geographical to geocentric */
static void forward(PJ_COORD &coo, PJ *P) {
coo = pj_geocentric_latitude(P, PJ_FWD, coo);
Expand Down
138 changes: 138 additions & 0 deletions src/coord_operation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/******************************************************************************
* Project: PROJ
* Purpose: PJCoordOperation methods
*
* Author: Even Rouault, <even.rouault at spatialys.com>
*
******************************************************************************
* Copyright (c) 2018-2024, Even Rouault, <even.rouault at spatialys.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#define FROM_PROJ_CPP

#include "proj.h"
#include "proj_internal.h"
#include <math.h>

#include "proj/internal/internal.hpp"

using namespace NS_PROJ::internal;

//! @cond Doxygen_Suppress
/**************************************************************************************/
PJCoordOperation::~PJCoordOperation() {
/**************************************************************************************/
proj_destroy(pj);
proj_destroy(pjSrcGeocentricToLonLat);
proj_destroy(pjDstGeocentricToLonLat);
}

/**************************************************************************************/
bool PJCoordOperation::isInstantiable() const {
/**************************************************************************************/
if (isInstantiableCached == INSTANTIABLE_STATUS_UNKNOWN)
isInstantiableCached = proj_coordoperation_is_instantiable(pj->ctx, pj);
return (isInstantiableCached == 1);
}

// Returns true if the passed operation uses NADCON5 grids for NAD83 to
// NAD83(HARN)
static bool isSpecialCaseForNAD83_to_NAD83HARN(const std::string &opName) {
return opName.find("NAD83 to NAD83(HARN) (47)") != std::string::npos ||
opName.find("NAD83 to NAD83(HARN) (48)") != std::string::npos ||
opName.find("NAD83 to NAD83(HARN) (49)") != std::string::npos ||
opName.find("NAD83 to NAD83(HARN) (50)") != std::string::npos;
}

// Returns true if the passed operation uses "GDA94 to WGS 84 (1)", which
// is the null transformation
static bool isSpecialCaseForGDA94_to_WGS84(const std::string &opName) {
return opName.find("GDA94 to WGS 84 (1)") != std::string::npos;
}

// Returns true if the passed operation uses "GDA2020 to WGS 84 (2)", which
// is the null transformation
static bool isSpecialCaseForWGS84_to_GDA2020(const std::string &opName) {
return opName.find("GDA2020 to WGS 84 (2)") != std::string::npos;
}

PJCoordOperation::PJCoordOperation(
int idxInOriginalListIn, double minxSrcIn, double minySrcIn,
double maxxSrcIn, double maxySrcIn, double minxDstIn, double minyDstIn,
double maxxDstIn, double maxyDstIn, PJ *pjIn, const std::string &nameIn,
double accuracyIn, double pseudoAreaIn, const char *areaNameIn,
const PJ *pjSrcGeocentricToLonLatIn, const PJ *pjDstGeocentricToLonLatIn)
: idxInOriginalList(idxInOriginalListIn), minxSrc(minxSrcIn),
minySrc(minySrcIn), maxxSrc(maxxSrcIn), maxySrc(maxySrcIn),
minxDst(minxDstIn), minyDst(minyDstIn), maxxDst(maxxDstIn),
maxyDst(maxyDstIn), pj(pjIn), name(nameIn), accuracy(accuracyIn),
pseudoArea(pseudoAreaIn), areaName(areaNameIn ? areaNameIn : ""),
isOffshore(areaName.find("- offshore") != std::string::npos),
isUnknownAreaName(areaName.empty() || areaName == "unknown"),
isPriorityOp(isSpecialCaseForNAD83_to_NAD83HARN(name) ||
isSpecialCaseForGDA94_to_WGS84(name) ||
isSpecialCaseForWGS84_to_GDA2020(name)),
pjSrcGeocentricToLonLat(pjSrcGeocentricToLonLatIn
? proj_clone(pjSrcGeocentricToLonLatIn->ctx,
pjSrcGeocentricToLonLatIn)
: nullptr),
pjDstGeocentricToLonLat(pjDstGeocentricToLonLatIn
? proj_clone(pjDstGeocentricToLonLatIn->ctx,
pjDstGeocentricToLonLatIn)
: nullptr) {
const auto IsLonLatOrLatLon = [](const PJ *crs, bool &isLonLatDegreeOut,
bool &isLatLonDegreeOut) {
const auto eType = proj_get_type(crs);
if (eType == PJ_TYPE_GEOGRAPHIC_2D_CRS ||
eType == PJ_TYPE_GEOGRAPHIC_3D_CRS) {
const auto cs = proj_crs_get_coordinate_system(crs->ctx, crs);
const char *direction = "";
double conv_factor = 0;
constexpr double EPS = 1e-14;
if (proj_cs_get_axis_info(crs->ctx, cs, 0, nullptr, nullptr,
&direction, &conv_factor, nullptr,
nullptr, nullptr) &&
ci_equal(direction, "East")) {
isLonLatDegreeOut = fabs(conv_factor - M_PI / 180) < EPS;
} else if (proj_cs_get_axis_info(crs->ctx, cs, 1, nullptr, nullptr,
&direction, &conv_factor, nullptr,
nullptr, nullptr) &&
ci_equal(direction, "East")) {
isLatLonDegreeOut = fabs(conv_factor - M_PI / 180) < EPS;
}
proj_destroy(cs);
}
};

const auto source = proj_get_source_crs(pj->ctx, pj);
if (source) {
IsLonLatOrLatLon(source, srcIsLonLatDegree, srcIsLatLonDegree);
proj_destroy(source);
}

const auto target = proj_get_target_crs(pj->ctx, pj);
if (target) {
IsLonLatOrLatLon(target, dstIsLonLatDegree, dstIsLatLonDegree);
proj_destroy(target);
}
}

//! @endcond
Loading

0 comments on commit 61da477

Please sign in to comment.