[mapserver-users] GRID labeling, OK, where are the MapServer GRID guru's??

Brent Fraser bfraser at geoanalytic.com
Tue Mar 18 21:46:07 EDT 2008


Bob,

  Good on you for pursuing this!  While I think the current grid object
satisfies most of mapserver implementors' needs, there is room for
improvement.  The ultimate would be a system that can produce reference
system labels like those found on topos (some are very similar to your
NG labels).

First, I see there is still a typo in mapgraticule.c, line 347 (current
SVN) should be

dStartY              = (pInfo->pboundinglines[0].point[1].y -
pInfo->pboundinglines[0].point[0].y) * dDeltaX +
pInfo->pboundinglines[0].point[0].y;

(note the last array index value of 0 not 1)

Second, (from my old notes on experimenting with labeling in v4.3) I
changed 661 thru 682 to:

  switch( ePosition )
  {
    case posBottom:
      pShape->line->point[1].y = pLayer->map->height;
      pShape->line->point[0].y = pLayer->map->height - (
fabs(rectLabel.maxx - rectLabel.minx) + 15 );  /* rectLabel is based
on non-rotated text (x is along the width of text) */
      break;

    case posTop:
      pShape->line->point[1].y = 0;
      pShape->line->point[0].y = fabs(rectLabel.maxx - rectLabel.minx) + 15;
      break;

    case posLeft:
      pShape->line->point[1].x = 0;
      pShape->line->point[0].x = fabs(rectLabel.maxx - rectLabel.minx) + 15;
      break;

    case posRight:
      pShape->line->point[1].x = pLayer->map->width;
      pShape->line->point[0].x = pLayer->map->width - (
fabs(rectLabel.maxx - rectLabel.minx) + 15 );
      break;
  }



And regarding labeling "outside" the map, I arranged my map file to draw:
1. all the usual raster and vector layers
2. a grid layer
3. a "margin" layer of blanking polygons (see below)
4. a grid layer of type annotation so no lines are drawn


Here's part of my map file (for version 4.3 so no telling what will happen
with v5.x):

SIZE 800 600
    :
    :

LAYER
  NAME "Margin"
  TRANSFORM FALSE
  STATUS DEFAULT
  TYPE POLYGON
  CLASS
     COLOR 255 255 255
  END
  FEATURE
     POINTS 0 0 0 600 70 600 70 0 0 0 END
     POINTS 70 0 70 70 800 70 800 0 70 0 END
     POINTS 70 600 800 600 800 530 70 530 70 600 END
     POINTS 730 70 730 530 800 530 800 70 730 70 END
  END
END

#-----------------------------------------------------------
LAYER
  NAME "NeatLine"
  TRANSFORM FALSE
  STATUS DEFAULT
  TYPE LINE
  CLASS
     COLOR 0 0 0
  END
  FEATURE
     POINTS 70 70 70 530 730 530 730 70 70 70 END
  END
END


#-----------------------------------------------------------
LAYER
  NAME "GRID"
  PROJECTION
	  "proj=latlong"
#	  "ellps=sphere"
	  "datum=WGS84"
  END
#  TYPE Line
  TYPE ANNOTATION
#  LABELCACHE off
  STATUS DEFAULT
  CLASS
	COLOR 128 128 128
#	  LABEL
#		TYPE BITMAP
#		SIZE MEDIUM
#		COLOR 128 128 89
#	  END
        LABEL
          color 0 0 0
#          COLOR 255 255 0
#          OUTLINECOLOR 0 0 0
          TYPE TRUETYPE
          FONT arial  #bd
          SIZE 12
          POSITION UC # AUTO
          ANGLE AUTO
#          OFFSET 4 4
#          PARTIALS false
#          WRAP " "
        END # Label
  END

  GRID
    LABELFORMAT "DDMM"
#    LABELFORMAT "DDMMSS"
#    MINSUBDIVIDE 6
#    MAXSUBDIVIDE 6
#    MININTERVAL 1.0
#    MAXINTERVAL 1.0
#    MINARCS 6
#    MAXARCS 6
  END
END

#-----------------------------------------------------------

END  # MAPFILE


  But in the end it is somewhat hacky and not perfect.  I think some
additional objects and properties are needed.  Last year I had a small
rant regarding graticules on the OSGeo mailing list (with no specific
solution reached).  Here's one record of it:

