小秋的家

          home

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            1 Posts :: 91 Stories :: 17 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(9)

          我參與的團隊

          搜索

          •  

          最新評論

          public class RectSelectAction extends Action {

              
          // --------------------------------------------------------- Instance
              
          // Variables

              
          // --------------------------------------------------------- Methods

              
          /**
               * Method execute
               * 
               * 
          @param mapping
               * 
          @param form
               * 
          @param request
               * 
          @param response
               * 
          @return ActionForward
               
          */

              
          public ActionForward execute(ActionMapping mapping, ActionForm form,
                      HttpServletRequest request, HttpServletResponse response) 
          {
                  DynaActionForm rectSelectForm 
          = (DynaActionForm) form;
                  String startx 
          = rectSelectForm.getString("startx");
                  String starty 
          = rectSelectForm.getString("starty");
                  String endx 
          = rectSelectForm.getString("endx");
                  String endy 
          = rectSelectForm.getString("endy");
                  Map map 
          = (Map) request.getSession().getAttribute("THEMAP");
                  Polygon polygon 
          = this.creatPolygon(map, startx, starty, endx, endy);
                  
          if (polygon == null{
                      ActionMessages msgs 
          = new ActionMessages();
                      msgs.add(ActionMessages.GLOBAL_MESSAGE, 
          new ActionMessage(
                              
          "com.suzhou.message.createPolygonFail"));
                      
          this.saveMessages(request, msgs);
                      
          return mapping.findForward("resultPage");
                  }

                  FeatureLayer menpaiLayer 
          = null;
                  
          for (int i = 0; i < map.getLayers().getCount(); i++{
                      
          if (map.getLayers().item(i).getName().equals("地物點")) {
                          menpaiLayer 
          = (FeatureLayer) map.getLayers().item(i);
                          System.out.println(menpaiLayer.getName());
                          System.out.println(menpaiLayer.getID());
                      }

                  }

                  
          if (menpaiLayer == null{
                      ActionMessages msgs 
          = new ActionMessages();
                      msgs.add(ActionMessages.GLOBAL_MESSAGE, 
          new ActionMessage(
                              
          "com.suzhou.message.layerNotExsist""地物點"));
                      
          this.saveMessages(request, msgs);
                      
          return mapping.findForward("resultPage");
                  }

                  map.getLayers().setGeometry(
          true);// 設置返回空間信息
                  menpaiLayer.getRecordset().clearRecordset();
                  menpaiLayer.getRecordset().clearEnvelope();
                  menpaiLayer.getRecordset().clearGeometry();
                  map.getLayers().setOrder(
          false);
                  menpaiLayer.setFilterObject(
          null);
                  Filter filter2 
          = new Filter();
          //        filter2.addSubField("BLOCKNAME");
          //        filter2.addSubField("MPNUM");
          //        filter2.addSubField("MPABNAME");
          //        filter2.addSubField("MPSUBNUM");
                  
          //filter2.setWhereExpression("");
                  filter2.setGlobalEnvelope(true);
                  filter2.setSpatialShape(polygon);
                  filter2.setRelation(Filter.AREA_INTERSECTION);
                  menpaiLayer.setFilterObject(filter2);
                  map.refresh();
                  menpaiLayer.setFilterObject(
          null);
                  
          if (menpaiLayer.getRecordset() == null
                          
          || menpaiLayer.getRecordset().getCount() < 1{
                      ActionMessages msgs 
          = new ActionMessages();
                      msgs.add(ActionMessages.GLOBAL_MESSAGE, 
          new ActionMessage(
                              
          "com.suzhou.message.objectNotFound"));
                      
          this.saveMessages(request, msgs);
                      
          return mapping.findForward("resultPage");
                  }
          else{
                      request.setAttribute(
          "result",menpaiLayer.getRecordset());
                      
          return mapping.findForward("resultPage");
                  }

              }


              
          /**
               * 建立矩形
               * 
               * 
          @param map
               * 
          @param startx:起點屏幕X坐標
               * 
          @param starty:起點屏幕Y坐標
               * 
          @param endx:終點屏幕X坐標
               * 
          @param endy:終點屏幕Y坐標
               * 
          @return
               
          */

              
          public Polygon creatPolygon(Map map, String startx, String starty,
                      String endx, String endy) 
          {
                  
          try {
                      Point pnt1 
          = map.toMapPoint(new Double(startx).doubleValue(),
                              
          new Double(starty).doubleValue());
                      Point pnt2 
          = map.toMapPoint(new Double(endx).doubleValue(),
                              
          new Double(endy).doubleValue());
                      Point pnt11 
          = new Point();
                      Point pnt22 
          = new Point();
                      pnt11.setX(pnt1.getX());
                      pnt11.setY(pnt2.getY());
                      pnt22.setX(pnt2.getX());
                      pnt22.setY(pnt1.getY());
                      Points points 
          = new Points();
                      points.addPointObject(pnt1);
                      points.addPointObject(pnt11);
                      points.addPointObject(pnt2);
                      points.addPointObject(pnt22);
                      Ring ring 
          = new Ring();
                      ring.setPoints(points);
                      Polygon polygon 
          = new Polygon();
                      polygon.addRing(ring);
                      
          return polygon;
                  }
           catch (Exception ex) {
                      
          return null;
                  }

              }

          }

          posted on 2008-06-03 15:30 棋劍小秋 閱讀(365) 評論(0)  編輯  收藏 所屬分類: GIS
          主站蜘蛛池模板: 司法| 固安县| 安乡县| 道孚县| 石城县| 大渡口区| 焦作市| 峨山| 炎陵县| 正定县| 蚌埠市| 闵行区| 关岭| 峨山| 衢州市| 南和县| 西乌| 岳池县| 湄潭县| 如皋市| 泰兴市| 青浦区| 白山市| 兴义市| 三门峡市| 昌黎县| 廉江市| 五河县| 普兰县| 宁陵县| 达孜县| 栖霞市| 白水县| 衢州市| 英德市| 博白县| 遵义市| 元朗区| 合水县| 谢通门县| 梨树县|