Revision 20660

View differences:

trunk/libraries/libFMap_dataFile/src-test/org/gvsig/data/datastores/vectorial/file/shp/SHPTest.java
8 8
import org.gvsig.data.DataManager;
9 9
import org.gvsig.data.IDataStoreParameters;
10 10
import org.gvsig.data.datastores.vectorial.file.DataStoreTest;
11
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore;
12
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStoreParameters;
11 13
import org.gvsig.data.datastores.vectorial.file.shp.Register;
12 14
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore;
13 15
import org.gvsig.data.datastores.vectorial.file.shp.SHPStoreParameters;
......
117 119
		}
118 120

  
119 121
	}
122

  
123
	public void test_Resources(){
124

  
125
		DataManager manager = DataManager.getManager();
126
		Register.selfRegister();
127

  
128
		SHPStoreParameters shpParameters;
129

  
130
		shpParameters=(SHPStoreParameters)manager.createDataStoreParameters(SHPStore.DATASTORE_NAME);
131
		shpParameters.setFile(fileNormal);
132

  
133
		try {
134
			DataStoreTest.doFileResourceTest(shpParameters);
135
		} catch (Exception e) {
136
			e.printStackTrace();fail();
137
		}
138
	}
139

  
120 140
}
trunk/libraries/libFMap_dataFile/src-test/org/gvsig/data/datastores/vectorial/file/dbf/DBFTest.java
112 112
		DataManager manager = DataManager.getManager();
113 113
		Register.selfRegister();
114 114

  
115
		ResourceManager resMan = ResourceManager.getResourceManager();
116

  
117
		DBFStore store=null;
118
		DBFStore store2=null;
119
		DBFStore store3=null;
120 115
		DBFStoreParameters dbfParameters;
121 116

  
122 117
		dbfParameters=(DBFStoreParameters)manager.createDataStoreParameters(DBFStore.DATASTORE_NAME);
123 118
		dbfParameters.setFile(file);
124 119

  
125 120
		try {
126
			store = (DBFStore)manager.createDataStore(dbfParameters);
127
			store2 = (DBFStore)manager.createDataStore(dbfParameters);
128
			store3 = (DBFStore)manager.createDataStore(dbfParameters);
129
		} catch (InitializeException e) {
121
			DataStoreTest.doFileResourceTest(dbfParameters);
122
		} catch (Exception e) {
130 123
			e.printStackTrace();fail();
131 124
		}
132

  
133
		int i=0;
134
		Resource res = null;
135
		Object obj = null;
136

  
137
		Iterator iter = resMan.iterator();
138
		while (iter.hasNext()){
139
			obj = iter.next();
140
			if (obj instanceof DBFResource){
141
				i++;
142
				res = (Resource)obj;
143
			}
144
		}
145

  
146
		assertEquals(1, i);
147

  
148
		assertEquals(3, res.getRefencesCount());
149

  
150
		try {
151
			store.close();
152
		} catch (CloseException e) {
153
			e.printStackTrace();fail();
154
		}
155

  
156
		assertEquals(false, res.isOpen());
157

  
158
		IDataCollection coll = null;
159

  
160
		try {
161
			coll =store.getDataCollection();
162
		} catch (ReadException e) {
163
			e.printStackTrace();fail();
164
		}
165
		assertEquals(true, res.isOpen());
166

  
167
		coll.dispose();
168

  
169
		try {
170
			store3.dispose();
171
		} catch (CloseException e) {
172
			e.printStackTrace();fail();
173
		}
174

  
175
		assertEquals(2, res.getRefencesCount());
176

  
177
		try {
178
			store2.dispose();
179
		} catch (CloseException e) {
180
			e.printStackTrace();fail();
181
		}
182

  
183
		assertEquals(1, res.getRefencesCount());
184

  
185
		try {
186
			store.dispose();
187
		} catch (CloseException e) {
188
			e.printStackTrace();fail();
189
		}
190

  
191
		assertEquals(0, res.getRefencesCount());
192
		res = null;
193

  
194
		i=0;
195
		iter = resMan.iterator();
196
		while (iter.hasNext()){
197
			obj = iter.next();
198
			if (obj instanceof DBFResource){
199
				i++;
200
				res = (Resource)obj;
201
			}
202
		}
203

  
204
		assertEquals(0, i);
205

  
206 125
	}
207 126
}
trunk/libraries/libFMap_dataFile/src-test/org/gvsig/data/datastores/vectorial/file/DataStoreTest.java
7 7

  
8 8
import org.cresques.cts.IProjection;
9 9
import org.gvsig.data.DataManager;
10
import org.gvsig.data.IDataCollection;
10 11
import org.gvsig.data.IDataStoreParameters;
11
import org.gvsig.data.commands.ICommandsRecord;
12
import org.gvsig.data.Resource;
13
import org.gvsig.data.ResourceManager;
14
import org.gvsig.data.datastores.vectorial.file.dbf.DBFResource;
12 15
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore;
13 16
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStoreParameters;
14 17
import org.gvsig.data.datastores.vectorial.file.dgn.DGNStore;
......
17 20
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStoreParameters;
18 21
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore;
19 22
import org.gvsig.data.datastores.vectorial.file.shp.SHPStoreParameters;
20
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP;
21 23
import org.gvsig.data.exception.CloseException;
22 24
import org.gvsig.data.exception.DataException;
23 25
import org.gvsig.data.exception.InitializeException;
......
25 27
import org.gvsig.data.exception.ReadException;
26 28
import org.gvsig.data.exception.WriteException;
27 29
import org.gvsig.data.vectorial.AttributeDescriptor;
28
import org.gvsig.data.vectorial.FeatureType;
30
import org.gvsig.data.vectorial.FeatureStore;
29 31
import org.gvsig.data.vectorial.IFeature;
30 32
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
31 33
import org.gvsig.data.vectorial.IFeatureCollection;
32 34
import org.gvsig.data.vectorial.IFeatureStore;
33 35
import org.gvsig.data.vectorial.IFeatureType;
34 36
import org.gvsig.data.vectorial.IsNotAttributeSettingException;
35
import org.gvsig.data.vectorial.IsNotFeatureSettingException;
36 37
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor;
37 38
import org.gvsig.exceptions.BaseException;
38 39

  
......
1091 1092
			e.printStackTrace();
1092 1093
		}
1093 1094
	}
1095

  
1096
	public static void doFileResourceTest(IFileStoreParameters params) throws Exception{
1097
		DataManager manager = DataManager.getManager();
1098

  
1099
		ResourceManager resMan = ResourceManager.getResourceManager();
1100

  
1101
		FeatureStore store=null;
1102
		FeatureStore store2=null;
1103
		FeatureStore store3=null;
1104
		store = (FeatureStore)manager.createDataStore(params);
1105
		store2 = (FeatureStore)manager.createDataStore(params);
1106
		store3 = (FeatureStore)manager.createDataStore(params);
1107

  
1108
		int i=0;
1109
		Resource res = null;
1110
		Object obj = null;
1111

  
1112
		Iterator iter = resMan.iterator();
1113
		while (iter.hasNext()){
1114
			obj = iter.next();
1115
			if (obj instanceof IFileResource){
1116
				res = (Resource)obj;
1117
				if (((IFileResource)res).getFile().getAbsoluteFile().equals(params.getFile().getAbsoluteFile())){
1118
					i++;
1119
				}
1120
			}
1121
		}
1122

  
1123
		assertEquals(1, i);
1124

  
1125
		assertEquals(3, res.getRefencesCount());
1126

  
1127
		store.close();
1128

  
1129
		assertEquals(false, res.isOpen());
1130

  
1131
		IDataCollection coll = null;
1132

  
1133
		coll =store.getDataCollection();
1134

  
1135
		coll.iterator().next();
1136

  
1137
		assertEquals(true, res.isOpen());
1138

  
1139
		coll.dispose();
1140

  
1141
		store3.dispose();
1142

  
1143
		assertEquals(2, res.getRefencesCount());
1144

  
1145
		store2.dispose();
1146

  
1147
		assertEquals(1, res.getRefencesCount());
1148

  
1149
		store.dispose();
1150

  
1151
		assertEquals(0, res.getRefencesCount());
1152
		res = null;
1153

  
1154
		i=0;
1155
		iter = resMan.iterator();
1156
		while (iter.hasNext()){
1157
			obj = iter.next();
1158
			if (obj instanceof IFileResource){
1159
				res = (Resource)obj;
1160
				if (((IFileResource)res).getFile().getAbsoluteFile().equals(params.getFile().getAbsoluteFile())){
1161
					i++;
1162
				}
1163
			}
1164
		}
1165

  
1166
		assertEquals(0, i);
1167

  
1168

  
1169
	}
1094 1170
}
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/base/MemoryStore.java
49 49
import java.util.ArrayList;
50 50

  
51 51
import org.gvsig.data.exception.CloseException;
52
import org.gvsig.data.exception.ReadException;
52 53
import org.gvsig.data.spatialprovisional.IExtent;
53 54
import org.gvsig.data.vectorial.FeatureStore;
54 55
import org.gvsig.data.vectorial.IFeature;
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/IFileResource.java
32 32

  
33 33
import java.io.File;
34 34

  
35
import org.gvsig.data.exception.OpenException;
36

  
35 37
/**
36 38
 * @author jmvivo
37 39
 *
38 40
 */
39 41
public interface IFileResource {
40 42
	public File getFile();
43

  
44
	/**
45
	 *
46
	 * @return number of real files used by this resource
47
	 */
48
	public int getTotalFiles();
41 49
}
42 50

  
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dxf/DXFStore.java
1003 1003
		}
1004 1004
		return src;
1005 1005
	}
1006

  
1007
	/* (non-Javadoc)
1008
	 * @see org.gvsig.data.vectorial.FeatureStore#doRefresh()
1009
	 */
1010
	protected void doRefresh() throws OpenException, InitializeException {
1011
		// TODO Auto-generated method stub
1012

  
1013
	}
1006 1014
}
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/FileResource.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.data.datastores.vectorial.file;
32

  
33
import java.io.File;
34

  
35
import org.gvsig.data.Resource;
36
import org.gvsig.data.exception.CloseException;
37
import org.gvsig.data.exception.DataException;
38
import org.gvsig.data.exception.InitializeException;
39
import org.gvsig.data.exception.OpenException;
40
import org.gvsig.data.exception.ResourceChangedException;
41

  
42
/**
43
 * @author jmvivo
44
 *
45
 */
46
public abstract class FileResource extends Resource implements IFileResource {
47

  
48
	protected File file;
49
	private long fileLastModified=0;
50
	private boolean opened;
51

  
52
	public FileResource(File aFile){
53
		this.file = aFile;
54
	}
55

  
56
	public void setFile(File aFile) throws InitializeException{
57
		if (this.getRefencesCount() > 0){
58
			throw new InitializeException("Resource in use",this.description());
59
		}
60
		this.file=aFile;
61
	}
62

  
63
	public File getFile(){
64
		return this.file;
65
	}
66

  
67
	/* (non-Javadoc)
68
	 * @see org.gvsig.data.Resource#isOpen()
69
	 */
70
	public boolean isOpen() {
71
		return this.opened;
72
	}
73

  
74
	/* (non-Javadoc)
75
	 * @see org.gvsig.data.Resource#doChanged()
76
	 */
77
	protected void doChanged() {
78
		this.updateLastModified();
79
	}
80

  
81
	protected void updateLastModified(){
82
		this.fileLastModified = this.file.lastModified();
83
	}
84

  
85
	protected void checkChanged() throws ResourceChangedException{
86
		if (this.fileLastModified == 0){
87
			return;
88
		}
89
		if (this.fileLastModified < this.file.lastModified()){
90
			this.changed();
91
			throw new ResourceChangedException(this.description());
92
		}
93
	}
94

  
95
	protected void setOpened(){
96
		this.opened=true;
97
	}
98

  
99
	/* (non-Javadoc)
100
	 * @see org.gvsig.data.Resource#doDispose()
101
	 */
102
	protected void doDispose() throws DataException{
103
		this.file = null;
104
	}
105

  
106
	/* (non-Javadoc)
107
	 * @see org.gvsig.data.Resource#doClose()
108
	 */
109
	protected boolean doClose() throws CloseException{
110
		this.opened= false;
111
		return true;
112
	}
113

  
114

  
115
	protected synchronized void checkOpen() throws OpenException{
116
		if (!this.isOpen()){
117
			this.open();
118
		}
119

  
120
	}
121

  
122
}
123

  
0 124

  
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dgn/DGNStore.java
928 928
		this.addFeature(new DGNFeature(feature));
