Revision 44669 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPStoreProvider.java
SHPStoreProvider.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
import org.apache.commons.io.FileUtils; |
32 | 32 |
import org.apache.commons.io.FilenameUtils; |
33 |
import org.cresques.cts.ICRSFactory; |
|
34 | 33 |
import org.cresques.cts.IProjection; |
35 | 34 |
import org.slf4j.Logger; |
36 | 35 |
import org.slf4j.LoggerFactory; |
37 | 36 |
|
38 | 37 |
import org.gvsig.fmap.dal.DataStore; |
39 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
40 | 38 |
import org.gvsig.fmap.dal.DataTypes; |
41 | 39 |
import org.gvsig.fmap.dal.FileHelper; |
42 | 40 |
import org.gvsig.fmap.dal.exception.CloseException; |
43 | 41 |
import org.gvsig.fmap.dal.exception.DataException; |
44 | 42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
45 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
46 | 43 |
import org.gvsig.fmap.dal.exception.ReadException; |
47 | 44 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
48 | 45 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
49 | 46 |
import org.gvsig.fmap.dal.feature.Feature; |
50 | 47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
51 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
52 | 48 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
53 | 49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
54 | 50 |
import org.gvsig.fmap.dal.feature.FeatureType; |
55 | 51 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
56 | 52 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
57 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
|
58 | 53 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
59 | 54 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
60 | 55 |
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
... | ... | |
85 | 80 |
*/ |
86 | 81 |
public class SHPStoreProvider extends DBFStoreProvider { |
87 | 82 |
|
88 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
89 |
private static final Logger logger = LoggerFactory.getLogger(SHPStoreProvider.class); |
|
90 |
public static String NAME = "Shape"; |
|
83 |
private static final GeometryManager GEOM_MANAGER = GeometryLocator.getGeometryManager(); |
|
84 |
private static final Logger LOGGER = LoggerFactory.getLogger(SHPStoreProvider.class); |
|
85 |
|
|
86 |
public static String NAME = DataStore.SHAPE_PROVIDER_NAME; |
|
91 | 87 |
public static String DESCRIPTION = "Shape file"; |
92 | 88 |
private ISHPFile shpFile; |
93 | 89 |
|
94 | 90 |
private MultiResource resource; |
95 | 91 |
|
96 |
protected static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY";
|
|
92 |
public static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY";
|
|
97 | 93 |
|
98 | 94 |
public static final String METADATA_DEFINITION_NAME = NAME; |
99 | 95 |
|
... | ... | |
229 | 225 |
|
230 | 226 |
attr.setObjectClass(Geometry.class); |
231 | 227 |
attr.setAllowNull(true); |
232 |
fType.setDefaultGeometryAttributeName(attr.getName()); |
|
228 |
// fType.setDefaultGeometryAttributeName(attr.getName());
|
|
233 | 229 |
return attr; |
234 | 230 |
|
235 | 231 |
} |
... | ... | |
249 | 245 |
return candidate; |
250 | 246 |
} |
251 | 247 |
|
252 |
protected static FeatureType removeGeometryColumn(EditableFeatureType fType) { |
|
253 |
Iterator<?> iter = fType.iterator(); |
|
254 |
FeatureAttributeDescriptor attr; |
|
255 |
while (iter.hasNext()) { |
|
256 |
attr = (FeatureAttributeDescriptor) iter.next(); |
|
257 |
if (attr.getType() == DataTypes.GEOMETRY) { |
|
258 |
iter.remove(); |
|
259 |
} |
|
248 |
protected EditableFeatureType getTheFeatureType() throws InitializeException{ |
|
249 |
try { |
|
250 |
this.open(); |
|
251 |
} catch (DataException e) { |
|
252 |
throw new InitializeException(this.getProviderName(), e); |
|
260 | 253 |
} |
261 |
fType.setDefaultGeometryAttributeName(null); |
|
262 |
return fType.getNotEditableCopy(); |
|
263 |
} |
|
264 |
|
|
265 |
protected EditableFeatureType getTheFeatureType() throws InitializeException, OpenException { |
|
266 | 254 |
final EditableFeatureType fType = super.getTheFeatureType(); |
267 |
this.open(); |
|
268 | 255 |
try { |
269 | 256 |
getResource().execute(new ResourceAction() { |
270 | 257 |
|
271 | 258 |
public Object run() throws Exception { |
272 | 259 |
EditableFeatureAttributeDescriptor attr = addGeometryColumn(fType); |
273 | 260 |
|
274 |
attr.setGeometryType(geomManager.getGeometryType(
|
|
261 |
attr.setGeometryType(GEOM_MANAGER.getGeometryType(
|
|
275 | 262 |
shpFile.getGeometryType(), |
276 | 263 |
shpFile.getGeometrySubType() |
277 | 264 |
)); |
... | ... | |
460 | 447 |
} catch (DataException e) { |
461 | 448 |
throw new PerformEditingException(this.getProviderName(), e); |
462 | 449 |
} |
463 |
// TODO Comprobar el campo de geometria |
|
464 |
|
|
465 |
final EditableFeatureType dbfFtype = fType.getEditable(); |
|
466 |
|
|
467 |
removeGeometryColumn(dbfFtype); |
|
468 |
|
|
469 | 450 |
try { |
470 | 451 |
// TODO repasar el concepto de enUso de un recurso. |
471 | 452 |
loTengoEnUso = true; |
... | ... | |
490 | 471 |
tmpParams.setSHPFile(str_base + ".shp"); |
491 | 472 |
tmpParams.setSHXFile(str_base + ".shx"); |
492 | 473 |
|
493 |
writer.begin(tmpParams, fType, dbfFtype, set.getSize());
|
|
474 |
writer.begin(tmpParams, fType, set.getSize()); |
|
494 | 475 |
|
495 | 476 |
iter = set.fastIterator(); |
496 | 477 |
while (iter.hasNext()) { |
... | ... | |
504 | 485 |
|
505 | 486 |
|
506 | 487 |
if (!shpParams.getDBFFile().delete()) { |
507 |
logger.debug("Can't delete dbf file '" + shpParams.getDBFFile() + "'.");
|
|
488 |
LOGGER.debug("Can't delete dbf file '" + shpParams.getDBFFile() + "'.");
|
|
508 | 489 |
throw new IOException("Can't delete dbf '" |
509 | 490 |
+ FilenameUtils.getBaseName(shpParams.getDBFFileName()) |
510 | 491 |
+ "' file to replace with the new dbf.\nThe new dbf is in temporary file '" + str_base |
511 | 492 |
+ "'"); |
512 | 493 |
} |
513 | 494 |
if (!shpParams.getSHPFile().delete()) { |
514 |
logger.debug("Can't delete dbf file '" + shpParams.getSHPFile() + "'.");
|
|
495 |
LOGGER.debug("Can't delete dbf file '" + shpParams.getSHPFile() + "'.");
|
|
515 | 496 |
throw new IOException("Can't delete shp '" |
516 | 497 |
+ FilenameUtils.getBaseName(shpParams.getSHPFileName()) |
517 | 498 |
+ "' file to replace with the new shp.\nThe new shp is in temporary file '" + str_base |
518 | 499 |
+ "'"); |
519 | 500 |
} |
520 | 501 |
if (!shpParams.getSHXFile().delete()) { |
521 |
logger.debug("Can't delete dbf file '" + shpParams.getSHXFile() + "'.");
|
|
502 |
LOGGER.debug("Can't delete dbf file '" + shpParams.getSHXFile() + "'.");
|
|
522 | 503 |
throw new IOException("Can't delete shx '" |
523 | 504 |
+ FilenameUtils.getBaseName(shpParams.getSHXFileName()) |
524 | 505 |
+ "' file to replace with the new shx.\nThe new shx is in temporary file '" + str_base |
525 | 506 |
+ "'"); |
526 | 507 |
} |
527 | 508 |
if (shpParams.getCPGFile().exists() && !shpParams.getCPGFile().delete()) { |
528 |
logger.debug("Can't delete cpg file '" + shpParams.getCPGFile() + "'.");
|
|
509 |
LOGGER.debug("Can't delete cpg file '" + shpParams.getCPGFile() + "'.");
|
|
529 | 510 |
throw new IOException("Can't delete cpg '" |
530 | 511 |
+ FilenameUtils.getBaseName(shpParams.getCPGFileName()) |
531 | 512 |
+ "' file to replace with the new cpg.\nThe new cpg is in temporary file '" + str_base |
... | ... | |
535 | 516 |
File prjFile = SHP.getPrjFile(shpParams.getSHPFile()); |
536 | 517 |
if (prjFile.exists()) { |
537 | 518 |
if (!prjFile.delete()) { |
538 |
logger.debug("Can't delete prj file '" + prjFile + "'.");
|
|
519 |
LOGGER.debug("Can't delete prj file '" + prjFile + "'.");
|
|
539 | 520 |
throw new IOException("Can't delete shx '" |
540 | 521 |
+ FilenameUtils.getBaseName(prjFile.getPath()) |
541 | 522 |
+ "' file to replace with the new shx.\nThe new shx is in temporary file '" |
... | ... | |
595 | 576 |
FeatureStore store = getFeatureStore(); |
596 | 577 |
FeatureType fType = store.getDefaultFeatureType(); |
597 | 578 |
|
598 |
// TODO Comprobar el campo de geometria |
|
599 |
EditableFeatureType dbfFtype = fType.getEditable(); |
|
600 |
|
|
601 |
removeGeometryColumn(dbfFtype); |
|
602 |
FeatureSet set = store.getFeatureSet(); |
|
603 |
|
|
604 | 579 |
writer = new SHPFeatureWriter(getProviderName()); |
605 |
|
|
606 |
writer.begin(getShpParameters(), fType, dbfFtype, set.getSize()); |
|
580 |
writer.begin(getShpParameters(), fType, store.getFeatureCount()); |
|
607 | 581 |
return null; |
608 | 582 |
} |
609 | 583 |
}); |
Also available in: Unified diff