Revision 21927 branches/Mobile_Compatible_Hito_1/libFMap_mobile_shp_driver/src-file/org/gvsig/data/datastores/vectorial/file/shp/utils/SHPPolygon.java

View differences:

SHPPolygon.java
50 50

  
51 51
/**
52 52
 * Elemento shape de tipo Pol?gono.
53
 *
53
 * 
54 54
 * @author Vicente Caballero Navarro
55 55
 */
56 56
public class SHPPolygon extends SHPMultiLine {
......
64 64

  
65 65
	/**
66 66
	 * Crea un nuevo SHPPolygon.
67
	 *
68
	 * @param type Tipo de shape.
69
	 *
67
	 * 
68
	 * @param type
69
	 *            Tipo de shape.
70
	 * 
70 71
	 * @throws ShapefileException
71 72
	 */
72 73
	public SHPPolygon(int type) {
73
		if ((type != SHP.POLYGON2D) &&
74
				(type != SHP.POLYGONM) &&
75
				(type != SHP.POLYGON3D)) {
76
//			throw new ShapefileException("No es de tipo 5, 15, o 25");
74
		if ((type != SHP.POLYGON2D) && (type != SHP.POLYGONM)
75
				&& (type != SHP.POLYGON3D)) {
76
			// throw new ShapefileException("No es de tipo 5, 15, o 25");
77 77
		}
78 78

  
79 79
		m_type = type;
......
94 94
		double minY = buffer.getDouble();
95 95
		double maxX = buffer.getDouble();
96 96
		double maxY = buffer.getDouble();
97
		Rectangle2D rec = new Rectangle2D.Double(minX, minY, maxX - minX,
98
				maxY - maxY);
97
		Rectangle2D rec = new Rectangle2D.Double(minX, minY, maxX - minX, maxY
98
				- maxY);
99 99
		int numParts = buffer.getInt();
100 100
		int numPoints = buffer.getInt();
101 101

  
......
107 107

  
108 108
		Point2D[] points = readPoints(buffer, numPoints);
109 109

  
110
		/* if (m_type == FConstant.SHAPE_TYPE_POLYGONZ) {
111
		   //z
112
		   buffer.position(buffer.position() + (2 * 8));
113
		   for (int t = 0; t < numPoints; t++) {
114
		       points[t].z = buffer.getDouble();
115
		   }
116
		   }
110
		/*
111
		 * if (m_type == FConstant.SHAPE_TYPE_POLYGONZ) { //z
112
		 * buffer.position(buffer.position() + (2 * 8)); for (int t = 0; t <
113
		 * numPoints; t++) { points[t].z = buffer.getDouble(); } }
117 114
		 */
118 115
		int offset = 0;
119 116
		int start;
......
143 140

  
144 141
	/**
145 142
	 * Lee los puntos del buffer.
146
	 *
143
	 * 
147 144
	 * @param buffer
148
	 * @param numPoints N?mero de puntos.
149
	 *
145
	 * @param numPoints
146
	 *            N?mero de puntos.
147
	 * 
150 148
	 * @return Vector de Puntos.
151 149
	 */
152 150
	private synchronized Point2D[] readPoints(final MappedByteBuffer buffer,
153
		final int numPoints) {
151
			final int numPoints) {
154 152
		Point2D[] points = new Point2D[numPoints];
155 153

  
156 154
		for (int t = 0; t < numPoints; t++) {
......
164 162
	 * @see com.iver.cit.gvsig.fmap.shp.SHPShape#write(ByteBuffer, IGeometry)
165 163
	 */
166 164
	public synchronized void write(ByteBuffer buffer, Geometry geometry) {
167
		//FPolygon2D polyLine;
168
		//polyLine = (FPolygon2D) geometry.getShape();
165
		// FPolygon2D polyLine;
166
		// polyLine = (FPolygon2D) geometry.getShape();
169 167
		Rectangle2D rec = geometry.getBounds2D();
170 168
		buffer.putDouble(rec.getMinX());
171 169
		buffer.putDouble(rec.getMinY());
172 170
		buffer.putDouble(rec.getMaxX());
173 171
		buffer.putDouble(rec.getMaxY());
174 172

  
175
		//////
176
		///obtainsPoints(geometry.getGeneralPathXIterator());
173
		// ////
174
		// /obtainsPoints(geometry.getGeneralPathXIterator());
177 175

  
178
		//int[] parts=polyLine.getParts();
179
		//FPoint2D[] points=polyLine.getPoints();
176
		// int[] parts=polyLine.getParts();
177
		// FPoint2D[] points=polyLine.getPoints();
180 178
		int nparts = parts.length;
181 179
		int npoints = points.length;
182 180

  
183
		//////
184
		///int npoints = polyLine.getNumPoints();
185
		///int nparts = polyLine.getNumParts();
181
		// ////
182
		// /int npoints = polyLine.getNumPoints();
183
		// /int nparts = polyLine.getNumParts();
186 184
		buffer.putInt(nparts);
187 185
		buffer.putInt(npoints);
188 186

  
189 187
		int count = 0;
190 188

  
191 189
		for (int t = 0; t < nparts; t++) {
192
			///buffer.putInt(polyLine.getPart(t));
190
			// /buffer.putInt(polyLine.getPart(t));
193 191
			buffer.putInt(parts[t]);
194 192
		}
195 193

  
196
		///FPoint[] points = polyLine.getPoints();
194
		// /FPoint[] points = polyLine.getPoints();
197 195
		for (int t = 0; t < points.length; t++) {
198
			///buffer.putDouble(points[t].x);
199
			///buffer.putDouble(points[t].y);
196
			// /buffer.putDouble(points[t].x);
197
			// /buffer.putDouble(points[t].y);
200 198
			buffer.putDouble(points[t].getX());
201 199
			buffer.putDouble(points[t].getY());
202 200
		}
203 201

  
204
		   if (m_type == SHP.POLYGON3D) {
205
		   double[] zExtreame = SHP.getZMinMax(zs);
206
		   if (Double.isNaN(zExtreame[0])) {
207
		       buffer.putDouble(0.0);
208
		       buffer.putDouble(0.0);
209
		   } else {
210
		       buffer.putDouble(zExtreame[0]);
211
		       buffer.putDouble(zExtreame[1]);
212
		   }
213
		   for (int t = 0; t < npoints; t++) {
214
		       double z = zs[t];
215
		       if (Double.isNaN(z)) {
216
		           buffer.putDouble(0.0);
217
		       } else {
218
		           buffer.putDouble(z);
219
		       }
220
		   }
221
		   }
202
		if (m_type == SHP.POLYGON3D) {
203
			double[] zExtreame = SHP.getZMinMax(zs);
204
			if (Double.isNaN(zExtreame[0])) {
205
				buffer.putDouble(0.0);
206
				buffer.putDouble(0.0);
207
			} else {
208
				buffer.putDouble(zExtreame[0]);
209
				buffer.putDouble(zExtreame[1]);
210
			}
211
			for (int t = 0; t < npoints; t++) {
212
				double z = zs[t];
213
				if (Double.isNaN(z)) {
214
					buffer.putDouble(0.0);
215
				} else {
216
					buffer.putDouble(z);
217
				}
218
			}
219
		}
222 220

  
223
		if ((m_type == SHP.POLYGONM) ||
224
				(m_type == SHP.POLYGON3D)) {
221
		if ((m_type == SHP.POLYGONM) || (m_type == SHP.POLYGON3D)) {
225 222
			buffer.putDouble(-10E40);
226 223
			buffer.putDouble(-10E40);
227 224

  
......
236 233
	 */
237 234
	public synchronized int getLength(Geometry fgeometry) {
238 235
		// FPolygon2D multi;
239
		//multi = (FPolygon2D) fgeometry.getShape();
240
		///int nrings = 0;
241
		///obtainsPoints(fgeometry.getGeneralPathXIterator());
236
		// multi = (FPolygon2D) fgeometry.getShape();
237
		// /int nrings = 0;
238
		// /obtainsPoints(fgeometry.getGeneralPathXIterator());
242 239

  
243
		//int[] parts=multi.getParts();
244
		//FPoint2D[] points;
245
		/////////
246
		//points = multi.getPoints();
240
		// int[] parts=multi.getParts();
241
		// FPoint2D[] points;
242
		// ///////
243
		// points = multi.getPoints();
247 244
		int npoints = points.length;
248 245

  
249
		///////////
250
		///nrings = multi.getNumParts();
251
		///int npoints = multi.getNumPoints();
246
		// /////////
247
		// /nrings = multi.getNumParts();
248
		// /int npoints = multi.getNumPoints();
252 249
		int length;
253 250

  
254 251
		if (m_type == SHP.POLYGON3D) {
255
			length = 44 + (4 * parts.length) + (16 * npoints) + (8 * npoints) +
256
				16 + (8 * npoints) + 16;
252
			length = 44 + (4 * parts.length) + (16 * npoints) + (8 * npoints)
253
					+ 16 + (8 * npoints) + 16;
257 254
		} else if (m_type == SHP.POLYGONM) {
258
			length = 44 + (4 * parts.length) + (16 * npoints) + (8 * npoints) +
259
				16;
255
			length = 44 + (4 * parts.length) + (16 * npoints) + (8 * npoints)
256
					+ 16;
260 257
		} else if (m_type == SHP.POLYGON2D) {
261 258
			length = 44 + (4 * parts.length) + (16 * npoints);
262 259
		} else {
263 260
			throw new IllegalStateException(
264
				"Expected ShapeType of Polygon, got " + m_type);
261
					"Expected ShapeType of Polygon, got " + m_type);
265 262
		}
266 263

  
267 264
		return length;

Also available in: Unified diff