Revision 1132

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/DbaseFileWriterNIO.java
181 181
          obj == null ? NULL_STRING : obj.toString()
182 182
        );
183 183
        break;
184
      case 'N':
184
     /* case 'N':
185 185
      case 'n':
186 186
        // int?
187 187
        if (header.getFieldDecimalCount(col) == 0) {
188 188
            
189 189
          o = formatter.getFieldString(
190
            fieldLen, 0, (Number) (obj == null ? NULL_NUMBER : obj)
190
            fieldLen, 0, (Number) (obj == null ? NULL_NUMBER : Double.valueOf(obj.toString()))
191 191
          );
192 192
          break;
193
        }
193
       
194
         }
195
      */
196
      case 'N':
197
      case 'n':
194 198
      case 'F':
195 199
      case 'f':
196 200
        o = formatter.getFieldString(fieldLen,
197 201
        header.getFieldDecimalCount(col),
198
        (Number) (obj == null ? NULL_NUMBER : obj)
202
        (Number) (obj == null ? NULL_NUMBER : Double.valueOf(obj.toString()))
199 203
        );
200 204
        break;
201 205
      case 'D':
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/ShapeFileHeader.java
59 59
 */
60 60
package com.iver.cit.gvsig.fmap.drivers.shp;
61 61

  
62
import java.io.IOException;
62 63
import java.nio.ByteBuffer;
63 64
import java.nio.ByteOrder;
64 65

  
......
270 271

  
271 272
        // that is all 100 bytes of the header.
272 273
    }
274
    public void write(ByteBuffer out,int type,
275
  		  int numGeoms,int length,double minX,double minY,double maxX,double maxY,double minZ,double maxZ,double minM,double maxM)
276
  		  throws IOException {
277
  		    out.order(ByteOrder.BIG_ENDIAN);
278
  		    
279
  		    out.putInt(myFileCode);
280
  		    
281
  		    for (int i = 0; i < 5; i++) {
282
  		      out.putInt(0); //Skip unused part of header
283
  		    }
273 284

  
285
  		    out.putInt(length);
286
  		    
287
  		    out.order(ByteOrder.LITTLE_ENDIAN);
288
  		    
289
  		    out.putInt(myVersion);
290
  		    out.putInt(type);
291
  		    
292
  		    //write the bounding box
293
  		    out.putDouble(minX);
294
  		    out.putDouble(minY);
295
  		    out.putDouble(maxX);
296
  		    out.putDouble(maxY);
297
  		    /*
298
  		    out.putDouble(minZ);
299
  		    out.putDouble(minZ);
300
  		    out.putDouble(maxM);
301
  		    out.putDouble(maxM);*/
302
  		    out.order(ByteOrder.BIG_ENDIAN);
303
  		    for (int i = 0; i < 8; i++) {
304
  		      out.putInt(0); //Skip unused part of header
305
  		    }
306
  		   
307
  		  }
308

  
274 309
    /**
275 310
     * Muestra por consola los warning.
276 311
     *
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/SHP.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.drivers.shp;
42 42

  
43
import java.io.File;
44

  
45
import com.hardcode.gdbms.engine.values.Value;
46
import com.iver.cit.gvsig.fmap.DriverException;
47
import com.iver.cit.gvsig.fmap.FMap;
48
import com.iver.cit.gvsig.fmap.drivers.shp.write.DBFFromSelected;
49
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiLine;
50
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiPoint;
51
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPoint;
52
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPolygon;
53
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPSHXFromSelectedVisitor;
54
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape;
55
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException;
56
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
57

  
58

  
59

  
43 60
/**
44
 * Clase con las constantes que representan los diferentes tipos de Shape.
61
 * Clase con las constantes que representan los diferentes tipos de Shape y
62
 * m?todos est?ticos relativos a los shapes.
45 63
 *
46 64
 * @author Vicente Caballero Navarro
47 65
 */
......
55 73
	public static final int POLYLINE3D = 13;
56 74
	public static final int POLYGON3D = 15;
57 75
	public static final int MULTIPOINT3D = 18;
76

  
77
	/**
78
	 * Crea a partir del tipo de geometr?a un shape del tipo m?s adecuado.
79
	 *
80
	 * @param type Tipo de geometr?a.
81
	 *
82
	 * @return Geometr?a m?s adecuada.
83
	 *
84
	 * @throws ShapefileException Se lanza cuando es causada por la creaci?n del shape.
85
	 */
86
	public static SHPShape create(int type) throws ShapefileException {
87
		SHPShape shape;
88

  
89
		switch (type) {
90
			case 1:
91
			case 11:
92
			case 21:
93
				shape = new SHPPoint(type);
94

  
95
				break;
96

  
97
			case 3:
98
			case 13:
99
			case 23:
100
				shape = new SHPMultiLine(type);
101

  
102
				break;
103

  
104
			case 5:
105
			case 15:
106
			case 25:
107
				shape = new SHPPolygon(type);
108

  
109
				break;
110

  
111
			case 8:
112
			case 18:
113
			case 28:
114
				shape = new SHPMultiPoint(type);
115

  
116
				break;
117

  
118
			default:
119
				shape = null;
120
		}
121

  
122
		return shape;
123
	}
124

  
125
	/**
126
	 * Devuelve el caracter que representa el tipo de valor del shape.
127
	 *
128
	 * @param i Tipo de Valor.
129
	 *
130
	 * @return Tipo de valor entendible por el formato shape.
131
	 */
132
	public static char getCharSelect(int i) {
133
		switch (i) {
134
			case Value.STRING:
135
				return 'M';
136

  
137
			case Value.DECIMAL:
138
			case Value.INTEGER:
139
				return 'N';
140

  
141
			case Value.DATE:
142
				return 'D';
143

  
144
			case Value.BOOLEAN:
145
				return 'L';
146
		}
147

  
148
		return 'C';
149
	}
150
	public static void SHPFileFromSelected(FMap map,File f){
151
	 	SHPSHXFromSelectedVisitor visitor = new SHPSHXFromSelectedVisitor();
152
		visitor.setFile(f);
153
		//int type=getTypeShape();
154
		//visitor.setType(5);
155
		try {
156
			map.getLayers().process(visitor);
157
			} catch (DriverException e1) {
158
				throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n",
159
						e1);
160
			} catch (VisitException e) {
161
				throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n",
162
						e);
163
			}
164
			
165
		DBFFromSelected dbf=new DBFFromSelected();
166
		dbf.setFile(f);
167
		dbf.setGeometries(visitor.getGeometries());
168
		dbf.setIsNewDBF(true);
169
		dbf.start(visitor.getSDS());
170
		dbf.createdbfRow();
171
		dbf.stop();
172
	
173
	 }
58 174
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/SHPPolygon.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.shp.write;
42

  
43
import com.iver.cit.gvsig.fmap.core.FPoint2D;
44
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
45
import com.iver.cit.gvsig.fmap.core.IGeometry;
46
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
47

  
48
import java.awt.geom.Rectangle2D;
49

  
50
import java.nio.ByteBuffer;
51
import java.nio.MappedByteBuffer;
52

  
53

  
54
/**
55
 * DOCUMENT ME!
56
 *
57
 * @author Vicente Caballero Navarro
58
 */
59
public class SHPPolygon extends SHPMultiLine {
60
	private int m_type;
61

  
62
	/**
63
	 * Crea un nuevo SHPPolygon.
64
	 */
65
	public SHPPolygon() {
66
		m_type = FConstant.SHAPE_TYPE_POLYGON;
67
	}
68

  
69
	/**
70
	 * Crea un nuevo SHPPolygon.
71
	 *
72
	 * @param type DOCUMENT ME!
73
	 *
74
	 * @throws ShapefileException DOCUMENT ME!
75
	 */
76
	public SHPPolygon(int type) throws ShapefileException {
77
		if ((type != FConstant.SHAPE_TYPE_POLYGON) &&
78
				(type != FConstant.SHAPE_TYPE_POLYGONM) &&
79
				(type != FConstant.SHAPE_TYPE_POLYGONZ)) {
80
			throw new ShapefileException("No es de tipo 5, 15, o 25");
81
		}
82

  
83
		m_type = type;
84
	}
85

  
86
	/**
87
	 * DOCUMENT ME!
88
	 *
89
	 * @return DOCUMENT ME!
90
	 */
91
	public int getShapeType() {
92
		return m_type;
93
	}
94

  
95
	/**
96
	 * DOCUMENT ME!
97
	 *
98
	 * @param buffer DOCUMENT ME!
99
	 * @param type DOCUMENT ME!
100
	 *
101
	 * @return DOCUMENT ME!
102
	 */
103
	public IGeometry read(MappedByteBuffer buffer, int type) {
104
		double minX = buffer.getDouble();
105
		double minY = buffer.getDouble();
106
		double maxX = buffer.getDouble();
107
		double maxY = buffer.getDouble();
108
		Rectangle2D rec = new Rectangle2D.Double(minX, minY, maxX - minX,
109
				maxY - maxY);
110
		int numParts = buffer.getInt();
111
		int numPoints = buffer.getInt();
112

  
113
		int[] partOffsets = new int[numParts];
114

  
115
		for (int i = 0; i < numParts; i++) {
116
			partOffsets[i] = buffer.getInt();
117
		}
118

  
119
		FPoint2D[] points = readPoints(buffer, numPoints);
120

  
121
		/* if (m_type == FConstant.SHAPE_TYPE_POLYGONZ) {
122
		   //z
123
		   buffer.position(buffer.position() + (2 * 8));
124
		   for (int t = 0; t < numPoints; t++) {
125
		       points[t].z = buffer.getDouble();
126
		   }
127
		   }
128
		 */
129
		int offset = 0;
130
		int start;
131
		int finish;
132
		int length;
133

  
134
		for (int part = 0; part < numParts; part++) {
135
			start = partOffsets[part];
136

  
137
			if (part == (numParts - 1)) {
138
				finish = numPoints;
139
			} else {
140
				finish = partOffsets[part + 1];
141
			}
142

  
143
			length = finish - start;
144

  
145
			FPoint2D[] pointsPart = new FPoint2D[length];
146

  
147
			for (int i = 0; i < length; i++) {
148
				pointsPart[i] = points[offset++];
149
			}
150
		}
151

  
152
		return (IGeometry) new FPolygon2D(getGeneralPathX(points, partOffsets));
153
	}
154

  
155
	/**
156
	 * DOCUMENT ME!
157
	 *
158
	 * @param buffer
159
	 * @param numPoints
160
	 *
161
	 * @return
162
	 */
163
	private FPoint2D[] readPoints(final MappedByteBuffer buffer,
164
		final int numPoints) {
165
		FPoint2D[] points = new FPoint2D[numPoints];
166

  
167
		for (int t = 0; t < numPoints; t++) {
168
			points[t] = new FPoint2D(buffer.getDouble(), buffer.getDouble());
169
		}
170

  
171
		return points;
172
	}
173

  
174
	/**
175
	 * DOCUMENT ME!
176
	 *
177
	 * @param buffer DOCUMENT ME!
178
	 * @param geometry DOCUMENT ME!
179
	 */
180
	public void write(ByteBuffer buffer, IGeometry geometry) {
181
		//FPolygon2D polyLine;
182
		//polyLine = (FPolygon2D) geometry.getShape();
183
		Rectangle2D rec = geometry.getBounds2D();
184
		buffer.putDouble(rec.getMinX());
185
		buffer.putDouble(rec.getMinY());
186
		buffer.putDouble(rec.getMaxX());
187
		buffer.putDouble(rec.getMaxY());
188

  
189
		//////
190
		obtainsPoints(geometry.getGeneralPathXIterator());
191

  
192
		//int[] parts=polyLine.getParts();
193
		//FPoint2D[] points=polyLine.getPoints();
194
		int nparts = parts.length;
195
		int npoints = points.length;
196

  
197
		//////
198
		///int npoints = polyLine.getNumPoints();
199
		///int nparts = polyLine.getNumParts();
200
		buffer.putInt(nparts);
201
		buffer.putInt(npoints);
202

  
203
		int count = 0;
204

  
205
		for (int t = 0; t < nparts; t++) {
206
			///buffer.putInt(polyLine.getPart(t));
207
			buffer.putInt(parts[t]);
208
		}
209

  
210
		///FPoint[] points = polyLine.getPoints();
211
		for (int t = 0; t < points.length; t++) {
212
			///buffer.putDouble(points[t].x);
213
			///buffer.putDouble(points[t].y);
214
			buffer.putDouble(points[t].getX());
215
			buffer.putDouble(points[t].getY());
216
		}
217

  
218
		/*   if (m_type == FConstant.SHAPE_TYPE_POLYGONZ) {
219
		   double[] zExtreame = JTSUtilities.zMinMax(points);
220
		   if (Double.isNaN(zExtreame[0])) {
221
		       buffer.putDouble(0.0);
222
		       buffer.putDouble(0.0);
223
		   } else {
224
		       buffer.putDouble(zExtreame[0]);
225
		       buffer.putDouble(zExtreame[1]);
226
		   }
227
		   for (int t = 0; t < npoints; t++) {
228
		       double z = points[t].z;
229
		       if (Double.isNaN(z)) {
230
		           buffer.putDouble(0.0);
231
		       } else {
232
		           buffer.putDouble(z);
233
		       }
234
		   }
235
		   }
236
		 */
237
		if ((m_type == FConstant.SHAPE_TYPE_POLYGONM) ||
238
				(m_type == FConstant.SHAPE_TYPE_POLYGONZ)) {
239
			buffer.putDouble(-10E40);
240
			buffer.putDouble(-10E40);
241

  
242
			for (int t = 0; t < npoints; t++) {
243
				buffer.putDouble(-10E40);
244
			}
245
		}
246
	}
247

  
248
	/**
249
	 * @see com.iver.cit.gvsig.fmap.shp.SHPShape#getLength(com.iver.cit.gvsig.core.BasicShape.FGeometry)
250
	 */
251
	public int getLength(IGeometry fgeometry) {
252
		// FPolygon2D multi;
253
		//multi = (FPolygon2D) fgeometry.getShape();
254
		///int nrings = 0;
255
		obtainsPoints(fgeometry.getGeneralPathXIterator());
256

  
257
		//int[] parts=multi.getParts();
258
		//FPoint2D[] points;
259
		/////////
260
		//points = multi.getPoints();
261
		int npoints = points.length;
262

  
263
		///////////
264
		///nrings = multi.getNumParts();
265
		///int npoints = multi.getNumPoints();
266
		int length;
267

  
268
		if (m_type == FConstant.SHAPE_TYPE_POLYGONZ) {
269
			length = 44 + (4 * parts.length) + (16 * npoints) + (8 * npoints) +
270
				16 + (8 * npoints) + 16;
271
		} else if (m_type == FConstant.SHAPE_TYPE_POLYGONM) {
272
			length = 44 + (4 * parts.length) + (16 * npoints) + (8 * npoints) +
273
				16;
274
		} else if (m_type == FConstant.SHAPE_TYPE_POLYGON) {
275
			length = 44 + (4 * parts.length) + (16 * npoints);
276
		} else {
277
			throw new IllegalStateException(
278
				"Expected ShapeType of Polygon, got " + m_type);
279
		}
280

  
281
		return length;
282
	}
283
}
0 284

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/SHPPoint.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.shp.write;
42

  
43
import com.iver.cit.gvsig.fmap.core.FPoint2D;
44
import com.iver.cit.gvsig.fmap.core.GeneralPathXIterator;
45
import com.iver.cit.gvsig.fmap.core.IGeometry;
46
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
47

  
48
import java.nio.ByteBuffer;
49
import java.nio.MappedByteBuffer;
50

  
51

  
52
/**
53
 * DOCUMENT ME!
54
 *
55
 * @author Vicente Caballero Navarro
56
 */
57
public class SHPPoint implements SHPShape {
58
	private int m_type;
59
	private FPoint2D point;
60

  
61
	/**
62
	 * Crea un nuevo SHPPoint.
63
	 *
64
	 * @param type DOCUMENT ME!
65
	 *
66
	 * @throws ShapefileException DOCUMENT ME!
67
	 */
68
	public SHPPoint(int type) throws ShapefileException {
69
		if ((type != FConstant.SHAPE_TYPE_POINT) &&
70
				(type != FConstant.SHAPE_TYPE_POINTM) &&
71
				(type != FConstant.SHAPE_TYPE_POINTZ)) { // 2d, 2d+m, 3d+m
72
			throw new ShapefileException("No es un punto 1,11 ni 21");
73
		}
74

  
75
		m_type = type;
76
	}
77

  
78
	/**
79
	 * Crea un nuevo SHPPoint.
80
	 */
81
	public SHPPoint() {
82
		m_type = FConstant.SHAPE_TYPE_POINT; //2d
83
	}
84

  
85
	/**
86
	 * DOCUMENT ME!
87
	 *
88
	 * @return DOCUMENT ME!
89
	 */
90
	public int getShapeType() {
91
		return m_type;
92
	}
93

  
94
	/**
95
	 * DOCUMENT ME!
96
	 *
97
	 * @param buffer DOCUMENT ME!
98
	 * @param type DOCUMENT ME!
99
	 *
100
	 * @return DOCUMENT ME!
101
	 */
102
	public IGeometry read(MappedByteBuffer buffer, int type) {
103
		double x = buffer.getDouble();
104
		double y = buffer.getDouble();
105
		double z = Double.NaN;
106

  
107
		if (m_type == FConstant.SHAPE_TYPE_POINTM) {
108
			buffer.getDouble();
109
		}
110

  
111
		if (m_type == FConstant.SHAPE_TYPE_POINTZ) {
112
			z = buffer.getDouble();
113
		}
114

  
115
		return (IGeometry) new FPoint2D(x, y);
116
	}
117

  
118
	/**
119
	 * DOCUMENT ME!
120
	 *
121
	 * @param buffer DOCUMENT ME!
122
	 * @param geometry DOCUMENT ME!
123
	 */
124
	public void write(ByteBuffer buffer, IGeometry geometry) {
125
		//FPoint2D p2d = ((FPoint2D) geometry.getShape());
126
		obtainsPoints(geometry.getGeneralPathXIterator());
127
		buffer.putDouble(point.getX());
128
		buffer.putDouble(point.getY());
129

  
130
		/*  if (m_type == FConstant.SHAPE_TYPE_POINTZ) {
131
		   if (Double.isNaN(p2d.getZ())) { // nan means not defined
132
		       buffer.putDouble(0.0);
133
		   } else {
134
		       buffer.putDouble(p2d.getZ());
135
		   }
136
		   }
137
		   if ((m_type == FConstant.SHAPE_TYPE_POINTZ) ||
138
		           (m_type == FConstant.SHAPE_TYPE_POINTM)) {
139
		       buffer.putDouble(-10E40); //M
140
		   }
141
		 */
142
	}
143

  
144
	/**
145
	 * @see com.iver.cit.gvsig.fmap.shp.SHPShape#getLength(int)
146
	 */
147
	public int getLength(IGeometry fgeometry) {
148
		int length;
149

  
150
		if (m_type == FConstant.SHAPE_TYPE_POINT) {
151
			length = 20;
152
		} else if (m_type == FConstant.SHAPE_TYPE_POINTM) {
153
			length = 28;
154
		} else if (m_type == FConstant.SHAPE_TYPE_POINTZ) {
155
			length = 36;
156
		} else {
157
			throw new IllegalStateException("Expected ShapeType of Point, got" +
158
				m_type);
159
		}
160

  
161
		return length;
162
	}
163

  
164
	/**
165
	 * @see com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape#obtainsPoints(com.iver.cit.gvsig.fmap.core.GeneralPathXIterator)
166
	 */
167
	public void obtainsPoints(GeneralPathXIterator iter) {
168
		GeneralPathXIterator theIterator = iter; //polyLine.getPathIterator(null, flatness);
169
		double[] theData = new double[6];
170

  
171
		while (!theIterator.isDone()) {
172
			//while not done
173
			int theType = theIterator.currentSegment(theData);
174

  
175
			point = new FPoint2D(theData[0], theData[1]);
176

  
177
			theIterator.next();
178
		} //end while loop
179
	}
180
}
0 181

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/SHPFileWrite.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.shp.write;
42

  
43
import com.iver.cit.gvsig.fmap.core.IGeometry;
44
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
45
import com.iver.cit.gvsig.fmap.drivers.shp.ShapeFileHeader;
46

  
47
import java.awt.geom.Rectangle2D;
48

  
49
import java.io.IOException;
50

  
51
import java.nio.ByteBuffer;
52
import java.nio.ByteOrder;
53
import java.nio.channels.FileChannel;
54

  
55

  
56
/**
57
 * DOCUMENT ME!
58
 *
59
 * @author Vicente Caballero Navarro
60
 */
61
public class SHPFileWrite {
62
	private SHPShape m_shape = null;
63
	private ByteBuffer m_bb = null;
64
	private ByteBuffer m_indexBuffer = null;
65
	private int m_pos = 0;
66
	private int m_offset;
67
	private int m_type;
68
	private int m_cnt;
69
	private FileChannel shpChannel;
70
	private FileChannel shxChannel;
71

  
72
	/**
73
	 * Crea un nuevo SHPFileWrite.
74
	 *
75
	 * @param shpChannel DOCUMENT ME!
76
	 * @param shxChannel DOCUMENT ME!
77
	 */
78
	public SHPFileWrite(FileChannel shpChannel, FileChannel shxChannel) {
79
		this.shpChannel = shpChannel;
80
		this.shxChannel = shxChannel;
81
	}
82

  
83
	/**
84
	 * Make sure our buffer is of size.
85
	 *
86
	 * @param size DOCUMENT ME!
87
	 */
88
	private void checkShapeBuffer(int size) {
89
		if (m_bb.capacity() < size) {
90
			m_bb = ByteBuffer.allocateDirect(size);
91
		}
92
	}
93

  
94
	/**
95
	 * Drain internal buffers into underlying channels.
96
	 *
97
	 * @throws IOException DOCUMENT ME!
98
	 */
99
	private void drain() throws IOException {
100
		m_bb.flip();
101
		m_indexBuffer.flip();
102

  
103
		while (m_bb.remaining() > 0)
104
			shpChannel.write(m_bb);
105

  
106
		while (m_indexBuffer.remaining() > 0)
107
			shxChannel.write(m_indexBuffer);
108

  
109
		m_bb.flip().limit(m_bb.capacity());
110
		m_indexBuffer.flip().limit(m_indexBuffer.capacity());
111
	}
112

  
113
	/**
114
	 * DOCUMENT ME!
115
	 */
116
	private void allocateBuffers() {
117
		m_bb = ByteBuffer.allocateDirect(16 * 1024);
118
		m_indexBuffer = ByteBuffer.allocateDirect(100);
119
	}
120

  
121
	/**
122
	 * Close the underlying Channels.
123
	 *
124
	 * @throws IOException DOCUMENT ME!
125
	 */
126
	public void close() throws IOException {
127
		shpChannel.close();
128
		shxChannel.close();
129
		shpChannel = null;
130
		shxChannel = null;
131
		m_shape = null;
132

  
133
		if (m_indexBuffer instanceof ByteBuffer) {
134
			if (m_indexBuffer != null) {
135
				///NIOUtilities.clean(m_indexBuffer);
136
			}
137
		}
138

  
139
		if (m_indexBuffer instanceof ByteBuffer) {
140
			if (m_indexBuffer != null) {
141
				///NIOUtilities.clean(m_bb);
142
			}
143
		}
144

  
145
		m_indexBuffer = null;
146
		m_bb = null;
147
	}
148

  
149
	/**
150
	 * DOCUMENT ME!
151
	 *
152
	 * @param geometries DOCUMENT ME!
153
	 * @param type DOCUMENT ME!
154
	 *
155
	 * @throws IOException DOCUMENT ME!
156
	 * @throws ShapefileException DOCUMENT ME!
157
	 */
158
	public void write(IGeometry[] geometries, int type)
159
		throws IOException, ShapefileException {
160
		m_shape = SHP.create(type);
161

  
162
		writeHeaders(geometries, type);
163

  
164
		m_pos = m_bb.position();
165

  
166
		for (int i = 0, ii = geometries.length; i < ii; i++) {
167
			writeGeometry(geometries[i]);
168
		}
169

  
170
		close();
171
	}
172

  
173
	/**
174
	 * DOCUMENT ME!
175
	 *
176
	 * @param geometries DOCUMENT ME!
177
	 * @param type DOCUMENT ME!
178
	 *
179
	 * @throws IOException DOCUMENT ME!
180
	 */
181
	private void writeHeaders(IGeometry[] geometries, int type)
182
		throws IOException {
183
		int fileLength = 100;
184
		Rectangle2D extent = null;
185

  
186
		for (int i = geometries.length - 1; i >= 0; i--) {
187
			IGeometry fgeometry = geometries[i];
188
			int size = m_shape.getLength(fgeometry) + 8;
189
			fileLength += size;
190

  
191
			if (extent == null) {
192
				extent = new Rectangle2D.Double(fgeometry.getBounds2D().getMinX(),
193
						fgeometry.getBounds2D().getMinY(),
194
						fgeometry.getBounds2D().getWidth(),
195
						fgeometry.getBounds2D().getHeight());
196
			} else {
197
				extent.add(fgeometry.getBounds2D());
198
			}
199
		}
200

  
201
		writeHeaders(extent, type, geometries.length, fileLength);
202
	}
203

  
204
	/**
205
	 * DOCUMENT ME!
206
	 *
207
	 * @param bounds DOCUMENT ME!
208
	 * @param type DOCUMENT ME!
209
	 * @param numberOfGeometries DOCUMENT ME!
210
	 * @param fileLength DOCUMENT ME!
211
	 *
212
	 * @throws IOException DOCUMENT ME!
213
	 */
214
	public void writeHeaders(Rectangle2D bounds, int type,
215
		int numberOfGeometries, int fileLength) throws IOException {
216
		/*try {
217
		   handler = type.getShapeHandler();
218
		   } catch (ShapefileException se) {
219
		     throw new RuntimeException("unexpected Exception",se);
220
		   }
221
		 */
222
		if (m_bb == null) {
223
			allocateBuffers();
224
		}
225

  
226
		ShapeFileHeader header = new ShapeFileHeader();
227

  
228
		header.write(m_bb, type, numberOfGeometries, fileLength / 2,
229
			bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(),
230
			bounds.getMaxY(), 0, 0, 0, 0);
231

  
232
		header.write(m_indexBuffer, type, numberOfGeometries,
233
			50 + (4 * numberOfGeometries), bounds.getMinX(), bounds.getMinY(),
234
			bounds.getMaxX(), bounds.getMaxY(), 0, 0, 0, 0);
235

  
236
		m_offset = 50;
237
		m_type = type;
238
		m_cnt = 0;
239

  
240
		shpChannel.position(0);
241
		shxChannel.position(0);
242
		drain();
243
	}
244

  
245
	/**
246
	 * DOCUMENT ME!
247
	 *
248
	 * @param g DOCUMENT ME!
249
	 *
250
	 * @throws IOException DOCUMENT ME!
251
	 */
252
	public void writeGeometry(IGeometry g) throws IOException {
253
		if (m_bb == null) {
254
			throw new IOException("Must write headers first");
255
		}
256

  
257
		m_pos = m_bb.position();
258

  
259
		int length = m_shape.getLength(g);
260

  
261
		// must allocate enough for shape + header (2 ints)
262
		checkShapeBuffer(length + 8);
263

  
264
		length /= 2;
265

  
266
		m_bb.order(ByteOrder.BIG_ENDIAN);
267
		m_bb.putInt(++m_cnt);
268
		m_bb.putInt(length);
269
		m_bb.order(ByteOrder.LITTLE_ENDIAN);
270
		m_bb.putInt(m_type);
271
		m_shape.write(m_bb, g);
272

  
273
		///assert (length * 2 == (m_bb.position() - m_pos) - 8);
274
		m_pos = m_bb.position();
275

  
276
		// write to the shx
277
		m_indexBuffer.putInt(m_offset);
278
		m_indexBuffer.putInt(length);
279
		m_offset += (length + 4);
280
		drain();
281

  
282
		///assert(m_bb.position() == 0);
283
	}
284
}
0 285

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/DBFFromSelected.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.shp.write;
42

  
43
import com.iver.cit.gvsig.fmap.core.IGeometry;
44
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileHeaderNIO;
45
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO;
46
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
47

  
48
import java.io.File;
49
import java.io.IOException;
50
import java.io.OutputStream;
51
import java.io.RandomAccessFile;
52

  
53
import java.net.MalformedURLException;
54
import java.net.URL;
55

  
56
import java.nio.channels.Channels;
57
import java.nio.channels.FileChannel;
58
import java.nio.channels.WritableByteChannel;
59

  
60

  
61
/**
62
 * Visitor de zoom a lo seleccionado.
63
 *
64
 * @author Vicente Caballero Navarro
65
 */
66
public class DBFFromSelected {
67
	private IGeometry[] fgs = null;
68
	private boolean hasdbf = false;
69
	private URL dbfURL = null;
70
	private int temp = 0;
71
	private DbaseFileWriterNIO dbfWrite;
72
	private Integer[] enteros;
73
	private SelectableDataSource sds;
74
	private Object[] record;
75

  
76
	//private DbaseFileNIO m_FichDbf = new DbaseFileNIO();
77

  
78
	/**
79
	 * Inserta el fichero.
80
	 *
81
	 * @param f Fichero.
82
	 */
83
	public void setFile(File f) {
84
		try {
85
			String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf");
86
			strFichDbf = strFichDbf.replaceAll("\\.SHP", ".DBF");
87
			dbfURL = new URL("file://" + strFichDbf);
88
		} catch (MalformedURLException e) {
89
			e.printStackTrace();
90
		}
91
	}
92

  
93
	/**
94
	 * Inserta true si se quiere crear el dbf vacio y no copiar el contenido de otro dbf.
95
	 *
96
	 * @param b True si se quiere crear vacio el dbf.
97
	 */
98
	public void setIsNewDBF(boolean b) {
99
		hasdbf = b;
100
	}
101

  
102
	/**
103
	 * Inserta las geometr?as.
104
	 *
105
	 * @param g Geometr?as.
106
	 */
107
	public void setGeometries(IGeometry[] g) {
108
		fgs = g;
109
	}
110

  
111
	/**
112
	 * Inicializa.
113
	 *
114
	 * @param sds Capa.
115
	 */
116
	public void start(SelectableDataSource sds) {
117
		//if (layer instanceof AlphanumericData) {
118
		try {
119
			this.sds = sds;
120

  
121
			if (!hasdbf) {
122
				DbaseFileHeaderNIO myHeader = DbaseFileHeaderNIO.createNewDbaseHeader();
123
				myHeader.setNumRecords(fgs.length);
124
				dbfWrite = new DbaseFileWriterNIO(myHeader,
125
						(FileChannel) getWriteChannel(getStorageURL(dbfURL)));
126
				enteros = new Integer[1];
127
			} else {
128
				//VectorialFileAdapter vfa=(VectorialFileAdapter)((SingleLayer)lv).getSource();
129
				DbaseFileHeaderNIO myHeader;
130

  
131
				myHeader = DbaseFileHeaderNIO.createDbaseHeader(sds);
132

  
133
				myHeader.setNumRecords(fgs.length);
134
				dbfWrite = new DbaseFileWriterNIO(myHeader,
135
						(FileChannel) getWriteChannel(getStorageURL(dbfURL)));
136
				record = new Object[sds.getFieldCount()];
137
			}
138
		} catch (IOException e) {
139
			e.printStackTrace();
140

  
141
			///} catch (DriverException e1) {
142
			//	e1.printStackTrace();
143
		} catch (com.hardcode.gdbms.engine.data.DriverException e2) {
144
			e2.printStackTrace();
145
		}
146

  
147
		//return true;
148
		//}
149
		//return false;
150
	}
151

  
152
	/**
153
	 * Finaliza.
154
	 */
155
	public void stop() {
156
		System.out.println("Acabado el DBF con NIO escritura");
157
	}
158

  
159
	/**
160
	 * Rellena los registros del dbf.
161
	 */
162
	public void createdbfRow() {
163
		for (int i = 0; i < fgs.length; i++) {
164
			try {
165
				if (!hasdbf) {
166
					enteros[0] = Integer.valueOf(String.valueOf(i));
167
					dbfWrite.write(enteros);
168
				} else {
169
					for (int r = 0; r < sds.getFieldCount(); r++) {
170
						record[r] = sds.getFieldValue(i, r);
171
					}
172

  
173
					dbfWrite.write(record);
174
				}
175
			} catch (com.hardcode.gdbms.engine.data.DriverException e) {
176
				e.printStackTrace();
177
			} catch (IOException e1) {
178
				e1.printStackTrace();
179
			}
180
		}
181
	}
182

  
183
	
184
	protected URL getStorageURL(URL url) throws java.net.MalformedURLException {
185
		return (temp == 0) ? url : getStorageFile(url).toURL();
186
	}
187

  
188
	protected File getStorageFile(URL url) {
189
		String f = url.getFile();
190
		f = temp + f.substring(f.lastIndexOf("/") + 1);
191

  
192
		File tf = new File(System.getProperty("java.io.tmpdir"), f);
193

  
194
		return tf;
195
	}
196

  
197
	private WritableByteChannel getWriteChannel(URL url)
198
		throws IOException {
199
		WritableByteChannel channel;
200

  
201
		if (url.getProtocol().equals("file")) {
202
			File f = new File(url.getFile());
203

  
204
			if (!f.exists() && !f.createNewFile()) {
205
				throw new IOException("Cannot create file " + f);
206
			}
207

  
208
			RandomAccessFile raf = new RandomAccessFile(f, "rw");
209
			channel = raf.getChannel();
210
		} else {
211
			OutputStream out = url.openConnection().getOutputStream();
212
			channel = Channels.newChannel(out);
213
		}
214

  
215
		return channel;
216
	}
217
}
0 218

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/SHPSHXFromSelectedVisitor.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.shp.write;
42

  
43
import com.iver.cit.gvsig.fmap.core.FShape;
44
import com.iver.cit.gvsig.fmap.core.IGeometry;
45
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
46
import com.iver.cit.gvsig.fmap.layers.FBitSet;
47
import com.iver.cit.gvsig.fmap.layers.FLayer;
48
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
49
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
50
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
51
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
52
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
53

  
54
import java.io.File;
55
import java.io.IOException;
56
import java.io.OutputStream;
57
import java.io.RandomAccessFile;
58

  
59
import java.net.MalformedURLException;
60
import java.net.URL;
61

  
62
import java.nio.channels.Channels;
63
import java.nio.channels.FileChannel;
64
import java.nio.channels.WritableByteChannel;
65

  
66

  
67
/**
68
 * Visitor de creaci?n de un shape de los elementos seleccionados.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class SHPSHXFromSelectedVisitor implements FeatureVisitor {
73
	private IGeometry[] fgs = null;
74
	private SelectableDataSource sds = null;
75
	private URL shpURL = null;
76
	private URL shxURL = null;
77
	private int temp = 0;
78
	private int type;
79
	private FBitSet bitset = null;
80
	private int num = 0;
81

  
82
	/**
83
	 * DOCUMENT ME!
84
	 *
85
	 * @param f DOCUMENT ME!
86
	 */
87
	public void setFile(File f) {
88
		try {
89
			shpURL = f.toURL();
90

  
91
			String strFichshx = f.getAbsolutePath().replaceAll("\\.shp", ".shx");
92
			strFichshx = strFichshx.replaceAll("\\.SHP", ".SHX");
93
			shxURL = new URL("file://" + strFichshx);
94
		} catch (MalformedURLException e) {
95
			e.printStackTrace();
96
		}
97
	}
98

  
99
	/**
100
	 * DOCUMENT ME!
101
	 *
102
	 * @param layer DOCUMENT ME!
103
	 *
104
	 * @return DOCUMENT ME!
105
	 */
106

  
107
	/*public void setType(int i) {
108
	   type = i;
109
	   }
110
	 */
111

  
112
	/**
113
	 * Inicializa el visitor.
114
	 *
115
	 * @param layer Capa.
116
	 *
117
	 * @return True si se inicializa correctamente.
118
	 */
119
	public boolean start(FLayer layer) {
120
		if (layer instanceof AlphanumericData && layer instanceof Selectable) {
121
			try {
122
				sds = ((AlphanumericData) layer).getRecordset();
123
				bitset = ((Selectable) layer).getSelection();
124

  
125
				///fgs = new IGeometry[(int) sds.getRowCount()];
126
				fgs = new IGeometry[bitset.cardinality()];
127

  
128
				///} catch (DriverException e) {
129
				///	e.printStackTrace();
130
			} catch (com.iver.cit.gvsig.fmap.DriverException e) {
131
				e.printStackTrace();
132
			}
133

  
134
			return true;
135
		}
136

  
137
		return false;
138
	}
139

  
140
	/**
141
	 * Finaliza el visitor.
142
	 *
143
	 * @param layer Capa.
144
	 */
145
	public void stop(FLayer layer) {
146
		SHPFileWrite filewrite;
147

  
148
		try {
149
			filewrite = new SHPFileWrite((FileChannel) getWriteChannel(
150
						getStorageURL(shpURL)),
151
					(FileChannel) getWriteChannel(getStorageURL(shxURL)));
152

  
153
			if (fgs.length > 0) {
154
				type = getTypeShape(fgs[0].getGeometryType());
155
				filewrite.write(fgs, type);
156
			}
157
		} catch (ShapefileException e1) {
158
			e1.printStackTrace();
159
		} catch (MalformedURLException e) {
160
			e.printStackTrace();
161
		} catch (IOException e) {
162
			e.printStackTrace();
163
		}
164

  
165
		System.out.println("Acabado SHP y SHX");
166
	}
167

  
168
	/**
169
	 * @see com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor#visit(com.iver.cit.gvsig.fmap.core.IGeometry,
170
	 * 		int)
171
	 */
172
	public void visit(IGeometry g, int index) throws VisitException {
173
		if (bitset.get(index)) {
174
			fgs[num] = g;
175
			num++;
176
		}
177
	}
178

  
179
	/**
180
	 * DOCUMENT ME!
181
	 *
182
	 * @param url DOCUMENT ME!
183
	 *
184
	 * @return DOCUMENT ME!
185
	 *
186
	 * @throws java.net.MalformedURLException DOCUMENT ME!
187
	 */
188
	protected URL getStorageURL(URL url) throws java.net.MalformedURLException {
189
		return (temp == 0) ? url : getStorageFile(url).toURL();
190
	}
191

  
192
	/**
193
	 * DOCUMENT ME!
194
	 *
195
	 * @param url DOCUMENT ME!
196
	 *
197
	 * @return DOCUMENT ME!
198
	 *
199
	 * @throws IOException DOCUMENT ME!
200
	 */
201
	private WritableByteChannel getWriteChannel(URL url)
202
		throws IOException {
203
		WritableByteChannel channel;
204

  
205
		if (url.getProtocol().equals("file")) {
206
			File f = new File(url.getFile());
207

  
208
			if (!f.exists() && !f.createNewFile()) {
209
				throw new IOException("Cannot create file " + f);
210
			}
211

  
212
			RandomAccessFile raf = new RandomAccessFile(f, "rw");
213
			channel = raf.getChannel();
214
		} else {
215
			OutputStream out = url.openConnection().getOutputStream();
216
			channel = Channels.newChannel(out);
217
		}
218

  
219
		return channel;
220
	}
221

  
222
	/**
223
	 * DOCUMENT ME!
224
	 *
225
	 * @param url DOCUMENT ME!
226
	 *
227
	 * @return DOCUMENT ME!
228
	 */
229
	protected File getStorageFile(URL url) {
230
		String f = url.getFile();
231
		f = temp + f.substring(f.lastIndexOf("/") + 1);
232

  
233
		File tf = new File(System.getProperty("java.io.tmpdir"), f);
234

  
235
		return tf;
236
	}
237

  
238
	/**
239
	 * DOCUMENT ME!
240
	 *
241
	 * @return DOCUMENT ME!
242
	 */
243
	public IGeometry[] getGeometries() {
244
		return fgs;
245
	}
246

  
247
	/**
248
	 * DOCUMENT ME!
249
	 *
250
	 * @param geometryType DOCUMENT ME!
251
	 *
252
	 * @return DOCUMENT ME!
253
	 */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff