Skip to content

Commit 4701966

Browse files
committed
Implement OGC (edge of pixel) extent calculation
1 parent 3b14862 commit 4701966

15 files changed

Lines changed: 38 additions & 73 deletions

src/hittest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) {
187187
&searchrect); /* project the searchrect to source coords */
188188
} else {
189189
searchrect.minx = searchrect.miny = 0;
190-
searchrect.maxx = map->width - 1;
191-
searchrect.maxy = map->height - 1;
190+
searchrect.maxx = map->width;
191+
searchrect.maxy = map->height;
192192
}
193193
#ifdef USE_GEOS
194194
msInitShape(&searchpoly);

src/interpolation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ int msInterpolationDataset(mapObj *map, imageObj *image,
138138
}
139139
} else {
140140
searchrect.minx = searchrect.miny = 0;
141-
searchrect.maxx = map->width - 1;
142-
searchrect.maxy = map->height - 1;
141+
searchrect.maxx = map->width;
142+
searchrect.maxy = map->height;
143143
}
144144

145145
layer->project =

src/mapchart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ int msDrawChartLayer(mapObj *map, layerObj *layer, imageObj *image) {
688688
searchrect = map->extent;
689689
else {
690690
searchrect.minx = searchrect.miny = 0;
691-
searchrect.maxx = map->width - 1;
692-
searchrect.maxy = map->height - 1;
691+
searchrect.maxx = map->width;
692+
searchrect.maxy = map->height;
693693
}
694694

695695
if ((map->projection.numargs > 0) && (layer->projection.numargs > 0))

src/mapcluster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,8 @@ int RebuildClusters(layerObj *layer, int isQuery) {
10821082
searchrect = map->extent;
10831083
else {
10841084
searchrect.minx = searchrect.miny = 0;
1085-
searchrect.maxx = map->width - 1;
1086-
searchrect.maxy = map->height - 1;
1085+
searchrect.maxx = map->width;
1086+
searchrect.maxy = map->height;
10871087
}
10881088

10891089
if (searchrect.minx == layerinfo->searchRect.minx &&

src/mapdraw.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ imageObj *msPrepareImage(mapObj *map, int allow_nonsquare) {
225225
} else
226226
map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height);
227227

228+
if (map->cellsize == 0) {
229+
msSetError(MS_MISCERR, "Invalid map extent or image size.", "msAdjustExtent()");
230+
return(NULL);
231+
}
232+
228233
status = msCalculateScale(map->extent, map->units, map->width, map->height,
229234
map->resolution, &map->scaledenom);
230235
if (status != MS_SUCCESS) {
@@ -1173,8 +1178,8 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) {
11731178

11741179
} else {
11751180
searchrect.minx = searchrect.miny = 0;
1176-
searchrect.maxx = map->width - 1;
1177-
searchrect.maxy = map->height - 1;
1181+
searchrect.maxx = map->width;
1182+
searchrect.maxy = map->height;
11781183
}
11791184

11801185
status = msLayerWhichShapes(layer, searchrect, MS_FALSE);

src/mapgraticule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ msGraticuleLayerGetIntersectionPoints(mapObj *map, layerObj *layer) {
663663
searchrect = map->extent;
664664
else {
665665
searchrect.minx = searchrect.miny = 0;
666-
searchrect.maxx = map->width - 1;
667-
searchrect.maxy = map->height - 1;
666+
searchrect.maxx = map->width;
667+
searchrect.maxy = map->height;
668668
}
669669

670670
if ((map->projection.numargs > 0) && (layer->projection.numargs > 0))

src/mapobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ int msMapScaleExtent(mapObj *map, double zoomfactor, double minscaledenom,
318318

319319
if (minscaledenom > 0 || maxscaledenom > 0) {
320320
/* ensure we are within the valid scale domain */
321-
md = (map->width - 1) /
321+
md = (map->width) /
322322
(map->resolution * msInchesPerUnit(map->units, center_y));
323323
if (minscaledenom > 0 && geo_width < minscaledenom * md)
324324
geo_width = minscaledenom * md;
@@ -422,14 +422,14 @@ int msMapComputeGeotransform(mapObj *map)
422422

423423
{
424424
/* Do we have all required parameters? */
425-
if (map->extent.minx == map->extent.maxx || map->width <= 1 ||
426-
map->height <= 1)
425+
if (map->extent.minx == map->extent.maxx || map->width <= 0 ||
426+
map->height <= 0)
427427
return MS_FAILURE;
428428

429429
const double geo_width = map->extent.maxx - map->extent.minx;
430430
const double geo_height = map->extent.maxy - map->extent.miny;
431-
return msMapComputeGeotransformEx(map, geo_width / (map->width - 1),
432-
geo_height / (map->height - 1));
431+
return msMapComputeGeotransformEx(map, geo_width / map->width,
432+
geo_height / map->height);
433433
}
434434

435435
/************************************************************************/

src/mapscale.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int msCalculateScale(rectObj extent, int units, int width, int height,
104104
case (MS_INCHES):
105105
case (MS_FEET):
106106
center_y = (extent.miny + extent.maxy) / 2.0;
107-
md = (width - 1) /
107+
md = (width) /
108108
(resolution *
109109
msInchesPerUnit(
110110
units, center_y)); /* remember, we use a pixel-center to
@@ -593,7 +593,7 @@ double GetDeltaExtentsUsingScale(double scale, int units, double centerLat,
593593
case (MS_FEET):
594594
/* remember, we use a pixel-center to pixel-center extent, hence the width-1
595595
*/
596-
md = (width - 1) / (resolution * msInchesPerUnit(units, centerLat));
596+
md = (width) / (resolution * msInchesPerUnit(units, centerLat));
597597
dfDelta = md * scale;
598598
break;
599599

src/maptemplate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ int setExtent(mapservObj *mapserv) {
219219
msInchesPerUnit(mapserv->map->units,
220220
0); /* user supplied a point and a scale denominator */
221221
mapserv->map->extent.minx =
222-
mapserv->mappnt.x - cellsize * (mapserv->map->width - 1) / 2.0;
222+
mapserv->mappnt.x - cellsize * (mapserv->map->width) / 2.0;
223223
mapserv->map->extent.miny =
224-
mapserv->mappnt.y - cellsize * (mapserv->map->height - 1) / 2.0;
224+
mapserv->mappnt.y - cellsize * (mapserv->map->height) / 2.0;
225225
mapserv->map->extent.maxx =
226-
mapserv->mappnt.x + cellsize * (mapserv->map->width - 1) / 2.0;
226+
mapserv->mappnt.x + cellsize * (mapserv->map->width) / 2.0;
227227
mapserv->map->extent.maxy =
228-
mapserv->mappnt.y + cellsize * (mapserv->map->height - 1) / 2.0;
228+
mapserv->mappnt.y + cellsize * (mapserv->map->height) / 2.0;
229229
break;
230230
default: /* use the default in the mapfile if it exists */
231231
if ((mapserv->map->extent.minx == mapserv->map->extent.maxx) &&

src/maptile.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ int msTileSetExtent(mapservObj *msObj) {
345345
#ifdef USE_TILE_API
346346

347347
mapObj *map = msObj->map;
348-
double dx, dy, buffer;
348+
double buffer;
349349
tileParams params;
350350

351351
/* Read the tile-mode map file parameters */
@@ -468,18 +468,6 @@ int msTileSetExtent(mapservObj *msObj) {
468468
msDebug("msTileSetExtent(): buffered image size (%d x %d)\n", map->width,
469469
map->height);
470470

471-
/*
472-
** Adjust the extents inwards by 1/2 pixel so they are from
473-
** center-of-pixel to center-of-pixel, instead of edge-to-edge.
474-
** This is the way mapserver does it.
475-
*/
476-
dx = (map->extent.maxx - map->extent.minx) / map->width;
477-
map->extent.minx += dx * 0.5;
478-
map->extent.maxx -= dx * 0.5;
479-
dy = (map->extent.maxy - map->extent.miny) / map->height;
480-
map->extent.miny += dy * 0.5;
481-
map->extent.maxy -= dy * 0.5;
482-
483471
/*
484472
** Ensure the labelcache buffer is greater than the tile buffer.
485473
*/

0 commit comments

Comments
 (0)