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