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

📄 esrigraphicfactory.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
//**********************************************************************////<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: EsriGraphicFactory.java,v $//$Revision: 1.1.4.9 $//$Date: 2008/01/25 17:44:27 $//$Author: dietrick $////**********************************************************************package com.bbn.openmap.dataAccess.shape;import java.io.EOFException;import java.io.IOException;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.ImageIcon;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.dataAccess.shape.input.LittleEndianInputStream;import com.bbn.openmap.io.BinaryFile;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.layer.shape.ShapeUtils;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.OMColor;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMPoly;import com.bbn.openmap.omGraphics.OMText;import com.bbn.openmap.proj.ProjMath;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.proj.coords.GeoCoordTransformation;public class EsriGraphicFactory implements ShapeConstants {    public static Logger logger = Logger.getLogger("com.bbn.openmap.dataAccess.EsriGraphicFactory");    protected int lineType = OMGraphic.LINETYPE_STRAIGHT;    protected GeoCoordTransformation dataTransformation = null;    protected Class precision = Float.TYPE;    public EsriGraphicFactory() {}    public EsriGraphicFactory(int lineType,            GeoCoordTransformation dataTransformation) {        this.lineType = lineType;        this.dataTransformation = dataTransformation;    }    public OMGraphicList getEsriGraphics(BinaryFile shp,                                         DrawingAttributes drawingAttributes,                                         Object pointRepresentation,                                         Projection mapProj, OMGraphicList list)            throws IOException, FormatException {        shp.seek(0);        Header header = new Header(shp);        if (logger.isLoggable(Level.FINE)) {            logger.fine(header.toString());        }        if (list == null) {            list = createEsriGraphicList(header.shapeType);        }        int offset = 100; // next byte past header;        // BAJ 20070604 Stop here for empty shape files        if (header.fileLength == offset) {            return list;        }        // Put a flag in here to force the file to be read until EOF        boolean ignoreFileLength = logger.isLoggable(Level.FINE);        EsriGraphicFactory.ReadByteTracker byteTracker = new EsriGraphicFactory.ReadByteTracker();        try {            OMGraphic eg = makeEsriGraphicFromRecord(offset,                    shp,                    drawingAttributes,                    pointRepresentation,                    byteTracker);            // 8 for shape type and record length            offset += byteTracker.currentCount + 8;            while (offset != header.fileLength || ignoreFileLength) {                projGraphicAndAdd(eg, list, mapProj);                try {                    eg = makeEsriGraphicFromRecord(offset,                            shp,                            drawingAttributes,                            pointRepresentation,                            byteTracker);                } catch (EOFException eof) {                    logger.fine("File length ("                            + header.fileLength                            + " bytes) is incorrect, file was read as much as possible ("                            + offset + " bytes).");                    eg = null;                    break;                }                // 8 for shape type and record length                offset += byteTracker.currentCount + 8;            }            if (eg != null) {                projGraphicAndAdd(eg, list, mapProj);            }        } catch (FormatException fe) {            fe.printStackTrace();        }        return list;    }    public OMGraphicList getEsriGraphics(LittleEndianInputStream iStream,                                         DrawingAttributes drawingAttributes,                                         Object pointRepresentation,                                         Projection mapProj, OMGraphicList list)            throws IOException, FormatException {        Header header = new Header(iStream);        if (logger.isLoggable(Level.FINE)) {            logger.fine(header.toString());        }        if (list == null) {            list = createEsriGraphicList(header.shapeType);        }        int offset = 100; // next byte past header;        // BAJ 20070604 Stop here for empty shape files        if (header.fileLength == offset) {            return list;        }        // Put a flag in here to force the file to be read until EOF        boolean ignoreFileLength = logger.isLoggable(Level.FINE);        EsriGraphicFactory.ReadByteTracker byteTracker = new EsriGraphicFactory.ReadByteTracker();        try {            OMGraphic eg = makeEsriGraphicFromRecord(offset,                    iStream,                    drawingAttributes,                    pointRepresentation,                    byteTracker);            // 8 for shape type and record length            offset += byteTracker.currentCount + 8;            while (offset != header.fileLength || ignoreFileLength) {                projGraphicAndAdd(eg, list, mapProj);                try {                    eg = makeEsriGraphicFromRecord(offset,                            iStream,                            drawingAttributes,                            pointRepresentation,                            byteTracker);                } catch (EOFException eof) {                    logger.fine("File length ("                            + header.fileLength                            + " bytes) is incorrect, file was read as much as possible ("                            + offset + " bytes).");                    eg = null;                    break;                }                // 8 for shape type and record length                offset += byteTracker.currentCount + 8;            }            if (eg != null) {                projGraphicAndAdd(eg, list, mapProj);            }        } catch (FormatException fe) {            fe.printStackTrace();        }        return list;    }    protected void projGraphicAndAdd(OMGraphic eg, OMGraphicList list,                                     Projection mapProj) {        if (eg != null) {            if (mapProj != null) {                eg.generate(mapProj);            }            list.add((OMGraphic) eg);        }    }    public OMGraphic makeEsriGraphicFromRecord(                                               int byteOffset,                                               BinaryFile shp,                                               DrawingAttributes drawingAttributes,                                               Object pointRepresentation,                                               ReadByteTracker byteTracker)            throws IOException, FormatException {        shp.seek(byteOffset);        shp.byteOrder(true);        int recordNumber = shp.readInteger();        int recordContentLength = shp.readInteger() * 2;        byteTracker.reset(recordContentLength);        OMGraphic omg = makeEsriGraphic(shp,                drawingAttributes,                pointRepresentation,                byteTracker);        if (omg != null) {            omg.putAttribute(SHAPE_INDEX_ATTRIBUTE, new Integer(recordNumber));        }        return omg;    }    public OMGraphic makeEsriGraphicFromRecord(                                               int byteOffset,                                               LittleEndianInputStream iStream,                                               DrawingAttributes drawingAttributes,                                               Object pointRepresentation,                                               ReadByteTracker byteTracker)            throws IOException, FormatException {        int recordNumber = iStream.readInt();        int recordContentLength = iStream.readInt() * 2;        byteTracker.reset(recordContentLength);        OMGraphic omg = makeEsriGraphic(iStream,                drawingAttributes,                pointRepresentation,                byteTracker);        if (omg != null) {            omg.putAttribute(SHAPE_INDEX_ATTRIBUTE, new Integer(recordNumber));        }        return omg;    }    /**     * Creates a OMGraphic from the shape file data.     *      * @param shapeType the shape file's shape type, enumerated in     *        <code>ShapeUtils</code>     * @param b the buffer pointing to the raw record data     * @param off the offset of the data starting point in the buffer     * @exception IOException if something goes wrong reading the file     * @see ShapeUtils     */    protected OMGraphic makeEsriGraphic(BinaryFile shpFile,                                        DrawingAttributes drawingAttributes,                                        Object pointRepresentation,                                        ReadByteTracker byteTracker)            throws IOException, FormatException {        /*         * SHAPE_TYPE_NULL = 0; SHAPE_TYPE_POINT = 1; SHAPE_TYPE_ARC = 3;         * SHAPE_TYPE_POLYLINE = 3; SHAPE_TYPE_POLYGON = 5;         * SHAPE_TYPE_MULTIPOINT = 8; SHAPE_TYPE_POINTZ = 11;         * SHAPE_TYPE_POLYLINEZ = 13; SHAPE_TYPE_POLYGONZ = 15;         * SHAPE_TYPE_MUILTIPOINTZ = 18; SHAPE_TYPE_POINTM = 21;         * SHAPE_TYPE_POLYLINEM = 23; SHAPE_TYPE_POLYGONM = 25;         * SHAPE_TYPE_MULTIPOINTM = 28; SHAPE_TYPE_MULTIPATCH = 31;         */        EsriGraphic eg = null;        shpFile.byteOrder(false);        int shapeType = shpFile.readInteger();        byteTracker.addRead(4);        switch (shapeType) {        case SHAPE_TYPE_NULL:            break;        case SHAPE_TYPE_POINT:            eg = createPointGraphic(shpFile,                    pointRepresentation,                    drawingAttributes,                    byteTracker);            break;        case SHAPE_TYPE_POLYLINE:            eg = createPolylineGraphic(shpFile, drawingAttributes, byteTracker);            break;        case SHAPE_TYPE_POLYGON:            eg = createPolygonGraphic(shpFile, drawingAttributes, byteTracker);            break;        case SHAPE_TYPE_MULTIPOINT:            eg = createMultiPointGraphic(shpFile,                    pointRepresentation,                    drawingAttributes,                    byteTracker);            break;        case SHAPE_TYPE_POINTZ:            eg = createPointZGraphic(shpFile,                    pointRepresentation,                    drawingAttributes,                    byteTracker);            break;        case SHAPE_TYPE_POLYLINEZ:            eg = createPolylineZGraphic(shpFile, drawingAttributes, byteTracker);            break;        case SHAPE_TYPE_POLYGONZ:            eg = createPolygonZGraphic(shpFile, drawingAttributes, byteTracker);            break;        case SHAPE_TYPE_MULTIPOINTZ:            eg = createMultiPointZGraphic(shpFile,                    pointRepresentation,                    drawingAttributes,                    byteTracker);            break;        case SHAPE_TYPE_POINTM:            eg = createPointMGraphic(shpFile,                    pointRepresentation,                    drawingAttributes,                    byteTracker);            break;        case SHAPE_TYPE_POLYLINEM:            eg = createPolylineMGraphic(shpFile, drawingAttributes, byteTracker);            break;        case SHAPE_TYPE_POLYGONM:            eg = createPolygonMGraphic(shpFile, drawingAttributes, byteTracker);            break;        case SHAPE_TYPE_MULTIPOINTM:            eg = createMultiPointMGraphic(shpFile,                    pointRepresentation,                    drawingAttributes,                    byteTracker);            break;        case SHAPE_TYPE_MULTIPATCH:        default:        }        return (OMGraphic) eg;    }    /**

⌨️ 快捷键说明

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