[cig-commits] r5632 - in cs/spatialdata-0.1/trunk: libsrc/geocoords
tests/libtests/geocoords
brad at geodynamics.org
brad at geodynamics.org
Tue Jan 2 22:46:39 PST 2007
Author: brad
Date: 2007-01-02 22:46:37 -0800 (Tue, 02 Jan 2007)
New Revision: 5632
Removed:
cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.cc
cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.hh
cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.icc
Modified:
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.cc
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.hh
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.icc
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.icc
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.icc
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh
cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.cc
cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc
cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh
cs/spatialdata-0.1/trunk/libsrc/geocoords/Projector.hh
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.cc
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.hh
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.cc
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.hh
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.cc
cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.hh
Log:
Changed geocoords interfaces to accept different numbers of spatial dimensions for coordinate systems (where appropriate).
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -22,7 +22,8 @@
// ----------------------------------------------------------------------
// Default constructor
spatialdata::geocoords::CSCart::CSCart(void) :
- _toMeters(1.0)
+ _toMeters(1.0),
+ _spaceDim(3)
{ // constructor
csType(CARTESIAN);
} // constructor
@@ -37,7 +38,8 @@
// Copy constructor
spatialdata::geocoords::CSCart::CSCart(const CSCart& cs) :
CoordSys(cs),
- _toMeters(cs._toMeters)
+ _toMeters(cs._toMeters),
+ _spaceDim(cs._spaceDim)
{ // copy constructor
} // copy constructor
@@ -49,12 +51,43 @@
} // initialize
// ----------------------------------------------------------------------
+// Set factor to convert coordinates to meters.
+void
+spatialdata::geocoords::CSCart::toMeters(const double scale)
+{ // toMeters
+ if (scale <= 0.0) {
+ std::ostringstream msg;
+ msg
+ << "Factor to convert coordinates to meters (" << scale
+ << ") must be positive.";
+ throw std::runtime_error(msg.str());
+ } // if
+ _toMeters = scale;
+} // toMeters
+
+// ----------------------------------------------------------------------
+// Set number of spatial dimensions in coordinate system.
+void
+spatialdata::geocoords::CSCart::spaceDim(const int ndims)
+{ // spaceDim
+ if (ndims < 1 || ndims > 3) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions (" << ndims
+ << ") must be >= 1 and <= 3.";
+ throw std::runtime_error(msg.str());
+ } // if
+ _spaceDim = ndims;
+} // spaceDim
+
+// ----------------------------------------------------------------------
// Pickle coordinate system to ascii stream.
void
spatialdata::geocoords::CSCart::pickle(std::ostream& s) const
{ // pickle
s << "cartesian {\n"
<< " to-meters = " << _toMeters << "\n"
+ << " space-dim = " << _spaceDim << "\n"
<< "}\n";
} // pickle
@@ -72,11 +105,14 @@
s.ignore(maxIgnore, '=');
if (0 == strcasecmp(token.c_str(), "to-meters")) {
s >> _toMeters;
+ } else if (0 == strcasecmp(token.c_str(), "space-dim")) {
+ s >> _spaceDim;
} else {
std::ostringstream msg;
msg << "Could not parse '" << token << "' into a CSCart token.\n"
- << "Known CSCart token:\n"
- << " to-meters";
+ << "Known CSCart tokens:\n"
+ << " to-meters"
+ << " space-dim";
throw std::runtime_error(msg.str().c_str());
} // else
s >> token;
@@ -85,7 +121,5 @@
throw std::runtime_error("I/O error while parsing CSCart settings.");
} // unpickle
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -64,6 +64,18 @@
*/
double toMeters(void) const;
+ /** Set number of spatial dimensions in coordinate system.
+ *
+ * @param ndims Number of dimensions
+ */
+ void spaceDim(const int ndims);
+
+ /** Get number of spatial dimensions in coordinate system.
+ *
+ * @returns Number of dimensions
+ */
+ int spaceDim(void) const;
+
/** Pickle coordinate system to ascii stream.
*
* @param s Output stream
@@ -89,6 +101,7 @@
// PRIVATE MEMBERS ////////////////////////////////////////////////////
double _toMeters; ///< Scale factor to convert coordinates to meters
+ int _spaceDim; ///< Number of spatial dimensions in coordinate system
}; // class CSCart
@@ -96,7 +109,5 @@
#endif // spatialdata_geocoodrs_cscart_hh
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.icc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSCart.icc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -21,13 +21,6 @@
return new CSCart(*this);
}
-// Set factor to convert coordinates to meters.
-inline
-void
-spatialdata::geocoords::CSCart::toMeters(const double scale) {
- _toMeters = scale;
-}
-
// Get factor to convert coordinates to meters.
inline
double
@@ -35,7 +28,12 @@
return _toMeters;
}
-// version
-// $Id$
+// Get number of spatial dimensions in coordinate system.
+inline
+int
+spatialdata::geocoords::CSCart::spaceDim(void) const {
+ return _spaceDim;
+}
+
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -30,6 +30,7 @@
// Default constructor
spatialdata::geocoords::CSGeo::CSGeo(void) :
_toMeters(1.0),
+ _spaceDim(3),
_ellipsoid("WGS84"),
_datumHoriz("WGS84"),
_datumVert("ellipsoid"),
@@ -53,6 +54,7 @@
spatialdata::geocoords::CSGeo::CSGeo(const CSGeo& cs) :
CoordSys(cs),
_toMeters(cs._toMeters),
+ _spaceDim(cs._spaceDim),
_ellipsoid(cs._ellipsoid),
_datumHoriz(cs._datumHoriz),
_datumVert(cs._datumVert),
@@ -62,6 +64,21 @@
} // copy constructor
// ----------------------------------------------------------------------
+// Set number of spatial dimensions in coordinate system.
+void
+spatialdata::geocoords::CSGeo::spaceDim(const int ndims)
+{ // spaceDim
+ if (ndims < 2 || ndims > 3) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions (" << ndims
+ << ") must be >= 2 and <= 3.";
+ throw std::runtime_error(msg.str());
+ } // if
+ _spaceDim = ndims;
+} // spaceDim
+
+// ----------------------------------------------------------------------
// Initialize coordinate system.
void
spatialdata::geocoords::CSGeo::initialize(void)
@@ -87,27 +104,33 @@
void
spatialdata::geocoords::CSGeo::toProjForm(double* coords,
const int numLocs,
- bool is2D) const
+ const int numDims) const
{ // toProjForm
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords) );
+ if (numDims != _spaceDim) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions of coordinates ("
+ << numDims << ") does not match number of spatial dimensions ("
+ << _spaceDim << ") of coordinate system.";
+ throw std::runtime_error(msg.str());
+ } // if
if (!_isGeocentric) {
// convert deg to rad
- const int numCoords = (is2D) ? 2 : 3;
- const int size = numCoords * numLocs;
+ const int size = numDims * numLocs;
const double degToRad = M_PI / 180.0;
- for (int i=0; i < size; i += numCoords) {
+ for (int i=0; i < size; i += numDims) {
coords[i ] *= degToRad;
coords[i+1] *= degToRad;
} // for
- if (!is2D && _toMeters != 1.0)
- for (int i=2; i < size; i += numCoords)
+ if (3 == numDims && _toMeters != 1.0)
+ for (int i=2; i < size; i += numDims)
coords[i] *= _toMeters;
} else {
- const int numCoords = (is2D) ? 2 : 3;
- const int size = numCoords * numLocs;
+ const int size = numDims * numLocs;
for (int i=0; i < size; ++i)
coords[i] *= _toMeters;
} // else
@@ -118,27 +141,33 @@
void
spatialdata::geocoords::CSGeo::fromProjForm(double* coords,
const int numLocs,
- bool is2D) const
+ const int numDims) const
{ // fromProjForm
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords) );
+ if (numDims != _spaceDim) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions of coordinates ("
+ << numDims << ") does not match number of spatial dimensions ("
+ << _spaceDim << ") of coordinate system.";
+ throw std::runtime_error(msg.str());
+ } // if
if (!_isGeocentric) {
// convert rad to deg
- const int numCoords = (is2D) ? 2 : 3;
- const int size = numCoords * numLocs;
+ const int size = numDims * numLocs;
const double radToDeg = 180.0 / M_PI;
- for (int i=0; i < size; i += numCoords) {
+ for (int i=0; i < size; i += numDims) {
coords[i ] *= radToDeg;
coords[i+1] *= radToDeg;
} // for
- if (!is2D && _toMeters != 1.0)
- for (int i=2; i < size; i += numCoords)
+ if (3 == numDims && _toMeters != 1.0)
+ for (int i=2; i < size; i += numDims)
coords[i] /= _toMeters;
} else {
- const int numCoords = (is2D) ? 2 : 3;
- const int size = numCoords * numLocs;
+ const int size = numDims * numLocs;
for (int i=0; i < size; ++i)
coords[i] /= _toMeters;
} // else
@@ -168,6 +197,7 @@
{ // pickle
s << "geographic {\n"
<< " to-meters = " << _toMeters << "\n"
+ << " space-dim = " << _spaceDim << "\n"
<< " ellipsoid = " << _ellipsoid << "\n"
<< " datum-horiz = " << _datumHoriz << "\n"
<< " datum-vert = " << _datumVert << "\n"
@@ -190,6 +220,8 @@
s.ignore(maxIgnore, '=');
if (0 == strcasecmp(token.c_str(), "to-meters")) {
s >> _toMeters;
+ } else if (0 == strcasecmp(token.c_str(), "space-dim")) {
+ s >> _spaceDim;
} else if (0 == strcasecmp(token.c_str(), "ellipsoid")) {
s >> _ellipsoid;
} else if (0 == strcasecmp(token.c_str(), "datum-horiz")) {
@@ -225,7 +257,5 @@
return geoid;
} // geoid
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -116,6 +116,18 @@
*/
double toMeters(void) const;
+ /** Set number of spatial dimensions in coordinate system.
+ *
+ * @param ndims Number of dimensions
+ */
+ virtual void spaceDim(const int ndims);
+
+ /** Get number of spatial dimensions in coordinate system.
+ *
+ * @returns Number of dimensions
+ */
+ int spaceDim(void) const;
+
/** Get proj form vertical datum.
*
* @returns Name of datum
@@ -130,23 +142,23 @@
/** Convert coordinates to PROJ4 useable form.
*
- * @param coords Array of coordinates [#locs*3]
+ * @param coords Array of coordinates [numLocs*numDims]
* @param numLocs Number of locations
- * @param is2D True if coordinates are 2D, false if 3D
+ * @param numDims Number of dimensions in coordinates
*/
virtual void toProjForm(double* coords,
const int numLocs,
- bool is2D) const;
+ const int numDims) const;
/** Convert coordinates from PROJ4 form to form associated w/coordsys.
*
- * @param coords Array of coordinates [#locs*3]
+ * @param coords Array of coordinates [numLocs*numDims]
* @param numLocs Number of locations
- * @param is2D True if coordinates are 2D, false if 3D
+ * @param numDims Number of dimensions in coordinates
*/
virtual void fromProjForm(double* coords,
const int numLocs,
- bool is2D) const;
+ const int numDims) const;
/** Get geoid.
*
* @returns Geoid
@@ -184,6 +196,7 @@
// PRIVATE MEMBERS ////////////////////////////////////////////////////
double _toMeters; ///< Factor to convert Cartesian coordinates to meters
+ int _spaceDim; ///< Number of spatial dimensions in coordinate system
std::string _ellipsoid; ///< Name of reference ellipsoid
std::string _datumHoriz; ///< Name of horizontal geographic datum
std::string _datumVert; ///< Name of vertical datum
@@ -197,7 +210,5 @@
#endif // spatialdata_geocoodrs_csgeo_hh
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.icc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeo.icc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -81,6 +81,13 @@
spatialdata::geocoords::CSGeo::toMeters(void) const
{ return _toMeters; }
+// Get number of spatial dimensions in coordinate system.
+inline
+int
+spatialdata::geocoords::CSGeo::spaceDim(void) const {
+ return _spaceDim;
+}
+
// Get proj form vertical datum.
inline
const char*
@@ -93,7 +100,5 @@
spatialdata::geocoords::CSGeo::projCoordSys(void) const
{ return _pCS; }
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -39,6 +39,7 @@
_localOrientation(0)
{ // constructor
CSGeo::isGeocentric(true);
+ CSGeo::spaceDim(3);
} // constructor
// ----------------------------------------------------------------------
@@ -77,7 +78,6 @@
*pElev = _originElev;
} // origin
-
// ----------------------------------------------------------------------
// Initialize the coordinate system.
void
@@ -177,12 +177,21 @@
void
spatialdata::geocoords::CSGeoLocalCart::toProjForm(double* coords,
const int numLocs,
- bool is2D) const
+ const int numDims) const
{ // toProjForm
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords));
assert(0 != _localOrientation);
+ if (numDims != CSGeo::spaceDim()) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions of coordinates ("
+ << numDims << ") does not match number of spatial dimensions ("
+ << CSGeo::spaceDim() << ") of coordinate system.";
+ throw std::runtime_error(msg.str());
+ } // if
+
const double scale = toMeters();
for (int iLoc=0, index=0; iLoc < numLocs; ++iLoc) {
// add origin to old to invert
@@ -210,12 +219,21 @@
void
spatialdata::geocoords::CSGeoLocalCart::fromProjForm(double* coords,
const int numLocs,
- bool is2D) const
+ const int numDims) const
{ // fromProjForm
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords) );
assert(0 != _localOrientation);
+ if (numDims != CSGeo::spaceDim()) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions of coordinates ("
+ << numDims << ") does not match number of spatial dimensions ("
+ << CSGeo::spaceDim() << ") of coordinate system.";
+ throw std::runtime_error(msg.str());
+ } // if
+
for (int iLoc=0, index=0; iLoc < numLocs; ++iLoc) {
const double xOld = coords[index ];
const double yOld = coords[index+1];
@@ -234,8 +252,7 @@
_localOrientation[8]*zOld - _originZ;
} // for
- const int numCoords = (is2D) ? 2 : 3;
- const int size = numLocs * numCoords;
+ const int size = numLocs * numDims;
const double scale = toMeters();
for (int i=0; i < size; ++i)
coords[i] /= scale;
@@ -427,7 +444,5 @@
"settings.");
} // unpickle
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -86,23 +86,23 @@
/** Convert coordinates to PROJ4 useable form.
*
- * @param coords Array of coordinates [#locs*3]
+ * @param coords Array of coordinates [numLocs*numDims]
* @param numLocs Number of locations
- * @param is2D True if coordinates are 2D, false if 3D
+ * @param numDims Number of spatial dimensions
*/
void toProjForm(double* coords,
const int numLocs,
- bool is2D =false) const;
+ const int numDims) const;
/** Convert coordinates from PROJ4 form to form associated w/coordsys.
*
- * @param coords Array of coordinates [#locs*3]
+ * @param coords Array of coordinates [numLocs*numDims]
* @param numLocs Number of locations
- * @param is2D True if coordinates are 2D, false if 3D
+ * @param numDims Number of spatial dimensions
*/
void fromProjForm(double* coords,
const int numLocs,
- bool is2D =false) const;
+ const int numDims) const;
/** Pickle coordinate system to ascii stream.
*
@@ -170,6 +170,7 @@
// PRIVATE METHODS ///////////////////////////////////////////////////
void isGecentric(const bool isGeocentric); ///< Not implemented
+ void spaceDim(const int ndims); ///< Not implemented
private :
// PRIVATE MEMBERS ////////////////////////////////////////////////////
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.icc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.icc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -39,7 +39,10 @@
_originElev = elev;
}
-// version
-// $Id$
+// Not implemented
+inline
+void
+spatialdata::geocoords::CSGeoLocalCart::spaceDim(const int ndims) {}
+
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -70,15 +70,22 @@
void
spatialdata::geocoords::CSGeoProj::toProjForm(double* coords,
const int numLocs,
- bool is2D) const
+ const int numDims) const
{ // toProjForm
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords));
assert(0 != _pProjector);
+ if (numDims != CSGeo::spaceDim()) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions of coordinates ("
+ << numDims << ") does not match number of spatial dimensions ("
+ << CSGeo::spaceDim() << ") of coordinate system.";
+ throw std::runtime_error(msg.str());
+ } // if
- const int numCoords = (is2D) ? 2 : 3;
- const int size = numCoords * numLocs;
- for (int i=0; i < size; i += numCoords) {
+ const int size = numLocs * numDims;
+ for (int i=0; i < size; i += numDims) {
double lon = 0;
double lat = 0;
_pProjector->invproject(&lon, &lat, coords[i ], coords[i+1]);
@@ -86,7 +93,7 @@
coords[i+1] = lat;
} // for
- CSGeo::toProjForm(coords, numLocs, is2D);
+ CSGeo::toProjForm(coords, numLocs, numDims);
} // toProjForm
// ----------------------------------------------------------------------
@@ -94,17 +101,24 @@
void
spatialdata::geocoords::CSGeoProj::fromProjForm(double* coords,
const int numLocs,
- bool is2D) const
+ const int numDims) const
{ // fromProjForm
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords));
assert(0 != _pProjector);
+ if (numDims != CSGeo::spaceDim()) {
+ std::ostringstream msg;
+ msg
+ << "Number of spatial dimensions of coordinates ("
+ << numDims << ") does not match number of spatial dimensions ("
+ << CSGeo::spaceDim() << ") of coordinate system.";
+ throw std::runtime_error(msg.str());
+ } // if
- CSGeo::fromProjForm(coords, numLocs, is2D);
+ CSGeo::fromProjForm(coords, numLocs, numDims);
- const int numCoords = (is2D) ? 2 : 3;
- const int size = numCoords * numLocs;
- for (int i=0; i < size; i += numCoords) {
+ const int size = numLocs * numDims;
+ for (int i=0; i < size; i += numDims) {
double x = 0;
double y = 0;
_pProjector->project(&x, &y, coords[i ], coords[i+1]);
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -64,23 +64,23 @@
/** Convert coordinates to PROJ4 useable form.
*
- * @param coords Array of coordinates [#locs*3]
+ * @param coords Array of coordinates [numLocs*numDims]
* @param numLocs Number of locations
- * @param is2D True if coordinates are 2D, false if 3D
+ * @param numDims Number of spatial dimensions
*/
void toProjForm(double* coords,
const int numLocs,
- bool is2D =false) const;
+ const int numDims) const;
/** Convert coordinates from PROJ4 form to form associated w/coordsys.
*
- * @param coords Array of coordinates [#locs*3]
+ * @param coords Array of coordinates [numLocs*numDims]
* @param numLocs Number of locations
- * @param is2D True if coordinates are 2D, false if 3D
+ * @param numDims Number of spatial dimensions
*/
void fromProjForm(double* coords,
const int numLocs,
- bool is2D =false) const;
+ const int numDims) const;
/** Pickle coordinate system to ascii stream.
*
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -67,7 +67,4 @@
(*ppCS)->unpickle(s);
} // unpickle
-// version
-// $Id$
-
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -34,9 +34,9 @@
void
spatialdata::geocoords::Converter::convert(double* coords,
const int numLocs,
+ const int numDims,
const CoordSys* pCSDest,
- const CoordSys* pCSSrc,
- bool is2D)
+ const CoordSys* pCSSrc)
{ // convert
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords));
@@ -53,14 +53,14 @@
{ // GEOGRAPHIC
const CSGeo* pGeoDest = dynamic_cast<const CSGeo*>(pCSDest);
const CSGeo* pGeoSrc = dynamic_cast<const CSGeo*>(pCSSrc);
- _convert(coords, numLocs, *pGeoDest, *pGeoSrc, is2D);
+ _convert(coords, numLocs, numDims, *pGeoDest, *pGeoSrc);
break;
} // GEOGRAPHIC
case spatialdata::geocoords::CoordSys::CARTESIAN :
{ // GEOGRAPHIC
const CSCart* pCartDest = dynamic_cast<const CSCart*>(pCSDest);
const CSCart* pCartSrc = dynamic_cast<const CSCart*>(pCSSrc);
- _convert(coords, numLocs, *pCartDest, *pCartSrc, is2D);
+ _convert(coords, numLocs, numDims, *pCartDest, *pCartSrc);
break;
} // GEOGRAPHIC
default :
@@ -74,23 +74,22 @@
void
spatialdata::geocoords::Converter::_convert(double* coords,
const int numLocs,
+ const int numDims,
const CSGeo& csDest,
- const CSGeo& csSrc,
- bool is2D)
+ const CSGeo& csSrc)
{ // convert
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords));
- csSrc.toProjForm(coords, numLocs, is2D);
+ csSrc.toProjForm(coords, numLocs, numDims);
- const int numCoords = is2D ? 2 : 3;
- double* pX = coords + 0; // lon
- double* pY = coords + 1; // lat
- double* pZ = (is2D) ? 0 : coords + 2;
+ double* pX = (numDims >= 1) ? coords + 0 : 0; // lon
+ double* pY = (numDims >= 2) ? coords + 1 : 0; // lat
+ double* pZ = (numDims >= 3) ? coords + 2 : 0; // elev
const char* srcDatumVert = csSrc.projDatumVert();
const char* destDatumVert = csDest.projDatumVert();
- if (!is2D && 0 != strcasecmp(srcDatumVert, destDatumVert)) {
+ if (numDims > 2 && 0 != strcasecmp(srcDatumVert, destDatumVert)) {
bool isMSLToWGS84 = true;
if (0 == strcasecmp(srcDatumVert, "mean sea level") &&
0 == strcasecmp(destDatumVert, "ellipsoid"))
@@ -116,7 +115,7 @@
throw std::runtime_error(msg.str());
} // if
int pjerrno = pj_transform(csSrc.projCoordSys(), csWGS84,
- numLocs, numCoords,
+ numLocs, numDims,
pX, pY, pZ);
if (0 != pjerrno) {
std::ostringstream msg;
@@ -124,7 +123,7 @@
<< " " << pj_strerrno(pjerrno) << "\n";
throw std::runtime_error(msg.str());
} // if
- const int size = numLocs * numCoords;
+ const int size = numLocs * numDims;
for (int i=0; i < size; i+=3) {
const double geoidHt =
CSGeo::geoid().elevation(coords[i], coords[i+1]);
@@ -132,7 +131,7 @@
} // for
pjerrno = pj_transform(csWGS84, csDest.projCoordSys(),
- numLocs, numCoords, pX, pY, pZ);
+ numLocs, numDims, pX, pY, pZ);
if (0 != pjerrno) {
std::ostringstream msg;
msg << "Error while converting coordinates:\n"
@@ -144,7 +143,7 @@
} else {
const int pjerrno =
pj_transform(csSrc.projCoordSys(), csDest.projCoordSys(),
- numLocs, numCoords, pX, pY, pZ);
+ numLocs, numDims, pX, pY, pZ);
if (0 != pjerrno) {
std::ostringstream msg;
msg << "Error while converting coordinates:\n"
@@ -153,7 +152,7 @@
} // if
} // else
- csDest.fromProjForm(coords, numLocs, is2D);
+ csDest.fromProjForm(coords, numLocs, numDims);
} // convert
// ----------------------------------------------------------------------
@@ -162,21 +161,18 @@
void
spatialdata::geocoords::Converter::_convert(double* coords,
const int numLocs,
+ const int numDims,
const CSCart& csDest,
- const CSCart& csSrc,
- bool is2D)
+ const CSCart& csSrc)
{ // convert
assert( (0 < numLocs && 0 != coords) ||
(0 == numLocs && 0 == coords));
- const int numCoords = is2D ? 2 : 3;
- const int size = numLocs*numCoords;
+ const int size = numLocs*numDims;
const double scale = csSrc.toMeters() / csDest.toMeters();
for (int i=0; i < size; ++i)
coords[i] *= scale;
} // convert
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -40,15 +40,15 @@
*
* @param coords Array of coordinates
* @param numLocs Number of location
+ * @param numDims Number of spatial dimensions in coordinates
* @param pCSDest Pointer to destination coordinate system
* @param pCSSrc Pointer to source coordinate system
- * @param is2D True if 2D, false if 3D
*/
static void convert(double* coords,
const int numLocs,
+ const int numDims,
const CoordSys* pCSDest,
- const CoordSys* pCSSrc,
- bool is2D =false);
+ const CoordSys* pCSSrc);
private :
// PRIVATE METHODS ////////////////////////////////////////////////////
@@ -58,30 +58,30 @@
*
* @param coords Array of coordinates
* @param numLocs Number of location
+ * @param numDims Number of spatial dimensions in coordinates
* @param csDest Destination coordinate system
* @param csSrc Source coordinate system
- * @param is2D True if 2D, false if 3D
*/
static void _convert(double* coords,
const int numLocs,
+ const int numDims,
const CSGeo& csDest,
- const CSGeo& csSrc,
- bool is2D =false);
+ const CSGeo& csSrc);
/** Convert coordinates from source Cartesian coordinate system to
* destination Cartesian coordinate system.
*
* @param coords Array of coordinates
* @param numLocs Number of location
+ * @param numDims Number of spatial dimensions in coordinates
* @param csDest Destination coordinate system
* @param csSrc Source coordinate system
- * @param is2D True if 2D, false if 3D
*/
static void _convert(double* coords,
const int numLocs,
+ const int numDims,
const CSCart& csDest,
- const CSCart& csSrc,
- bool is2D =false);
+ const CSCart& csSrc);
}; // class Converter
Deleted: cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -1,118 +0,0 @@
-// -*- C++ -*-
-//
-// ======================================================================
-//
-// Brad T. Aagaard
-// U.S. Geological Survey
-//
-// {LicenseText}
-//
-// ======================================================================
-//
-
-#include <portinfo>
-
-#include "GeoCoordSys.hh" // implementation of class methods
-
-extern "C" {
-#include "proj_api.h" // USES PROJ4
-};
-
-#include <stdexcept> // USES std::runtime_error, std::exception
-#include <sstream> // USES std::ostringsgream
-
-// ----------------------------------------------------------------------
-// Default constructor
-spatialdata::GeoCoordSys::GeoCoordSys(void) :
- _projection("aea"),
- _ellipsoid("WGS84"),
- _datumHoriz("WGS84"),
- _datumVert("WGS84 ellipsoid"),
- _units("m"),
- _pCS(0)
-{ // constructor
-} // constructor
-
-// ----------------------------------------------------------------------
-// Default destructor
-spatialdata::GeoCoordSys::~GeoCoordSys(void)
-{ // destructor
- pj_free(_pCS);
-} // destructor
-
-// ----------------------------------------------------------------------
-// Copy constructor.
-spatialdata::GeoCoordSys::GeoCoordSys(const GeoCoordSys& cs) :
- _projection(cs._projection),
- _ellipsoid(cs._ellipsoid),
- _datumHoriz(cs._datumHoriz),
- _datumVert(cs._datumVert),
- _units(cs._units),
- _pCS(0)
-{ // copy constructor
- // initialize if cs has already been initialized
- if (0 != cs._pCS)
- initialize();
-} // copy constructor
-
-// ----------------------------------------------------------------------
-// operator=
-const spatialdata::GeoCoordSys&
-spatialdata::GeoCoordSys::operator=(const GeoCoordSys& cs)
-{ // operator=
- if (this != &cs) {
- _projection = cs._projection;
- _ellipsoid = cs._ellipsoid;
- _datumHoriz = cs._datumHoriz;
- _datumVert = cs._datumVert;
- _units = cs._units;
- if (0 != cs._pCS)
- initialize();
- } // if
-
- return *this;
-} // operator=
-
-// ----------------------------------------------------------------------
-// Initialize projector.
-void
-spatialdata::GeoCoordSys::initialize(void)
-{ // initialize
- std::ostringstream args;
- args
- << "+proj=" << _projection
- << " +ellps=" << _ellipsoid
- << " +datum=" << _datumHoriz
- << " +units=" << _units;
-
- pj_free(_pCS);
- _pCS = pj_init_plus(args.str().c_str());
- if (0 == _pCS) {
- std::ostringstream msg;
- msg << "Error while initializing coordinate system:\n"
- << " " << pj_strerrno(pj_errno) << "\n"
- << " projection: " << _projection << "\n"
- << " ellipsoid: " << _ellipsoid << "\n"
- << " horiz. datum: " << _datumHoriz << "\n"
- << " units: " << _units << "\n";
- throw std::runtime_error(msg.str());
- } // if
-} // initialize
-
-// ----------------------------------------------------------------------
-// Are coordinate systems the same?
-bool
-spatialdata::operator==(const spatialdata::GeoCoordSys& a,
- const spatialdata::GeoCoordSys& b)
-{ // operator==
- return ( 0 == strcmp(a._projection, b._projection) &&
- 0 == strcmp(a._ellipsoid, b._ellipsoid) &&
- 0 == strcmp(a._datumHoriz, b._datumHoriz) &&
- 0 == strcmp(a._datumVert, b._datumVert) &&
- 0 == strcmp(a._units, b._units) );
-} // operator==
-
-// version
-// $Id$
-
-// End of file
Deleted: cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -1,153 +0,0 @@
-// -*- C++ -*-
-//
-// ======================================================================
-//
-// Brad T. Aagaard
-// U.S. Geological Survey
-//
-// {LicenseText}
-//
-// ======================================================================
-//
-
-/** @file libsrc/geocoords/GeoCoordSys.hh
- *
- * @brief C++ GeoCoordSys object
- *
- * C++ object for managing parameters defining a coordinate system.
- */
-
-#if !defined(spatialdata_geocoordsys_hh)
-#define spatialdata_geocoordsys_hh
-
-namespace spatialdata {
- class GeoCoordSys;
- bool operator==(const GeoCoordSys&,
- const GeoCoordSys&); // forward declaration
-}; // namespace spatialdata
-
-#include "proj4fwd.h" // Proj4 forward declaration
-
-/// C++ object for managing parameters defining a coordinate system
-class spatialdata::GeoCoordSys
-{ // class GeoCoordSys
- public :
- // PUBLIC METHODS /////////////////////////////////////////////////////
-
- /// Default constructor
- GeoCoordSys(void);
-
- /// Default destructor
- ~GeoCoordSys(void);
-
- /** Copy constructor.
- *
- * @param cs Coordinate system to copy
- */
- GeoCoordSys(const GeoCoordSys& cs);
-
- /** operator=
- *
- * @param cs Coordinate system to copy
- *
- * @param returns Reference to this
- */
- const GeoCoordSys& operator=(const GeoCoordSys& cs);
-
- /** Set projection.
- *
- * @param projection Name of projection
- */
- void projection(const char* name);
-
- /** Get name of projection.
- *
- * @returns Name of projection
- */
- const char* projection(void) const;
-
- /** Set reference ellipsoid.
- *
- * @param name Name of reference ellipsoid
- */
- void ellipsoid(const char* name);
-
- /** Get reference ellipsoid.
- *
- * @returns Name of reference ellipsoid
- */
- const char* ellipsoid(void) const;
-
- /** Set horizontal datum.
- *
- * @param name Name of horizontal datum
- */
- void datumHoriz(const char* name);
-
- /** Get horizontal datum.
- *
- * @returns Name of datum
- */
- const char* datumHoriz(void) const;
-
- /** Set vertical datum.
- *
- * @param name Name of vertical datum
- */
- void datumVert(const char* name);
-
- /** Get horizontal datum.
- *
- * @returns Name of datum
- */
- const char* datumVert(void) const;
-
- /** Set units of coordinate system.
- *
- * @param name Name of units
- */
- void units(const char* name);
-
- /** Get units of coordinate system.
- *
- * @returns Name of units
- */
- const char* units(void) const;
-
- /// Initialize projector.
- void initialize(void);
-
- /** Get coordinate system.
- *
- * @returns Coordinate system
- */
- const projPJ coordsys(void) const;
-
- /** Are coordinate systems the same?
- *
- * @returns True if coordinate systems are the same, false otherwise
- */
- friend bool spatialdata::operator==(const GeoCoordSys& a,
- const GeoCoordSys& b);
-
-private :
- // PRIVATE MEMBERS ////////////////////////////////////////////////////
-
- const char* _projection; ///< Name of projection
- const char* _ellipsoid; ///< Name of reference ellipsoid
- const char* _datumHoriz; ///< Name of horizontal geographic datum
- const char* _datumVert; ///< Name of vertical datum
- const char* _units; ///< Name of units in projection
-
- projPJ _pCS; ///< Pointer to coordinate system
-
-}; // class GeoCoordSys
-
-#include "GeoCoordSys.icc" // inline methods
-
-#endif // spatialdata_geocoordsys_hh
-
-// version
-// $Id$
-
-// End of file
Deleted: cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.icc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/GeoCoordSys.icc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -1,88 +0,0 @@
-// -*- C++ -*-
-//
-// ======================================================================
-//
-// Brad T. Aagaard
-// U.S. Geological Survey
-//
-// {LicenseText}
-//
-// ======================================================================
-//
-
-#if !defined(spatialdata_geocoordsys_hh)
-#error "GeoCoordSys.icc must only be included from GeoCoordSys.hh"
-#endif
-
-// Set projection.
-inline
-void
-spatialdata::GeoCoordSys::projection(const char* name)
-{ _projection = name; }
-
-// Get name of projection.
-inline
-const char*
-spatialdata::GeoCoordSys::projection(void) const
-{ return _projection; }
-
-// Set reference ellipsoid.
-inline
-void
-spatialdata::GeoCoordSys::ellipsoid(const char* name)
-{ _ellipsoid = name; }
-
-// Get reference ellipsoid.
-inline
-const char*
-spatialdata::GeoCoordSys::ellipsoid(void) const
-{ return _ellipsoid; }
-
-// Set horizontal datum.
-inline
-void
-spatialdata::GeoCoordSys::datumHoriz(const char* name)
-{ _datumHoriz = name; }
-
-// Get horizontal datum.
-inline
-const char*
-spatialdata::GeoCoordSys::datumHoriz(void) const
-{ return _datumHoriz; }
-
-// Set vertical datum.
-inline
-void
-spatialdata::GeoCoordSys::datumVert(const char* name)
-{ _datumVert = name; }
-
-// Get vertical datum.
-inline
-const char*
-spatialdata::GeoCoordSys::datumVert(void) const
-{ return _datumVert; }
-
-// Set units of coordinate system.
-inline
-void
-spatialdata::GeoCoordSys::units(const char* name)
-{ _units = name; }
-
-// Get units of coordinate system.
-inline
-const char*
-spatialdata::GeoCoordSys::units(void) const
-{ return _units; }
-
-// Get coordinate system
-inline
-const projPJ
-spatialdata::GeoCoordSys::coordsys(void) const
-{ return _pCS; }
-
-// Get
-
-// version
-// $Id$
-
-// End of file
Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/Projector.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/Projector.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/Projector.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -140,7 +140,5 @@
#endif // spatialdata_geocoords_projector_hh
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -31,7 +31,7 @@
} // testConstructor
// ----------------------------------------------------------------------
-// Test toMeters
+// Test toMeters()
void
spatialdata::geocoords::TestCSCart::testToMeters(void)
{ // testToMeters
@@ -43,6 +43,17 @@
} // testToMeters
// ----------------------------------------------------------------------
+// Test spaceDim()
+void
+spatialdata::geocoords::TestCSCart::testSpaceDim(void)
+{ // testSpaceDim
+ CSCart cs;
+ const int spaceDim = 2;
+ cs.spaceDim(spaceDim);
+ CPPUNIT_ASSERT_EQUAL(spaceDim, cs.spaceDim());
+} // testSpaceDim
+
+// ----------------------------------------------------------------------
// Test initialize()
void
spatialdata::geocoords::TestCSCart::testInitialize(void)
@@ -58,7 +69,9 @@
{ // testPickle
CSCart csA;
const double toMeters = 5.4;
+ const int spaceDim = 2;
csA.toMeters(toMeters);
+ csA.spaceDim(spaceDim);
std::stringstream s;
csA.pickle(s);
@@ -68,9 +81,8 @@
const double tolerance = 1.0e-6;
CPPUNIT_ASSERT_DOUBLES_EQUAL(toMeters, csB.toMeters(), tolerance);
+ CPPUNIT_ASSERT_EQUAL(spaceDim, csB.spaceDim());
} // testPickle
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSCart.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -37,6 +37,7 @@
CPPUNIT_TEST_SUITE( TestCSCart );
CPPUNIT_TEST( testConstructor );
CPPUNIT_TEST( testToMeters );
+ CPPUNIT_TEST( testSpaceDim );
CPPUNIT_TEST( testInitialize );
CPPUNIT_TEST( testPickle );
CPPUNIT_TEST_SUITE_END();
@@ -50,6 +51,9 @@
/// Test toMeters()
void testToMeters(void);
+ /// Test spaceDim()
+ void testSpaceDim(void);
+
/// Test initialize()
void testInitialize(void);
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -88,9 +88,21 @@
const double toMeters = 5.53;
cs.toMeters(toMeters);
CPPUNIT_ASSERT_DOUBLES_EQUAL(toMeters, cs.toMeters(), tolerance);
-} // testElevToMeters
+} // testToMeters
// ----------------------------------------------------------------------
+// Test spaceDim()
+void
+spatialdata::geocoords::TestCSGeo::testSpaceDim(void)
+{ // testSpaceDim
+ CSGeo cs;
+ CPPUNIT_ASSERT_EQUAL(3, cs.spaceDim());
+ const int spaceDim = 2;
+ cs.spaceDim(spaceDim);
+ CPPUNIT_ASSERT_EQUAL(spaceDim, cs.spaceDim());
+} // testSpaceDim
+
+// ----------------------------------------------------------------------
// Test initialize()
void
spatialdata::geocoords::TestCSGeo::testInitialize(void)
@@ -110,24 +122,24 @@
const double tolerance = 1.0e-6;
{ // 2D
- const bool is2D = true;
const int numLocs = 4;
- const int numCoords = 2;
+ const int numDims = 2;
const double coords[] = { 28.0, 23.0,
- 42.0, 34.0,
- -12.0, 65.7,
- 64.3, -163.0 };
+ 42.0, 34.0,
+ -12.0, 65.7,
+ 64.3, -163.0 };
cs.isGeocentric(true);
- const int size = numLocs * numCoords;
+ cs.spaceDim(numDims);
+ const int size = numLocs * numDims;
double* vals = new double[size];
memcpy(vals, coords, size*sizeof(double));
- cs.toProjForm(vals, numLocs, is2D);
+ cs.toProjForm(vals, numLocs, numDims);
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/coords[i], tolerance);
cs.isGeocentric(false);
memcpy(vals, coords, size*sizeof(double));
- cs.toProjForm(vals, numLocs, is2D);
+ cs.toProjForm(vals, numLocs, numDims);
const double degToRad = M_PI / 180.0;
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/(coords[i]*degToRad),
@@ -136,24 +148,24 @@
} // 2D
{ // 3D
- const bool is2D = false;
const int numLocs = 4;
- const int numCoords = 3;
+ const int numDims = 3;
const double coords[] = { 28.0, 23.0, 3.4,
- 42.0, 34.0, 3.5,
- -12.0, 65.7, 12.6,
- 64.3, -163.0, -1.5 };
+ 42.0, 34.0, 3.5,
+ -12.0, 65.7, 12.6,
+ 64.3, -163.0, -1.5 };
cs.isGeocentric(true);
- const int size = numLocs * numCoords;
+ cs.spaceDim(numDims);
+ const int size = numLocs * numDims;
double* vals = new double[size];
memcpy(vals, coords, size*sizeof(double));
- cs.toProjForm(vals, numLocs, is2D);
+ cs.toProjForm(vals, numLocs, numDims);
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/coords[i], tolerance);
cs.isGeocentric(false);
memcpy(vals, coords, size*sizeof(double));
- cs.toProjForm(vals, numLocs, is2D);
+ cs.toProjForm(vals, numLocs, numDims);
const double degToRad = M_PI / 180.0;
for (int i=0; i < size; i += 3) {
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/(coords[i]*degToRad),
@@ -177,24 +189,24 @@
const double tolerance = 1.0e-6;
{ // 2D
- const bool is2D = true;
const int numLocs = 4;
- const int numCoords = 2;
+ const int numDims = 2;
const double coords[] = { 28.0, 23.0,
42.0, 34.0,
-12.0, 65.7,
64.3, -163.0 };
cs.isGeocentric(true);
- const int size = numLocs * numCoords;
+ cs.spaceDim(numDims);
+ const int size = numLocs * numDims;
double* vals = new double[size];
memcpy(vals, coords, size*sizeof(double));
- cs.fromProjForm(vals, numLocs, is2D);
+ cs.fromProjForm(vals, numLocs, numDims);
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/coords[i], tolerance);
cs.isGeocentric(false);
memcpy(vals, coords, size*sizeof(double));
- cs.fromProjForm(vals, numLocs, is2D);
+ cs.fromProjForm(vals, numLocs, numDims);
const double radToDeg = 180.0 / M_PI;
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/(coords[i]*radToDeg),
@@ -203,24 +215,24 @@
} // 2D
{ // 3D
- const bool is2D = false;
const int numLocs = 4;
- const int numCoords = 3;
+ const int numDims = 3;
const double coords[] = { 28.0, 23.0, 3.4,
42.0, 34.0, 3.5,
-12.0, 65.7, 12.6,
64.3, -163.0, -1.5 };
cs.isGeocentric(true);
- const int size = numLocs * numCoords;
+ cs.spaceDim(numDims);
+ const int size = numLocs * numDims;
double* vals = new double[size];
memcpy(vals, coords, size*sizeof(double));
- cs.fromProjForm(vals, numLocs, is2D);
+ cs.fromProjForm(vals, numLocs, numDims);
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/coords[i], tolerance);
cs.isGeocentric(false);
memcpy(vals, coords, size*sizeof(double));
- cs.fromProjForm(vals, numLocs, is2D);
+ cs.fromProjForm(vals, numLocs, numDims);
const double radToDeg = 180.0 / M_PI;
for (int i=0; i < size; i += 3) {
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/(coords[i]*radToDeg),
@@ -244,6 +256,7 @@
const char* datumVert = "mean sea level";
const bool isGeocentric = true;
const double toMeters = 7.3;
+ const int spaceDim = 2;
CSGeo csA;
csA.ellipsoid(ellipsoid);
@@ -251,6 +264,7 @@
csA.datumVert(datumVert);
csA.isGeocentric(isGeocentric);
csA.toMeters(toMeters);
+ csA.spaceDim(spaceDim);
std::stringstream s;
csA.pickle(s);
@@ -264,9 +278,8 @@
CPPUNIT_ASSERT(0 == strcasecmp(datumVert, csB.datumVert()));
CPPUNIT_ASSERT(isGeocentric == csB.isGeocentric());
CPPUNIT_ASSERT_DOUBLES_EQUAL(toMeters, csB.toMeters(), tolerance);
+ CPPUNIT_ASSERT_EQUAL(spaceDim, csB.spaceDim());
} // testPickle
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeo.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -41,6 +41,7 @@
CPPUNIT_TEST( testDatumVert );
CPPUNIT_TEST( testGeocentric );
CPPUNIT_TEST( testToMeters );
+ CPPUNIT_TEST( testSpaceDim );
CPPUNIT_TEST( testInitialize );
CPPUNIT_TEST( testToProjForm );
CPPUNIT_TEST( testFromProjForm );
@@ -68,6 +69,9 @@
/// Test toMeters()
void testToMeters(void);
+ /// Test spaceDim()
+ void testSpaceDim(void);
+
/// Test initialize()
void testInitialize(void);
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -80,11 +80,11 @@
cs.datumVert(_DATUMVERT);
cs.initialize();
- const int numCoords = 3;
- const int size = _NUMLOCS * numCoords;
+ const int numDims = 3;
+ const int size = _NUMLOCS * numDims;
double* vals = new double[size];
memcpy(vals, _XYZLOCAL, size*sizeof(double));
- cs.toProjForm(vals, _NUMLOCS);
+ cs.toProjForm(vals, _NUMLOCS, numDims);
const double tolerance = 1.0e-6;
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/_XYZECEF[i], tolerance);
@@ -104,11 +104,11 @@
cs.datumVert(_DATUMVERT);
cs.initialize();
- const int numCoords = 3;
- const int size = _NUMLOCS * numCoords;
+ const int numDims = 3;
+ const int size = _NUMLOCS * numDims;
double* vals = new double[size];
memcpy(vals, _XYZECEF, size*sizeof(double));
- cs.fromProjForm(vals, _NUMLOCS);
+ cs.fromProjForm(vals, _NUMLOCS, numDims);
const double tolerance = 1.0e-6;
for (int i=0; i < size; ++i)
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/_XYZLOCAL[i], tolerance);
@@ -145,7 +145,5 @@
CPPUNIT_ASSERT_DOUBLES_EQUAL(toMeters, csB.toMeters(), tolerance);
} // testPickle
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoLocalCart.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -84,7 +84,5 @@
#endif // spatialdata_geocoords_testcsgeolocalcart_hh
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -73,11 +73,11 @@
cs.initialize();
- const int numCoords = 3;
- const int size = _NUMLOCS * numCoords;
+ const int numDims = 3;
+ const int size = _NUMLOCS * numDims;
double* vals = new double[size];
memcpy(vals, _XYZ, size*sizeof(double));
- cs.toProjForm(vals, _NUMLOCS);
+ cs.toProjForm(vals, _NUMLOCS, numDims);
const double degToRad = M_PI / 180.0;
const double tolerance = 1.0e-5;
for (int i=0; i < size; i+=3) {
@@ -111,8 +111,8 @@
cs.initialize();
- const int numCoords = 3;
- const int size = _NUMLOCS * numCoords;
+ const int numDims = 3;
+ const int size = _NUMLOCS * numDims;
double* vals = new double[size];
memcpy(vals, _LONLATNAD27ELEV, size*sizeof(double));
const double degToRad = M_PI / 180.0;
@@ -121,7 +121,7 @@
vals[i+1] *= degToRad;
} // for
- cs.fromProjForm(vals, _NUMLOCS);
+ cs.fromProjForm(vals, _NUMLOCS, numDims);
const double tolerance = 1.0e-6;
for (int i=0; i < size; ++i)
@@ -159,7 +159,5 @@
CPPUNIT_ASSERT(0 == strcasecmp(_DATUMVERT, csB.datumVert()));
} // testPickle
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestCSGeoProj.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -78,7 +78,5 @@
#endif // spatialdata_geocoords_testcsgeolocalcart_hh
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.cc 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.cc 2007-01-03 06:46:37 UTC (rev 5632)
@@ -47,12 +47,12 @@
csDest.initialize();
const int numLocs = _NUMLOCS;
- const int numCoords = 3;
- const int size = numLocs*numCoords;
+ const int numDims = 3;
+ const int size = numLocs*numDims;
double* coords = new double [size];
memcpy(coords, _LONLATNAD27ELEV, size*sizeof(double));
- Converter::convert(coords, numLocs, &csDest, &csSrc);
+ Converter::convert(coords, numLocs, numDims, &csDest, &csSrc);
const double* valsE = _LONLATWGS84GEOID;
const double tolerance = 1.0e-06;
@@ -80,12 +80,12 @@
csDest.initialize();
const int numLocs = _NUMLOCS;
- const int numCoords = 3;
- const int size = numLocs*numCoords;
+ const int numDims = 3;
+ const int size = numLocs*numDims;
double* coords = new double [size];
memcpy(coords, _LONLATWGS84GEOID, size*sizeof(double));
- Converter::convert(coords, numLocs, &csDest, &csSrc);
+ Converter::convert(coords, numLocs, numDims, &csDest, &csSrc);
const double* valsE = _LONLATNAD27ELEV;
const double tolerance = 1.0e-06;
@@ -114,12 +114,12 @@
csDest.initialize();
const int numLocs = _NUMLOCS;
- const int numCoords = 3;
- const int size = numLocs*numCoords;
+ const int numDims = 3;
+ const int size = numLocs*numDims;
double* coords = new double[size];
memcpy(coords, _LONLATWGS84GEOID, size*sizeof(double));
- Converter::convert(coords, numLocs, &csDest, &csSrc);
+ Converter::convert(coords, numLocs, numDims, &csDest, &csSrc);
const double* valsE = _XYZECEF;
const double tolerance = 1.0e-06;
@@ -148,12 +148,12 @@
csDest.initialize();
const int numLocs = _NUMLOCS;
- const int numCoords = 3;
- const int size = numLocs*numCoords;
+ const int numDims = 3;
+ const int size = numLocs*numDims;
double* coords = new double[size];
memcpy(coords, _XYZECEF, size*sizeof(double));
- Converter::convert(coords, numLocs, &csDest, &csSrc);
+ Converter::convert(coords, numLocs, numDims, &csDest, &csSrc);
const double* valsE = _LONLATWGS84GEOID;
const double tolerance = 1.0e-06;
@@ -182,12 +182,12 @@
csDest.initialize();
const int numLocs = _NUMLOCS;
- const int numCoords = 3;
- const int size = numLocs*numCoords;
+ const int numDims = 3;
+ const int size = numLocs*numDims;
double* coords = new double [size];
memcpy(coords, _LONLATNAD27ELEV, size*sizeof(double));
- Converter::convert(coords, numLocs, &csDest, &csSrc);
+ Converter::convert(coords, numLocs, numDims, &csDest, &csSrc);
const double* valsE = _XYZLOCAL;
const double tolerance = 1.0e-06;
@@ -219,12 +219,12 @@
csDest.initialize();
const int numLocs = _NUMLOCS;
- const int numCoords = 3;
- const int size = numLocs*numCoords;
+ const int numDims = 3;
+ const int size = numLocs*numDims;
double* coords = new double [size];
memcpy(coords, _XYZLOCAL, size*sizeof(double));
- Converter::convert(coords, numLocs, &csDest, &csSrc);
+ Converter::convert(coords, numLocs, numDims, &csDest, &csSrc);
const double* valsE = _LONLATNAD27ELEV;
const double tolerance = 1.0e-06;
@@ -254,12 +254,12 @@
csDest.initialize();
const int numLocs = _NUMLOCS;
- const int numCoords = 3;
- const int size = numLocs*numCoords;
+ const int numDims = 3;
+ const int size = numLocs*numDims;
double* coords = new double [size];
memcpy(coords, _XYZLOCAL, size*sizeof(double));
- Converter::convert(coords, numLocs, &csDest, &csSrc);
+ Converter::convert(coords, numLocs, numDims, &csDest, &csSrc);
const double* valsE = _XYZLOCAL;
const double tolerance = 1.0e-06;
@@ -274,7 +274,5 @@
delete[] coords; coords = 0;
} // TestCartToCart
-// version
-// $Id$
// End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.hh 2007-01-03 04:59:30 UTC (rev 5631)
+++ cs/spatialdata-0.1/trunk/tests/libtests/geocoords/TestConverter.hh 2007-01-03 06:46:37 UTC (rev 5632)
@@ -87,7 +87,5 @@
#endif // spatialdata_geocoords_testconverter_hh
-// version
-// $Id$
// End of file
More information about the cig-commits
mailing list