    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/io/shpapi/SHPPolyLine3D.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005       Department of Geography, University of Bonn
    006     and
    007       lat/lon GmbH
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035    ----------------------------------------------------------------------------*/
    036    package org.deegree.io.shpapi;
    037
    038    import org.deegree.model.spatialschema.ByteUtils;
    039    import org.deegree.model.spatialschema.Curve;
    040    import org.deegree.model.spatialschema.LineString;
    041
    042    /**
    043     *
    044     *
    045     *
    046     * @version $Revision: 18195 $
    047     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    048     * @author last edited by: $Author: mschneider $
    049     *
    050     * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    051     *
    052     * @since 2.0
    053     */
    054    public class SHPPolyLine3D extends SHPPolyLine {
    055
    056        /**
    057         * @param recBuf
    058         */
    059        public SHPPolyLine3D( byte[] recBuf ) {
    060
    061            super( recBuf );
    062
    063            int pointsStart = 0;
    064            int sumPoints = 0;
    065
    066            envelope = ShapeUtils.readBox( recBuf, 4 );
    067
    068            numParts = ByteUtils.readLEInt( recBuffer, 36 );
    069            numPoints = ByteUtils.readLEInt( recBuffer, 40 );
    070
    071            pointsStart = ShapeConst.PARTS_START + ( numParts * 4 );
    072
    073            points = new SHPPoint[numParts][];
    074
    075            for ( int j = 0; j < numParts; j++ ) {
    076
    077                int firstPointNo = 0;
    078                int nextFirstPointNo = 0;
    079                int offset = 0;
    080                int lnumPoints = 0;
    081
    082                // get number of first point of current part out of ESRI shape Record:
    083                firstPointNo = ByteUtils.readLEInt( recBuffer, ShapeConst.PARTS_START + ( j * 4 ) );
    084
    085                // calculate offset of part in bytes, count from the beginning of recordbuffer
    086                offset = pointsStart + ( firstPointNo * 16 );
    087
    088                // get number of first point of next part ...
    089                if ( j < numParts - 1 ) {
    090                    // ... usually out of ESRI shape Record
    091                    nextFirstPointNo = ByteUtils.readLEInt( recBuffer, ShapeConst.PARTS_START + ( ( j + 1 ) * 4 ) );
    092                }
    093                // ... for the last part as total number of points
    094                else if ( j == numParts - 1 ) {
    095                    nextFirstPointNo = numPoints;
    096                }
    097
    098                // calculate number of points per part due to distance and
    099                // calculate some checksum for the total number of points to be worked
    100                lnumPoints = nextFirstPointNo - firstPointNo;
    101                sumPoints += lnumPoints;
    102
    103                // allocate memory for the j-th part
    104                points[j] = new SHPPoint[lnumPoints];
    105
    106                int zPos = pointsStart + 16 * numPoints + 16;
    107
    108                // create the points of the j-th part from the buffer
    109                for ( int i = 0; i < lnumPoints; i++ ) {
    110                    double z = ByteUtils.readLEDouble( recBuffer, zPos );
    111                    zPos += 8;
    112                    SHPPoint dummyPoint = new SHPPoint( recBuf, offset + ( i * 16 ) );
    113                    points[j][i] = new SHPPoint3D( dummyPoint.x, dummyPoint.y, z );
    114                }
    115
    116            }
    117
    118        }
    119
    120        /**
    121         * @param curve
    122         */
    123        public SHPPolyLine3D( Curve[] curve ) {
    124            super( curve );
    125            double xmin = curve[0].getEnvelope().getMin().getX();
    126            double xmax = curve[0].getEnvelope().getMax().getX();
    127            double ymin = curve[0].getEnvelope().getMin().getY();
    128            double ymax = curve[0].getEnvelope().getMax().getY();
    129
    130            numParts = curve.length;
    131
    132            numPoints = 0;
    133
    134            points = new SHPPoint[numParts][];
    135
    136            try {
    137                // create SHPPoints from the GM_Points array
    138                for ( int i = 0; i < numParts; i++ ) {
    139
    140                    LineString ls = curve[i].getAsLineString();
    141
    142                    numPoints += ls.getNumberOfPoints();
    143
    144                    points[i] = new SHPPoint3D[ls.getNumberOfPoints()];
    145
    146                    for ( int j = 0; j < ls.getNumberOfPoints(); j++ ) {
    147                        points[i][j] = new SHPPoint3D( ls.getPositionAt( j ) );
    148                        if ( points[i][j].x > xmax ) {
    149                            xmax = points[i][j].x;
    150                        } else if ( points[i][j].x < xmin ) {
    151                            xmin = points[i][j].x;
    152                        }
    153                        if ( points[i][j].y > ymax ) {
    154                            ymax = points[i][j].y;
    155                        } else if ( points[i][j].y < ymin ) {
    156                            ymin = points[i][j].y;
    157                        }
    158                    }
    159
    160                }
    161            } catch ( Exception e ) {
    162                System.out.println( "SHPPolyLine:: " + e );
    163            }
    164
    165            envelope = new SHPEnvelope( xmin, xmax, ymax, ymin );
    166        }
    167
    168        /**
    169         * @param points
    170         */
    171        public SHPPolyLine3D( SHPPoint3D[][] points ) {
    172            super( (Curve[]) null );
    173            this.points = points;
    174            this.numParts = points.length;
    175
    176        }
    177
    178    }