-
-
Notifications
You must be signed in to change notification settings - Fork 360
/
MapThread.java
105 lines (90 loc) · 2.74 KB
/
MapThread.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// $Id$
//
// See README_THREADTEST.TXT for usage details.
//
import edu.umn.gis.mapscript.*;
public class MapThread extends Thread {
MapThread(String mapfile, int iterations, int id) {
this.mapfile = mapfile;
this.iterations = iterations;
this.id=id;
}
public void run() {
System.out.println("Thread "+id+" running...");
/*
Uncomment this if you need to reschedule threads
if (id>=5) {
try {
sleep(10000);
} catch(InterruptedException ie) {
ie.printStackTrace();
}
}
*/
for( int i = 0; i < iterations; i++ ) {
mapObj map = new mapObj(mapfile);
long path=Math.round(Math.random()*10);
if ( path > 5 ) {
System.out.println("Thread "+id+"-"+i+" querying...");
query(map);
} else {
System.out.println("Thread "+id+"-"+i+" using geos to create a buffer...");
try {
createBuffer(map);
} catch(Exception e) {
System.out.println("have you enabled GEOS support? "+e.getMessage());
}
}
// We use this to test swig's memory management code
//System.gc();
//map.draw().save("/tmp/mapthread"+id+"-"+i+".png", map);
map.draw();
}
mapscript.msConnPoolCloseUnreferenced();
System.out.println("Thread "+id+" done.");
}
public void createBuffer(mapObj map) {
layerObj layer = map.getLayer(3);
if (layer!=null) {
layer.open();
layer.queryByIndex(map,0,-1,mapscriptConstants.MS_FALSE);
shapeObj shape=layer.getShape(layer.getResults().getResult(0));
if (shape!=null) {
shapeObj buffer=shape.buffer(0.1);
if (buffer != null) {
layerObj bufferLayer=new layerObj(map);
bufferLayer.setStatus(mapscriptConstants.MS_DEFAULT);
bufferLayer.setDebug(mapscriptConstants.MS_ON);
bufferLayer.setName("BUFFER");
//bufferLayer.setType(mapscriptConstants.MS_LAYER_POLYGON);
bufferLayer.setProjection("init=epsg:4326");
bufferLayer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
bufferLayer.setOpacity(50);
classObj clazz=new classObj(bufferLayer);
clazz.setName("Buffer class");
styleObj style=new styleObj(clazz);
colorObj green=new colorObj(0,254,0,-4);
//green.setRGB(0,254,0);
style.setColor(green);
bufferLayer.addFeature(buffer);
} else {
System.out.println("Buffer shape is NULL!");
}
}
}
}
public void query(mapObj map) {
layerObj layer = map.getLayer(3);
if (layer!=null) {
layer.setTemplate("template.html");
String filter="A Point";
layer.queryByAttributes(map,"FNAME", filter, mapscriptConstants.MS_MULTIPLE);
layer.open();
System.out.println( " numresults: " +layer.getNumResults() );
layer.close();
}
}
String mapfile;
int iterations;
int id;
}