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

📄 geointersectionlayer.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (fileDataList.size() == 0) {            JLabel label = new JLabel("No Shape Files Loaded", JButton.CENTER);            c.anchor = GridBagConstraints.CENTER;            gridbag.setConstraints(label, c);            p.add(label);        }        c.fill = GridBagConstraints.BOTH;        c.weighty = 1;        JLabel filler = new JLabel("");        gridbag.setConstraints(filler, c);        p.add(filler);        p.revalidate();    }    JPanel fileListControl;    JPanel panel = null;    JCheckBox showCrossingsButton;    JCheckBox pointCheckButton;    public Component getGUI() {        if (panel == null) {            panel = new JPanel();            GridBagLayout gridbag = new GridBagLayout();            GridBagConstraints c = new GridBagConstraints();            panel.setLayout(gridbag);            c.gridx = GridBagConstraints.REMAINDER;            c.weightx = 1.0;            c.insets = new Insets(1, 5, 1, 5);            c.fill = GridBagConstraints.HORIZONTAL;            JPanel daPanel1 = PaletteHelper.createHorizontalPanel("Paint Settings for Shapes");            daPanel1.add(shapeDA.getGUI());            JPanel daPanel2 = PaletteHelper.createHorizontalPanel("Paint Settings for Intersected Shapes");            daPanel2.add(shapeDASelected.getGUI());            gridbag.setConstraints(daPanel1, c);            gridbag.setConstraints(daPanel2, c);            panel.add(daPanel1);            panel.add(daPanel2);            c.weighty = 1.0;            c.fill = GridBagConstraints.BOTH;            JPanel tablePanel = getFileListControl();            gridbag.setConstraints(tablePanel, c);            panel.add(tablePanel);            JPanel checkPanel = new JPanel();            GridBagLayout gb = new GridBagLayout();            checkPanel.setLayout(gb);            GridBagConstraints c2 = new GridBagConstraints();            c2.anchor = GridBagConstraints.WEST;            c2.gridx = GridBagConstraints.REMAINDER;            showCrossingsButton = new JCheckBox("Show Crossing Points", showCrossingPoints);            showCrossingsButton.setToolTipText("<html>Show ordered points where drawn lines cross Shapes.");            showCrossingsButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent ae) {                    setShowCrossingPoints(((JCheckBox) ae.getSource()).isSelected());                    doPrepare();                }            });            gb.setConstraints(showCrossingsButton, c2);            checkPanel.add(showCrossingsButton);            pointCheckButton = new JCheckBox("Click Creates Image Mask", showCrossingPoints);            pointCheckButton.setToolTipText("<html>When clicking on Shape, create image mask that shows Geo point<br>intersection vs. Java 2D. Green is good.");            pointCheckButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent ae) {                    setCreatePointCheck(((JCheckBox) ae.getSource()).isSelected());                    doPrepare();                }            });            gb.setConstraints(pointCheckButton, c2);            checkPanel.add(pointCheckButton);            c.weightx = 0;            c.weighty = 0;            c.fill = GridBagConstraints.NONE;            gridbag.setConstraints(checkPanel, c);            panel.add(checkPanel);            JButton addButton = new JButton("Add Shape File...");            addButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent ae) {                    addShapeFileFromUser();                }            });            c.insets = new Insets(5, 5, 5, 5);            gridbag.setConstraints(addButton, c);            panel.add(addButton);        }        return panel;    }    public static class OMPolyRegion extends GeoRegion.Impl {        public OMPoly poly;        public OMPolyRegion(OMPoly omp) {            super(omp.getLatLonArray(), false);            poly = omp;        }        public Object getID() {            return GeoIntersectionLayer.OMPolyRegion.this;        }    }    public static class OMLineSegment implements GeoSegment {        Geo[] geos;        float[] segArray;        public OMLineSegment(OMLine oml) {            segArray = oml.getLL();            geos = new Geo[2];            geos[0] = new Geo(segArray[0], segArray[1]);            geos[1] = new Geo(segArray[2], segArray[3]);        }        /*         * (non-Javadoc)         *          * @see com.bbn.openmap.geo.GeoSegment#getSeg()         */        public Geo[] getSeg() {            return geos;        }        /*         * (non-Javadoc)         *          * @see com.bbn.openmap.geo.GeoSegment#getSegArray()         */        public float[] getSegArray() {            return segArray;        }        /*         * (non-Javadoc)         *          * @see com.bbn.openmap.geo.GeoExtent#getID()         */        public Object getID() {            return this;        }        public BoundingCircle getBoundingCircle() {            return new BoundingCircle.Impl(getSeg());        }    }    protected class RemoveShapesActionListener implements ActionListener {        protected OMGraphicList mainDataList;        protected OMGraphicList toBeRemoved;        public RemoveShapesActionListener(OMGraphicList mdl, OMGraphicList tbr) {            mainDataList = mdl;            toBeRemoved = tbr;        }        public void actionPerformed(ActionEvent ae) {            mainDataList.remove(toBeRemoved);            rebuildFileListControl();            GeoIntersectionLayer.this.doPrepare();        }    }    public boolean isShowCrossingPoints() {        return showCrossingPoints;    }    public void setShowCrossingPoints(boolean showCrossingPoints) {        this.showCrossingPoints = showCrossingPoints;    }    public void propertyChange(PropertyChangeEvent evt) {        shapeDA.setTo(fileDataList);        repaint();    }    public DrawingAttributes getShapeDA() {        return shapeDA;    }    public void setShapeDA(DrawingAttributes shapeDA) {        this.shapeDA = shapeDA;    }    public DrawingAttributes getShapeDASelected() {        return shapeDASelected;    }    public void setShapeDASelected(DrawingAttributes shapeDASelected) {        this.shapeDASelected = shapeDASelected;    }    public boolean isCreatePointCheck() {        return createPointCheck;    }    public void setCreatePointCheck(boolean createPointCheck) {        this.createPointCheck = createPointCheck;    }        public void runGeoTests(int numIterations, int numToSkipAtStart) {        Projection proj = new Mercator(new LatLonPoint(35f, -90f), 100000000, 800, 800);        double[] results = new double[7];        for (int i = 0; i < numIterations; i++) {            boolean countThisIteration = (i >= numToSkipAtStart);            long startTime = System.currentTimeMillis();            setProjection(proj.makeClone());            calculateIntersectionsWithDrawnList();            long endTime = System.currentTimeMillis();            if (countThisIteration) {                results[0] += endTime - startTime;            }            OMGraphic omg = new OMLine(20f, -125f, 30f, -70f, OMGraphic.LINETYPE_GREATCIRCLE);            getDrawnIntersectorList().add(omg);            startTime = System.currentTimeMillis();            calculateIntersectionsWithDrawnList();            endTime = System.currentTimeMillis();            if (countThisIteration) {                results[1] += endTime - startTime;            }            setShowCrossingPoints(true);            startTime = System.currentTimeMillis();            calculateIntersectionsWithDrawnList();            endTime = System.currentTimeMillis();            if (countThisIteration) {                results[2] += endTime - startTime;            }            getDrawnIntersectorList().clear();            setShowCrossingPoints(false);            float[] coords = new float[] { 33.4f, -77.2f, 34f, -79.5f, 35f,                    -90f, 40f, -100f, 45f, -101f, 50f, -83.2f, 35f, -65.7f,                    -34f, -70.5f, 33.4f, -77.2f };            omg = new OMPoly(coords, OMPoly.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE);            getDrawnIntersectorList().add(omg);            startTime = System.currentTimeMillis();            calculateIntersectionsWithDrawnList();            endTime = System.currentTimeMillis();            if (countThisIteration) {                results[3] += endTime - startTime;            }            setShowCrossingPoints(true);            startTime = System.currentTimeMillis();            calculateIntersectionsWithDrawnList();            endTime = System.currentTimeMillis();            if (countThisIteration) {                results[4] += endTime - startTime;            }            omg.setFillPaint(Color.red);            setShowCrossingPoints(false);            startTime = System.currentTimeMillis();            calculateIntersectionsWithDrawnList();            endTime = System.currentTimeMillis();            if (countThisIteration) {                results[5] += endTime - startTime;            }            setShowCrossingPoints(true);            startTime = System.currentTimeMillis();            calculateIntersectionsWithDrawnList();            endTime = System.currentTimeMillis();            if (countThisIteration) {                results[6] += endTime - startTime;            }            System.out.print(".");            System.out.flush();                    }        double numIterationsCounted = numIterations - numToSkipAtStart;        Debug.output("For " + numIterationsCounted + " iterations");        Debug.output(" avg time to calculate without Intersection: "                + (results[0] / numIterationsCounted) + " ms");        Debug.output(" avg time to calculate with Intersection line: "                + (results[1] / numIterationsCounted) + " ms");        Debug.output(" avg time to calculate with Intersection line with crossing points: "                + (results[2] / numIterationsCounted) + " ms");        Debug.output(" avg time to calculate with Intersection poly: "                + (results[3] / numIterationsCounted) + " ms");        Debug.output(" avg time to calculate with Intersection poly with crossing points: "                + (results[4] / numIterationsCounted) + " ms");        Debug.output(" avg time to calculate with Intersection Containment poly: "                + (results[5] / numIterationsCounted) + " ms");        Debug.output(" avg time to calculate with Intersection Containment poly and crossing points: "                + (results[6] / numIterationsCounted) + " ms");    }    public static void main(String[] argv) {        Debug.init();        ArgParser argp = new ArgParser("GeoIntersectionLayer");        argp.add("shape", "Shape file to use for GeoRegions in index.", 1);        argp.parse(argv);        String[] files = argp.getArgValues("shape");        if (files != null && files.length > 0 && files[0].endsWith(".shp")) {            File file = new File(files[0]);            GeoIntersectionLayer gil = new GeoIntersectionLayer();            Debug.output("Loading shape file: " + file.getName());            long startTime = System.currentTimeMillis();            gil.addShapeFile(file);            long endTime = System.currentTimeMillis();            Debug.output(" time to load file: " + (endTime - startTime) + " ms");            gil.runGeoTests(25, 3);                    } else {            argp.printUsage();            System.exit(0);        }    }}

⌨️ 快捷键说明

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