1begin locpt name
2  box -1, -1, 1, 1
3  fill
4  clearpath
5  move 2, 0
6  font "Helvetica", 3.5
7  label name
8end
9
10let polygonColorList = split("red blue green orange")
11
12# Draw all polygons in different colors and also save them into a list.
13#
14newpage "eps", "tutorialjts2.eps", 85, 50
15dataset "shapefile", "coastline.shp", ""
16worlds 600000, 5100000, 1500000, 6100000
17while Mapyrus.fetch.more
18do
19  fetch
20  let polygonList[Mapyrus.fetch.count] = GEOMETRY
21  clearpath
22  addpath GEOMETRY
23  color "lightgray"
24  fill
25  color polygonColorList[Mapyrus.fetch.count]
26  stroke
27done
28let nPolygons = length(polygonList)
29
30# Read list of points, finding which polygon contains each point,
31# and then drawing the point in a different colour depending on
32# which polygon contains the point.
33#
34dataset "textfile", "locations.txt", "delimiter=,"
35while Mapyrus.fetch.more
36do
37  fetch
38  let found = 0, i = 1
39  while found == 0 and i <= nPolygons
40  do
41    if contains(polygonList[i], $1, $2)
42    then
43      # This polygon contains point, draw point in color of polygon.
44      #
45      color polygonColorList[i]
46      clearpath
47      move $1, $2
48      locpt $3
49      let found = 1
50    endif
51    let i = i + 1
52  done
53done
54