http://www.mail-archive.com/discuss@lists.osgeo.org/msg00935.html

Keep up the good work!
Brent Fraser

> All,
>
> I've (we've) been messing with this GRID object and Labeling while trying
> to get a USNG grid output with labels
>
> The results are meant to look like the left edge of the attached image.
> The other three sides are being repositioned by some semi-known process.
>
> Essentially the labels should be:
>
> First two characters are super-scripted, the next two characters are
> Normal, and the last four are also super-scripted.   We've mussed with
> MapServer code and come up with a method for handling the different
> styling via a layer in the MAPFILE, using  a LABELFORMAT option of NG1(1st
> 2 chars), NG2 (2nd 2 chars) and NG3 (the last 4 chars).  This is set up
> along the lines of the DDMMSS options for LAT/LON.
>
> You can see that there is something wonky about the justification of the
> labels.  Right now we have space padding in front of and behind the
> superscripted items, we'll address that separately once we get past this
> label justification thing.
>
> So the question is, what is the sequence of events for a GRID with labels,
> being applied to the result?  Where in the Code could/should the
> justifications be eliminated for the GRID writing process (I understand
> that there needs to be a process for aligning along the edges) so that the
> regular Labeling parameters, specifically, the OFFSET param, are adhered
> to.
>
> I've tried all sorts of different combinations of settings to get the
> right output, and I can only seem to get one edge to display properly.
>
> Furthering this output option a little more, anyone done any work with
> labeling along the outside of a map image?  I could use an option like
> this for printing for example.
>
> Thanks
>
> bobb
>
>
> The image results are from using this MapFile:
>
> MAP
>   NAME 'USNG'
>   SIZE 800 650
>   STATUS ON
>   ##IMAGECOLOR 254 254 254
>   ##EXTENT 540000 135000 600000 175000
>   EXTENT 593133.398829 170094.734526 593893.148973 170712.010326
>   UNITS FEET
>
>   FONTSET ./0000_00/MN_Line_Experiments/fonts/font.list
>   SYMBOLSET ./0000_00/MN_Line_Experiments/symbols/symbol.list
>
>   TRANSPARENT TRUE
>   IMAGETYPE PNG
>
>   WEB
>     IMAGEPATH "/mnt/VECTOR00/output/"
>     IMAGEURL "/tmp/"
>   END
>
> # EPSG:26915
>
>   LAYER
>     NAME "grid"
>     TYPE LINE
>     STATUS DEFAULT
>     CLASS
>       NAME "Graticule"
>       COLOR 0 0 0
>       SYMBOL 'circle'
>       SIZE 1
>     END
>     PROJECTION
>       "init=epsg:26915"
>     END
>     GRID
>       LABELFORMAT "NG1"
>     END
>   END
>
>   LAYER
>     NAME "ng1"
>     TYPE LINE
>     STATUS DEFAULT
>     CLASS
>       LABEL
>         COLOR  0 0 0
>         FONT mono
>         TYPE truetype
>         SIZE 6
>         OUTLINECOLOR 255 255 254
>         FORCE true
>         POSITION cl
>         #OFFSET 0 0
>       END
>     END
>     PROJECTION
>       "init=epsg:26915"
>     END
>     GRID
>       LABELFORMAT "NG1"
>     END
>   END
>
>   LAYER
>     NAME "ng2"
>     TYPE LINE
>     STATUS DEFAULT
>     CLASS
>       LABEL
>         COLOR  0 0 0
>         FONT mono
>         TYPE truetype
>         SIZE 12
>         OUTLINECOLOR 255 255 254
>         FORCE true
>         POSITION cl
>       END
>     END
>     PROJECTION
>       "init=epsg:26915"
>     END
>     GRID
>       LABELFORMAT "NG2"
>     END
>   END
>
>   LAYER
>     NAME "ng3"
>     TYPE LINE
>     STATUS DEFAULT
>     CLASS
>       LABEL
>         COLOR  0 0 0
>         FONT mono
>         TYPE truetype
>         SIZE 6
>         OUTLINECOLOR 255 255 254
>         FORCE true
>         #OFFSET 0 0
>         POSITION cl
>       END
>     END
>     PROJECTION
>       "init=epsg:26915"
>     END
>     GRID
>       LABELFORMAT "NG3"
>     END
>   END
>
>
> END ## end Map
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>
>




More information about the mapserver-users mailing list