posts - 119, comments - 62, trackbacks - 0, articles - 0

arcIMS如何实现多边形选择

Posted on 2007-03-20 17:16 Kevin Meng 阅读(384) 评论(1)  编辑  收藏
下面是矩形选择的源代码。多边形选择多加点就可以了。
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;
        }

    }

}

Feedback

# re: arcIMS如何实现多边形选择  回复  更多评论   

2008-09-10 11:21 by onejavaer
请问一下 您是使用ArcIMS WebADF结合Strtus进行开发的吗?
我开发WebGIS一直使用ArcIMS的HtmlViewer模式了 没有尝试使用ADF 有些不清楚的地方请您指点一下 谢谢

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


网站导航: