Revision 32880 branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/shp/SHPStoreProvider.java
SHPStoreProvider.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import org.cresques.cts.IProjection; |
34 | 34 |
import org.gvsig.fmap.crs.CRSFactory; |
35 |
import org.gvsig.fmap.dal.DataStore; |
|
35 | 36 |
import org.gvsig.fmap.dal.DataTypes; |
37 |
import org.gvsig.fmap.dal.FileHelper; |
|
36 | 38 |
import org.gvsig.fmap.dal.exception.CloseException; |
37 | 39 |
import org.gvsig.fmap.dal.exception.DataException; |
38 | 40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
... | ... | |
67 | 69 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
68 | 70 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
69 | 71 |
import org.gvsig.fmap.geom.primitive.Envelope; |
70 |
import org.gvsig.tools.ToolsLocator; |
|
71 |
import org.gvsig.tools.dynobject.DynClass; |
|
72 |
import org.gvsig.tools.dynobject.DynField; |
|
73 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
74 | 72 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
75 | 73 |
import org.gvsig.tools.exception.BaseException; |
76 | 74 |
import org.slf4j.Logger; |
... | ... | |
82 | 80 |
public static String NAME = "Shape"; |
83 | 81 |
public static String DESCRIPTION = "Shape file"; |
84 | 82 |
private SHPFile shpFile; |
85 |
// private ResourceProvider shpResource; |
|
86 |
// private ResourceProvider shxResource; |
|
87 | 83 |
|
88 | 84 |
private MultiResource resource; |
89 | 85 |
|
90 | 86 |
protected static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY"; |
91 |
protected static final String DYNFIELD_SRSORIGINALPARAMETERS_NAME = "SRSOriginalParameters"; |
|
92 |
private static final String DYNCLASS_NAME = "SHPStore"; |
|
93 |
protected static DynClass DYNCLASS = null; |
|
94 | 87 |
|
88 |
public static final String METADATA_DEFINITION_NAME = NAME; |
|
89 |
|
|
95 | 90 |
private SHPFeatureWriter writer = null; |
96 | 91 |
|
97 | 92 |
public SHPStoreProvider(SHPStoreParameters params, |
98 | 93 |
DataStoreProviderServices storeServices) |
99 | 94 |
throws InitializeException { |
100 |
super(params, storeServices,ToolsLocator |
|
101 |
.getDynObjectManager().createDynObject(DYNCLASS)); |
|
95 |
super( |
|
96 |
params, |
|
97 |
storeServices, |
|
98 |
FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
|
99 |
); |
|
102 | 100 |
} |
103 | 101 |
|
104 | 102 |
protected void init(DBFStoreParameters params, |
... | ... | |
108 | 106 |
super.init(params, storeServices); |
109 | 107 |
} |
110 | 108 |
|
109 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
|
110 |
if( DataStore.METADATA_CRS.equalsIgnoreCase(name) ) { |
|
111 |
return this.shpFile.getSRSParameters(); |
|
112 |
} else if( DataStore.METADATA_ENVELOPE.equalsIgnoreCase(name) ) { |
|
113 |
try { |
|
114 |
return this.shpFile.getFullExtent(); |
|
115 |
} catch (ReadException e) { |
|
116 |
return null; |
|
117 |
} |
|
118 |
} |
|
119 |
return super.getDynValue(name); |
|
120 |
} |
|
121 |
|
|
111 | 122 |
protected void initResource(DBFStoreParameters params, |
112 | 123 |
DataStoreProviderServices storeServices) throws InitializeException { |
124 |
|
|
113 | 125 |
SHPStoreParameters shpParams = (SHPStoreParameters) params; |
114 | 126 |
resource = |
115 | 127 |
(MultiResource) createResource(MultiResource.TYPE_NAME, |
... | ... | |
179 | 191 |
getResource().notifyOpen(); |
180 | 192 |
} |
181 | 193 |
|
182 |
|
|
183 |
protected static void registerDynClass() { |
|
184 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
|
185 |
DynClass dynClass; |
|
186 |
DynField field; |
|
187 |
if (DYNCLASS == null) { |
|
188 |
|
|
189 |
DynClass dbfDynClass = DBFStoreProvider.DYNCLASS; |
|
190 |
dynClass = dynman.add(DYNCLASS_NAME); |
|
191 |
|
|
192 |
|
|
193 |
field = dynClass.addDynField(DYNFIELD_SRSORIGINALPARAMETERS_NAME); |
|
194 |
field.setType(DataTypes.STRING); |
|
195 |
field.setDescription("SRS original parameters"); |
|
196 |
|
|
197 |
// The SHP store parameters extend the DBF store parameters |
|
198 |
dynClass.extend(dbfDynClass); |
|
199 |
|
|
200 |
DYNCLASS = dynClass; |
|
201 |
} |
|
202 |
|
|
203 |
} |
|
204 |
|
|
205 |
|
|
206 | 194 |
protected static EditableFeatureAttributeDescriptor addGeometryColumn( |
207 | 195 |
EditableFeatureType fType) { |
208 | 196 |
|
... | ... | |
277 | 265 |
// // TODO petar ?? |
278 | 266 |
// srs = "EPSG:23030"; |
279 | 267 |
// } |
280 |
IProjection srs = getShpParameters().getSRS();
|
|
268 |
IProjection srs = getShpParameters().getCRS();
|
|
281 | 269 |
if (srs == null) { |
282 | 270 |
srs = CRSFactory.getCRS("EPSG:23030"); |
283 | 271 |
} |
... | ... | |
295 | 283 |
} |
296 | 284 |
} |
297 | 285 |
|
298 |
private String getSRSFromPrj(String srsParameters) { |
|
299 |
// TODO identificar que SRS hay que usar, ya sea |
|
300 |
// el que se recibe de los parametros o el que |
|
301 |
// conicida con el que se ha encontrado en el |
|
302 |
// prg... y si ninguna de las dos que? |
|
303 |
return null; |
|
304 |
} |
|
286 |
// private String getSRSFromPrj(String srsParameters) {
|
|
287 |
// // TODO identificar que SRS hay que usar, ya sea
|
|
288 |
// // el que se recibe de los parametros o el que
|
|
289 |
// // conicida con el que se ha encontrado en el
|
|
290 |
// // prg... y si ninguna de las dos que?
|
|
291 |
// return null;
|
|
292 |
// }
|
|
305 | 293 |
|
306 | 294 |
protected SHPStoreParameters getShpParameters() { |
307 | 295 |
return (SHPStoreParameters) getParameters(); |
... | ... | |
425 | 413 |
|
426 | 414 |
} |
427 | 415 |
|
428 |
protected void loadMetadataValues() throws DynFieldNotFoundException, |
|
429 |
ReadException { |
|
430 |
super.loadMetadataValues(); |
|
431 |
|
|
432 |
this.setDynValue(DYNFIELD_SRSORIGINALPARAMETERS_NAME, |
|
433 |
this.shpFile.getSRSParameters()); |
|
434 |
|
|
435 |
this.setDynValue("DefaultSRS", this.getShpParameters() |
|
436 |
.getSRS()); |
|
437 |
|
|
438 |
this.setDynValue("Envelope", shpFile.getFullExtent()); |
|
439 |
|
|
440 |
} |
|
441 |
|
|
442 |
|
|
443 | 416 |
protected void closeFile() throws CloseException { |
444 | 417 |
super.closeFile(); |
445 | 418 |
if (!this.shpFile.isOpen()) { |
... | ... | |
499 | 472 |
SHPStoreParameters shpParams = getShpParameters(); |
500 | 473 |
SHPStoreParameters tmpParams = |
501 | 474 |
(SHPStoreParameters) shpParams.getCopy(); |
502 |
tmpParams.setDBFFileName(tmpParams.getDBFFileName()
|
|
475 |
tmpParams.setDBFFile(tmpParams.getDBFFileName() |
|
503 | 476 |
+ ".tmp"); |
504 |
tmpParams.setSHPFileName(tmpParams.getSHPFileName()
|
|
477 |
tmpParams.setSHPFile(tmpParams.getSHPFileName() |
|
505 | 478 |
+ ".tmp"); |
506 |
tmpParams.setSHXFileName(tmpParams.getSHXFileName()
|
|
479 |
tmpParams.setSHXFile(tmpParams.getSHXFileName() |
|
507 | 480 |
+ ".tmp"); |
508 | 481 |
|
509 | 482 |
writer.begin(tmpParams, fType, dbfFtype, set.getSize()); |
Also available in: Unified diff