小秋的家

home

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

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 棋剑小秋 阅读(355) 评论(0)  编辑  收藏 所属分类: GIS

只有注册用户登录后才能发表评论。


网站导航: