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

📄 vmap2shape.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 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/distapps/openmap/src/openmap/com/bbn/openmap/layer/vpf/VMAP2Shape.java,v $// $RCSfile: VMAP2Shape.java,v $// $Revision: 1.2.2.5 $// $Date: 2005/09/09 21:23:07 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.vpf;import java.io.FileInputStream;import java.io.IOException;import java.util.Properties;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.MoreMath;import com.bbn.openmap.dataAccess.shape.EsriShapeExport;import com.bbn.openmap.layer.shape.ShapeFile;import com.bbn.openmap.layer.shape.ShapeUtils;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMPoly;import com.bbn.openmap.omGraphics.SinkGraphic;import com.bbn.openmap.proj.DrawUtil;import com.bbn.openmap.proj.ProjMath;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.PropUtils;/** * Convert NIMA VMAP geospatial data into ESRI shapefile format. */public class VMAP2Shape {    protected static final String DEF_VMAP_TYPE = "bnd";    protected static final String DEF_PROPS_FILE_NAME = System.getProperty("user.home")            + System.getProperty("file.separator") + "openmap.properties";    protected static final String DEF_PREFIX = "vmapref";    protected static final boolean DEF_DO_THINNING = false;    protected static final float DEF_FAN_EPS = 0.1f;    protected static final float DEF_ZERO_EPS = 0.0001f;    protected static final float DEF_THRESHOLD = 0.5f;    protected String vmaptype = DEF_VMAP_TYPE;    protected String propsFileName = DEF_PROPS_FILE_NAME;    protected String prefix = DEF_PREFIX;    protected boolean doThinning = DEF_DO_THINNING;    protected float fan_eps = DEF_FAN_EPS;    protected float zero_eps = DEF_ZERO_EPS;    protected float threshold = DEF_THRESHOLD;    protected LibrarySelectionTable lst;    protected transient LayerGraphicWarehouseSupport warehouse;    public VMAP2Shape() {}    /**     * Will load the properties set in the VPF2Shape object, fetch the     * OMGraphics from the VPF database, and write the shape file.     *      * @param shapeFileName     */    public void writeShapeFile(String shapeFileName) {        setProperties(prefix, loadProperties());        writeShapeFile(shapeFileName, getRectangle());    }    /**     * Write the shape file, assumes that the properties have been     * loaded and the graphics fetched from the VPF database.     *      * @param shapeFileName the file name to write the shapes into.     * @param graphics OMGraphics from VPF database to write to shape     *        file.     */    public void writeShapeFile(String shapeFileName, OMGraphicList graphics) {        try {            ShapeFile s = new ShapeFile(shapeFileName);            int nGraphics = graphics.size();            if (nGraphics > 0) {                OMGraphic omg = graphics.getOMGraphicAt(0);                if ((omg instanceof OMPoly)                        && (omg.getRenderType() == OMGraphic.RENDERTYPE_LATLON)) {                    int shapeType = ((OMPoly) omg).isPolygon() ? ShapeUtils.SHAPE_TYPE_POLYGON                            : ShapeUtils.SHAPE_TYPE_ARC;                    System.out.println("shapeType=" + shapeType);                    s.setShapeType(shapeType);                }            }            System.out.println(nGraphics + " candidates.");            if (doThinning) {                OMGraphicList saveGraphics = new OMGraphicList();                for (int i = 0; i < nGraphics; i++) {                    OMGraphic omg = graphics.getOMGraphicAt(i);                    if ((omg instanceof OMPoly)                            && (omg.getRenderType() == OMGraphic.RENDERTYPE_LATLON)) {                        OMPoly poly = (OMPoly) omg;                        if (maybeThrowAwayPoly(poly)) {                            continue;                        }                        saveGraphics.addOMGraphic(poly);                    } else {                        System.out.println("Skipping candidate: "                                + omg.getClass().toString() + ", "                                + omg.getRenderType());                    }                }                                graphics = saveGraphics;                // join polylines                if (false) {                    nGraphics = graphics.size();                    System.out.println("Joining " + nGraphics + " polyline candidates.");                    graphics = joinCommonLines(graphics, zero_eps);                }            }            // Using com.bbn.openmap.dataAccess.shape package to write            // shape file:            EsriShapeExport ese = new EsriShapeExport(graphics, (Projection) null, shapeFileName);            ese.export();            // Instead of using com.bbn.openmap.layer.shape package to            // write shape file:            // int nDumped = 0;            // nGraphics = graphics.size();            // System.out.println("Dumping " + nGraphics + "            // graphics.");            // for (int i = 0; i < nGraphics; i++) {            // OMPoly poly = (OMPoly) graphics.getOMGraphicAt(i);            // float[] radians = poly.getLatLonArray();            // ESRIPolygonRecord epr = new ESRIPolygonRecord();            // epr.add(radians);            // epr.setPolygon(poly.isPolygon());//set POLYGON vs ARC            // s.add(epr);            // ++nDumped;            // }            //            // s.verify(true, true);            // s.verify(true, true);            // s.close();            // System.out.println("Wrote " + nDumped + " Graphics.");        } catch (java.io.IOException e) {            e.printStackTrace();        }    }    /**     * Iterates through graphic list finding non-connected polylines.     * iterates over these to find lines with common endpoints and     * joining them.     *      * @param list     * @param zero_eps     * @return     */    protected static OMGraphicList joinCommonLines(OMGraphicList list,                                                   float zero_eps) {        int size = list.size();        int len1, len2;        float lat1, lon1, lat2, lon2;        OMGraphic obj;        OMGraphicList newGraphics = new OMGraphicList();        OMGraphicList plineGraphics = new OMGraphicList();        // check for non-connected polylines        System.out.println("finding polylines...");        for (int i = 0; i < size; i++) {            obj = list.getOMGraphicAt(i);            if ((obj instanceof OMPoly) && !((OMPoly) obj).isPolygon()) {                plineGraphics.addOMGraphic(obj);            } else {                newGraphics.addOMGraphic(obj);            }        }        // iterate through the polylines and join lines with common        // endpoints        size = plineGraphics.size();        OMPoly poly1, poly2;        float[] rads1, rads2, radians;        System.out.println("maybe joining " + size + " polylines...");        // nasty!: > O(n^2)        for (int i = 0; i < size; i++) {            if (i % 500 == 0) {                System.out.println("checking pline i=" + i);            }            for (int j = 0; j < size; j++) {                if (i == j) {                    continue;                }                obj = plineGraphics.getOMGraphicAt(i);                if (obj instanceof SinkGraphic) {                    continue;                }                poly1 = (OMPoly) obj;                rads1 = poly1.getLatLonArray();                len1 = rads1.length;                lat1 = ProjMath.radToDeg(rads1[len1 - 2]);                lon1 = ProjMath.radToDeg(rads1[len1 - 1]);                obj = plineGraphics.getOMGraphicAt(j);                if (obj instanceof SinkGraphic) {                    continue;                }                poly2 = (OMPoly) obj;                rads2 = poly2.getLatLonArray();                len2 = rads2.length;                lat2 = ProjMath.radToDeg(rads2[0]);                lon2 = ProjMath.radToDeg(rads2[1]);                if (MoreMath.approximately_equal(lat1, lat2, zero_eps)                        && MoreMath.approximately_equal(lon1, lon2, zero_eps)) {                    // System.out.println("joining...");                    radians = new float[len1 + len2 - 2];                    System.arraycopy(rads1, 0, radians, 0, len1);                    System.arraycopy(rads2, 0, radians, len1 - 2, len2);                    poly1.setLocation(radians, OMGraphic.RADIANS);                    plineGraphics.setOMGraphicAt(SinkGraphic.getSharedInstance(),                            j);                    j = -1;// redo search                }            }        }        // add the joined lines back to the data set        size = plineGraphics.size();        for (int i = 0; i < size; i++) {            obj = plineGraphics.getOMGraphicAt(i);            if (obj instanceof OMPoly) {                newGraphics.addOMGraphic(obj);            }        }        return newGraphics;    }    /** traverse array and coalesce adjacent points which are the same */    public static float[] coalesce_points(float[] radians, float eps,                                          boolean ispolyg) {        int write = 2;        int len = radians.length;        for (int i = write - 2, j = write; j < len; j += 2) {            float lat1 = ProjMath.radToDeg(radians[i]);            float lon1 = ProjMath.radToDeg(radians[i + 1]);            float lat2 = ProjMath.radToDeg(radians[j]);            float lon2 = ProjMath.radToDeg(radians[j + 1]);            if (MoreMath.approximately_equal(lat1, lat2, eps)                    && MoreMath.approximately_equal(lon1, lon2, eps)) {                continue;            }

⌨️ 快捷键说明

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