Coverage details for edu.umn.gis.mapscript.MapScriptBean

LineHitsSource
1 // A Java MapScript module for MapServer.
2 // See <http://mapserver.gis.umn.edu> for information on MapServer.
3 //
4 // Copyright (C) 2003 Andrew Collins <andrewrcollins@yahoo.com>
5 //
6 // This library is free software; you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General
8 // Public License as published by the Free Software Foundation;
9 // either version 2.1 of the License, or (at your option) any
10 // later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty
14 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 // See the GNU Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General
18 // Public License along with this library; if not, write to
19 // the Free Software Foundation, Inc., 59 Temple Place,
20 // Suite 330, Boston, MA 02111-1307 USA
21 package edu.umn.gis.mapscript;
22  
23 import edu.umn.gis.mapscript.imp.*;
24  
25 import java.io.*;
26  
27 import java.util.*;
28  
29  
30 /**
31  * DOCUMENT ME!
32  *
33  * @author <a href="mailto:ADDRESS">NAME</a>
34  *
35  * @todo CLASS_DESCRIPTION
36  */
37 public class MapScriptBean
38 {
39   /**
40    * DOCUMENT ME!
41    *
42    * @todo FIELD_DESCRIPTION
43    */
44   private List theResultValues;
45  
46   /**
47    * DOCUMENT ME!
48    *
49    * @todo FIELD_DESCRIPTION
50    */
51   private String imagePath;
52  
53   /**
54    * DOCUMENT ME!
55    *
56    * @todo FIELD_DESCRIPTION
57    */
58   private String map;
59  
60   /**
61    * DOCUMENT ME!
62    *
63    * @todo FIELD_DESCRIPTION
64    */
65   private String mapImage;
66  
67   /**
68    * DOCUMENT ME!
69    *
70    * @todo FIELD_DESCRIPTION
71    */
72   private String mapPath;
73  
74   /**
75    * DOCUMENT ME!
76    *
77    * @todo FIELD_DESCRIPTION
78    */
79   private String referenceImage;
80  
81   /**
82    * DOCUMENT ME!
83    *
84    * @todo FIELD_DESCRIPTION
85    */
86   private String scaleBarImage;
87  
88   /**
89    * DOCUMENT ME!
90    *
91    * @todo FIELD_DESCRIPTION
92    */
93   private layerObj theLayer;
94  
95   /**
96    * DOCUMENT ME!
97    *
98    * @todo FIELD_DESCRIPTION
99    */
100   private mapObj theMap;
101  
102   /**
103    * DOCUMENT ME!
104    *
105    * @todo FIELD_DESCRIPTION
106    */
107   private pointObj thePoint;
108  
109   /**
110    * DOCUMENT ME!
111    *
112    * @todo FIELD_DESCRIPTION
113    */
114   private pointObj theQueryPoint;
115  
116   /**
117    * DOCUMENT ME!
118    *
119    * @todo FIELD_DESCRIPTION
120    */
121   private rectObj theCurrent;
122  
123   /**
124    * DOCUMENT ME!
125    *
126    * @todo FIELD_DESCRIPTION
127    */
128   private rectObj theMaximum;
129  
130   /**
131    * DOCUMENT ME!
132    *
133    * @todo FIELD_DESCRIPTION
134    */
135   private rectObj theQueryRectangle;
136  
137   /**
138    * DOCUMENT ME!
139    *
140    * @todo FIELD_DESCRIPTION
141    */
142   private rectObj theRectangle;
143  
144   /**
145    * Create new MapScriptBean object.
146    */
147   public MapScriptBean()
1480  {
1490    theMap = null;
1500    thePoint = null;
1510    theQueryPoint = null;
1520    theCurrent = null;
1530    theMaximum = null;
1540    theQueryRectangle = null;
1550    theRectangle = null;
1560  }
157  
158   /**
159    * DOCUMENT ME!
160    *
161    * @param minX PARAMETER
162    * @param maxX PARAMETER
163    * @param minY PARAMETER
164    * @param maxY PARAMETER
165    *
166    * @todo METHOD_DESCRIPTION
167    */
168   public void setCurrent(double minX, double maxX, double minY, double maxY)
169   {
1700    freeCurrent();
1710    theCurrent = new rectObj();
1720    theCurrent.setMinx(minX);
1730    theCurrent.setMaxx(maxX);
1740    theCurrent.setMiny(minY);
1750    theCurrent.setMaxy(maxY);
1760  }
177  
178   /**
179    * DOCUMENT ME!
180    *
181    * @return RETURN
182    *
183    * @todo METHOD_DESCRIPTION
184    */
185   public int getHeight()
186   {
1870    return theMap.getHeight();
188   }
189  
190   /**
191    * DOCUMENT ME!
192    *
193    * @param imagePath PARAMETER
194    *
195    * @todo METHOD_DESCRIPTION
196    */
197   public void setImagePath(String imagePath)
198   {
1990    System.out.println("image path=[" + imagePath + "]");
2000    this.imagePath = imagePath;
2010  }
202  
203   /**
204    * DOCUMENT ME!
205    *
206    * @return RETURN
207    *
208    * @todo METHOD_DESCRIPTION
209    */
210   public String getImagePath()
211   {
2120    System.out.println("image path=[" + imagePath + "]");
213  
2140    return imagePath;
215   }
216  
217   /**
218    * DOCUMENT ME!
219    *
220    * @param name PARAMETER
221    *
222    * @return RETURN
223    *
224    * @todo METHOD_DESCRIPTION
225    */
226   public boolean getLayerByName(String name)
227   {
2280    theLayer = theMap.getLayerByName(name);
229  
2300    return theLayer != null;
231   }
232  
233   /**
234    * DOCUMENT ME!
235    *
236    * @param map PARAMETER
237    *
238    * @todo METHOD_DESCRIPTION
239    */
240   public void setMap(String map)
241   {
2420    this.map = map;
2430  }
244  
245   /**
246    * DOCUMENT ME!
247    *
248    * @return RETURN
249    *
250    * @todo METHOD_DESCRIPTION
251    */
252   public String getMap()
253   {
2540    return map;
255   }
256  
257   /**
258    * DOCUMENT ME!
259    *
260    * @param mapImage PARAMETER
261    *
262    * @todo METHOD_DESCRIPTION
263    */
264   public void setMapImage(String mapImage)
265   {
2660    this.mapImage = mapImage;
2670  }
268  
269   /**
270    * DOCUMENT ME!
271    *
272    * @return RETURN
273    *
274    * @todo METHOD_DESCRIPTION
275    */
276   public String getMapImage()
277   {
2780    return mapImage;
279   }
280  
281   /**
282    * DOCUMENT ME!
283    *
284    * @param mapPath PARAMETER
285    *
286    * @todo METHOD_DESCRIPTION
287    */
288   public void setMapPath(String mapPath)
289   {
2900    System.out.println("map path=[" + mapPath + "]");
2910    this.mapPath = mapPath;
2920  }
293  
294   /**
295    * DOCUMENT ME!
296    *
297    * @return RETURN
298    *
299    * @todo METHOD_DESCRIPTION
300    */
301   public String getMapPath()
302   {
3030    System.out.println("map path=[" + mapPath + "]");
304  
3050    return mapPath;
306   }
307  
308   /**
309    * DOCUMENT ME!
310    *
311    * @param maxX PARAMETER
312    *
313    * @todo METHOD_DESCRIPTION
314    */
315   public void setMaxX(double maxX)
316   {
3170    rectObj extent = theMap.getExtent();
3180    extent.setMaxx(maxX);
3190  }
320  
321   /**
322    * DOCUMENT ME!
323    *
324    * @return RETURN
325    *
326    * @todo METHOD_DESCRIPTION
327    */
328   public double getMaxX()
329   {
3300    rectObj extent = theMap.getExtent();
331  
3320    return extent.getMaxx();
333   }
334  
335   /**
336    * DOCUMENT ME!
337    *
338    * @param maxY PARAMETER
339    *
340    * @todo METHOD_DESCRIPTION
341    */
342   public void setMaxY(double maxY)
343   {
3440    rectObj extent = theMap.getExtent();
3450    extent.setMaxy(maxY);
3460  }
347  
348   /**
349    * DOCUMENT ME!
350    *
351    * @return RETURN
352    *
353    * @todo METHOD_DESCRIPTION
354    */
355   public double getMaxY()
356   {
3570    rectObj extent = theMap.getExtent();
358  
3590    return extent.getMaxy();
360   }
361  
362   /**
363    * DOCUMENT ME!
364    *
365    * @param minX PARAMETER
366    * @param maxX PARAMETER
367    * @param minY PARAMETER
368    * @param maxY PARAMETER
369    *
370    * @todo METHOD_DESCRIPTION
371    */
372   public void setMaximum(double minX, double maxX, double minY, double maxY)
373   {
3740    freeMaximum();
3750    theMaximum = new rectObj();
3760    theMaximum.setMinx(minX);
3770    theMaximum.setMaxx(maxX);
3780    theMaximum.setMiny(minY);
3790    theMaximum.setMaxy(maxY);
3800  }
381  
382   /**
383    * DOCUMENT ME!
384    *
385    * @param minX PARAMETER
386    *
387    * @todo METHOD_DESCRIPTION
388    */
389   public void setMinX(double minX)
390   {
3910    rectObj extent = theMap.getExtent();
3920    extent.setMinx(minX);
3930  }
394  
395   /**
396    * DOCUMENT ME!
397    *
398    * @return RETURN
399    *
400    * @todo METHOD_DESCRIPTION
401    */
402   public double getMinX()
403   {
4040    rectObj extent = theMap.getExtent();
405  
4060    return extent.getMinx();
407   }
408  
409   /**
410    * DOCUMENT ME!
411    *
412    * @param minY PARAMETER
413    *
414    * @todo METHOD_DESCRIPTION
415    */
416   public void setMinY(double minY)
417   {
4180    rectObj extent = theMap.getExtent();
4190    extent.setMiny(minY);
4200  }
421  
422   /**
423    * DOCUMENT ME!
424    *
425    * @return RETURN
426    *
427    * @todo METHOD_DESCRIPTION
428    */
429   public double getMinY()
430   {
4310    rectObj extent = theMap.getExtent();
432  
4330    return extent.getMiny();
434   }
435  
436   /**
437    * DOCUMENT ME!
438    *
439    * @param x PARAMETER
440    * @param y PARAMETER
441    *
442    * @todo METHOD_DESCRIPTION
443    */
444   public void setPoint(double x, double y)
445   {
4460    freePoint();
4470    thePoint = new pointObj();
4480    thePoint.setX(x);
4490    thePoint.setY(y);
4500  }
451  
452   /**
453    * DOCUMENT ME!
454    *
455    * @param x PARAMETER
456    * @param y PARAMETER
457    *
458    * @todo METHOD_DESCRIPTION
459    */
460   public void setQueryPoint(double x, double y)
461   {
4620    freeQueryPoint();
4630    theQueryPoint = new pointObj();
4640    theQueryPoint.setX(x);
4650    theQueryPoint.setY(y);
4660  }
467  
468   /**
469    * DOCUMENT ME!
470    *
471    * @param minX PARAMETER
472    * @param maxX PARAMETER
473    * @param minY PARAMETER
474    * @param maxY PARAMETER
475    *
476    * @todo METHOD_DESCRIPTION
477    */
478   public void setQueryRectangle(double minX, double maxX, double minY,
479     double maxY)
480   {
4810    freeQueryRectangle();
4820    theQueryRectangle = new rectObj();
4830    theQueryRectangle.setMinx(minX);
4840    theQueryRectangle.setMaxx(maxX);
4850    theQueryRectangle.setMiny(minY);
4860    theQueryRectangle.setMaxy(maxY);
4870  }
488  
489   /**
490    * DOCUMENT ME!
491    *
492    * @param minX PARAMETER
493    * @param maxX PARAMETER
494    * @param minY PARAMETER
495    * @param maxY PARAMETER
496    *
497    * @todo METHOD_DESCRIPTION
498    */
499   public void setRectangle(double minX, double maxX, double minY, double maxY)
500   {
5010    freeRectangle();
5020    theRectangle = new rectObj();
5030    theRectangle.setMinx(minX);
5040    theRectangle.setMaxx(maxX);
5050    theRectangle.setMiny(minY);
5060    theRectangle.setMaxy(maxY);
5070  }
508  
509   /**
510    * DOCUMENT ME!
511    *
512    * @return RETURN
513    *
514    * @todo METHOD_DESCRIPTION
515    */
516   public String getReferenceImage()
517   {
5180    return referenceImage;
519   }
520  
521   /**
522    * DOCUMENT ME!
523    *
524    * @return RETURN
525    *
526    * @todo METHOD_DESCRIPTION
527    */
528   public List getResultValues()
529   {
5300    System.out.println("result values=[" + theResultValues + "]");
531  
5320    return theResultValues;
533   }
534  
535   /**
536    * DOCUMENT ME!
537    *
538    * @return RETURN
539    *
540    * @todo METHOD_DESCRIPTION
541    */
542   public String getScaleBarImage()
543   {
5440    return scaleBarImage;
545   }
546  
547   /**
548    * DOCUMENT ME!
549    *
550    * @param status PARAMETER
551    *
552    * @todo METHOD_DESCRIPTION
553    */
554   public void setStatus(boolean status)
555   {
5560    if (status)
557     {
5580      theLayer.setStatus(MapScript.MS_ON);
559     }
560     else
561     {
5620      theLayer.setStatus(MapScript.MS_OFF);
563     }
5640  }
565  
566   /**
567    * DOCUMENT ME!
568    *
569    * @return RETURN
570    *
571    * @todo METHOD_DESCRIPTION
572    */
573   public int getWidth()
574   {
5750    return theMap.getWidth();
576   }
577  
578   /**
579    * Utility function to convert a pixel position to geocoded position. The
580    * parameter invert could be set to true for Y pixel coordinates where the
581    * UL &gt; LR. Else set to false.
582    *
583    * @param pix PARAMETER
584    * @param pixMin PARAMETER
585    * @param pixMax PARAMETER
586    * @param geoMin PARAMETER
587    * @param geoMax PARAMETER
588    * @param invert PARAMETER
589    *
590    * @return RETURN
591    */
592   public double convertPixToGeo(int pix, int pixMin, int pixMax, double geoMin,
593     double geoMax, boolean invert)
594   {
5950    if (pix < pixMin)
596     {
5970      return -1D;
598     }
599  
6000    if (pix > pixMax)
601     {
6020      return -1D;
603     }
604  
6050    if ((pixMin >= pixMax) || (geoMin >= geoMax))
606     {
6070      return -1D;
608     }
609  
6100    double widthGeo = geoMax - geoMin;
6110    double widthPix = pixMax - pixMin;
6120    double pixToGeo = widthGeo / widthPix;
613     double deltaPix;
614  
6150    if (invert)
616     {
6170      deltaPix = pixMax - pix;
618     }
619     else
620     {
6210      deltaPix = pix - pixMin;
622     }
623  
6240    double geo = geoMin + (deltaPix * pixToGeo);
625  
6260    return geo;
627   }
628  
629   /**
630    * DOCUMENT ME!
631    *
632    * @todo METHOD_DESCRIPTION
633    */
634   public void doQueryByPoint()
635   {
6360    System.out.println("Doing QueryByPoint ...");
637  
6380    int returnValue = theMap.queryByPoint(theQueryPoint, MapScript.MS_SINGLE,
639         -1D);
6400    System.out.println("returnValue=[" + returnValue + "]");
6410    System.out.println("QueryByPoint done.");
6420  }
643  
644   /**
645    * DOCUMENT ME!
646    *
647    * @todo METHOD_DESCRIPTION
648    */
649   public void doQueryByRectangle()
650   {
6510    System.out.println("Doing QueryByRectangle ...");
652  
6530    int returnValue = theMap.queryByRect(theQueryRectangle);
6540    System.out.println("returnValue=[" + returnValue + "]");
6550    System.out.println("QueryByRectangle done.");
6560  }
657  
658   /**
659    * DOCUMENT ME!
660    *
661    * @todo METHOD_DESCRIPTION
662    */
663   public void draw()
664   {
6650    draw(false);
6660  }
667  
668   /**
669    * DOCUMENT ME!
670    *
671    * @todo METHOD_DESCRIPTION
672    */
673   public void drawQuery()
674   {
6750    draw(true);
676  
6770    int numberLayers = theMap.getNumlayers();
6780    List resultValues = new ArrayList();
679  
6800    for (int i = 0; i < numberLayers; i++)
681     {
6820      layerObj layer = theMap.getLayer(i);
6830      resultCacheObj resultCache = layer.getResultcache();
684  
6850      if (resultCache != null)
686       {
6870        int numberResults = resultCache.getNumresults();
688  
6890        if (numberResults != 0)
690         {
6910          layer.open(theMap.getShapepath());
692  
6930          for (int j = 0; j < numberResults; j++)
694           {
6950            resultCacheMemberObj resultCacheMember = layer.getResult(j);
696  
6970            if (resultCacheMember != null)
698             {
6990              shapeObj shape = layer.getShape(resultCacheMember.getTileindex(),
700                   resultCacheMember.getShapeindex());
701  
7020              if (shape != null)
703               {
7040                int numberValues = shape.getNumvalues();
705  
7060                for (int k = 0; k < numberValues; k++)
707                 {
7080                  String value = shape.getValue(k);
7090                  resultValues.add(value);
710                 }
711  
7120                shape.delete();
713               }
714             }
715           }
716  
7170          layer.close();
718         }
719       }
720     }
721  
7220    theResultValues = resultValues;
7230  }
724  
725   /**
726    * DOCUMENT ME!
727    *
728    * @todo METHOD_DESCRIPTION
729    */
730   public void freeCurrent()
731   {
7320    if (theCurrent != null)
733     {
7340      System.out.println("Freeing Current ...");
7350      theCurrent.delete();
7360      System.out.println("Current freed.");
7370      theCurrent = null;
738     }
739     else
740     {
7410      System.out.println("Current already freed.");
742     }
7430  }
744  
745   /**
746    * DOCUMENT ME!
747    *
748    * @todo METHOD_DESCRIPTION
749    */
750   public void freeMap()
751   {
7520    if (theMap != null)
753     {
7540      System.out.println("Freeing map ...");
7550      theMap.delete();
7560      System.out.println("Map freed.");
7570      theMap = null;
758     }
759     else
760     {
7610      System.out.println("Map already freed.");
762     }
7630  }
764  
765   /**
766    * DOCUMENT ME!
767    *
768    * @todo METHOD_DESCRIPTION
769    */
770   public void freeMaximum()
771   {
7720    if (theMaximum != null)
773     {
7740      System.out.println("Freeing Maximum ...");
7750      theMaximum.delete();
7760      System.out.println("Maximum freed.");
7770      theMaximum = null;
778     }
779     else
780     {
7810      System.out.println("Maximum already freed.");
782     }
7830  }
784  
785   /**
786    * DOCUMENT ME!
787    *
788    * @todo METHOD_DESCRIPTION
789    */
790   public void freePoint()
791   {
7920    if (thePoint != null)
793     {
7940      System.out.println("Freeing Point ...");
7950      thePoint.delete();
7960      System.out.println("Point freed.");
7970      thePoint = null;
798     }
799     else
800     {
8010      System.out.println("Point already freed.");
802     }
8030  }
804  
805   /**
806    * DOCUMENT ME!
807    *
808    * @todo METHOD_DESCRIPTION
809    */
810   public void freeQueryPoint()
811   {
8120    if (theQueryPoint != null)
813     {
8140      System.out.println("Freeing Query Point ...");
8150      theQueryPoint.delete();
8160      System.out.println("Query Point freed.");
8170      theQueryPoint = null;
818     }
819     else
820     {
8210      System.out.println("Query Point already freed.");
822     }
8230  }
824  
825   /**
826    * DOCUMENT ME!
827    *
828    * @todo METHOD_DESCRIPTION
829    */
830   public void freeQueryRectangle()
831   {
8320    if (theQueryRectangle != null)
833     {
8340      System.out.println("Freeing Query Rectangle ...");
8350      theQueryRectangle.delete();
8360      System.out.println("Query Rectangle freed.");
8370      theQueryRectangle = null;
838     }
839     else
840     {
8410      System.out.println("Query Rectangle already freed.");
842     }
8430  }
844  
845   /**
846    * DOCUMENT ME!
847    *
848    * @todo METHOD_DESCRIPTION
849    */
850   public void freeRectangle()
851   {
8520    if (theRectangle != null)
853     {
8540      System.out.println("Freeing Rectangle ...");
8550      theRectangle.delete();
8560      System.out.println("Rectangle freed.");
8570      theRectangle = null;
858     }
859     else
860     {
8610      System.out.println("Rectangle already freed.");
862     }
8630  }
864  
865   /**
866    * DOCUMENT ME!
867    *
868    * @todo METHOD_DESCRIPTION
869    */
870   public void load()
871   {
8720    String mapFile = mapPath + map;
8730    System.out.println("Loading map=[" + mapFile + "] ...");
8740    theMap = new mapObj(mapFile);
8750    System.out.println("map=[" + mapFile + "] loaded.");
8760  }
877  
878   /**
879    * DOCUMENT ME!
880    *
881    * @param factor PARAMETER
882    *
883    * @todo METHOD_DESCRIPTION
884    */
885   public void zoomPoint(int factor)
886   {
8870    theMap.zoomPoint(factor, thePoint, theMap.getWidth(), theMap.getHeight(),
888       theCurrent, theMaximum);
8890  }
890  
891   /**
892    * DOCUMENT ME!
893    *
894    * @todo METHOD_DESCRIPTION
895    */
896   public void zoomRectangle()
897   {
8980    theMap.zoomRectangle(theRectangle, theMap.getWidth(), theMap.getHeight(),
899       theCurrent, theMaximum);
9000  }
901  
902   /**
903    * DOCUMENT ME!
904    *
905    * @param doQuery PARAMETER
906    *
907    * @todo METHOD_DESCRIPTION
908    */
909   private void draw(boolean doQuery)
910   {
9110    imageObj theImage = null;
912  
9130    if (doQuery)
914     {
9150      System.out.println("Drawing map (and doing query) ...");
9160      theImage = theMap.drawQuery();
9170      System.out.println("Map drawn (and did query).");
918     }
919     else
920     {
9210      System.out.println("Drawing map ...");
9220      theImage = theMap.draw();
9230      System.out.println("Map drawn.");
924     }
925  
9260    System.out.println("Saving image ...");
927  
9280    String timeStamp = (new Long((new Date()).getTime())).toString();
9290    String mapImage = timeStamp + "m.png";
9300    int returnValue = theImage.saveImage(imagePath + mapImage,
931         MapScript.MS_PNG, 0, 0, 95);
9320    System.out.println("map path=[" + imagePath + mapImage + "]");
9330    System.out.println("returnValue=[" + returnValue + "]");
9340    System.out.println("map image=[" + mapImage + "] saved.");
9350    System.out.println("Freeing image ...");
9360    theImage.delete();
9370    System.out.println("Image freed.");
9380    this.mapImage = mapImage;
9390    System.out.println("Drawing ScaleBar ...");
940  
9410    imageObj theScalebarImage = theMap.drawScalebar();
9420    System.out.println("ScaleBar drawn.");
9430    System.out.println("Saving ScaleBar image ...");
9440    timeStamp = (new Long((new Date()).getTime())).toString();
945  
9460    String scaleBarImage = timeStamp + "sb.png";
9470    returnValue = theScalebarImage.saveImage(imagePath + scaleBarImage,
948         MapScript.MS_PNG, 0, 0, 95);
9490    System.out.println("ScaleBar path=[" + imagePath + scaleBarImage + "]");
9500    System.out.println("returnValue=[" + returnValue + "]");
9510    System.out.println("ScaleBar image=[" + scaleBarImage + "] saved.");
9520    System.out.println("Freeing ScaleBar image ...");
9530    theScalebarImage.delete();
9540    System.out.println("ScaleBar image freed.");
9550    this.scaleBarImage = scaleBarImage;
9560  }
957 }

this report was generated by version 1.0.2 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.