MCPcopy Create free account
hub / github.com/OSGeo/PROJ / parse_coord

Function parse_coord

src/apps/gie.cpp:812–871  ·  view source on GitHub ↗

/

Source from the content-addressed store, hash-verified

810
811/*****************************************************************************/
812static PJ_COORD parse_coord(const char *args) {
813 /*****************************************************************************
814 Attempt to interpret args as a PJ_COORD.
815 ******************************************************************************/
816 int i;
817 char *endp;
818 char *dmsendp;
819 const char *prev = args;
820 PJ_COORD a = proj_coord(0, 0, 0, 0);
821
822 T.dimensions_given = 0;
823 for (i = 0; i < 4; i++) {
824 /* proj_strtod doesn't read values like 123d45'678W so we need a bit */
825 /* of help from proj_dmstor. proj_strtod effectively ignores what */
826 /* comes after "d", so we use that fact that when dms is larger than */
827 /* d the value was stated in "dms" form. */
828 /* This could be avoided if proj_dmstor used the same proj_strtod() */
829 /* as gie, but that is not the case (yet). When we remove projects.h */
830 /* from the public API we can change that. */
831
832 // Even Rouault: unsure about the above. Coordinates are not necessarily
833 // geographic coordinates, and the roundtrip through radians for
834 // big projected coordinates cause inaccuracies, that can cause
835 // test failures when testing points at edge of grids.
836 // For example 1501000.0 becomes 1501000.000000000233
837 double d;
838 while (*prev && isspace(*prev))
839 ++prev;
840 if (strncmp(prev, "HUGE_VAL", strlen("HUGE_VAL")) == 0) {
841 d = HUGE_VAL;
842 endp = const_cast<char *>(prev) + strlen("HUGE_VAL");
843 } else {
844 d = proj_strtod(prev, &endp);
845 }
846 if (!std::isnan(d) && *endp != '\0' && !isspace(*endp)) {
847 double dms = PJ_TODEG(proj_dmstor(prev, &dmsendp));
848 /* TODO: When projects.h is removed, call proj_dmstor() in all cases
849 */
850 if (d != dms && fabs(d) < fabs(dms) && fabs(dms) < fabs(d) + 1) {
851 d = dms;
852 endp = dmsendp;
853 }
854 /* A number like -81d00'00.000 will be parsed correctly by both */
855 /* proj_strtod and proj_dmstor but only the latter will return */
856 /* the correct end-pointer. */
857 if (d == dms && endp != dmsendp)
858 endp = dmsendp;
859 }
860
861 /* Break out if there were no more numerals */
862 if (prev == endp)
863 return i > 1 ? a : proj_coord_error();
864
865 a.v[i] = d;
866 prev = endp;
867 T.dimensions_given++;
868 }
869

Callers 2

acceptFunction · 0.85
expectFunction · 0.85

Calls 4

proj_coordFunction · 0.85
proj_dmstorFunction · 0.85
proj_coord_errorFunction · 0.85
proj_strtodFunction · 0.70

Tested by

no test coverage detected