929 929
	}
930 930

  
931
	/* (non-Javadoc)
932
	 * @see org.gvsig.data.vectorial.FeatureStore#doRefresh()
933
	 */
934
	protected void doRefresh() throws OpenException, InitializeException {
935
		// TODO Auto-generated method stub
936
	}
937

  
931 938
}
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/shp/SHPResource.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.data.datastores.vectorial.file.shp;
32

  
33
import java.awt.geom.Point2D;
34
import java.io.File;
35
import java.io.FileInputStream;
36
import java.io.FileNotFoundException;
37
import java.io.IOException;
38
import java.nio.ByteOrder;
39
import java.nio.channels.FileChannel;
40

  
41
import org.gvsig.data.datastores.vectorial.file.FileResource;
42
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP;
43
import org.gvsig.data.datastores.vectorial.file.shp.utils.ShapeFileHeader2;
44
import org.gvsig.data.exception.CloseException;
45
import org.gvsig.data.exception.OpenException;
46
import org.gvsig.data.exception.ReadException;
47
import org.gvsig.data.spatialprovisional.Extent;
48
import org.gvsig.data.spatialprovisional.IExtent;
49

  
50
import com.iver.cit.gvsig.fmap.core.FNullGeometry;
51
import com.iver.cit.gvsig.fmap.core.FShape;
52
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
53
import com.iver.cit.gvsig.fmap.core.IGeometry;
54
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
55
import com.iver.utiles.bigfile.BigByteBuffer2;
56

  
57
/**
58
 * @author jmvivo
59
 *
60
 */
61
public class SHPResource extends FileResource {
62
	private boolean firstOpen = true;
63

  
64
	private Extent extent;
65
	private int type;
66

  
67
	private SHPStoreParameters params;
68
	private FileInputStream fin;
69
	private FileChannel channel;
70
	private BigByteBuffer2 bb;
71
	private File fileShx;
72
	private FileInputStream finShx;
73
	private FileChannel channelShx;
74
	private BigByteBuffer2 bbShx;
75

  
76

  
77

  
78
	SHPResource (SHPStoreParameters params){
79
		super(params.getSHPFile());
80
		this.params = params;
81
		this.fileShx = params.getSHXFile();
82
	}
83

  
84
	/* (non-Javadoc)
85
	 * @see org.gvsig.data.Resource#description()
86
	 */
87
	public String description() {
88
		if (this.getFile()!= null){
89
			return "SHP File resource: " + this.getFile().getAbsolutePath();
90
		} else{
91
			return "SHP File resource: {No file}";
92
		}
93
	}
94

  
95
	/* (non-Javadoc)
96
	 * @see org.gvsig.data.Resource#getKey()
97
	 */
98
	public String getKey() {
99
		return "SHP:"+this.getFile().getAbsolutePath();
100
	}
101

  
102
	/* (non-Javadoc)
103
	 * @see org.gvsig.data.datastores.vectorial.file.IFileResource#getTotalFiles()
104
	 */
105
	public int getTotalFiles() {
106
		return 2;
107
	}
108

  
109

  
110

  
111

  
112
	/* (non-Javadoc)
113
	 * @see org.gvsig.data.Resource#doOpen()
114
	 */
115
	protected boolean doOpen() throws OpenException {
116
		if (this.firstOpen){
117
			this.updateLastModified();
118
		} else{
119
			this.checkChanged();
120
		}
121
		this.openShp();
122
		this.setOpened();
123
		return true;
124
	}
125

  
126
	/* (non-Javadoc)
127
	 * @see org.gvsig.data.Resource#doClose()
128
	 */
129
	protected boolean doClose() throws CloseException{
130
		CloseException ret = null;
131

  
132
		try {
133
			channel.close();
134
			channelShx.close();
135
		} catch (IOException e) {
136
			ret = new CloseException(this.description(),e);
137
		} finally {
138
			try {
139
				fin.close();
140
				finShx.close();
141
			} catch (IOException e1) {
142
				ret = new CloseException(this.description(),e1);
143
			}
144
		}
145

  
146
		if (ret != null) {
147
			throw ret;
148
		}
149
		bb = null;
150
		bbShx = null;
151

  
152

  
153
		return super.doClose();
154
	}
155

  
156

  
157

  
158
	private void openShp() throws OpenException{
159
		try {
160
			fin = new FileInputStream(this.getFile());
161

  
162

  
163
			// Open the file and then get a channel from the stream
164
			channel = fin.getChannel();
165

  
166
			// long size = channel.size();
167

  
168
			// Get the file's size and then map it into memory
169
			// bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
170
			bb = new BigByteBuffer2(channel, FileChannel.MapMode.READ_ONLY);
171
			finShx = new FileInputStream(this.fileShx);
172

  
173
			// Open the file and then get a channel from the stream
174
			channelShx = finShx.getChannel();
175

  
176
//			long sizeShx = channelShx.size();
177

  
178
			// Get the file's size and then map it into memory
179
			// bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
180
			// bbShx = channelShx.map(FileChannel.MapMode.READ_ONLY, 0, sizeShx);
181
			bbShx = new BigByteBuffer2(channelShx, FileChannel.MapMode.READ_ONLY);
182
			bbShx.order(ByteOrder.BIG_ENDIAN);
183

  
184

  
185
//			create a new header.
186
			ShapeFileHeader2 myHeader = new ShapeFileHeader2();
187

  
188
			bb.position(0);
189

  
190
			// read the header
191
			myHeader.readHeader(bb);
192

  
193
			extent = new Extent(myHeader.myXmin, myHeader.myYmin,myHeader.myXmax,myHeader.myYmax);
194
//			extent = new Rectangle2D.Double(myHeader.myXmin, myHeader.myYmin,
195
//			myHeader.myXmax - myHeader.myXmin,
196
//			myHeader.myYmax - myHeader.myYmin);
197

  
198
			type = myHeader.myShapeType;
199

  
200
			double x = myHeader.myXmin;
201
			double y = myHeader.myYmin;
202
			double w = myHeader.myXmax - myHeader.myXmin;
203
			double h = myHeader.myYmax - myHeader.myYmin;
204

  
205
			if (w == 0) {
206
				x -= 0.1;
207
				w = 0.2;
208
			}
209

  
210
			if (h == 0) {
211
				y -= 0.1;
212
				h = 0.2;
213
			}
214

  
215

  
216
		} catch (FileNotFoundException e) {
217
			throw new OpenException(this.description(),e);
218
		} catch (IOException e) {
219
			throw new OpenException(this.description(),e);
220
		}
221

  
222

  
223
	}
224

  
225
	protected IExtent getFullExtent() throws ReadException{
226
		this.checkOpen();
227
		return this.extent;
228
	}
229

  
230
	protected boolean isEditable(){
231
		return this.getFile().canWrite() && this.fileShx.canWrite();
232
	}
233

  
234
	protected int getGeometryType() throws ReadException {
235
		this.checkOpen();
236
		int auxType = 0;
237

  
238
		switch (type) {
239
		case (SHP.POINT2D):
240
		case (SHP.POINT3D):
241
			auxType = auxType | FShape.POINT;
242

  
243
		break;
244

  
245
		case (SHP.POLYLINE2D):
246
		case (SHP.POLYLINE3D):
247
			auxType = auxType | FShape.LINE;
248

  
249
		break;
250

  
251
		case (SHP.POLYGON2D):
252
		case (SHP.POLYGON3D):
253
			auxType = auxType | FShape.POLYGON;
254

  
255
		break;
256
		case (SHP.MULTIPOINT2D):
257
		case (SHP.MULTIPOINT3D):
258
			auxType = auxType | FShape.MULTIPOINT;
259

  
260
		break;
261
		}
262

  
263
		return auxType;
264
	}
265

  
266
	protected synchronized IGeometry getGeometry(long position) throws ReadException {
267
		this.checkOpen();
268
		Point2D p = new Point2D.Double();
269
		int numParts;
270
		int numPoints;
271
		int i;
272
		int j;
273
		int shapeType;
274

  
275
		bb.position(getPositionForRecord(position));
276
		bb.order(ByteOrder.LITTLE_ENDIAN);
277

  
278
		shapeType = bb.getInt();
279
		//el shape tal con tema tal y n?mro tal es null
280
		if (shapeType==SHP.NULL){
281
			return new FNullGeometry();
282
		}
283

  
284
		// retrieve that shape.
285
		// tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
286
		switch (type) {
287
		case (SHP.POINT2D):
288
			p = readPoint(bb);
289

  
290
		return ShapeFactory.createPoint2D(p.getX(), p.getY());
291

  
292
		case (SHP.POLYLINE2D):
293

  
294
			bb.position(bb.position() + 32);
295
		numParts = bb.getInt();
296
		numPoints = bb.getInt();
297

  
298
		// part indexes.
299
		// Geometry geom = GeometryFactory.toGeometryArray();
300
		GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
301
				numPoints);
302

  
303
		int[] tempParts = new int[numParts];
304

  
305
		for (i = 0; i < numParts; i++) {
306
			tempParts[i] = bb.getInt();
307
		}
308

  
309
		j = 0;
310

  
311
		for (i = 0; i < numPoints; i++) {
312
			p = readPoint(bb);
313

  
314
			if (i == tempParts[j]) {
315
				elShape.moveTo(p.getX(), p.getY());
316

  
317
				if (j < (numParts - 1)) {
318
					j++;
319
				}
320
			} else {
321
				elShape.lineTo(p.getX(), p.getY());
322
			}
323
		}
324

  
325
		return ShapeFactory.createPolyline2D(elShape);
326

  
327
		case (SHP.POLYGON2D):
328

  
329
			//	            	BoundingBox = readRectangle(bb);
330
//			bb.getDouble();
331
//			bb.getDouble();
332
//			bb.getDouble();
333
//			bb.getDouble();
334
			bb.position(bb.position() + 32);
335
		numParts = bb.getInt();
336

  
337
		numPoints = bb.getInt();
338

  
339
		// part indexes.
340
		// Geometry geom = GeometryFactory.toGeometryArray();
341
		elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, numPoints);
342

  
343
		tempParts = new int[numParts];
344

  
345
		for (i = 0; i < numParts; i++) {
346
			tempParts[i] = bb.getInt();
347
		}
348

  
349
		j = 0;
350

  
351
		for (i = 0; i < numPoints; i++) {
352
			p = readPoint(bb);
353

  
354
			if (i == tempParts[j]) {
355
				elShape.moveTo(p.getX(), p.getY());
356

  
357
				if (j < (numParts - 1)) {
358
					j++;
359
				}
360
			} else {
361
				if (i==numPoints-1){
362
					elShape.closePath();
363
				}else{
364
					elShape.lineTo(p.getX(), p.getY());
365
				}
366
			}
367
		}
368

  
369
		return ShapeFactory.createPolygon2D(elShape);
370

  
371
		case (SHP.POINT3D):
372

  
373
			double x = bb.getDouble();
374
		double y = bb.getDouble();
375
		double z = bb.getDouble();
376

  
377
		return ShapeFactory.createPoint3D(x, y, z);
378

  
379
		case (SHP.POLYLINE3D):
380
			bb.position(bb.position() + 32);
381
		numParts = bb.getInt();
382
		numPoints = bb.getInt();
383
		elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, numPoints);
384
		tempParts = new int[numParts];
385

  
386
		for (i = 0; i < numParts; i++) {
387
			tempParts[i] = bb.getInt();
388
		}
389

  
390
		j = 0;
391

  
392
		for (i = 0; i < numPoints; i++) {
393
			p = readPoint(bb);
394

  
395
			if (i == tempParts[j]) {
396
				elShape.moveTo(p.getX(), p.getY());
397

  
398
				if (j < (numParts - 1)) {
399
					j++;
400
				}
401
			} else {
402
				elShape.lineTo(p.getX(), p.getY());
403
			}
404
		}
405

  
406
		double[] boxZ = new double[2];
407
		boxZ[0] = bb.getDouble();
408
		boxZ[1] = bb.getDouble();
409

  
410
		double[] pZ = new double[numPoints];
411

  
412
		for (i = 0; i < numPoints; i++) {
413
			pZ[i] = bb.getDouble();
414
		}
415

  
416
		return ShapeFactory.createPolyline3D(elShape, pZ);
417
		case (SHP.POLYGON3D):
418
			bb.position(bb.position() + 32);
419
		numParts = bb.getInt();
420
		numPoints = bb.getInt();
421
		elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, numPoints);
422
		tempParts = new int[numParts];
423

  
424
		for (i = 0; i < numParts; i++) {
425
			tempParts[i] = bb.getInt();
426
		}
427

  
428
		j = 0;
429

  
430
		for (i = 0; i < numPoints; i++) {
431
			p = readPoint(bb);
432

  
433
			if (i == tempParts[j]) {
434
				elShape.moveTo(p.getX(), p.getY());
435

  
436
				if (j < (numParts - 1)) {
437
					j++;
438
				}
439
			} else {
440
				if (i==numPoints-1){
441
					elShape.closePath();
442
				}else{
443
					elShape.lineTo(p.getX(), p.getY());
444
				}
445
			}
446
		}
447

  
448
		double[] boxpoZ = new double[2];
449
		boxpoZ[0] = bb.getDouble();
450
		boxpoZ[1] = bb.getDouble();
451

  
452
		double[] poZ = new double[numPoints];
453

  
454
		for (i = 0; i < numPoints; i++) {
455
			poZ[i] = bb.getDouble();
456
		}
457

  
458
		return ShapeFactory.createPolygon3D(elShape, poZ);
459

  
460
		case (SHP.MULTIPOINT2D):
461
			bb.position(bb.position() + 32);
462
		numPoints = bb.getInt();
463

  
464
		double[] tempX = new double[numPoints];
465
		double[] tempY = new double[numPoints];
466

  
467
		for (i = 0; i < numPoints; i++) {
468
			tempX[i] = bb.getDouble();
469
			tempY[i] = bb.getDouble();
470
		}
471

  
472
		return ShapeFactory.createMultipoint2D(tempX, tempY);
473

  
474
		case (SHP.MULTIPOINT3D):
475
			bb.position(bb.position() + 32);
476
		numPoints = bb.getInt();
477

  
478
		double[] temX = new double[numPoints];
479
		double[] temY = new double[numPoints];
480
		double[] temZ = new double[numPoints];
481

  
482
		for (i = 0; i < numPoints; i++) {
483
			temX[i] = bb.getDouble();
484
			temY[i] = bb.getDouble();
485
			//temZ[i] = bb.getDouble();
486
		}
487

  
488
		for (i = 0; i < numPoints; i++) {
489
			temZ[i] = bb.getDouble();
490
		}
491
		return ShapeFactory.createMultipoint3D(temX, temY, temZ);
492
		}
493

  
494
		return null;
495

  
496

  
497
	}
498

  
499
	private long getPositionForRecord(long numRec)
500
	{
501
		// shx file has a 100 bytes header, then, records
502
		// 8 bytes length, one for each entity.
503
		// first 4 bytes are the offset
504
		// next 4 bytes are length
505

  
506
		int posIndex = 100 + ((int)numRec * 8);
507
		// bbShx.position(posIndex);
508
		long pos = 8 + 2* bbShx.getInt(posIndex);
509

  
510
		return pos;
511
	}
512
	/**
513
	 * Reads the Point from the shape file.
514
	 *
515
	 * @param in ByteBuffer.
516
	 *
517
	 * @return Point2D.
518
	 */
519
	private synchronized Point2D readPoint(BigByteBuffer2 in){
520
		// create a new point
521
		Point2D.Double tempPoint = new Point2D.Double();
522

  
523
		// bytes 1 to 4 are the type and have already been read.
524
		// bytes 4 to 12 are the X coordinate
525
		in.order(ByteOrder.LITTLE_ENDIAN);
526
		tempPoint.setLocation(in.getDouble(), in.getDouble());
527

  
528
		return tempPoint;
529
	}
530

  
531
	/**
532
	 * Lee un rect?ngulo del fichero.
533
	 *
534
	 * @param in ByteBuffer.
535
	 *
536
	 * @return Rect?ngulo.
537
	 *
538
	 * @throws IOException
539
	 */
540
	private synchronized IExtent readRectangle(BigByteBuffer2 in){
541
		in.order(ByteOrder.LITTLE_ENDIAN);
542
		double x = in.getDouble();
543
		double y = in.getDouble();
544

  
545
		double x2 = in.getDouble();
546

  
547
		if (x2-x == 0) {
548
			x2 = 0.2;
549
			x -= 0.1;
550
		}
551

  
552
		double y2 = in.getDouble();
553

  
554
		if (y2-y == 0) {
555
			y2 = 0.2;
556
			y -= 0.1;
557
		}
558
		IExtent tempRect = new Extent(x,y,x2,y2);
559
		return tempRect;
560
	}
