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

📄 geoarray.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//**********************************************************************////<copyright>////BBN Technologies//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: GeoArray.java,v $//$Revision: 1.1.4.2 $//$Date: 2007/02/13 20:00:53 $//$Author: dietrick $////**********************************************************************package com.bbn.openmap.geo;/** * A GeoArray is a interface that represents a set of Geo information. Rather * than keeping a set of Geo[] around and managing the memory for all of those * objects, the GeoArray provides an object that just holds onto the coordinates * of those points. *  * @author dietrick */public interface GeoArray {    /**     * Get a Geo represented by the index i.     *      * @param i     * @return     */    Geo get(int i);    /**     * Load the values for Geo at index i into ret.     *      * @param i     * @param ret     * @return     */    Geo get(int i, Geo ret);    /**     * Get the number of Geo points represented by this array.     *      * @return     */    int getSize();    /**     * Convert the GeoArray to an array of Geos.     *      * @return     */    Geo[] toPointArray();    /**     * Convert the GeoArray to an array of decimal degree values, alternating     * lat, lon, lat, lon.     *      * @return     */    double[] toLLDegrees();    /**     * Convert the GeoArray to an array of radian values, alternating lat, lon,     * lat, lon.     *      * @return     */    double[] toLLRadians();    /**     * @param index the index of the Geo in the GeoArray to compare.     * @param comp the Geo to compare to the indexed value.     * @return true of x, y, and z of the Geos match.     */    boolean equals(int index, Geo comp);    /**     * Compute the area of the GeoArray polygon on the surface of a unit sphere     * given an enumeration of its point. For a non unit sphere, multiply this     * by the radius of sphere squared.     *      * @return area value.     */    double area();    /**     * Ensure that the Geo array starts and ends with the same values. Will     * replace the current coord array with one three floats longer if needed.     */    void closeArray();    /**     * Modify, if needed, the Geo array with the duplicates removed.     */    void removeDups();    /**     * A Mutable GeoArray is one where the points can be modified.     *      * @author dietrick     */    public static interface Mutable extends GeoArray {        /**         * Set the values for the provided index to the values represented by g.         *          * @param i         * @param g         */        void set(int i, Geo g);        /**         * Set the values for the provided index to the values x, y, z, which         * are vector Geo values, *not* lat, lon and height.         *          * @param i         * @param x         * @param y         * @param z         */        void set(int i, double x, double y, double z);        /**         * Set the values for the provided index to the latitude, longitude.         *          * @param i         * @param lat         * @param lon         * @param isDegrees true if lat/lon in decimal degrees.         */        void set(int i, double lat, double lon, boolean isDegrees);    }    /**     * An abstract parent implementation class of GeoArray that handles common     * methods.     *      * @author dietrick     */    public static abstract class Adapter implements GeoArray {        /**         * Convert the GeoArray to an array of Geos.         *          * @return         */        public Geo[] toPointArray() {            int size = getSize();            Geo[] geos = new Geo[size];            for (int i = 0; i < size; i++) {                geos[i] = get(i, new Geo());            }            return geos;        }        /**         * Convert the GeoArray to an array of decimal degree values,         * alternating lat, lon, lat, lon.         *          * @return         */        public double[] toLLDegrees() {            int size = getSize();            double[] coords = new double[size * 2];            Geo storage = new Geo();            for (int i = 0; i < size; i++) {                get(i, storage);                int loc = i * 2;                coords[loc] = storage.getLatitude();                coords[loc + 1] = storage.getLongitude();            }            return coords;        }        /**         * Convert the GeoArray to an array of radian values, alternating lat,         * lon, lat, lon.         *          * @return         */        public double[] toLLRadians() {            int size = getSize();            double[] coords = new double[size * 2];            Geo storage = new Geo();            for (int i = 0; i < size; i++) {                get(i, storage);                int loc = i * 2;                coords[loc] = storage.getLatitudeRadians();                coords[loc + 1] = storage.getLongitudeRadians();            }            return coords;        }        /**         * Computes the area of a polygon on the surface of a unit sphere. For a         * non unit sphere, multiply this by the radius of sphere squared.         */        public double area() {            int count = 0;            double area = 0;            Geo v0 = get(0, new Geo());            Geo v1 = get(1, new Geo());            Geo p0 = v0;            Geo p1 = v1;            Geo p2 = new Geo();            int size = getSize();            for (int i = 2; i < size; i++) {                count = count + 1;                get(i, p2);                area = area + Geo.angle(p0, p1, p2);                p0.initialize(p1);                p1.initialize(p2);            }            count = count + 1;            p2.initialize(v0);            area = area + Geo.angle(p0, p1, p2);            p0.initialize(p1);            p1.initialize(p2);            count = count + 1;            p2.initialize(v1);            area = area + Geo.angle(p0, p1, p2);            return area - (count - 2) * Math.PI;        }    }    /**     * An implementation of GeoArray and GeoArray.Mutable that contains     * float-precision values. Holds the coordinates in a float array of x, y,     * z, x, y, z values.     *      * @author dietrick     */    public static class Float extends Adapter implements Mutable {        private float[] coords;        public Float(Geo[] geos) {            coords = new float[geos.length * 3];            for (int i = 0; i < geos.length; i++) {                int loc = i * 3;                Geo geo = geos[i];                coords[loc] = (float) geo.x();                coords[loc + 1] = (float) geo.y();                coords[loc + 2] = (float) geo.z();            }        }        public Float(GeoArray ga) {            int size = ga.getSize();            coords = new float[size * 3];            Geo geo = new Geo();            for (int i = 0; i < size; i++) {                int loc = i * 3;                ga.get(i, geo);                coords[loc] = (float) geo.x();                coords[loc + 1] = (float) geo.y();                coords[loc + 2] = (float) geo.z();            }        }        protected Float(float[] coords) {            this.coords = coords;        }        public static Float createFromLatLonDegrees(float[] latlondeg) {            int numCoordSets = latlondeg.length / 2;            float[] coords = new float[numCoordSets * 3];            Geo geo = new Geo();            for (int i = 0; i < numCoordSets; i++) {                geo.initialize(latlondeg[i * 2], latlondeg[i * 2 + 1]);                int loc = i * 3;                coords[loc] = (float) geo.x();                coords[loc + 1] = (float) geo.y();                coords[loc + 2] = (float) geo.z();            }            return new Float(coords);        }        public static Float createFromLatLonDegrees(double[] latlondeg) {            int numCoordSets = latlondeg.length / 2;            float[] coords = new float[numCoordSets * 3];            Geo geo = new Geo();            for (int i = 0; i < numCoordSets; i++) {

⌨️ 快捷键说明

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