[mapserver-commits] r12510 - branches/branch-5-4/mapserver
svn at osgeo.org
svn at osgeo.org
Thu Sep 1 12:29:20 EDT 2011
Author: hobu
Date: 2011-09-01 09:29:20 -0700 (Thu, 01 Sep 2011)
New Revision: 12510
Modified:
branches/branch-5-4/mapserver/mapprojhack.c
branches/branch-5-4/mapserver/mapserver.h
Log:
backport mapprojhack.c to 5.4 for #2008
Modified: branches/branch-5-4/mapserver/mapprojhack.c
===================================================================
--- branches/branch-5-4/mapserver/mapprojhack.c 2011-09-01 14:03:03 UTC (rev 12509)
+++ branches/branch-5-4/mapserver/mapprojhack.c 2011-09-01 16:29:20 UTC (rev 12510)
@@ -26,27 +26,9 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
****************************************************************************/
-/* ====================================================================
- This file includes only mapproject.h (which includes projects.h)
- and none of the windows include files. This is because of a conflict
- in names (PJ_VALUE) between the projects.h and windows include file
- winreg.h.
- ==================================================================== */
-
-/* Make sure we include projects.h before mapproject.h, because proj_api.h
- * may end up being included instead by mapproject.h ifdef USE_PROJ_API_H
- */
-#ifdef USE_PROJ
-#include <projects.h>
-#endif
-
#include <string.h>
-#include "mapproject.h"
+#include "mapserver.h"
-enum MS_UNITS {MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, MS_DD,
- MS_PIXELS};
-
-
/************************************************************************/
/* ConvertProjUnitStringToMS */
/* */
@@ -67,7 +49,7 @@
}
else if (strcmp(pszProjUnit, "mi") ==0 || strcmp(pszProjUnit, "us-mi") ==0)
{
- return MS_FEET;
+ return MS_MILES;
}
else if (strcmp(pszProjUnit, "in") ==0 || strcmp(pszProjUnit, "us-in") ==0 )
{
@@ -77,45 +59,16 @@
{
return MS_FEET;
}
+ else if (strcmp(pszProjUnit, "kmi") == 0)
+ {
+ return MS_NAUTICALMILES;
+ }
return -1;
}
#endif /* def USE_PROJ */
/************************************************************************/
-/* pj_units[] copy. It is safer for win32 builds to include a */
-/* copy of pj_units instead of trying to get the variable from */
-/* the proj dll. */
-/************************************************************************/
-#ifdef USE_PROJ
-struct PJ_UNITS
-pj_units_copy[] = {
- {"km", "1000.", "Kilometer"},
- {"m", "1.", "Meter"},
- {"dm", "1/10", "Decimeter"},
- {"cm", "1/100", "Centimeter"},
- {"mm", "1/1000", "Millimeter"},
- {"kmi", "1852.0", "International Nautical Mile"},
- {"in", "0.0254", "International Inch"},
- {"ft", "0.3048", "International Foot"},
- {"yd", "0.9144", "International Yard"},
- {"mi", "1609.344", "International Statute Mile"},
- {"fath", "1.8288", "International Fathom"},
- {"ch", "20.1168", "International Chain"},
- {"link", "0.201168", "International Link"},
- {"us-in", "1./39.37", "U.S. Surveyor's Inch"},
- {"us-ft", "0.304800609601219", "U.S. Surveyor's Foot"},
- {"us-yd", "0.914401828803658", "U.S. Surveyor's Yard"},
- {"us-ch", "20.11684023368047", "U.S. Surveyor's Chain"},
- {"us-mi", "1609.347218694437", "U.S. Surveyor's Statute Mile"},
- {"ind-yd", "0.91439523", "Indian Yard"},
- {"ind-ft", "0.30479841", "Indian Foot"},
- {"ind-ch", "20.11669506", "Indian Chain"},
- {(char *)0, (char *)0, (char *)0}
-};
-#endif /* def USE_PROJ */
-
-/************************************************************************/
/* int GetMapserverUnitUsingProj(projectionObj *psProj) */
/* */
/* Return a mapserver unit corresponding to the projection */
@@ -124,19 +77,67 @@
int GetMapserverUnitUsingProj(projectionObj *psProj)
{
#ifdef USE_PROJ
- struct PJ_UNITS *lu;
- if (psProj && psProj->proj)
+ char *proj_str;
+
+ if( pj_is_latlong( psProj->proj ) )
+ return MS_DD;
+
+ proj_str = pj_get_def( psProj->proj, 0 );
+
+/* -------------------------------------------------------------------- */
+/* Handle case of named units. */
+/* -------------------------------------------------------------------- */
+ if( strstr(proj_str,"units=") != NULL )
{
- if (psProj->proj->is_latlong)
- return MS_DD;
+ char units[32];
+ char *blank;
- /* psProj->proj->to_meter; */
- for (lu = pj_units_copy; lu->id ; ++lu)
- {
- if (strtod(lu->to_meter, NULL) == psProj->proj->to_meter)
- return ConvertProjUnitStringToMS(lu->id);
- }
+ strlcpy( units, (strstr(proj_str,"units=")+6), sizeof(units) );
+ pj_dalloc( proj_str );
+
+ blank = strchr(units, ' ');
+ if( blank != NULL )
+ *blank = '\0';
+
+ return ConvertProjUnitStringToMS( units );
}
+
+/* -------------------------------------------------------------------- */
+/* Handle case of to_meter value. */
+/* -------------------------------------------------------------------- */
+ if( strstr(proj_str,"to_meter=") != NULL )
+ {
+ char to_meter_str[32];
+ char *blank;
+ double to_meter;
+
+ strlcpy(to_meter_str,(strstr(proj_str,"to_meter=")+9),
+ sizeof(to_meter_str));
+ pj_dalloc( proj_str );
+
+ blank = strchr(to_meter_str, ' ');
+ if( blank != NULL )
+ *blank = '\0';
+
+ to_meter = atof(to_meter_str);
+
+ if( fabs(to_meter-1.0) < 0.0000001 )
+ return MS_METERS;
+ else if( fabs(to_meter-1000.0) < 0.00001 )
+ return MS_KILOMETERS;
+ else if( fabs(to_meter-0.3048) < 0.0001 )
+ return MS_FEET;
+ else if( fabs(to_meter-0.0254) < 0.0001 )
+ return MS_INCHES;
+ else if( fabs(to_meter-1609.344) < 0.001 )
+ return MS_MILES;
+ else if( fabs(to_meter-1852.0) < 0.1 )
+ return MS_NAUTICALMILES;
+ else
+ return -1;
+ }
+
+ pj_dalloc( proj_str );
#endif
return -1;
}
Modified: branches/branch-5-4/mapserver/mapserver.h
===================================================================
--- branches/branch-5-4/mapserver/mapserver.h 2011-09-01 14:03:03 UTC (rev 12509)
+++ branches/branch-5-4/mapserver/mapserver.h 2011-09-01 16:29:20 UTC (rev 12510)
@@ -359,7 +359,7 @@
/* General enumerated types - needed by scripts */
enum MS_FILE_TYPE {MS_FILE_MAP, MS_FILE_SYMBOL};
-enum MS_UNITS {MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, MS_DD, MS_PIXELS, MS_PERCENTAGES};
+enum MS_UNITS {MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, MS_DD, MS_PIXELS, MS_PERCENTAGES, MS_NAUTICALMILES};
enum MS_SHAPE_TYPE {MS_SHAPE_POINT, MS_SHAPE_LINE, MS_SHAPE_POLYGON, MS_SHAPE_NULL};
enum MS_LAYER_TYPE {MS_LAYER_POINT, MS_LAYER_LINE, MS_LAYER_POLYGON, MS_LAYER_RASTER, MS_LAYER_ANNOTATION, MS_LAYER_QUERY, MS_LAYER_CIRCLE, MS_LAYER_TILEINDEX, MS_LAYER_CHART};
enum MS_FONT_TYPE {MS_TRUETYPE, MS_BITMAP};
More information about the mapserver-commits
mailing list