561

  
562
	public IExtent getBoundingBox(long featureIndex) throws ReadException {
563
		this.checkOpen();
564
		Point2D p = new Point2D.Double();
565
		IExtent BoundingBox = null;
566
		try {
567
			bb.position(getPositionForRecord(featureIndex));
568
		}catch (Exception e) {
569
			e.printStackTrace();
570
//			logger.error(" Shapefile is corrupted. Drawing aborted. ="+e+ "  "+"index = "+index);
571
		}
572
		bb.order(ByteOrder.LITTLE_ENDIAN);
573

  
574
		int tipoShape = bb.getInt();
575

  
576
		//AZABALA: si tipoShape viene con valores erroneos deja de funcionar
577
		//el metodo getShape(i)
578
//		if (tipoShape != SHP.NULL) {
579
//		type = tipoShape;
580

  
581
//		}
582

  
583
		// retrieve that shape.
584
		// tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
585
		switch (tipoShape) {
586
		case (SHP.POINT2D):
587
		case (SHP.POINT3D):
588
			p = readPoint(bb);
589
		BoundingBox = new Extent(p.getX() - 0.1, p.getY() - 0.1,p.getX()+0.2,p.getY()+0.2);
590
//		new Rectangle2D.Double(p.getX() - 0.1,
591
//		p.getY() - 0.1, 0.2, 0.2);
592

  
593
		break;
594

  
595
		case (SHP.POLYLINE2D):
596
		case (SHP.POLYGON2D):
597
		case (SHP.MULTIPOINT2D):
598
		case (SHP.POLYLINE3D):
599
		case (SHP.POLYGON3D):
600
		case (SHP.MULTIPOINT3D):
601

  
602
			// BoundingBox
603
			BoundingBox = readRectangle(bb);
604

  
605
		break;
606
		}
607

  
608
		return BoundingBox;
609
	}
610

  
611
	/**
612
	 * @return
613
	 */
614
	public String getSRS() {
615
		// TODO Auto-generated method stub
616
		return null;
617
	}
