[Mapserver-users] MapScript, help starting?

Junkmail Box junkmail at deathkeep.com
Thu Feb 27 08:33:35 PST 2003


I'm having trouble getting started using Perl MapScript. The doc at
http://mapserver.gis.umn.edu/doc36/perlmapscript-reference.html doesn't
give a lot for examples of getting started. They do give this, though:

#!/usr/bin/perl
use mapscript;
my $map = new mapObj('arcata.map') or die('Unable to open mapfile.');
my $img = $map->draw() or die('Unable to draw map');
my $void = $img->saveImage('example.png', $mapscript::MS_PNG, $map->{transparent}, $map->{interlace}, 0);

However, when I run it, example.png is an empty file.

Any ideas on what the problem could be?
Are there any tutorials on getting started using MapScript?

arcata.map is a map file, and works with the mapserv CGI binary just fine.
And $map->{numlayers} properly says there are 3 layers in the map. So I
know mapscript is seeing the arcata.map file, and that arcata.map is
valid. The arcata.map file is as follows:


#
# map file - Arcata demo
#
NAME ARCATADEMO
STATUS ON
SIZE 504 504
EXTENT 407375  4522866  410627 4526910
UNITS METERS
SHAPEPATH "/usr/local/mapserv/htdocs/arcata"
IMAGECOLOR 255 255 255
IMAGETYPE JPEG

# web interface definition
WEB
  # the template for browsing mode
  TEMPLATE arcata.html
  MINSCALE 1000
  MAXSCALE 1550000
  IMAGEPATH "/usr/local/mapserv/tmp/"
  IMAGEURL "/tmp/"
END

# reference (thumbnail) map
REFERENCE
  IMAGE arcata_thumbnail.jpg
  EXTENT 404958.660383 4520848.011905 413035.327051 4528936.011905
  SIZE 216 216
  STATUS ON
  COLOR -1 -1 -1
  OUTLINECOLOR 255 0 0
END

## legend - automatically generated from any classes that have a NAME
attribute
#LEGEND
#  KEYSIZE 18 12
#  LABEL
#    TYPE BITMAP
#    SIZE MEDIUM
#    COLOR 0 0 89
#  END
#  STATUS ON
#END

# scalebar
SCALEBAR
  IMAGECOLOR 0 0 0
  LABEL
    COLOR 255 255 255
    SIZE medium
  END
  STYLE 1
  SIZE 288 6
  COLOR 255 255 255
  UNITS MILES
  INTERVALS 4
  TRANSPARENT TRUE
  STATUS ON
END



### LAYER DEFINITIONS


### parcel divisions
LAYER
  NAME parcels
  TYPE POLYGON
  DATA parcels
  STATUS OFF

  # what template to use for displaying a query about a parcel
  TEMPLATE /usr/local/mapserv/htdocs/arcata/parcel_query_template.html

  # when labeling parcels, the owner's name is the label to use
  LABELITEM OWNER_NAME

  # color-code certain parcels, depending on the owner
  CLASSITEM OWNER_ADD
  CLASS
    #EXPRESSION "ARCATA PLAZA"
    EXPRESSION /ARCATA*/
    COLOR 128 255 255
    OUTLINECOLOR 0 255 0
    LABEL
      COLOR 0 0 0
    END
  END
  CLASS
    EXPRESSION /CALIFORNIA*/
    COLOR 200 200 200
    OUTLINECOLOR 0 255 0
    LABEL
      COLOR 0 0 0
    END
  END
  # default parcel coloration
  CLASS
    NAME "Parcel"
    OUTLINECOLOR 255 0 0
    COLOR 255 120 120
    LABEL
      COLOR 255 255 255
    END
  END

END


### creeks
LAYER
  NAME creeks
  STATUS OFF
  DATA creeks
  TYPE LINE

  CLASS
    NAME "Creek"
    COLOR 0 0 255
  END

  # template to use if someone queries a creek
  TEMPLATE creeks_query_template.html
END


### roads
LAYER
  NAME roads
  STATUS ON
  DATA roads
  TYPE LINE

  CLASS
    NAME "Road"
    COLOR 0 0 0
    LABEL
      COLOR 128 128 128
    END
  END

  # label roads, and allow a user to query a road
  LABELITEM FNAME
  TEMPLATE roads_query_template.html
END

### END OF LAYER DEFINITIONS
END # end of map file







More information about the MapServer-users mailing list