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

📄 geointersectionlayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************////<copyright>////BBN Technologies, a Verizon Company//10 Moulton Street//Cambridge, MA 02138//(617) 873-8000////Copyright (C) BBNT Solutions LLC. All rights reserved.////</copyright>//**********************************************************************////$Source:///cvs/darwars/ambush/aar/src/com/bbn/ambush/mission/MissionHandler.java,v//$//$RCSfile: GeoIntersectionLayer.java,v $//$Revision: 1.1.2.1 $//$Date: 2005/08/09 21:17:55 $//$Author: dietrick $////**********************************************************************package com.bbn.openmap.layer.test;import java.awt.Color;import java.awt.Component;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.Rectangle;import java.awt.Shape;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.File;import java.net.MalformedURLException;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.filechooser.FileFilter;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.dataAccess.shape.DbfTableModel;import com.bbn.openmap.dataAccess.shape.EsriGraphicList;import com.bbn.openmap.event.MapMouseEvent;import com.bbn.openmap.geo.BoundaryCrossing;import com.bbn.openmap.geo.BoundingCircle;import com.bbn.openmap.geo.ExtentIndex;import com.bbn.openmap.geo.ExtentIndexImpl;import com.bbn.openmap.geo.Geo;import com.bbn.openmap.geo.GeoPath;import com.bbn.openmap.geo.GeoPoint;import com.bbn.openmap.geo.GeoRegion;import com.bbn.openmap.geo.GeoSegment;import com.bbn.openmap.geo.Intersection;import com.bbn.openmap.layer.editor.EditorLayer;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.OMAction;import com.bbn.openmap.omGraphics.OMColor;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMLine;import com.bbn.openmap.omGraphics.OMPoint;import com.bbn.openmap.omGraphics.OMPoly;import com.bbn.openmap.omGraphics.OMRaster;import com.bbn.openmap.omGraphics.OMTextLabeler;import com.bbn.openmap.omGraphics.SinkGraphic;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.FileUtils;import com.bbn.openmap.util.PaletteHelper;import com.bbn.openmap.util.PropUtils;/** * This layer demonstrates the use of the com.bbn.openmap.geo package * to do intersection calculations in lat/lon space. It allows you to * load shape files for sample data sets, and then draw lines, * polygons and points on the map to as test cases for intersections * on the sample data sets. The ToolPanel will hold controls for * choosing what kind of things to draw, and how they should be * rendered. The palette for this layer controls the sample data sets, * letting you add and remove data files and change their colors. * <P> *  * If you draw a line, polyline or point, the shapes in the data sets * that intersect with them will be rendered in the 'select' colors. * If you draw a closed polygon with a fill color, the data set shapes * inside the polygon will also be selected. The palette has controls * for showing the actual points of intersection for paths and their * sample data regions. There is also an option to allow mouse clicks * on a data set region to create an image over the bounding rectangle * for that region, checking the Geo point intersection algorithm * against the Java 2D algorithm for the shape in projected pixel * space. An all-green image is good, pixels where the algorithms * differ will be red. * <P> *  * The properties for this layer are: *  * <pre> *   geo.class=com.bbn.openmap.layer.test.GeoIntersectionLayer *   geo.prettyName=GEO Intersections *   geo.editor=com.bbn.openmap.layer.editor.DrawingEditorTool *   geo.showAttributes=true *   geo.loaders=lines polys points *   geo.mouseModes=Gestures *   geo.lines.class=com.bbn.openmap.tools.drawing.OMLineLoader *   geo.polys.class=com.bbn.openmap.tools.drawing.OMPolyLoader *   geo.points.class=com.bbn.openmap.tools.drawing.OMPointLoader *   geo.shapeFileList=geocounties geolakes geocountries *   geo.geocounties=/data/shape/usa/counties.shp *   geo.geolakes=/data/shape/world/lakes.shp *   geo.geocountries=/data/shape/world/cntry02/cntry02.shp *   # Colors for regular, unselected data shapes *   geo.fillColor=FF333399 *   geo.selectColor=ffff9900 *   geo.mattingColor=ffff9900 *   # Colors for data shapes intersected by drawn shapes *   geo.selected.fillColor=FFFFFF00 *   geo.selected.selectColor=ffff9900 *   geo.selected.mattingColor=ffff9900 * </pre> *  * @author dietrick */public class GeoIntersectionLayer extends EditorLayer implements        PropertyChangeListener {    /** This list holds the OMGraphics that have been drawn. */    protected OMGraphicList drawnList = new OMGraphicList();    /** This list holds the EsriGraphicLists from the Shape files. */    protected OMGraphicList fileDataList = new OMGraphicList();    /**     * This list holds the BoundaryCrossings and the image masks     * created from Intersection queries.     */    protected OMGraphicList intersectionResultList = new OMGraphicList();    /** The RegionIndex organizing the Shape OMGraphics for searching. */    protected ExtentIndexImpl regionIndex = null;    protected DrawingAttributes shapeDA = new DrawingAttributes();    protected DrawingAttributes shapeDASelected = new DrawingAttributes();    public final static String ShapeFileListProperty = "shapeFileList";    public final static String ShapeFileProperty = "shapeFile";    public final static String ShowCrossingPointsProperty = "showCrossingPoints";    public final static String PointCheckProperty = "pointCheck";    public final static String SHAPE_FILE_NAME_ATTRIBUTE = "SHAPE_FILE_NAME";    public final static String SHAPE_VISIBILITY_CONTROL_ATTRIBUTE = "SHAPE_VISIBILITY_CONTROL";    public final static String SHAPE_CONTROL_ATTRIBUTE = "SHAPE_CONTROL";    protected boolean showCrossingPoints = false;    protected boolean createPointCheck = false;    public static boolean DEBUG = false;    /**     *      */    public GeoIntersectionLayer() {        super();        DEBUG = Debug.debugging("geo");        shapeDA.getPropertyChangeSupport().addPropertyChangeListener(this);    }    public void setProperties(String prefix, Properties props) {        super.setProperties(prefix, props);        shapeDA.setProperties(prefix, props);        prefix = PropUtils.getScopedPropertyPrefix(prefix);        shapeDASelected.setProperties(prefix + "selected", props);        Vector v = PropUtils.parseSpacedMarkers(props.getProperty(prefix                + ShapeFileListProperty));        for (Iterator it = v.iterator(); it.hasNext();) {            String markerName = (String) it.next();            String shapeFileName = props.getProperty(prefix + markerName);            if (shapeFileName != null) {                File sf = new File(shapeFileName);                if (sf.exists()) {                    addShapeFile(sf);                }            }        }    }    public OMGraphicList prepare() {        OMGraphicList list = getList();        if (list == null) {            list = new OMGraphicList();            // If there isn't any data loaded, ask the user for a            // file.            if (fileDataList.size() == 0) {                addShapeFileFromUser();            }        } else {            list.clear();        }        // If we created any pixel intersection images before, time to        // get rid of them.        intersectionResultList.clear();        ExtentIndex rIndex = getRegionIndex(true);        for (Iterator it = drawnList.iterator(); it.hasNext();) {            OMGraphic omg = (OMGraphic) it.next();            if (omg instanceof OMLine                    || (omg instanceof OMPoly && !((OMPoly) omg).isPolygon())) {                if (DEBUG) {                    Debug.output("GeoIntersectLayer(" + getName()                            + "): Checking line against RegionIndex");                }                GeoPath path = getPathFromOMGraphic(omg);                Iterator intrsctns = null;                Iterator crssngs = null;                if (showCrossingPoints) {                    BoundaryCrossing.Collector results = BoundaryCrossing.getCrossings(path,                            rIndex);                    intrsctns = results.iterator();                    crssngs = results.getCrossings();                } else {                    intrsctns = Intersection.intersect(path, rIndex);                }                while (intrsctns.hasNext()) {                    OMPolyRegion ompr = (OMPolyRegion) intrsctns.next();                    setRegionAsSelected(ompr);                    if (DEBUG) {                        Debug.output("GeoIntersectLayer(" + getName()                                + "): Set Poly for hit");                    }                }                int num = 0;                while (crssngs != null && crssngs.hasNext()) {                    BoundaryCrossing bc = (BoundaryCrossing) crssngs.next();                    Geo geo = bc.getGeo();                    OMPoint pgeo = new OMPoint((float) geo.getLatitude(), (float) geo.getLongitude());                    pgeo.setFillPaint(Color.WHITE);                    pgeo.putAttribute(OMGraphic.LABEL,                            new OMTextLabeler(Integer.toString(num++)));                    intersectionResultList.add(pgeo);                }            } else if (omg instanceof OMPoly) {                for (Iterator hits = Intersection.intersect(new OMPolyRegion((OMPoly) omg),                        rIndex); hits.hasNext();) {                    setRegionAsSelected((OMPolyRegion) hits.next());                    if (DEBUG) {                        Debug.output("GeoIntersectLayer(" + getName()                                + "): Set Poly for hit");                    }                }            } else if (omg instanceof OMPoint) {                OMPoint omp = (OMPoint) omg;                for (Iterator hits = Intersection.intersect(new GeoPoint.Impl(omp.getLat(), omp.getLon()),                        rIndex); hits.hasNext();) {                    setRegionAsSelected((OMPolyRegion) hits.next());                    if (DEBUG) {                        Debug.output("GeoIntersectLayer(" + getName()                                + "): Set Poly for hit");                    }                }            }        }        list.add(intersectionResultList);        list.add(drawnList);

⌨️ 快捷键说明

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