618

  
619
}
620

  
0 621

  
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/shp/ShpFeature.java
26 26

  
27 27
public class ShpFeature extends DBFFeature{
28 28
	protected static Locale ukLocale = new Locale("en", "UK");
29
	protected IExtent extent=null;
29 30
//	private SHPStore store;
30 31
//	private long featureIndex;
31 32

  
......
39 40

  
40 41

  
41 42

  
43

  
44
	/* (non-Javadoc)
45
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.DBFFeature#load()
46
	 */
47
	protected void load() throws ReadException {
48
		// TODO Auto-generated method stub
49
		super.load();
50
		this.extent= ((SHPStore)store).getBoundingBox(featureIndex);
51
	}
52

  
53

  
54

  
55

  
42 56
	protected void loadValue(IFeatureAttributeDescriptor descriptor) throws ReadException, IsNotFeatureSettingException {
43 57
		if (descriptor.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)){
44 58
			this.setGeometry(((AttributeDescriptor)descriptor).originalPosition(), ((SHPStore)store).getGeometry(featureIndex) );
......
53 67
		return new ShpFeatureID((SHPStore)this.store,featureIndex);
54 68
	}
55 69

  
56
	public IExtent getExtent() {
57
		return ((SHPStore)store).getBoundingBox(featureIndex);
70
	public IExtent getExtent(){
71
		return this.extent;
58 72
	}
59 73

  
60 74
	public List getAllSRS() {
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/shp/SHPStore.java
8 8
import java.lang.ref.WeakReference;
9 9
import java.nio.ByteOrder;
10 10
import java.nio.channels.FileChannel;
11
import java.security.KeyException;
11 12
import java.util.Collection;
12 13
import java.util.Iterator;
13 14
import java.util.List;
......
17 18
import org.gvsig.data.IDataExplorer;
18 19
import org.gvsig.data.IDataExplorerParameters;
19 20
import org.gvsig.data.IDataStoreParameters;
21
import org.gvsig.data.ResourceManager;
20 22
import org.gvsig.data.datastores.vectorial.IFeaturesWriter;
21 23
import org.gvsig.data.datastores.vectorial.file.DataExplorerFileParameters;
22 24
import org.gvsig.data.datastores.vectorial.file.dbf.DBFDataExplorer;
23 25
import org.gvsig.data.datastores.vectorial.file.dbf.DBFFeatureCollection;
24 26
import org.gvsig.data.datastores.vectorial.file.dbf.DBFFeatureCollectionBitSet;
25 27
import org.gvsig.data.datastores.vectorial.file.dbf.DBFFeatureCollectionWithFeatureID;
28
import org.gvsig.data.datastores.vectorial.file.dbf.DBFResource;
26 29
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore;
27 30
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP;
28 31
import org.gvsig.data.datastores.vectorial.file.shp.utils.ShapeFileHeader2;
29 32
import org.gvsig.data.exception.CloseException;
33
import org.gvsig.data.exception.DataException;
30 34
import org.gvsig.data.exception.InitializeException;
31 35
import org.gvsig.data.exception.OpenException;
32 36
import org.gvsig.data.exception.ReadException;
......
58 62
	public static String DATASTORE_NAME = "SHPStore";
59 63
	private SHPStoreParameters shpParameters=null;
60 64
	private File fileShp;
61
	private FileInputStream fin;
62
	private FileChannel channel;
63
	private BigByteBuffer2 bb;
64
	private File fileShx;
65
	private FileInputStream finShx;
66
	private FileChannel channelShx;
67
	private BigByteBuffer2 bbShx;
68
	private Extent extent;
69
	private int type;
65
	private SHPResource shp=null;
70 66

  
71 67

  
72
	 public void init(IDataStoreParameters parameters) throws InitializeException {
73
		 super.init(parameters);
74
			featureType=super.getDefaultFeatureType();
68
	public void init(IDataStoreParameters parameters) throws InitializeException {
69
		super.init(parameters);
70
		featureType=super.getDefaultFeatureType();
75 71

  
76
			AttributeDescriptor dad=new AttributeDescriptor();
77
			try {
78
				dad.loading();
79
				dad.setName("GEOMETRY");
80
				dad.setType(IFeatureAttributeDescriptor.TYPE_GEOMETRY);
81
				dad.stopLoading();
82
			} catch (IsNotAttributeSettingException e1) {
83
				// TODO Auto-generated catch block
84
				e1.printStackTrace();
85
			}
86
	        featureType.add(dad);
87
	        featureType.setDefaultGeometry("GEOMETRY");
72
		AttributeDescriptor dad=new AttributeDescriptor();
73
		try {
74
			dad.loading();
75
			dad.setName("GEOMETRY");
76
			dad.setType(IFeatureAttributeDescriptor.TYPE_GEOMETRY);
77
			dad.stopLoading();
78
		} catch (IsNotAttributeSettingException e1) {
79
			throw new InitializeException(this.getName(),e1);
80
		}
81
		featureType.add(dad);
82
		featureType.setDefaultGeometry("GEOMETRY");
88 83

  
89
	        SHPStoreParameters shpParameters=(SHPStoreParameters)parameters;
84
		this.shpParameters=(SHPStoreParameters)parameters;
90 85

  
91
			fileShp = shpParameters.getSHPFile();
86
		fileShp = this.shpParameters.getSHPFile();
92 87

  
93
			try {
94
				fin = new FileInputStream(fileShp);
88
		SHPResource tmpResource = new SHPResource(this.shpParameters);
95 89

  
90
		ResourceManager resMan = ResourceManager.getResourceManager();
96 91

  
97
			// Open the file and then get a channel from the stream
98
			channel = fin.getChannel();
92
		 try {
93
			 this.shp = (SHPResource)resMan.addResource(tmpResource);
94
		 } catch (DataException e1) {
95
			 throw new InitializeException(this.getName(),e1);
96
		 }
99 97

  
100
			// long size = channel.size();
98
	}
101 99

  
102
			// Get the file's size and then map it into memory
103
			// bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
104
	        bb = new BigByteBuffer2(channel, FileChannel.MapMode.READ_ONLY);
105
	        fileShx=SHP.getShxFile(shpParameters.getFile());
106
	        finShx = new FileInputStream(fileShx);
107 100

  
108
	        // Open the file and then get a channel from the stream
109
	        channelShx = finShx.getChannel();
110

  
111
//	        long sizeShx = channelShx.size();
112

  
113
	        // Get the file's size and then map it into memory
114
	        // bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
115
	        // bbShx = channelShx.map(FileChannel.MapMode.READ_ONLY, 0, sizeShx);
116
	        bbShx = new BigByteBuffer2(channelShx, FileChannel.MapMode.READ_ONLY);
117
	        bbShx.order(ByteOrder.BIG_ENDIAN);
118
			} catch (FileNotFoundException e) {
119
				throw new OpenException(getName(),e);
120
			} catch (IOException e) {
121
				throw new OpenException(getName(),e);
122
			}
123

  
124
	    }
125

  
126

  
127
//	 private IFeatureAttributeDescriptor createFeatureAttribute(int i) {
128
//	        char fieldType = dbf.getFieldType(i);
129
//	        DefaultAttributeDescriptor dad=new DefaultAttributeDescriptor();
130
//	        dad.setOrdinal(i);
131
//	        dad.setName(dbf.getFieldName(i));
132
//	        dad.setSize(dbf.getFieldLength(i));
133
//	        if (fieldType == 'L') {
134
//	        	dad.setType(IFeatureAttributeDescriptor.TYPE_BOOLEAN);
135
//
136
//	        } else if ((fieldType == 'F') || (fieldType == 'N')) {
137
//	        	int precision = dbf.getFieldDecimalLength(i);
138
//	        	if (precision > 0){
139
//	        		dad.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE);
140
//	        		dad.setPrecision(precision);
141
//	        	} else{
142
//	        		dad.setType(IFeatureAttributeDescriptor.TYPE_INT);
143
//	        	}
144
//	        } else if (fieldType == 'C') {
145
//	        	dad.setType(IFeatureAttributeDescriptor.TYPE_STRING);
146
//	        } else if (fieldType == 'D') {
147
//	        	dad.setType(IFeatureAttributeDescriptor.TYPE_DATE);
148
//	        } else {
149
////	            throw new BadFieldDriverException(getName(),null,String.valueOf(fieldType));
150
//	        }
151
//	      	return dad;
152
//
153
//	    }
154

  
155 101
	protected void doFinishEdition() throws WriteException, ReadException {
156
		IFeaturesWriter writer = getFeaturesWriter();
157
        writer.init(this);
158
        writer.updateFeatureType(getDefaultFeatureType());
159
        writer.preProcess();
160
        Collection collection=getDataCollection();
161
        Iterator iterator=collection.iterator();
162
        IFeature feature;
163
        while (iterator.hasNext()) {
164
        	feature= (IFeature) iterator.next();
165
			writer.insertFeature(feature);
166
		}
167
        writer.postProcess();
102
		super.doFinishEdition();
103
		this.shp.changed(this);
168 104

  
169 105
	}
170 106

  
......
191 127
			if (featureManager.contains(id)) {
192 128
				return featureManager.getFeature(id,this);
193 129
			}
194
    	}
130
		}
195 131
		long position=((ShpFeatureID)id).getIndex();
196 132
		ShpFeature feature=new ShpFeature(getDefaultFeatureType(),this,position);
197 133
		return feature;
......
200 136

  
201 137
	public List getFeatureTypes() {
202 138
		featureTypes.set(0,getDefaultFeatureType());
203
        return featureTypes;
139
		return featureTypes;
204 140
	}
205 141

  
206 142
	public IFeatureType getDefaultFeatureType() {
207 143
		if (isEditing()){
208
//    		Aqu? hay que construir un FeatureType con los cambios que se hayan hecho en la edici?n.
209
    		return attributeManager.getFeatureType();
210
    	}
211
        return featureType;
144
//			Aqu? hay que construir un FeatureType con los cambios que se hayan hecho en la edici?n.
145
			return attributeManager.getFeatureType();
146
		}
147
		return featureType;
212 148
	}
