⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createtop.java

📁 JAVA+MO(for JAVA)开发的基于遗传算法的最短路径源代码
💻 JAVA
字号:
package BestRoadGA;
import com.esri.mo2.ui.bean.Map;
import com.esri.mo2.data.feat.MapDataset;
import com.esri.mo2.data.feat.BaseQueryFilter;
import com.esri.mo2.data.feat.Cursor;
import com.esri.mo2.file.shp.ShapefileFeature;

import java.util.ArrayList;
import com.esri.mo2.cs.geom.Polyline;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JOptionPane;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2005-8-9
 * Time: 17:03:18
 * To change this template use File | Settings | File Templates.
 */
public class createTop
{
    public createTop() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private boolean adjacencyTable[][]; //存储点与线的邻接表关系,如果线中包含点,则值为1;不包含,为0。
                                        //数组第一个下标表示点的位置,第二个下标表示线的位置。
    Map map1=new Map();
    com.esri.mo2.map.dpy.FeatureLayer flayer1=null;

    private ArrayList node=new ArrayList();
    private ArrayList pointCoord=new ArrayList();
    private LineBean rLine[];
    private int pointID[];
    private com.esri.mo2.cs.geom.Point pointCoordinate[];
    private com.esri.mo2.cs.geom.Point startPCoord[];
    private com.esri.mo2.cs.geom.Point endPCoord[];


    private int pNum=0;     //存储网络图中点集的个数
    private int lNum=0;     //存储网络图中线集的个数

    public boolean[][] getAdjacencyTable()
    {
        return adjacencyTable;
    }

    public LineBean[] getLine()
    {
        return rLine;
    }

    public ArrayList getPointIdList() {
        return node;
    }

    public int[] getPointID()
    {
        return pointID;
    }

    public com.esri.mo2.cs.geom.Point[] getPointCoord()
    {
        return pointCoordinate;
    }

    public int getPointNum()
    {
        return pNum;
    }

    public int getLineNum()
    {
        return lNum;
    }

    public createTop(Map map,com.esri.mo2.map.dpy.FeatureLayer flayer)
    //构造函数
    {
        readLayerData(map,flayer);      //获取线集rLine[]
        createNode(rLine);       //获取结点集node
        createPointIDAndCoord();      //获取点集pointID[]
        createAdjacencyTable(rLine);     //创建邻接表,保存在全局数组变量adjacencyTable[][]中
    }

    private void readLayerData (Map map,com.esri.mo2.map.dpy.FeatureLayer flayer)
    //读取线状地物shape文件的数据,并且返回自定义类的线数组
    {
        map1=map;
        flayer1=flayer;
        try
        {
            MapDataset dataset1=flayer.getDataset();
            ShapefileFeature sfFeature = null;
            BaseQueryFilter bFilter = new BaseQueryFilter();
            Cursor cursor=dataset1.search(bFilter);
            while(cursor != null && cursor.hasMore())
            {
                cursor.next();
                lNum++;
            }
            cursor=dataset1.search(bFilter);
            rLine=new LineBean[lNum];
            startPCoord = new com.esri.mo2.cs.geom.Point[lNum];
            endPCoord = new com.esri.mo2.cs.geom.Point[lNum];
            for(int i=0;i<lNum;i++)
            {
                rLine[i]=new LineBean();
                sfFeature = (ShapefileFeature)cursor.next();
                Polyline pline=(Polyline)sfFeature.getGeometry();
                if(pline.size()>0)
                {
                    startPCoord[i]=new com.esri.mo2.cs.geom.Point();
                    startPCoord[i]=pline.getPath(0).getStartPoint();

                    endPCoord[i] = new com.esri.mo2.cs.geom.Point();
                    endPCoord[i] = pline.getPath(pline.size() - 1).getEndPoint();
                }
                else
                {
                    JLabel lblMessage = new JLabel("路段数据为空,拓扑关系建立错误!请检查数据!");
                    lblMessage.setFont(new Font("宋体", Font.BOLD, 16));
                    JOptionPane.showMessageDialog(null, lblMessage, "提示:",JOptionPane.DEFAULT_OPTION);
                }
                rLine[i].id=sfFeature.getDataID().getID();         //给线的ID赋值
                rLine[i].startNode=Integer.parseInt(sfFeature.getValue(1).toString()); //获取字段FNODE_的值
                rLine[i].endNode=Integer.parseInt(sfFeature.getValue(2).toString()); //获取字段TNODE_的值
                rLine[i].weight=Double.parseDouble(sfFeature.getValue(3).toString()); //获取字段LENGTH的值
                rLine[i].name=sfFeature.getValue(5).toString(); //获取字段LM的值
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    private void createNode(LineBean line[])
    //定义拓扑返回拓扑定义后所得到的NODE节点集,保存ArrayList类型的全局变量:node中
    {
        int n=line.length;
        int startPoint,endPoint;
        startPoint=line[0].startNode;
        endPoint=line[0].endNode;
        line[0].startIndex=0;
        line[0].endIndex=1;
        node.add(new Integer(startPoint));
        node.add(new Integer(endPoint));
        pointCoord.add(new com.esri.mo2.cs.geom.Point(startPCoord[0]));
        pointCoord.add(new com.esri.mo2.cs.geom.Point(endPCoord[0]));
        for(int i=1;i<n;i++)
        {
            int index;
            startPoint=line[i].startNode;
            endPoint=line[i].endNode;

            if(!node.contains(new Integer(startPoint)))
            {
                index=node.size();
                line[i].startIndex=index;
                node.add(new Integer(startPoint));
                pointCoord.add(new com.esri.mo2.cs.geom.Point(startPCoord[i]));
            }
            else
            {
                index=node.indexOf(new Integer(startPoint));
                line[i].startIndex=index;
            }
            if(!node.contains(new Integer(endPoint)))
            {
                index=node.size();
                line[i].endIndex=index;
                node.add(new Integer(endPoint));
                pointCoord.add(new com.esri.mo2.cs.geom.Point(endPCoord[i]));
            }
            else
            {
                index=node.indexOf(new Integer(endPoint));
                line[i].endIndex=index;
            }
        }
    }

    private void createPointIDAndCoord()
    {
        pNum=node.size();
        pointCoordinate=new com.esri.mo2.cs.geom.Point[pNum];

        pointID=new int[pNum];
        for(int i=0;i<pNum;i++)
        {
            pointID[i]=Integer.parseInt(node.get(i).toString());
           // startPCoord[i]=new com.esri.mo2.cs.geom.Point();
            pointCoordinate[i]=(com.esri.mo2.cs.geom.Point)pointCoord.get(i);
        }
    }

    private void createAdjacencyTable(LineBean rline[])
    //创建邻接关系表
    {
        int pIndex1,pIndex2;
        int rNum=rline.length;
        adjacencyTable=new boolean[pNum][rNum];
        for(int i=0;i<pNum;i++)
            for(int j=0;j<rNum;j++)
            {
                adjacencyTable[i][j]=false;
            }
        for(int i=0;i<rNum;i++)
        {
            pIndex1=rline[i].startIndex;
            pIndex2=rline[i].endIndex;
            adjacencyTable[pIndex1][i]=true;
            adjacencyTable[pIndex2][i]=true;
        }
    }

    private void jbInit() throws Exception {
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -