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

📄 esrishapeexport.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* *  File: EsriShapeExport.java *  OptiMetrics, Inc. *  2107 Laurel Bush Road - Suite 209 *  Bel Air, MD 21015 *  (410)569 - 6081 */package com.bbn.openmap.dataAccess.shape;import java.awt.BasicStroke;import java.awt.BorderLayout;import java.awt.Component;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileOutputStream;import java.net.MalformedURLException;import java.util.ArrayList;import java.util.Iterator;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import com.bbn.openmap.dataAccess.shape.output.DbfOutputStream;import com.bbn.openmap.dataAccess.shape.output.ShpOutputStream;import com.bbn.openmap.dataAccess.shape.output.ShxOutputStream;import com.bbn.openmap.omGraphics.BasicStrokeEditor;import com.bbn.openmap.omGraphics.OMCircle;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicConstants;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.OMRangeRings;import com.bbn.openmap.omGraphics.OMRect;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.ArgParser;import com.bbn.openmap.util.ColorFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.FileUtils;import com.bbn.openmap.util.PropUtils;/** * Provides methods for saving OMGraphicLists as ShapeFiles. This code * was originally submitted by Karl Stuempfle of OptiMetrics, and I * modified it a little to add a user interface to modify the DBF * files if the user wants to. * <P> *  * Since Shape files can only hold one type of graphic, this class * will create one to three different lists as needed, for points, * lines and polygons. * <P> *  * If the OMGraphicList holds it's DbfTableModel as a DBF_ATTRIBUTE * attribute, if so, it will be used for the shape file database file. */public class EsriShapeExport implements ShapeConstants, OMGraphicConstants {    /**     * The source graphics to write to a shape file.     */    protected OMGraphicList graphicList = null;    /**     * The optional DbfTableModel that describes properties for the     * OMGraphics. This should be set as the DBF_ATTRIBUTE attribute     * of the OMGraphicList.     */    protected DbfTableModel masterDBF = null;    /**     * The projection needed to convert other OMGraphicTypes to     * polygons.     */    protected Projection projection;    /**     * The path where the shape files should be written.     */    protected String filePath;    /**     * Gets set automatically if Debug.debugging("shape");     */    protected boolean DEBUG = false;    /**     * A list of ESEInterface classes, holding information for     * different type ESRIGraphicLists created from the OMGraphicList.     */    protected ArrayList eseInterfaces = new ArrayList();    /**     * Flag for whether the DBF file should be written when the     * OMGraphicList is exported to a .shp/.shx file. The .dbf file     * will be created if set to true, and this is true by default.     */    protected boolean writeDBF = true;    /**     * Flad to note whether, if a DbfTableModel is set, to add the     * rendering information (DrawingAttributes contents) about the     * OMGraphics to the contents of the DbfTableModel. False by     * default. Doesn't do anything yet.     */    protected boolean dbfHasRenderingInfo = false;    /**     * Create an EsriShapeExport object.     *      * @param list the OMGraphicList to export.     * @param proj the Projection of the map, needed to convert some     *        OMGraphic types to OMPolys.     * @param pathToFile the file path of the shape file to save to.     *        If null, the user will be queried. If not null, the     *        files will be saved without any GUI confirmation.     */    public EsriShapeExport(OMGraphicList list, Projection proj,            String pathToFile) {        setGraphicList(list);        projection = proj;        filePath = pathToFile;        DEBUG = Debug.debugging("shape");    }    /**     * Create an EsriShapeExport object.     *      * @param list the EsriGraphicList to export.     * @param dbf the DbfTableModel holding the attributes for the     *        list objects.     * @param pathToFile the file path of the shape file to save to.     *        If null, the user will be queried. If not null, the     *        files will be saved without any GUI confirmation.     */    public EsriShapeExport(EsriGraphicList list, DbfTableModel dbf,            String pathToFile) {        setGraphicList(list);        setMasterDBF(dbf);        filePath = pathToFile;        DEBUG = Debug.debugging("shape");    }    /**     * Set the OMGraphicList to use for export. If the DBF_ATTRIBUTE     * object in the attribute hashtable of the OMGraphicList holds a     * DbfTableModel, it will be used in the export.     */    public void setGraphicList(OMGraphicList list) {        graphicList = list;        if (list != null) {            Object obj = list.getAttribute(DBF_ATTRIBUTE);            // Do this check for backward compatibility            if (obj == null) {                obj = list.getAppObject();            }            if (obj instanceof DbfTableModel) {                masterDBF = (DbfTableModel) obj;                Debug.message("shape", "Setting master DBF in ESE");            }        }    }    public OMGraphicList getGraphicList() {        return graphicList;    }    public void setProjection(Projection proj) {        projection = proj;    }    public Projection getProjection() {        return projection;    }    public void setFilePath(String pathToFile) {        filePath = pathToFile;    }    public String getFilePath() {        return filePath;    }    protected EsriPolygonList polyList = null;    protected EsriPolylineList lineList = null;    protected EsriPointList pointList = null;    /**     * Return the polygon list, create it if needed.     */    protected EsriPolygonList getPolyList() {        if (polyList == null) {            polyList = new EsriPolygonList();            polyList.setTable(getMasterDBFHeaderClone());        }        return polyList;    }    /**     * Return the line list, create it if needed.     */    protected EsriPolylineList getLineList() {        if (lineList == null) {            lineList = new EsriPolylineList();            lineList.setTable(getMasterDBFHeaderClone());        }        return lineList;    }    /**     * Return the point list, create it if needed. If the masterDBF     * object exists, then a new one is created, which matching     * structure, and put under the DBF_ATTRIBUTE attribute key the     * new list that is returned. If there isn't a masterDBF object,     * then a default one will be created under that key.     */    protected EsriPointList getPointList() {        if (pointList == null) {            pointList = new EsriPointList();            pointList.setTable(getMasterDBFHeaderClone());        }        return pointList;    }    /**     * Add a graphic to the list, and add the record to the list's     * DbfTableModel if both exist.     */    protected void addGraphic(EsriGraphicList egl, OMGraphic graphic,                              ArrayList record) {        egl.add(graphic);        DbfTableModel dtm = egl.getTable();        if (dtm != null && record != null) {            dtm.addRecord(record);        }    }    /** Scoping method to call addGraphic with the right list. */    protected void addPolygon(OMGraphic graphic, ArrayList record) {        addGraphic(getPolyList(), graphic, record);    }    /** Scoping method to call addGraphic with the right list. */    protected void addLine(OMGraphic graphic, ArrayList record) {        addGraphic(getLineList(), graphic, record);    }    /** Scoping method to call addGraphic with the right list. */    protected void addPoint(OMGraphic graphic, ArrayList record) {        addGraphic(getPointList(), graphic, record);    }    /**     * Set the DbfTableModel representing the dbf file for the main     * OMGraphicList. Can also be passed to this object as an     * attribute under the DBF_ATTRIBUTE key within the top level     * OMGraphicList.     */    public void setMasterDBF(DbfTableModel dbf) {        masterDBF = dbf;    }    /**     * Get the DbfTableModel representing the dbf file for the main     * OMGraphicList.     */    public DbfTableModel getMasterDBF() {        return masterDBF;    }    /**     * Set whether the DBF file should be written when the     * OMGraphicList is exported to a .shp/.shx file. The .dbf file     * will be created if set to true, and this is true by default.     */    public void setWriteDBF(boolean value) {        writeDBF = value;    }    /**     * Get whether the DBF file should be written when the     * OMGraphicList is exported to a .shp/.shx file.     */    public boolean getWriteDBF() {        return writeDBF;    }    /**     * Get whether the DBF file should have the DrawingAttributes     * information added to the DbfTableModel if it isn't already     * there.     */    public void setDBFHasRenderingInfo(boolean value) {        dbfHasRenderingInfo = value;    }    /**     * Get whether the DBF file should have the DrawingAttributes     * information added to the DbfTableModel if it isn't already     * there.     */    public boolean getDBFHasRenderingInfo() {        return dbfHasRenderingInfo;    }    /**     * If the OMGraphicList has a DbfTableModel in its AppObject slot,     * a new DbfTableModel is created that has the same structure.     *      * @return DbfTableModel that matches the structure that is in the     *         OMGraphicList AppObject.     */    protected DbfTableModel getMasterDBFHeaderClone() {        if (masterDBF != null) {            return masterDBF.headerClone();        }        return null;    }    /**     * Gets the DbfTableModel record at the index. Used when the     * OMGraphicList contents are being split up into different type     * EsriGraphicLists, and the records are being split into     * different tables, too.     */    protected ArrayList getMasterDBFRecord(int index) {        try {            if (masterDBF != null) {                return (ArrayList) masterDBF.getRecord(index);            }        } catch (IndexOutOfBoundsException ioobe) {        }        return null;    }

⌨️ 快捷键说明

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