Revision 20437 trunk/libraries/libDataSourceBaseDrivers/src/org/gvsig/data/datastores/vectorial/file/shp/ShpFeature.java

View differences:

ShpFeature.java
8 8
import java.util.Locale;
9 9

  
10 10
import org.gvsig.data.datastores.vectorial.file.dbf.DBFFeature;
11
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore;
11 12
import org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile;
12 13
import org.gvsig.data.exception.ReadException;
13 14
import org.gvsig.data.spatialprovisional.IExtent;
......
20 21
import com.iver.cit.gvsig.fmap.core.IGeometry;
21 22

  
22 23

  
23
public class ShpFeature extends Feature{
24
public class ShpFeature extends DBFFeature{
24 25
	protected static Locale ukLocale = new Locale("en", "UK");
25
	private SHPStore store;
26
	private long featureIndex;
26
//	private SHPStore store;
27
//	private long featureIndex;
27 28

  
28
	ShpFeature(IFeatureType featureType, SHPStore store,long featureIndex) {
29
		super(featureType);
30
		this.store=store;
31
		this.featureIndex=featureIndex;
29
	ShpFeature(IFeatureType featureType, SHPStore store,long featureIndex) throws ReadException {
30
		super(featureType,store,featureIndex);
31
		load();
32
//		this.store=store;
33
//		this.featureIndex=featureIndex;
34

  
32 35
	}
33 36

  
34 37

  
35
	void load(DbaseFile dbf,IGeometry geometry) throws ReadException{
38
	protected void load() throws ReadException{
36 39
		Iterator iterator=featureType.iterator();
37 40
		try{
38 41
			this.loading();
......
41 44
				int i=descriptor.ordinal();
42 45
				String fieldType=descriptor.getDataType();
43 46
				if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)){
44
					this.setGeometry(i,geometry);
47
					this.setGeometry(i,((SHPStore)store).getGeometry(i));
45 48
				}
46
				if (dbf.getFieldCount()<=i)
47
					return ;
48
				String value=dbf.getStringFieldValue((int) this.featureIndex, i);
49
				value=value.trim();
50

  
51
				if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_STRING)){
52
					this.set(i,value);
53
				}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){
54
					try{
55
						Double.parseDouble(value);
56
					}catch (NumberFormatException e) {
57
						value="0";
58
					}
59
					this.set(i,Double.parseDouble(value));
60
				}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_INT)){
61
					this.set(i,Integer.parseInt(value));
62
				}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){
63
					this.set(i,Float.parseFloat(value));
64
				}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_LONG)){
65
					this.set(i,Long.parseLong(value));
66
				}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){
67
					this.set(i,Boolean.parseBoolean(value));
68
				}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){
69
					this.set(i,Byte.parseByte(value));
70
				}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DATE)){
71
					String year = value.substring(0, 4);
72
					String month = value.substring(4, 6);
73
					String day = value.substring(6, 8);
74
					DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, ukLocale);
75
					/* Calendar c = Calendar.getInstance();
76
					 c.clear();
77
					 c.set(Integer.parseInt(year), Integer.parseInt(month),
78
					 Integer.parseInt(day));
79
					 c.set(Calendar.MILLISECOND, 0); */
80
					String strAux = month + "/" + day + "/" + year;
81
					Date dat=null;
82
					try {
83
						dat = df.parse(strAux);
84
					} catch (ParseException e) {
85
						throw new ReadException(this.store.getName(),e);
86
					}
87
					this.set(i,dat);
88
				}else{
89
					this.set(i,null);
90
				}
91 49
			}
92 50
			this.stopLoading();
93 51
		}catch (IsNotFeatureSettingException e) {
......
98 56

  
99 57

  
100 58
	public IFeatureID getID() {
101
		return new ShpFeatureID(this.store,featureIndex);
59
		return new ShpFeatureID((SHPStore)this.store,featureIndex);
102 60
	}
103 61

  
104 62
	public IExtent getExtent() {
105
		return store.getBoundingBox(featureIndex);
63
		return ((SHPStore)store).getBoundingBox(featureIndex);
106 64
	}
107 65

  
108 66
	public List getAllSRS() {
......
121 79
			return new int[]{geometry.getGeometryType()};
122 80
		return null;
123 81
	}
82

  
83

  
84

  
85

  
124 86
}

Also available in: Unified diff