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

📄 esrishapeexport.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 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.*;import java.awt.event.*;import java.io.*;import java.net.MalformedURLException;import java.util.*;import javax.swing.*;import com.bbn.openmap.omGraphics.*;import com.bbn.openmap.dataAccess.shape.output.*;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's AppObject holds a DbfTableModel, 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 in the AppObject 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 AppObject in 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 in     * the AppObject of the new list that is returned. If there isn't a     * masterDBF object, then the AppObject is set to null, and a default one     * will be created.     */    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 in the     * EsriGraphicList under the DBF_ATTRIBUTE key.     */    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;    }    /**     * Separates the graphics from the OMGraphicList into Polygon, Polyline and     * Point lists, then passes the desired shape lists to their respective     * export functions to be added to an EsriLayer of the same type and     * prepared for export. OMGraphics that are on sublists within the top-level     * OMGraphicList will be simply written to the appropriate list at the top     * level of that list. They will be handled as multi-part geometries.     * <p>     *      * Separating the graphics into the three types is necessary due to shape     * file specification limitations which will only allow shape files to be of     * one type.     * <P>     *      * For OMGraphicLists that are actually EsriGraphicLists, this export method     * will be redirected to a different method that will handle     * sub-OMGraphicLists as multi-part geometries.     * <P>     *      * If you want to write out multi-part geometries and have a regular     * OMGraphicList, you have to convert them to EsriGraphicLists first (and

⌨️ 快捷键说明

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