Skip to content
Permalink
Browse files

Use proj geodesic.h instead of GeographicLib

Because it contains the same functionality and avoids a new
dependency
  • Loading branch information
nyalldawson committed Jan 4, 2019
1 parent 9c7be5f commit c9c502a852a7f1e44687127d809247b34d3f08a6
@@ -30,7 +30,6 @@ RUN apt-get update \
libfcgi-dev \
libgdal-dev \
libgeos-dev \
libgeographic-dev \
libgsl-dev \
libpq-dev \
libproj-dev \
@@ -30,7 +30,6 @@ RUN apt-get update \
libexpat1-dev \
libfcgi-dev \
libgdal-dev \
libgeographic-dev \
libgeos-dev \
libgsl-dev \
libpq-dev \
@@ -297,7 +297,6 @@ IF(WITH_CORE)
FIND_PACKAGE(GDAL)
FIND_PACKAGE(Expat REQUIRED)
FIND_PACKAGE(Spatialindex REQUIRED)
FIND_PACKAGE(GeographicLib REQUIRED)
IF (WITH_GUI)
FIND_PACKAGE(Qwt REQUIRED)
ENDIF (WITH_GUI)
@@ -10,7 +10,6 @@ Build-Depends:
dh-python,
flex,
grass-dev,
libgeographic-dev,
libexiv2-dev,
libexpat1-dev,
libfcgi-dev,
@@ -187,7 +186,6 @@ Depends:
libexiv2-dev,
libexpat1-dev,
libgdal-dev (>= 1.11),
libgeographic-dev,
libgeos-dev (>= 3.0.0),
libgsl-dev,
libpq-dev,
@@ -264,7 +264,7 @@ new subdirectory called `build` or `build-qt5` in it.
=== Install build dependencies ===

```
dnf install qt5-qtwebkit-devel qt5-qtlocation-devel qt5-qttools-static qca-qt5-devel qca-qt5-ossl qt5-qt3d-devel python3-qt5-devel python3-qscintilla-qt5-devel qscintilla-qt5-devel python3-qscintilla-devel python3-qscintilla-qt5 clang flex bison geos-devel gdal-devel sqlite-devel libspatialite-devel qt5-qtsvg-devel qt5-qtxmlpatterns-devel spatialindex-devel expat-devel proj-devel qwt-qt5-devel gsl-devel postgresql-devel cmake python3-future gdal-python3 python3-psycopg2 python3-PyYAML python3-pygments python3-jinja2 python3-OWSLib qca-qt5-ossl qwt-qt5-devel qtkeychain-qt5-devel qwt-devel sip-devel libzip-devel exiv2-devel GeographicLib-devel
dnf install qt5-qtwebkit-devel qt5-qtlocation-devel qt5-qttools-static qca-qt5-devel qca-qt5-ossl qt5-qt3d-devel python3-qt5-devel python3-qscintilla-qt5-devel qscintilla-qt5-devel python3-qscintilla-devel python3-qscintilla-qt5 clang flex bison geos-devel gdal-devel sqlite-devel libspatialite-devel qt5-qtsvg-devel qt5-qtxmlpatterns-devel spatialindex-devel expat-devel proj-devel qwt-qt5-devel gsl-devel postgresql-devel cmake python3-future gdal-python3 python3-psycopg2 python3-PyYAML python3-pygments python3-jinja2 python3-OWSLib qca-qt5-ossl qwt-qt5-devel qtkeychain-qt5-devel qwt-devel sip-devel libzip-devel exiv2-devel
```

To build QGIS server additional dependencies are required:
@@ -67,7 +67,6 @@ BuildRequires: libspatialite-devel
BuildRequires: proj-devel
BuildRequires: spatialindex-devel
BuildRequires: grass-devel
BuildRequires: GeographicLib-devel

