File: shp2img.rb

package info (click to toggle)
mapserver 6.4.1-5%2Bdeb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 12,960 kB
  • ctags: 19,791
  • sloc: ansic: 119,501; cpp: 54,044; python: 3,055; xml: 1,676; cs: 875; lex: 741; yacc: 707; java: 588; perl: 428; makefile: 382; sh: 373; tcl: 158; ruby: 55
file content (44 lines) | stat: -rwxr-xr-x 890 bytes parent folder | download | duplicates (18)
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')