File: shp2img.rb

package info (click to toggle)
mapserver 5.6.5-2%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 15,900 kB
  • ctags: 25,593
  • sloc: ansic: 201,813; cpp: 49,629; cs: 11,792; python: 5,233; perl: 3,249; sh: 1,199; makefile: 884; lex: 592; java: 466; xml: 373; yacc: 334; tcl: 158; ruby: 53
file content (44 lines) | stat: -rwxr-xr-x 890 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby 

require "mapscript"
include Mapscript

filename = ARGV[0]

shapefile = ShapefileObj.new(filename, -1)

shapepath = File.dirname(filename)
shapename = File.basename(filename, "....")

map = MapObj.new('')
map.shapepath = shapepath
map.height = 200
map.width = 200
map.extent = shapefile.bounds

$shapetypes =
{
   MS_SHAPEFILE_POINT      => MS_LAYER_POINT,
   MS_SHAPEFILE_ARC        => MS_LAYER_LINE,
   MS_SHAPEFILE_POLYGON    => MS_LAYER_POLYGON,
   MS_SHAPEFILE_MULTIPOINT => MS_LAYER_LINE
}

layer = LayerObj.new(map)
layer.name = shapename
layer.type = $shapetypes[shapefile.type]
layer.status = MS_ON
layer.data = shapename

cls = ClassObj.new(layer)
style = StyleObj.new()
color = ColorObj.new()
color.red = 107
color.green = 158
color.blue = 160
style.color = color
cls.insertStyle(style)

#map.save(shapename+'.map')
img = map.draw
img.save(shapename+'.png')