# Other stuff
BuildRequires: exiv2-devel
@@ -1250,10 +1250,8 @@ INCLUDE_DIRECTORIES(SYSTEM
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
${Qt5SerialPort_INCLUDE_DIRS}
${GeographicLib_INCLUDE_DIR}
)

ADD_DEFINITIONS(${GeographicLib_DEFINITIONS})

IF (HAVE_OPENCL)
SET(QGIS_CORE_SRCS ${QGIS_CORE_SRCS}
@@ -1380,7 +1378,6 @@ TARGET_LINK_LIBRARIES(qgis_core
${SQLITE3_LIBRARY}
${SPATIALITE_LIBRARY}
${LIBZIP_LIBRARY}
${GeographicLib_LIBRARIES}
)

IF (Qt5SerialPort_FOUND)
@@ -34,8 +34,7 @@
#include "qgsunittypes.h"
#include "qgsexception.h"

#include <GeographicLib/Geodesic.hpp>
#include <GeographicLib/GeodesicLine.hpp>
#include <geodesic.h>

#define DEG2RAD(x) ((x)*M_PI/180)
#define RAD2DEG(r) (180.0 * (r) / M_PI)
@@ -476,9 +475,13 @@ double QgsDistanceArea::latitudeGeodesicCrossesDateLine( const QgsPointXY &pp1,
double lat = p2y;
double lon = p2x;

GeographicLib::Geodesic geod( mSemiMajor, 1 / mInvFlattening );
GeographicLib::GeodesicLine line = geod.InverseLine( p1y, p1x, p2y, p2x );
double intersectionDist = line.Distance();
geod_geodesic geod;
geod_init( &geod, mSemiMajor, 1 / mInvFlattening );

geod_geodesicline line;
geod_inverseline( &line, &geod, p1y, p1x, p2y, p2x, GEOD_ALL );

double intersectionDist = line.s13;

int iterations = 0;
double t = 0;
@@ -500,8 +503,8 @@ double QgsDistanceArea::latitudeGeodesicCrossesDateLine( const QgsPointXY &pp1,
}
QgsDebugMsgLevel( QStringLiteral( "Narrowed window to %1, %2 - %3, %4" ).arg( p1x ).arg( p1y ).arg( p2x ).arg( p2y ), 4 );

line = geod.InverseLine( p1y, p1x, p2y, p2x );
intersectionDist = line.Distance() * 0.5;
geod_inverseline( &line, &geod, p1y, p1x, p2y, p2x, GEOD_ALL );
intersectionDist = line.s13 * 0.5;
}
else
{
@@ -513,9 +516,10 @@ double QgsDistanceArea::latitudeGeodesicCrossesDateLine( const QgsPointXY &pp1,

// now work out the point on the geodesic this far from p1 - this becomes our new candidate for crossing the date line

// (use LONG_UNROLL - we don't want to wrap longitudes > 180 around)
( void )line.GenPosition( false, intersectionDist, GeographicLib::GeodesicLine::LATITUDE | GeographicLib::GeodesicLine::LONGITUDE | GeographicLib::GeodesicLine::LONG_UNROLL,
lat, lon, t, t, t, t, t, t );
geod_position( &line, intersectionDist, &lat, &lon, &t );
// we don't want to wrap longitudes > 180 around)
if ( lon < 0 )
lon += 360;

iterations++;
QgsDebugMsgLevel( QStringLiteral( "After %1 iterations lon is %2, lat is %3, dist from p1: %4" ).arg( iterations ).arg( lon ).arg( lat ).arg( intersectionDist ), 4 );
@@ -532,7 +536,8 @@ QList< QList<QgsPointXY> > QgsDistanceArea::geodesicLine( const QgsPointXY &p1,
return QList< QList< QgsPointXY > >() << ( QList< QgsPointXY >() << p1 << p2 );
}

GeographicLib::Geodesic geod( mSemiMajor, 1 / mInvFlattening );
geod_geodesic geod;
geod_init( &geod, mSemiMajor, 1 / mInvFlattening );

QgsPointXY pp1, pp2;
try
@@ -546,15 +551,17 @@ QList< QList<QgsPointXY> > QgsDistanceArea::geodesicLine( const QgsPointXY &p1,
return QList< QList< QgsPointXY > >();
}

GeographicLib::GeodesicLine line = geod.InverseLine( pp1.y(), pp1.x(), pp2.y(), pp2.x() );
const double totalDist = line.Distance();
geod_geodesicline line;
geod_inverseline( &line, &geod, pp1.y(), pp1.x(), pp2.y(), pp2.x(), GEOD_ALL );
const double totalDist = line.s13;

QList< QList< QgsPointXY > > res;
QList< QgsPointXY > currentPart;
currentPart << p1;
double d = interval;
double prevLon = p1.x();
bool lastRun = false;
double t = 0;
while ( true )
{
double lat, lon;
@@ -567,7 +574,7 @@ QList< QList<QgsPointXY> > QgsDistanceArea::geodesicLine( const QgsPointXY &p1,
}
else
{
( void )line.Position( d, lat, lon );
geod_position( &line, d, &lat, &lon, &t );
}

if ( breakLine && ( ( prevLon < -120 && lon > 120 ) || ( prevLon > 120 && lon < -120 ) ) )

3 comments on commit c9c502a

@marisn

This comment has been minimized.

Copy link
Contributor

@marisn marisn replied Jan 8, 2019

Something seems to be missing:

src/core/qgsdistancearea.cpp: In member function ‘double QgsDistanceArea::latitudeGeodesicCrossesDateLine(const QgsPointXY&, const QgsPointXY&, double&) const’:
src/core/qgsdistancearea.cpp:482:3: error: ‘geod_inverseline’ was not declared in this scope
geod_inverseline( &line, &geod, p1y, p1x, p2y, p2x, GEOD_ALL );
^~~~~~~~~~~~~~~~
src/core/qgsdistancearea.cpp:482:3: note: suggested alternative: ‘geod_inverse’
geod_inverseline( &line, &geod, p1y, p1x, p2y, p2x, GEOD_ALL );
^~~~~~~~~~~~~~~~
geod_inverse
src/core/qgsdistancearea.cpp:484:33: error: ‘struct geod_geodesicline’ has no member named ‘s13’
const double totalDist = line.s13;
^~~
src/core/qgsdistancearea.cpp:485:34: error: ‘struct geod_geodesicline’ has no member named ‘s13’
double intersectionDist = line.s13;
^~~
src/core/qgsdistancearea.cpp:508:31: error: ‘struct geod_geodesicline’ has no member named ‘s13’
intersectionDist = line.s13 * 0.5;
^~~
src/core/qgsdistancearea.cpp: In member function ‘QVector<QVector > QgsDistanceArea::geodesicLine(const QgsPointXY&, const QgsPointXY&, double, bool) const’:
src/core/qgsdistancearea.cpp:558:3: error: ‘geod_inverseline’ was not declared in this scope
geod_inverseline( &line, &geod, pp1.y(), pp1.x(), pp2.y(), pp2.x(), GEOD_ALL );
^~~~~~~~~~~~~~~~
src/core/qgsdistancearea.cpp:558:3: note: suggested alternative: ‘geod_inverse’
geod_inverseline( &line, &geod, pp1.y(), pp1.x(), pp2.y(), pp2.x(), GEOD_ALL );
^~~~~~~~~~~~~~~~
geod_inverse
src/core/qgsdistancearea.cpp:559:33: error: ‘struct geod_geodesicline’ has no member named ‘s13’
const double totalDist = line.s13;

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Jan 10, 2019

@marisn You need to upgrade to proj >= 4.9.3

@elpaso

This comment has been minimized.

Copy link
Contributor

@elpaso elpaso replied Jan 10, 2019

@nyalldawson can you add a CMAKE check for the minimum required proj version?

Please sign in to comment.
You can’t perform that action at this time.