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

📄 geoarray.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                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 createFromLatLonRadians(float[] latlonrad) {            int numCoordSets = latlonrad.length / 2;            float[] coords = new float[numCoordSets * 3];            Geo geo = new Geo();            for (int i = 0; i < numCoordSets; i++) {                geo.initializeRadians(latlonrad[i * 2], latlonrad[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 createFromLatLonRadians(double[] latlonrad) {            int numCoordSets = latlonrad.length / 2;            float[] coords = new float[numCoordSets * 3];            Geo geo = new Geo();            for (int i = 0; i < numCoordSets; i++) {                geo.initializeRadians(latlonrad[i * 2], latlonrad[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 createFromGeoCoords(float[] xyz) {            return new Float(xyz);        }        public int getSize() {            if (coords != null) {                return coords.length / 3;            }            return 0;        }        public void set(int i, double x, double y, double z) {            int loc = i * 3;            coords[loc] = (float) x;            coords[loc + 1] = (float) y;            coords[loc + 2] = (float) z;        }        public void set(int i, Geo g) {            set(i, g.x(), g.y(), g.z());        }        public void set(int i, double lat, double lon, boolean isDegrees) {            set(i, new Geo(lat, lon, isDegrees));        }        public Geo get(int i) {            return get(i, new Geo());        }        public Geo get(int i, Geo ret) {            int loc = i * 3;            double x = coords[loc];            double y = coords[loc + 1];            double z = coords[loc + 2];            ret.initialize(x, y, z);            return ret;        }        public boolean equals(int index, Geo comp) {            int loc = index * 3;            double x = coords[loc];            double y = coords[loc + 1];            double z = coords[loc + 2];            return x == comp.x() && y == comp.y() && z == comp.z();        }        /**         * 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.         */        public void closeArray() {            int l = coords.length;            int i = l - 3;            if (coords[0] != coords[i] || coords[1] != coords[i + 1]                    || coords[2] != coords[i + 2]) {                float[] newCoords = new float[l + 3];                System.arraycopy(coords, 0, newCoords, 0, l);                newCoords[l] = coords[0];                newCoords[l + 1] = coords[1];                newCoords[l + 2] = coords[2];                coords = newCoords;            }        }        /**         * Modify, if needed, the Geo array with the duplicates removed.         */        public void removeDups() {            Geo[] ga = toPointArray();            Geo[] r = new Geo[ga.length];            int p = 0;            for (int i = 0; i < ga.length; i++) {                if (p == 0 || !(r[p - 1].equals(ga[i]))) {                    r[p] = ga[i];                    p++;                }            }            if (p != ga.length) {                coords = new float[p * 3];                for (int i = 0; i < p; i++) {                    int loc = i * 3;                    Geo geo = r[i];                    coords[loc] = (float) geo.x();                    coords[loc + 1] = (float) geo.y();                    coords[loc + 2] = (float) geo.z();                }            }        }    }    /**     * An implementation of GeoArray and GeoArray.Mutable that contains     * double-precision values. Holds the coordinates in a double array of x, y,     * z, x, y, z values.     *      * @author dietrick     */    public static class Double extends Adapter implements Mutable {        private double[] coords;        public Double(Geo[] geos) {            coords = new double[geos.length * 3];            for (int i = 0; i < geos.length; i++) {                int loc = i * 3;                Geo geo = geos[i];                coords[loc] = geo.x();                coords[loc + 1] = geo.y();                coords[loc + 2] = geo.z();            }        }        public Double(GeoArray ga) {            int size = ga.getSize();            coords = new double[size * 3];            Geo geo = new Geo();            for (int i = 0; i < size; i++) {                int loc = i * 3;                ga.get(i, geo);                coords[loc] = geo.x();                coords[loc + 1] = geo.y();                coords[loc + 2] = geo.z();            }        }        protected Double(double[] coords) {            this.coords = coords;        }        public static Double createFromLatLonDegrees(double[] latlondeg) {            int numCoordSets = latlondeg.length / 2;            double[] coords = new double[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] = geo.x();                coords[loc + 1] = geo.y();                coords[loc + 2] = geo.z();            }            return new Double(coords);        }        public static Double createFromLatLonRadians(double[] latlonrad) {            int numCoordSets = latlonrad.length / 2;            double[] coords = new double[numCoordSets * 3];            Geo geo = new Geo();            for (int i = 0; i < numCoordSets; i++) {                geo.initializeRadians(latlonrad[i * 2], latlonrad[i * 2 + 1]);                int loc = i * 3;                coords[loc] = geo.x();                coords[loc + 1] = geo.y();                coords[loc + 2] = geo.z();            }            return new Double(coords);        }        public static Double createFromGeoCoords(double[] xyz) {            return new Double(xyz);        }        public int getSize() {            if (coords != null) {                return coords.length / 3;            }            return 0;        }        public void set(int i, double x, double y, double z) {            int loc = i * 3;            coords[loc] = x;            coords[loc + 1] = y;            coords[loc + 2] = z;        }        public void set(int i, Geo g) {            set(i, g.x(), g.y(), g.z());        }        public void set(int i, double lat, double lon, boolean isDegrees) {            set(i, new Geo(lat, lon, isDegrees));        }        public Geo get(int i) {            return get(i, new Geo());        }        public Geo get(int i, Geo ret) {            if (ret == null) {                ret = new Geo();            }            int loc = i * 3;            double x = coords[loc];            double y = coords[loc + 1];            double z = coords[loc + 2];            ret.initialize(x, y, z);            return ret;        }        public boolean equals(int index, Geo comp) {            int loc = index * 3;            double x = coords[loc];            double y = coords[loc + 1];            double z = coords[loc + 2];            return x == comp.x() && y == comp.y() && z == comp.z();        }        /**         * Ensure that the Geo array starts and ends with the same values. Will         * replace the current coord array with one three double longer if         * needed.         */        public void closeArray() {            int l = coords.length;            int i = l - 3;            if (coords[0] != coords[i] || coords[1] != coords[i + 1]                    || coords[2] != coords[i + 2]) {                double[] newCoords = new double[l + 3];                System.arraycopy(coords, 0, newCoords, 0, l);                newCoords[l] = coords[0];                newCoords[l + 1] = coords[1];                newCoords[l + 2] = coords[2];                coords = newCoords;            }        }        /**         * Modify, if needed, the Geo array with the duplicates removed.         */        public void removeDups() {            Geo[] ga = toPointArray();            Geo[] r = new Geo[ga.length];            int p = 0;            for (int i = 0; i < ga.length; i++) {                if (p == 0 || !(r[p - 1].equals(ga[i]))) {                    r[p] = ga[i];                    p++;                }            }            if (p != ga.length) {                coords = new double[p * 3];                for (int i = 0; i < p; i++) {                    int loc = i * 3;                    Geo geo = r[i];                    coords[loc] = geo.x();                    coords[loc + 1] = geo.y();                    coords[loc + 2] = geo.z();                }            }        }    }}

⌨️ 快捷键说明

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