Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Several projection interface changes. Hid PROJ.4 PJ struct in all fun…

…ction calls. Changed io_projection to latlon and added code to load from a mapfile. Changed projargs to args in projectionObj.

git-svn-id: http://svn.osgeo.org/mapserver/trunk@434 7532c77e-422f-0410-93f4-f0b67bdd69e2
  • Loading branch information...
commit ab7fde552694185b8af7c1ceb3381b7f5d7c261b 1 parent 5735146
@sdlime sdlime authored
View
2  map.h
@@ -550,7 +550,7 @@ typedef struct { /* structure for a map */
int imagetype, imagequality;
projectionObj projection; /* projection information for output map */
- projectionObj io_projection; /* Display projection, usually geographic */
+ projectionObj latlon; /* geographic projection definition */
referenceMapObj reference;
scalebarObj scalebar;
View
37 mapfile.c
@@ -485,7 +485,7 @@ int msInitProjection(projectionObj *p)
#ifdef USE_PROJ
p->numargs = 0;
p->proj = NULL;
- if((p->projargs = (char **)malloc(MS_MAXPROJARGS*sizeof(char *))) == NULL) {
+ if((p->args = (char **)malloc(MS_MAXPROJARGS*sizeof(char *))) == NULL) {
msSetError(MS_MEMERR, NULL, "initProjection()");
return(-1);
}
@@ -502,8 +502,8 @@ void msFreeProjection(projectionObj *p) {
p->proj = NULL;
}
- msFreeCharArray(p->projargs, p->numargs);
- p->projargs = NULL;
+ msFreeCharArray(p->args, p->numargs);
+ p->args = NULL;
p->numargs = 0;
#endif
}
@@ -514,7 +514,7 @@ int msProcessProjection(projectionObj *p)
#ifdef USE_PROJ
assert( p->proj == NULL );
- if( strcasecmp(p->projargs[0],"GEOGRAPHIC") == 0 ) {
+ if( strcasecmp(p->args[0],"GEOGRAPHIC") == 0 ) {
msSetError(MS_PROJERR,
"PROJECTION 'GEOGRAPHIC' no longer supported.\n"
"Provide explicit definition.\n"
@@ -524,12 +524,12 @@ int msProcessProjection(projectionObj *p)
return(-1);
}
- if (strcasecmp(p->projargs[0], "AUTO") == 0) {
+ if (strcasecmp(p->args[0], "AUTO") == 0) {
p->proj = NULL;
return 0;
}
- if( !(p->proj = pj_init(p->numargs, p->projargs)) ) {
+ if( !(p->proj = pj_init(p->numargs, p->args)) ) {
msSetError(MS_PROJERR, pj_strerrno(pj_errno),
"msProcessProjection()");
return(-1);
@@ -559,7 +559,7 @@ static int loadProjection(projectionObj *p)
break;
case(MS_STRING):
case(MS_AUTO):
- p->projargs[i] = strdup(msyytext);
+ p->args[i] = strdup(msyytext);
i++;
break;
@@ -599,7 +599,7 @@ int msLoadProjectionString(projectionObj *p, char *value)
}
trimmed[i_out] = '\0';
- p->projargs = split(trimmed,'+', &p->numargs);
+ p->args = split(trimmed,'+', &p->numargs);
free( trimmed );
}
@@ -608,7 +608,7 @@ int msLoadProjectionString(projectionObj *p, char *value)
*/
else
{
- p->projargs = split(value,',', &p->numargs);
+ p->args = split(value,',', &p->numargs);
}
return msProcessProjection( p );
@@ -626,7 +626,7 @@ static void writeProjection(projectionObj *p, FILE *stream, char *tab) {
if(p->numargs > 0) {
fprintf(stream, "%sPROJECTION\n", tab);
for(i=0; i<p->numargs; i++)
- fprintf(stream, " %s%s\n", tab, p->projargs[i]);
+ fprintf(stream, " %s%s\n", tab, p->args[i]);
fprintf(stream, "%sEND\n", tab);
}
#endif
@@ -2740,12 +2740,19 @@ int initMap(mapObj *map)
initReferenceMap(&map->reference);
initQueryMap(&map->querymap);
- if(msInitProjection(&map->projection) == -1)
+#ifdef USE_PROJ
+ if(msInitProjection(&(map->projection)) == -1)
return(-1);
-
- if(msInitProjection(&map->io_projection) == -1)
+ if(msInitProjection(&(map->latlon)) == -1)
return(-1);
+ // initialize a default "geographic" projection
+ map->latlon.numargs = 2;
+ map->latlon.args[0] = strdup("proj=latlong");
+ map->latlon.args[1] = strdup("ellps=clrk66"); // probably want a different ellipsoid
+ if(msProcessProjection(&(map->latlon)) == -1) return(-1);
+#endif
+
return(0);
}
@@ -2967,6 +2974,10 @@ mapObj *msLoadMap(char *filename)
case(INTERLACE):
if((map->interlace = getSymbol(2, MS_ON,MS_OFF)) == -1) return(NULL);
break;
+ case(LATLON):
+ msFreeProjection(&map->latlon);
+ if(loadProjection(&map->latlon) == -1) return(NULL);
+ break;
case(LAYER):
if(map->numlayers == MS_MAXLAYERS) {
msSetError(MS_IDENTERR, "Too many layers defined.", "msLoadMap()");
View
1  mapfile.h
@@ -135,5 +135,6 @@
#define LABELREQUIRES 1119
#define METADATA 1120
+#define LATLON 1121
#endif /* MAPFILE_H */
View
1  maplexer.l
@@ -125,6 +125,7 @@ char *msyystring=NULL;
<INITIAL,OBJECT_STRING>labelminscale { return(LABELMINSCALE); }
<INITIAL,OBJECT_STRING>labelrequires { return(LABELREQUIRES); }
<INITIAL,OBJECT_STRING>labelsizeitem { return(LABELSIZEITEM); }
+<INITIAL,OBJECT_STRING>latlon { return(LATLON); }
<INITIAL,OBJECT_STRING>layer { return(LAYER); }
<INITIAL,OBJECT_STRING>legend { return(LEGEND); }
<INITIAL>log { return(LOG); }
View
77 mapproject.c
@@ -1,23 +1,22 @@
#include "map.h"
#include "mapproject.h"
-#ifdef USE_PROJ
-
-void msProjectPoint(PJ *in, PJ *out, pointObj *point)
+int msProjectPoint(projectionobj *in, projectionobj *out, pointObj *point)
{
+#ifdef USE_PROJ
projUV p;
- if( in && out )
+ if( in->proj && out->proj )
{
- if( pj_is_latlong(in) )
+ if( pj_is_latlong(in->proj) )
{
point->x *= DEG_TO_RAD;
point->y *= DEG_TO_RAD;
}
- pj_transform( in, out, 1, 0, &(point->x), &(point->y), NULL );
+ pj_transform( in->proj, out->proj, 1, 0, &(point->x), &(point->y), NULL );
- if( pj_is_latlong(out) )
+ if( pj_is_latlong(out->proj) )
{
point->x *= RAD_TO_DEG;
point->y *= RAD_TO_DEG;
@@ -28,31 +27,36 @@ void msProjectPoint(PJ *in, PJ *out, pointObj *point)
p.u = point->x;
p.v = point->y;
- if(in==NULL) { /* input coordinates are lat/lon */
+ if(in->proj==NULL) { /* input coordinates are lat/lon */
p.u *= DEG_TO_RAD; /* convert to radians */
p.v *= DEG_TO_RAD;
- p = pj_fwd(p, out);
+ p = pj_fwd(p, out->proj);
} else {
- if(out==NULL) { /* output coordinates are lat/lon */
- p = pj_inv(p, in);
+ if(out->proj==NULL) { /* output coordinates are lat/lon */
+ p = pj_inv(p, in->proj);
p.u *= RAD_TO_DEG; /* convert to decimal degrees */
p.v *= RAD_TO_DEG;
} else { /* need to go from one projection to another */
- p = pj_inv(p, in);
- p = pj_fwd(p, out);
+ p = pj_inv(p, in->proj);
+ p = pj_fwd(p, out->proj);
}
}
point->x = p.u;
point->y = p.v;
}
- return;
+ return(MS_SUCCESS);
+#else
+ msSetError(MS_PROJERR, "Projection support is not available.", "msProjectPoint()");
+ return(MS_FAILURE);
+#endif
}
#define NUMBER_OF_SAMPLE_POINTS 100
-void msProjectRect(PJ *in, PJ *out, rectObj *rect)
+int msProjectRect(projectionobj *in, projectionobj *out, rectObj *rect)
{
+#ifdef USE_PROJ
pointObj prj_point;
rectObj prj_rect;
@@ -64,7 +68,7 @@ void msProjectRect(PJ *in, PJ *out, rectObj *rect)
prj_point.x = rect->minx;
prj_point.y = rect->miny;
- msProjectPoint(in, out, &prj_point);
+ msProjectPoint(in->proj, out->proj, &prj_point);
prj_rect.minx = prj_rect.maxx = prj_point.x;
prj_rect.miny = prj_rect.maxy = prj_point.y;
@@ -72,7 +76,7 @@ void msProjectRect(PJ *in, PJ *out, rectObj *rect)
for(x=rect->minx+dx; x<=rect->maxx; x+=dx) {
prj_point.x = x;
prj_point.y = rect->miny;
- msProjectPoint(in, out, &prj_point);
+ msProjectPoint(in->proj, out->proj, &prj_point);
prj_rect.miny = MS_MIN(prj_rect.miny, prj_point.y);
prj_rect.maxy = MS_MAX(prj_rect.maxy, prj_point.y);
prj_rect.minx = MS_MIN(prj_rect.minx, prj_point.x);
@@ -80,7 +84,7 @@ void msProjectRect(PJ *in, PJ *out, rectObj *rect)
prj_point.x = x;
prj_point.y = rect->maxy;
- msProjectPoint(in, out, &prj_point);
+ msProjectPoint(in->proj, out->proj, &prj_point);
prj_rect.miny = MS_MIN(prj_rect.miny, prj_point.y);
prj_rect.maxy = MS_MAX(prj_rect.maxy, prj_point.y);
prj_rect.minx = MS_MIN(prj_rect.minx, prj_point.x);
@@ -92,7 +96,7 @@ void msProjectRect(PJ *in, PJ *out, rectObj *rect)
for(y=rect->miny+dy; y<=rect->maxy; y+=dy) {
prj_point.y = y;
prj_point.x = rect->minx;
- msProjectPoint(in, out, &prj_point);
+ msProjectPoint(in->proj, out->proj, &prj_point);
prj_rect.minx = MS_MIN(prj_rect.minx, prj_point.x);
prj_rect.maxx = MS_MAX(prj_rect.maxx, prj_point.x);
prj_rect.miny = MS_MIN(prj_rect.miny, prj_point.y);
@@ -100,7 +104,7 @@ void msProjectRect(PJ *in, PJ *out, rectObj *rect)
prj_point.x = rect->maxx;
prj_point.y = y;
- msProjectPoint(in, out, &prj_point);
+ msProjectPoint(in->proj, out->proj, &prj_point);
prj_rect.minx = MS_MIN(prj_rect.minx, prj_point.x);
prj_rect.maxx = MS_MAX(prj_rect.maxx, prj_point.x);
prj_rect.miny = MS_MIN(prj_rect.miny, prj_point.y);
@@ -113,23 +117,40 @@ void msProjectRect(PJ *in, PJ *out, rectObj *rect)
rect->maxx = prj_rect.maxx;
rect->maxy = prj_rect.maxy;
- return;
+ return(MS_SUCCESS);
+#else
+ msSetError(MS_PROJERR, "Projection support is not available.", "msProjectRect()");
+ return(MS_FAILURE);
+#endif
}
-void msProjectPolyline(PJ *in, PJ *out, shapeObj *poly)
+int msProjectShape(projectionobj *in, projectionobj *out, shapeObj *shape)
{
+#ifdef USE_PROJ
int i,j;
- for(i=0; i<poly->numlines; i++)
- for(j=0; j<poly->line[i].numpoints; j++)
- msProjectPoint(in, out, &(poly->line[i].point[j]));
+ for(i=0; i<shape->numlines; i++)
+ for(j=0; j<shape->line[i].numpoints; j++)
+ msProjectPoint(in->proj, out->proj, &(shape->line[i].point[j]));
+
+ return(MS_SUCCESS);
+#else
+ msSetError(MS_PROJERR, "Projection support is not available.", "msProjectShape()");
+ return(MS_FAILURE);
+#endif
}
-void msProjectLine(PJ *in, PJ *out, lineObj *line)
+int msProjectLine(projectionobj *in, projectionobj *out, lineObj *line)
{
+#ifdef USE_PROJ
int i;
for(i=0; i<line->numpoints; i++)
- msProjectPoint(in, out, &(line->point[i]));
-}
+ msProjectPoint(in->proj, out->proj, &(line->point[i]));
+
+ return(MS_SUCCESS);
+#else
+ msSetError(MS_PROJERR, "Projection support is not available.", "msProjectLine()");
+ return(MS_FAILURE);
#endif
+}
View
14 mapproject.h
@@ -12,19 +12,17 @@ extern "C" {
#endif
typedef struct {
- char **projargs; /* variable number of projection args */
+ char **args; /* variable number of projection args */
int numargs; /* actual number of projection args */
#ifdef USE_PROJ
PJ *proj; /* a projection structure for the PROJ package */
#endif
} projectionObj;
-#ifdef USE_PROJ
-void msProjectPoint(PJ *in, PJ *out, pointObj *point);
-void msProjectPolyline(PJ *in, PJ *out, shapeObj *poly);
-void msProjectLine(PJ *in, PJ *out, lineObj *line);
-void msProjectRect(PJ *in, PJ *out, rectObj *rect);
-#endif
+int msProjectPoint(projectionObj *in, projectionObj *out, pointObj *point);
+int msProjectShape(projectionObj *in, projectionObj *out, shapeObj *shape);
+int msProjectLine(projectionObj *in, projectionObj *out, lineObj *line);
+int msProjectRect(projectionObj *in, projectionObj *out, rectObj *rect);
int msOGCWKT2ProjectionObj( const char *pszWKT,
projectionObj *proj );
@@ -33,7 +31,7 @@ int msInitProjection(projectionObj *p);
int msProcessProjection(projectionObj *p);
int msLoadProjectionString(projectionObj *p, char *value);
-/* Provides compatibliity with PROJ.4 4.4.2 */
+/* Provides compatiblity with PROJ.4 4.4.2 */
#ifndef PJ_VERSION
# define pj_is_latlong(x) ((x)->is_latlong)
#endif
View
10 mapserv.c
@@ -306,7 +306,7 @@ void loadForm()
if(Map->projection.proj && !pj_is_latlong(Map->projection.proj)
&& (Map->extent.minx >= -180.0 && Map->extent.minx <= 180.0)
&& (Map->extent.miny >= -90.0 && Map->extent.miny <= 90.0))
- msProjectRect(Map->io_projection.proj,
+ msProjectRect(Map->latlon.proj,
Map->projection.proj,
&(Map->extent)); // extent is a in lat/lon
#endif
@@ -399,7 +399,7 @@ void loadForm()
if(Map->projection.proj && !pj_is_latlong(Map->projection.proj)
&& (line.point[j].x >= -180.0 && line.point[j].x <= 180.0)
&& (line.point[j].y >= -90.0 && line.point[j].y <= 90.0))
- msProjectPoint(Map->io_projection.proj,
+ msProjectPoint(Map->latlon.proj,
Map->projection.proj,
&line.point[j]); // point is a in lat/lon
#endif
@@ -977,7 +977,7 @@ void returnCoordinate()
#ifdef USE_PROJ
if(Map->projection.proj != NULL && !pj_is_latlong(Map->projection.proj) ) {
pointObj p=MapPnt;
- msProjectPoint(Map->projection.proj, Map->io_projection.proj, &p);
+ msProjectPoint(Map->projection.proj, Map->latlon.proj, &p);
sprintf(ms_error.message, "%s Computed lat/lon value is (%g, %g).\n", ms_error.message, p.x, p.y);
}
#endif
@@ -1135,8 +1135,8 @@ char *processLine(char *instr, int mode)
&& !pj_is_latlong(Map->projection.proj) ) {
llextent=Map->extent;
llpoint=MapPnt;
- msProjectRect(Map->projection.proj, Map->io_projection.proj, &llextent);
- msProjectPoint(Map->projection.proj, Map->io_projection.proj, &llpoint);
+ msProjectRect(Map->projection.proj, Map->latlon.proj, &llextent);
+ msProjectPoint(Map->projection.proj, Map->latlon.proj, &llpoint);
sprintf(repstr, "%f", llpoint.x);
outstr = gsub(outstr, "[maplon]", repstr);
View
6 maputil.c
@@ -343,7 +343,7 @@ int msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, gdImagePtr img, i
#ifdef USE_PROJ
if((layer->projection.numargs > 0) && (map->projection.numargs > 0))
- msProjectPoint(layer->projection.proj, map->projection.proj, point);
+ msProjectPoint(&layer->projection, &ap->projection, point);
#endif
switch(layer->type) {
@@ -431,7 +431,7 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, gdImagePtr img, i
#ifdef USE_PROJ
if((layer->projection.numargs > 0) && (map->projection.numargs > 0))
- msProjectPolyline(layer->projection.proj, map->projection.proj, shape);
+ msProjectShape(&layer->projection, &map->projection, shape);
#endif
switch(layer->type) {
@@ -836,7 +836,7 @@ int msDrawLayer(mapObj *map, layerObj *layer, gdImagePtr img)
searchrect = map->extent;
#ifdef USE_PROJ
if((map->projection.numargs > 0) && (layer->projection.numargs > 0))
- msProjectRect(map->projection.proj, layer->projection.proj, &searchrect); // project the searchrect to source coords
+ msProjectRect(&map->projection, &layer->projection, &searchrect); // project the searchrect to source coords
#endif
status = msLayerWhichShapes(layer, searchrect);
if(status == MS_DONE) { // no overlap
View
4 mapwms.c
@@ -288,8 +288,8 @@ void msWMSPrintLatLonBoundingBox(const char *tabspace,
rectObj ll_ext;
ll_ext = *extent;
- if (srcproj->proj && !pj_is_latlong(srcproj->proj)) {
- msProjectRect(srcproj->proj, NULL, &ll_ext);
+ if (srcproj->numargs > 0 && !pj_is_latlong(srcproj->proj)) {
+ msProjectRect(srcproj, NULL, &ll_ext);
}
printf("%s<LatLonBoundingBox minx=\"%g\" miny=\"%g\" maxx=\"%g\" maxy=\"%g\" />\n",
Please sign in to comment.
Something went wrong with that request. Please try again.