213 149

  
214 150
	public boolean isWithDefaultLegend() {
......
233 169

  
234 170
	protected void doOpen() throws OpenException {
235 171
		super.doOpen();
236
//		 create a new header.
237
		ShapeFileHeader2 myHeader = new ShapeFileHeader2();
238

  
239
		bb.position(0);
240

  
241
		// read the header
242
		myHeader.readHeader(bb);
243

  
244
		extent = new Extent(myHeader.myXmin, myHeader.myYmin,myHeader.myXmax,myHeader.myYmax);
245
//		extent = new Rectangle2D.Double(myHeader.myXmin, myHeader.myYmin,
246
//				myHeader.myXmax - myHeader.myXmin,
247
//				myHeader.myYmax - myHeader.myYmin);
248

  
249
		type = myHeader.myShapeType;
250

  
251
		double x = myHeader.myXmin;
252
		double y = myHeader.myYmin;
253
		double w = myHeader.myXmax - myHeader.myXmin;
254
		double h = myHeader.myYmax - myHeader.myYmin;
255

  
256
		if (w == 0) {
257
			x -= 0.1;
258
			w = 0.2;
172
		try {
173
			featureType.setGeometryTypes(new int[]{this.shp.getGeometryType()});
174
		} catch (ReadException e) {
175
			throw new OpenException("Can't read type",this.getName(),e);
259 176
		}
260 177

  
261
		if (h == 0) {
262
			y -= 0.1;
263
			h = 0.2;
264
		}
265
		featureType.setGeometryTypes(new int[]{getGeometryType()});
266
		// String strFichDbf = m_Path.toLowerCase().replaceAll("\\.shp", ".dbf");
267
//		String strFichDbf = fileShp.getAbsolutePath().replaceAll("\\.shp", ".dbf");
268
//		strFichDbf = strFichDbf.replaceAll("\\.SHP", ".DBF");
269
//
270
//		DbaseFileNIO m_FichDbf = new DbaseFileNIO();
271
//
272
//		try {
273
//			m_FichDbf.open(new File(strFichDbf));
274
//		} catch (IOException e) {
275
////			throw new FileNotFoundDriverException(getName(),e,strFichDbf);
276
//		}
277
//		numReg = m_FichDbf.getRecordCount();
278

  
279 178
	}
280 179

  
281 180
	protected void doClose() throws CloseException {
282 181
		super.doClose();
283
		CloseException ret = null;
284

  
285 182
		try {
286
			channel.close();
287
            channelShx.close();
288
		} catch (IOException e) {
289
			ret = new CloseException(getName(),e);
290
		} finally {
291
			try {
292
				fin.close();
293
				finShx.close();
294
			} catch (IOException e1) {
295
				ret = new CloseException(getName(),e1);
296
			}
183
			this.shp.close();
184
		} catch (DataException e) {
185
			throw new CloseException(this.getName(),e);
297 186
		}
298 187

  
299
//		if (ret != null) {
300
//			throw ret;
301
//		}
302
		bb = null;
303
		bbShx = null;
304 188

  
305 189
	}
306 190

  
307 191
	protected void doDispose() throws CloseException {
308
		super.doDispose();
192
		ResourceManager resMan = ResourceManager.getResourceManager();
193

  
194
    	try {
195
			resMan.remove(this.shp);
196
		} catch (DataException e1) {
197
			throw new CloseException(this.getName(),e1);
198
		} catch (KeyException e) {
199
			// TODO Auto-generated catch block
200
			throw new CloseException(this.getName(),e);
201
		}
202

  
203
		this.shp = null;
204
		this.featureType=null;
205
		this.metadata=null;
206

  
309 207
	}
310 208

  
311 209
	public boolean isEditable() {
312
		if (super.isEditable() && fileShp.canWrite() && fileShx.canWrite()) return true;
210
		if (super.isEditable() && this.shp.isEditable()) return true;
313 211
		return false;
314 212
	}
315 213

  
......
317 215
		if (metadata==null){
318 216
			IMetadataManager manager=MetadataManager.getManager();
319 217
			metadata=manager.create(DATASTORE_NAME);
320
			IExtent extent=getFullExtent();
218
			IExtent extent=this.shp.getFullExtent();
321 219
			metadata.set("extent",extent);
322
			String srs=getSRS();
220
			String srs=this.shp.getSRS();
323 221
			metadata.set("srs",srs);
324 222
		}
325 223
		if (this.alterMode){
326 224
			IExtent extent=(IExtent)metadata.get("extent");
327 225
			IFeatureCollection featureCollection=(IFeatureCollection)getDataCollection();
328
	    	if (spatialManager.isFullExtentDirty()){
329
	    		if (!featureCollection.isEmpty()){
330
	    			Iterator featureIterator=featureCollection.iterator();
331
	    			extent = ((IFeature)featureIterator.next()).getExtent();
332
	    			while(featureIterator.hasNext()){
333
	    				IFeature feature=(IFeature)featureIterator.next();
334
	    				IExtent boundExtent=feature.getExtent();
335
	    				if (boundExtent!=null)
336
	    					extent.add(boundExtent);
337
	    			}
338
	    		}
339
	    	}
340
	    	metadata.set("extent",extent);
226
			if (spatialManager.isFullExtentDirty()){
227
				if (!featureCollection.isEmpty()){
228
					Iterator featureIterator=featureCollection.iterator();
229
					extent = ((IFeature)featureIterator.next()).getExtent();
230
					while(featureIterator.hasNext()){
231
						IFeature feature=(IFeature)featureIterator.next();
232
						IExtent boundExtent=feature.getExtent();
233
						if (boundExtent!=null)
234
							extent.add(boundExtent);
235
					}
236
				}
237
			}
238
			metadata.set("extent",extent);
341 239
		}
342 240
		return metadata;
343 241
	}
344 242
//	protected IFeature getFeatureByPosition(IFeatureType featureType,long position) throws ReadException {
345
//		ShpFeature feature=new ShpFeature(featureType,this,position);
346
//		feature.load(dbf, this.getGeometry(position));
347
//		return feature;
243
//	ShpFeature feature=new ShpFeature(featureType,this,position);
244
//	feature.load(dbf, this.getGeometry(position));
245
//	return feature;
348 246
//	}
349 247

  
350 248
	protected IFeaturesWriter getFeaturesWriter() {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff