Revision 38340
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/dgn/TestDGN.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. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.store.dgn; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
|
|
37 |
public class TestDGN extends BaseTestFeatureStore { |
|
38 |
|
|
39 |
public static final File file_prueba = new File(TestDGN.class.getResource( |
|
40 |
"data/prueba.dgn").getFile()); |
|
41 |
|
|
42 |
/* |
|
43 |
* (non-Javadoc) |
|
44 |
* |
|
45 |
* @see |
|
46 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters |
|
47 |
* () |
|
48 |
*/ |
|
49 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
50 |
throws DataException { |
|
51 |
DGNStoreParameters dgnParameters = null; |
|
52 |
|
|
53 |
dgnParameters = (DGNStoreParameters) dataManager |
|
54 |
.createStoreParameters(DGNStoreProvider.NAME); |
|
55 |
|
|
56 |
dgnParameters.setFile(file_prueba.getAbsolutePath()); |
|
57 |
dgnParameters.setCRS("EPSG:23030"); |
|
58 |
return dgnParameters; |
|
59 |
} |
|
60 |
|
|
61 |
/* |
|
62 |
* (non-Javadoc) |
|
63 |
* |
|
64 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer() |
|
65 |
*/ |
|
66 |
public boolean hasExplorer() { |
|
67 |
// TODO Auto-generated method stub |
|
68 |
return false; |
|
69 |
} |
|
70 |
|
|
71 |
public boolean usesResources() { |
|
72 |
return true; |
|
73 |
} |
|
74 |
|
|
75 |
|
|
76 |
public void testLegendAndLabeling() throws Exception { |
|
77 |
FeatureStore store = (FeatureStore) dataManager |
|
78 |
.createStore(getDefaultDataStoreParameters()); |
|
79 |
|
|
80 |
assertNotNull(store.invokeDynMethod("getLegend", null)); |
|
81 |
assertNotNull(store.invokeDynMethod("getLabeling", null)); |
|
82 |
store.dispose(); |
|
83 |
} |
|
84 |
} |
|
0 | 85 |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/Bug15643Test.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 |
package org.gvsig.fmap.dal.store.shp; |
|
23 |
|
|
24 |
import junit.framework.TestCase; |
|
25 |
|
|
26 |
import com.vividsolutions.jts.geom.Coordinate; |
|
27 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DALLocator; |
|
30 |
import org.gvsig.fmap.dal.DataManager; |
|
31 |
import org.gvsig.fmap.dal.DataTypes; |
|
32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
34 |
import org.gvsig.fmap.dal.feature.Feature; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
37 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
|
42 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
43 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
44 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
45 |
import org.gvsig.tools.exception.BaseException; |
|
46 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
47 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
48 |
import org.gvsig.tools.visitor.Visitor; |
|
49 |
|
|
50 |
/** |
|
51 |
* Code to test bug gvsig-desktop#15643. This is based on the code provided by |
|
52 |
* the bug reporter (see ticket), thanks to him!! |
|
53 |
* |
|
54 |
* @author gvSIG Team |
|
55 |
* @version $Id$ |
|
56 |
*/ |
|
57 |
public class Bug15643Test extends TestCase { |
|
58 |
|
|
59 |
public void testBug15643() throws Exception { |
|
60 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
61 |
DataManager manager = DALLocator.getDataManager(); |
|
62 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
63 |
|
|
64 |
EditableFeatureType type = new DefaultEditableFeatureType(); |
|
65 |
GeometryType geometryType = |
|
66 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
67 |
Geometry.SUBTYPES.GEOM2D); |
|
68 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
69 |
.setGeometryType(geometryType); |
|
70 |
type.setDefaultGeometryAttributeName("geom"); |
|
71 |
type.add("float", DataTypes.FLOAT).setSize(5); |
|
72 |
type.add("double", DataTypes.DOUBLE).setSize(5); |
|
73 |
type.add("int", DataTypes.INT).setSize(5); |
|
74 |
type.add("long", DataTypes.LONG).setSize(5); |
|
75 |
|
|
76 |
NewFeatureStoreParameters destParams = |
|
77 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
78 |
"FilesystemExplorer", "Shape"); |
|
79 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
80 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
81 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
82 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
83 |
destParams.setDefaultFeatureType(type); |
|
84 |
|
|
85 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
86 |
FeatureStore store = |
|
87 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
88 |
|
|
89 |
store.edit(); |
|
90 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
91 |
com.vividsolutions.jts.geom.Geometry g = |
|
92 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
|
93 |
|
|
94 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME); |
|
95 |
GeometryOperation converter = |
|
96 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
|
97 |
Geometry.SUBTYPES.GEOM2D); |
|
98 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
99 |
ctx.setAttribute(FromJTS.PARAM, g); |
|
100 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx); |
|
101 |
feature.setGeometry(feature.getType() |
|
102 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
|
103 |
feature.setFloat("float", 34.0f); |
|
104 |
feature.setDouble("double", 34.0d); |
|
105 |
feature.setInt("int", 34); |
|
106 |
feature.setLong("long", 34l); |
|
107 |
store.insert(feature); |
|
108 |
store.finishEditing(); |
|
109 |
|
|
110 |
store.accept(new Visitor() { |
|
111 |
|
|
112 |
public void visit(Object obj) throws VisitCanceledException, |
|
113 |
BaseException { |
|
114 |
Feature feature = (Feature) obj; |
|
115 |
assertEquals(34.0f, feature.getFloat("float")); |
|
116 |
assertEquals(34.0d, feature.getDouble("double")); |
|
117 |
assertEquals(34, feature.getInt("int")); |
|
118 |
assertEquals(34l, feature.getLong("long")); |
|
119 |
} |
|
120 |
}); |
|
121 |
|
|
122 |
store.dispose(); |
|
123 |
} |
|
124 |
|
|
125 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/Bug15670Test.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 |
package org.gvsig.fmap.dal.store.shp; |
|
23 |
|
|
24 |
import junit.framework.TestCase; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.DALLocator; |
|
27 |
import org.gvsig.fmap.dal.DataManager; |
|
28 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
29 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
30 |
import org.gvsig.fmap.dal.feature.Feature; |
|
31 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
32 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
33 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
34 |
import org.gvsig.fmap.geom.Geometry; |
|
35 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
36 |
import org.gvsig.fmap.geom.GeometryManager; |
|
37 |
import org.gvsig.fmap.geom.primitive.Point; |
|
38 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
39 |
import org.gvsig.tools.exception.BaseException; |
|
40 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
41 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
42 |
import org.gvsig.tools.visitor.Visitor; |
|
43 |
|
|
44 |
/** |
|
45 |
* Code to test bug gvsig-desktop#15670. This is based on the code provided by |
|
46 |
* the bug reporter (see ticket), thanks to him!! |
|
47 |
* |
|
48 |
* @author gvSIG Team |
|
49 |
* @version $Id$ |
|
50 |
*/ |
|
51 |
public class Bug15670Test extends TestCase { |
|
52 |
|
|
53 |
public void testBug15670() throws Exception { |
|
54 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
55 |
DataManager manager = DALLocator.getDataManager(); |
|
56 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
57 |
|
|
58 |
EditableFeatureType type = new DefaultEditableFeatureType(); |
|
59 |
GeometryType geometryType = |
|
60 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
61 |
Geometry.SUBTYPES.GEOM2D); |
|
62 |
type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
63 |
.setGeometryType(geometryType); |
|
64 |
type.setDefaultGeometryAttributeName("GEOMETRY"); |
|
65 |
|
|
66 |
NewFeatureStoreParameters destParams = |
|
67 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
68 |
"FilesystemExplorer", "Shape"); |
|
69 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
70 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
71 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
72 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
73 |
destParams.setDefaultFeatureType(type); |
|
74 |
|
|
75 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
76 |
FeatureStore store = |
|
77 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
78 |
|
|
79 |
store.edit(); |
|
80 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
81 |
final Point geom = |
|
82 |
geometryManager.createPoint(10.0, 10.0, Geometry.SUBTYPES.GEOM2D); |
|
83 |
feature.setGeometry("GEOMETRY", geom); |
|
84 |
store.insert(feature); |
|
85 |
store.finishEditing(); |
|
86 |
|
|
87 |
store.accept(new Visitor() { |
|
88 |
|
|
89 |
public void visit(Object obj) throws VisitCanceledException, |
|
90 |
BaseException { |
|
91 |
Feature feature = (Feature) obj; |
|
92 |
assertEquals(geom, feature.getGeometry("GEOMETRY")); |
|
93 |
} |
|
94 |
}); |
|
95 |
store.dispose(); |
|
96 |
} |
|
97 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/Bug15617Test.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 |
package org.gvsig.fmap.dal.store.shp; |
|
23 |
|
|
24 |
import junit.framework.TestCase; |
|
25 |
|
|
26 |
import com.vividsolutions.jts.geom.Coordinate; |
|
27 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DALLocator; |
|
30 |
import org.gvsig.fmap.dal.DataManager; |
|
31 |
import org.gvsig.fmap.dal.DataTypes; |
|
32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
34 |
import org.gvsig.fmap.dal.feature.Feature; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
37 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
|
42 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
43 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
44 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
45 |
import org.gvsig.tools.exception.BaseException; |
|
46 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
47 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
48 |
import org.gvsig.tools.visitor.Visitor; |
|
49 |
|
|
50 |
/** |
|
51 |
* Code to test bug gvsig-desktop#15617. |
|
52 |
* |
|
53 |
* @author gvSIG Team |
|
54 |
* @version $Id$ |
|
55 |
*/ |
|
56 |
public class Bug15617Test extends TestCase { |
|
57 |
|
|
58 |
public void testBug15617() throws Exception { |
|
59 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
60 |
DataManager manager = DALLocator.getDataManager(); |
|
61 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
62 |
|
|
63 |
EditableFeatureType type = new DefaultEditableFeatureType(); |
|
64 |
GeometryType geometryType = |
|
65 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
66 |
Geometry.SUBTYPES.GEOM2D); |
|
67 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
68 |
.setGeometryType(geometryType); |
|
69 |
type.setDefaultGeometryAttributeName("geom"); |
|
70 |
// type.add("float", DataTypes.FLOAT).setSize(5); |
|
71 |
// type.add("double", DataTypes.DOUBLE).setSize(5); |
|
72 |
type.add("int", DataTypes.INT).setSize(5); |
|
73 |
// type.add("long", DataTypes.LONG).setSize(5); |
|
74 |
type.add("bool", DataTypes.BOOLEAN); |
|
75 |
|
|
76 |
NewFeatureStoreParameters destParams = |
|
77 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
78 |
"FilesystemExplorer", "Shape"); |
|
79 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
80 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
81 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
82 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
83 |
destParams.setDefaultFeatureType(type); |
|
84 |
|
|
85 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
86 |
FeatureStore store = |
|
87 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
88 |
|
|
89 |
store.edit(); |
|
90 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
91 |
com.vividsolutions.jts.geom.Geometry g = |
|
92 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
|
93 |
|
|
94 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME); |
|
95 |
GeometryOperation converter = |
|
96 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
|
97 |
Geometry.SUBTYPES.GEOM2D); |
|
98 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
99 |
ctx.setAttribute(FromJTS.PARAM, g); |
|
100 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx); |
|
101 |
feature.setGeometry(feature.getType() |
|
102 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
|
103 |
// feature.setFloat("float", 34.0f); |
|
104 |
// feature.setDouble("double", 34.0d); |
|
105 |
feature.setInt("int", 25); |
|
106 |
// feature.setLong("long", 34l); |
|
107 |
feature.setBoolean("bool", true); |
|
108 |
assertEquals(true, feature.getBoolean("bool")); |
|
109 |
store.insert(feature); |
|
110 |
store.finishEditing(); |
|
111 |
|
|
112 |
store.accept(new Visitor() { |
|
113 |
|
|
114 |
public void visit(Object obj) throws VisitCanceledException, |
|
115 |
BaseException { |
|
116 |
Feature feature = (Feature) obj; |
|
117 |
// assertEquals(34.0f, feature.getFloat("float")); |
|
118 |
// assertEquals(34.0d, feature.getDouble("double")); |
|
119 |
assertEquals(25, feature.getInt("int")); |
|
120 |
// assertEquals(34l, feature.getLong("long")); |
|
121 |
assertEquals(true, feature.getBoolean("bool")); |
|
122 |
} |
|
123 |
}); |
|
124 |
|
|
125 |
store.dispose(); |
|
126 |
} |
|
127 |
|
|
128 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/Bug15671Test.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 |
package org.gvsig.fmap.dal.store.shp; |
|
23 |
|
|
24 |
import junit.framework.TestCase; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.DALLocator; |
|
27 |
import org.gvsig.fmap.dal.DataManager; |
|
28 |
import org.gvsig.fmap.dal.DataTypes; |
|
29 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
30 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
31 |
import org.gvsig.fmap.dal.feature.Feature; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
33 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
34 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
35 |
import org.gvsig.fmap.geom.Geometry; |
|
36 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
37 |
import org.gvsig.fmap.geom.GeometryManager; |
|
38 |
import org.gvsig.fmap.geom.primitive.NullGeometry; |
|
39 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
40 |
import org.gvsig.tools.exception.BaseException; |
|
41 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
42 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
43 |
import org.gvsig.tools.visitor.Visitor; |
|
44 |
|
|
45 |
/** |
|
46 |
* Code to test bug gvsig-desktop#15671. This is based on the code provided by |
|
47 |
* the bug reporter (see ticket), thanks to him!! |
|
48 |
* |
|
49 |
* @author gvSIG Team |
|
50 |
* @version $Id$ |
|
51 |
*/ |
|
52 |
public class Bug15671Test extends TestCase { |
|
53 |
|
|
54 |
public void testBug15671() throws Exception { |
|
55 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
56 |
DataManager manager = DALLocator.getDataManager(); |
|
57 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
58 |
|
|
59 |
EditableFeatureType type = new DefaultEditableFeatureType(); |
|
60 |
GeometryType geometryType = |
|
61 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
62 |
Geometry.SUBTYPES.GEOM2D); |
|
63 |
type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
64 |
.setGeometryType(geometryType); |
|
65 |
type.setDefaultGeometryAttributeName("GEOMETRY"); |
|
66 |
type.add("double", DataTypes.DOUBLE); |
|
67 |
|
|
68 |
NewFeatureStoreParameters destParams = |
|
69 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
70 |
"FilesystemExplorer", "Shape"); |
|
71 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
72 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
73 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
74 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
75 |
destParams.setDefaultFeatureType(type); |
|
76 |
|
|
77 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
78 |
FeatureStore store = |
|
79 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
80 |
|
|
81 |
store.edit(); |
|
82 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
83 |
NullGeometry geom = |
|
84 |
geometryManager.createNullGeometry(Geometry.SUBTYPES.GEOM2D); |
|
85 |
feature.setGeometry("GEOMETRY", geom); |
|
86 |
feature.setDouble("double", 42.0d); |
|
87 |
store.insert(feature); |
|
88 |
store.finishEditing(); |
|
89 |
|
|
90 |
store.accept(new Visitor() { |
|
91 |
|
|
92 |
public void visit(Object obj) throws VisitCanceledException, |
|
93 |
BaseException { |
|
94 |
Feature feature = (Feature) obj; |
|
95 |
Geometry geometry = feature.getGeometry("GEOMETRY"); |
|
96 |
assertEquals( |
|
97 |
"Read geometry must be of Null Geometry type instead of " |
|
98 |
+ geometry.getGeometryType().getName(), |
|
99 |
Geometry.TYPES.NULL, geometry.getType()); |
|
100 |
} |
|
101 |
}); |
|
102 |
store.dispose(); |
|
103 |
} |
|
104 |
|
|
105 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/Bug15597Test.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 |
package org.gvsig.fmap.dal.store.shp; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import org.gvsig.fmap.dal.DALLocator; |
|
29 |
import org.gvsig.fmap.dal.DataManager; |
|
30 |
import org.gvsig.fmap.dal.DataTypes; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
32 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
33 |
import org.gvsig.fmap.dal.feature.Feature; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
37 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
41 |
import org.gvsig.fmap.geom.GeometryManager; |
|
42 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
43 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
44 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
45 |
|
|
46 |
/** |
|
47 |
* Code to test bug gvsig-desktop#15597. This is based on the code provided by |
|
48 |
* the bug reporter (see ticket), thanks to him!! |
|
49 |
* |
|
50 |
* @author gvSIG Team |
|
51 |
* @version $Id$ |
|
52 |
*/ |
|
53 |
public class Bug15597Test extends TestCase { |
|
54 |
private static final String TEMP_PATH = System.getProperty("java.io.tmpdir") + File.separator; |
|
55 |
|
|
56 |
public void testBug15642() throws Exception { |
|
57 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
58 |
DataManager manager = DALLocator.getDataManager(); |
|
59 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
60 |
|
|
61 |
//Create a feature type with two fields: "geom" and "field1" |
|
62 |
EditableFeatureType type = new DefaultEditableFeatureType(); |
|
63 |
GeometryType geometryType = |
|
64 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
65 |
Geometry.SUBTYPES.GEOM2D); |
|
66 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
67 |
.setGeometryType(geometryType); |
|
68 |
type.setDefaultGeometryAttributeName("geom"); |
|
69 |
type.add("field1", DataTypes.STRING).setSize(2); |
|
70 |
|
|
71 |
//Create a store |
|
72 |
NewFeatureStoreParameters destParams = |
|
73 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
74 |
"FilesystemExplorer", "Shape"); |
|
75 |
destParams.setDynValue("shpfile", TEMP_PATH + "mySHP.shp"); |
|
76 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
77 |
destParams.setDefaultFeatureType(type); |
|
78 |
|
|
79 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
80 |
FeatureStore store = |
|
81 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
82 |
|
|
83 |
|
|
84 |
//Edit the store and add a new Feature. |
|
85 |
store.edit(); |
|
86 |
|
|
87 |
EditableFeature feature1 = store.createNewFeature().getEditable(); |
|
88 |
feature1.setGeometry(type.getDefaultGeometryAttributeIndex(), |
|
89 |
geometryManager.createPoint(0, 0, SUBTYPES.GEOM2D)); |
|
90 |
feature1.set("field1", "Hi"); |
|
91 |
|
|
92 |
store.insert(feature1); |
|
93 |
|
|
94 |
//Finish the edition |
|
95 |
store.finishEditing(); |
|
96 |
|
|
97 |
//Edit the feature type and add a new field: "field2" |
|
98 |
store.edit(); |
|
99 |
|
|
100 |
EditableFeatureType type2 = |
|
101 |
store.getDefaultFeatureType().getEditable(); |
|
102 |
type2.add("field2", DataTypes.STRING).setSize(10); |
|
103 |
store.update(type2); |
|
104 |
|
|
105 |
assertEquals(store.getDefaultFeatureType().getAttributeDescriptors().length, 3); |
|
106 |
|
|
107 |
//Add a second feature |
|
108 |
EditableFeature feature2 = store.createNewFeature().getEditable(); |
|
109 |
feature2.setGeometry(type2.getDefaultGeometryAttributeIndex(), |
|
110 |
geometryManager.createPoint(1, 1, SUBTYPES.GEOM2D)); |
|
111 |
feature2.set("field1", "Hi"); |
|
112 |
feature2.set("field2", "Max"); |
|
113 |
|
|
114 |
store.insert(feature2); |
|
115 |
|
|
116 |
//The edition is not finished. Check if all the features have the two fields |
|
117 |
FeatureSet featureSet = store.getFeatureSet(); |
|
118 |
DisposableIterator it = featureSet.fastIterator(); |
|
119 |
|
|
120 |
it.hasNext(); |
|
121 |
Feature feature = (Feature)it.next(); |
|
122 |
assertNotNull(feature.getDefaultGeometry()); |
|
123 |
assertEquals("Hi", feature.get("field1")); |
|
124 |
assertNull(feature.get("field2")); |
|
125 |
|
|
126 |
it.hasNext(); |
|
127 |
feature = (Feature)it.next(); |
|
128 |
assertNotNull(feature.getDefaultGeometry()); |
|
129 |
assertEquals("Hi", feature.get("field1")); |
|
130 |
assertEquals("Max", feature.get("field2")); |
|
131 |
|
|
132 |
it.dispose(); |
|
133 |
store.finishEditing(); |
|
134 |
|
|
135 |
//Edit the feature type and remove the field: "field1" |
|
136 |
store.edit(); |
|
137 |
|
|
138 |
EditableFeatureType type3 = |
|
139 |
store.getDefaultFeatureType().getEditable(); |
|
140 |
type3.remove("field1"); |
|
141 |
store.update(type3); |
|
142 |
|
|
143 |
assertEquals(store.getDefaultFeatureType().getAttributeDescriptors().length, 2); |
|
144 |
|
|
145 |
//Finish the edition |
|
146 |
store.finishEditing(); |
|
147 |
|
|
148 |
//Check if all the features have one field |
|
149 |
featureSet = store.getFeatureSet(); |
|
150 |
it = featureSet.fastIterator(); |
|
151 |
|
|
152 |
it.hasNext(); |
|
153 |
feature = (Feature)it.next(); |
|
154 |
assertNotNull(feature.getDefaultGeometry()); |
|
155 |
assertEquals("", feature.get("field2")); |
|
156 |
|
|
157 |
it.hasNext(); |
|
158 |
feature = (Feature)it.next(); |
|
159 |
assertNotNull(feature.getDefaultGeometry()); |
|
160 |
assertEquals("Max", feature.get("field2")); |
|
161 |
|
|
162 |
it.dispose(); |
|
163 |
store.dispose(); |
|
164 |
} |
|
165 |
} |
|
0 | 166 |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/TestSHP.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. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.store.shp; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
import java.util.Iterator; |
|
32 |
|
|
33 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
34 |
import org.gvsig.fmap.dal.exception.DataException; |
|
35 |
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
|
36 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
37 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
38 |
import org.gvsig.fmap.dal.feature.Feature; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
42 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
43 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
44 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
45 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
46 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
|
47 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
|
48 |
|
|
49 |
public class TestSHP extends BaseTestEditableFeatureStore { |
|
50 |
|
|
51 |
private FilesystemServerExplorer myExplorer; |
|
52 |
|
|
53 |
public static final File file_prueba = new File(TestSHP.class.getResource( |
|
54 |
"data/prueba.shp").getFile()); |
|
55 |
public static final File file_prueba_destino = new File(file_prueba |
|
56 |
.getParent() |
|
57 |
+ File.separatorChar + "pruebaTemp.shp"); |
|
58 |
public static final File file_pruebaNull = new File(TestSHP.class |
|
59 |
.getResource("data/pruebaNull.shp").getFile()); |
|
60 |
|
|
61 |
public static final File file_poly_valencia = new File(TestSHP.class |
|
62 |
.getResource("data/poly-valencia.shp").getFile()); |
|
63 |
|
|
64 |
public void testSimpleIteration() throws Exception { |
|
65 |
|
|
66 |
FeatureStore store = null; |
|
67 |
SHPStoreParameters shpParameters = null; |
|
68 |
|
|
69 |
shpParameters = (SHPStoreParameters) dataManager |
|
70 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
71 |
|
|
72 |
// shpParameters.setFile(file_poly_valencia); |
|
73 |
shpParameters.setFile(file_prueba); |
|
74 |
|
|
75 |
shpParameters.setCRS("EPSG:23030"); |
|
76 |
|
|
77 |
store = (FeatureStore) dataManager.createStore(shpParameters); |
|
78 |
FeatureSet set; |
|
79 |
FeatureType type = store.getDefaultFeatureType(); |
|
80 |
set = store.getFeatureSet(); |
|
81 |
|
|
82 |
System.out.println("Num:" + set.getSize()); |
|
83 |
DisposableIterator it = set.iterator(); |
|
84 |
Iterator ftIt; |
|
85 |
FeatureAttributeDescriptor desc; |
|
86 |
|
|
87 |
int i = 0; |
|
88 |
Feature feature; |
|
89 |
while (it.hasNext()) { |
|
90 |
ftIt = type.iterator(); |
|
91 |
|
|
92 |
feature = (Feature) it.next(); |
|
93 |
// while (ftIt.hasNext()) { |
|
94 |
// desc = (FeatureAttributeDescriptor) ftIt.next(); |
|
95 |
// System.out.println(desc.getName() + ":" |
|
96 |
// + feature.get(desc.getIndex())); |
|
97 |
// |
|
98 |
// } |
|
99 |
// System.out.println(feature.get("NOMBRE")); |
|
100 |
System.out.print(feature.getDefaultEnvelope() + "\t"); |
|
101 |
// System.out.print(feature.getDefaultGeometry() + "\t"); |
|
102 |
// System.out.println(feature.get("NOMBRE")); |
|
103 |
System.out.println("row:" + i); |
|
104 |
i++; |
|
105 |
|
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
it.dispose(); |
|
110 |
set.dispose(); |
|
111 |
|
|
112 |
store.dispose(); |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
public void testEditing(Object x) throws Exception { |
|
117 |
FeatureStore store = null; |
|
118 |
SHPStoreParameters shpParameters = null; |
|
119 |
|
|
120 |
shpParameters = (SHPStoreParameters) dataManager |
|
121 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
122 |
|
|
123 |
shpParameters.setFile(file_poly_valencia); |
|
124 |
|
|
125 |
store = (FeatureStore) dataManager.createStore(shpParameters); |
|
126 |
FeatureSet set; |
|
127 |
FeatureType type = store.getDefaultFeatureType(); |
|
128 |
System.err.println("Antes de la edici?n"); |
|
129 |
set = store.getFeatureSet(); |
|
130 |
System.out.println("Num:" + set.getSize()); |
|
131 |
DisposableIterator it = set.iterator(); |
|
132 |
Iterator ftIt; |
|
133 |
FeatureAttributeDescriptor desc; |
|
134 |
|
|
135 |
int i = 0; |
|
136 |
Feature feature; |
|
137 |
while (it.hasNext()) { |
|
138 |
ftIt = type.iterator(); |
|
139 |
|
|
140 |
feature = (Feature) it.next(); |
|
141 |
// while (ftIt.hasNext()) { |
|
142 |
// desc = (FeatureAttributeDescriptor) ftIt.next(); |
|
143 |
// System.out.println(desc.getName() + ":" |
|
144 |
// + feature.get(desc.getIndex())); |
|
145 |
// |
|
146 |
// } |
|
147 |
// System.out.println(feature.get("NOMBRE")); |
|
148 |
System.out.print(feature.getDefaultEnvelope() + "\t"); |
|
149 |
// System.out.print(feature.getDefaultGeometry() + "\t"); |
|
150 |
// System.out.println(feature.get("NOMBRE")); |
|
151 |
System.out.println("row:" + i); |
|
152 |
i++; |
|
153 |
|
|
154 |
|
|
155 |
} |
|
156 |
|
|
157 |
it.dispose(); |
|
158 |
set.dispose(); |
|
159 |
store.edit(); |
|
160 |
EditableFeature ef = store.createNewFeature(); |
|
161 |
store.insert(ef); |
|
162 |
store.finishEditing(); |
|
163 |
System.err.println("Despu?s de la edici?n"); |
|
164 |
set = store.getFeatureSet(); |
|
165 |
System.out.println("Num:" + set.getSize()); |
|
166 |
it = set.iterator(); |
|
167 |
|
|
168 |
i = 0; |
|
169 |
while (it.hasNext()) { |
|
170 |
ftIt = type.iterator(); |
|
171 |
|
|
172 |
feature = (Feature) it.next(); |
|
173 |
// while (ftIt.hasNext()) { |
|
174 |
// desc = (FeatureAttributeDescriptor) ftIt.next(); |
|
175 |
// System.out.println(desc.getName() + ":" |
|
176 |
// + feature.get(desc.getIndex())); |
|
177 |
// |
|
178 |
// } |
|
179 |
// System.out.println(feature.get("NOMBRE")); |
|
180 |
System.out.print(feature.getDefaultEnvelope() + "\t"); |
|
181 |
// System.out.print(feature.getDefaultGeometry() + "\t"); |
|
182 |
// System.out.println(feature.get("NOMBRE")); |
|
183 |
System.out.println("row:" + i); |
|
184 |
i++; |
|
185 |
|
|
186 |
|
|
187 |
} |
|
188 |
|
|
189 |
it.dispose(); |
|
190 |
set.dispose(); |
|
191 |
|
|
192 |
store.dispose(); |
|
193 |
|
|
194 |
} |
|
195 |
|
|
196 |
public void testExport(Object x) throws Exception { |
|
197 |
DBFStoreParameters dbfParameters = null; |
|
198 |
|
|
199 |
dbfParameters = (DBFStoreParameters) dataManager |
|
200 |
.createStoreParameters(DBFStoreProvider.NAME); |
|
201 |
|
|
202 |
dbfParameters.setFile(file_prueba); |
|
203 |
|
|
204 |
FeatureStore store = (FeatureStore) dataManager |
|
205 |
.createStore(dbfParameters); |
|
206 |
FilesystemServerExplorerParameters explorerParams = (FilesystemServerExplorerParameters) dataManager |
|
207 |
.createServerExplorerParameters(FilesystemServerExplorerParameters.DYNCLASS_NAME); |
|
208 |
explorerParams.setRoot(file_prueba.getParent()); |
|
209 |
|
|
210 |
FilesystemServerExplorer explorer = (FilesystemServerExplorer) dataManager |
|
211 |
.createServerExplorer(explorerParams); |
|
212 |
|
|
213 |
NewFeatureStoreParameters newParams = (NewFeatureStoreParameters) explorer |
|
214 |
.getAddParameters(file_prueba_destino); |
|
215 |
|
|
216 |
store.export(explorer, DBFStoreProvider.NAME, newParams); |
|
217 |
|
|
218 |
FeatureStore result = (FeatureStore) dataManager.createStore(newParams); |
|
219 |
|
|
220 |
FeatureSet set = result.getFeatureSet(); |
|
221 |
FeatureSet originalSet = store.getFeatureSet(); |
|
222 |
assertEquals(set.getSize(), originalSet.getSize()); |
|
223 |
|
|
224 |
DisposableIterator originalIter = originalSet.iterator(); |
|
225 |
DisposableIterator iter = set.iterator(); |
|
226 |
while (iter.hasNext()) { |
|
227 |
assertEquals(originalIter.next(), iter.next()); |
|
228 |
} |
|
229 |
|
|
230 |
originalIter.dispose(); |
|
231 |
iter.dispose(); |
|
232 |
result.dispose(); |
|
233 |
explorer.remove(newParams); |
|
234 |
|
|
235 |
} |
|
236 |
|
|
237 |
/* |
|
238 |
* (non-Javadoc) |
|
239 |
* |
|
240 |
* @see |
|
241 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters |
|
242 |
* () |
|
243 |
*/ |
|
244 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
245 |
throws DataException { |
|
246 |
SHPStoreParameters shpParameters = (SHPStoreParameters) dataManager |
|
247 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
248 |
|
|
249 |
// shpParameters.setFile(file_poly_valencia); |
|
250 |
shpParameters.setFile(file_prueba); |
|
251 |
shpParameters.setCRS("EPSG:23030"); |
|
252 |
return shpParameters; |
|
253 |
} |
|
254 |
|
|
255 |
/* |
|
256 |
* (non-Javadoc) |
|
257 |
* |
|
258 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer() |
|
259 |
*/ |
|
260 |
public boolean hasExplorer() { |
|
261 |
return true; |
|
262 |
} |
|
263 |
|
|
264 |
/* |
|
265 |
* (non-Javadoc) |
|
266 |
* |
|
267 |
* @seeorg.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore# |
|
268 |
* getDefaultNewDataStoreParameters() |
|
269 |
*/ |
|
270 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters() |
|
271 |
throws Exception { |
|
272 |
SHPStoreParameters parameters = (SHPStoreParameters) this |
|
273 |
.getDefaultDataStoreParameters(); |
|
274 |
|
|
275 |
if (this.myExplorer == null) { |
|
276 |
FeatureStore store = (FeatureStore) dataManager |
|
277 |
.createStore(parameters); |
|
278 |
myExplorer = (FilesystemServerExplorer) store.getExplorer(); |
|
279 |
store.dispose(); |
|
280 |
} |
|
281 |
|
|
282 |
SHPNewStoreParameters result = (SHPNewStoreParameters) myExplorer |
|
283 |
.getAddParameters(file_prueba_destino); |
|
284 |
|
|
285 |
result.setCRS(parameters.getCRS()); |
|
286 |
return result; |
|
287 |
} |
|
288 |
|
|
289 |
public boolean usesResources() { |
|
290 |
return true; |
|
291 |
} |
|
292 |
|
|
293 |
public boolean resourcesNotifyChanges() { |
|
294 |
return true; |
|
295 |
} |
|
296 |
|
|
297 |
} |
|
0 | 298 |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/Bug15642Test.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 |
package org.gvsig.fmap.dal.store.shp; |
|
23 |
|
|
24 |
import junit.framework.TestCase; |
|
25 |
|
|
26 |
import com.vividsolutions.jts.geom.Coordinate; |
|
27 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DALLocator; |
|
30 |
import org.gvsig.fmap.dal.DataManager; |
|
31 |
import org.gvsig.fmap.dal.DataTypes; |
|
32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
37 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
|
42 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
43 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
44 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
45 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
46 |
|
|
47 |
/** |
|
48 |
* Code to test bug gvsig-desktop#15642. This is based on the code provided by |
|
49 |
* the bug reporter (see ticket), thanks to him!! |
|
50 |
* |
|
51 |
* @author gvSIG Team |
|
52 |
* @version $Id$ |
|
53 |
*/ |
|
54 |
public class Bug15642Test extends TestCase { |
|
55 |
|
|
56 |
public void testBug15642() throws Exception { |
|
57 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
58 |
DataManager manager = DALLocator.getDataManager(); |
|
59 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
60 |
|
|
61 |
EditableFeatureType type = new DefaultEditableFeatureType(); |
|
62 |
GeometryType geometryType = |
|
63 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
64 |
Geometry.SUBTYPES.GEOM2D); |
|
65 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
66 |
.setGeometryType(geometryType); |
|
67 |
type.setDefaultGeometryAttributeName("geom"); |
|
68 |
type.add("float", DataTypes.FLOAT).setSize(5); |
|
69 |
type.add("long", DataTypes.LONG).setSize(5); |
|
70 |
|
|
71 |
NewFeatureStoreParameters destParams = |
|
72 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
73 |
"FilesystemExplorer", "Shape"); |
|
74 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
75 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
76 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
77 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
78 |
destParams.setDefaultFeatureType(type); |
|
79 |
|
|
80 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
81 |
FeatureStore store = |
|
82 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
83 |
|
|
84 |
store.edit(); |
|
85 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
86 |
com.vividsolutions.jts.geom.Geometry g = |
|
87 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
|
88 |
|
|
89 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME); |
|
90 |
GeometryOperation converter = |
|
91 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
|
92 |
Geometry.SUBTYPES.GEOM2D); |
|
93 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
94 |
ctx.setAttribute(FromJTS.PARAM, g); |
|
95 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx); |
|
96 |
feature.setGeometry(feature.getType() |
|
97 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
|
98 |
feature.setFloat("float", 34.0f); |
|
99 |
feature.setLong("long", 34l); |
|
100 |
store.insert(feature); |
|
101 |
store.finishEditing(); |
|
102 |
|
|
103 |
FeatureAttributeDescriptor defaultGeometryAttribute = |
|
104 |
store.getDefaultFeatureType().getDefaultGeometryAttribute(); |
|
105 |
|
|
106 |
geometryType = defaultGeometryAttribute.getGeomType(); |
|
107 |
assertEquals(Geometry.TYPES.POINT, geometryType.getType()); |
|
108 |
assertEquals(Geometry.SUBTYPES.GEOM2D, geometryType.getSubType()); |
|
109 |
|
|
110 |
store.dispose(); |
|
111 |
} |
|
112 |
|
|
113 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_dalfile/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/dbf/JoinTransform.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.dbf; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Arrays; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.Map; |
|
8 |
import java.util.Map.Entry; |
|
9 |
|
|
10 |
import org.gvsig.fmap.dal.exception.DataException; |
|
11 |
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform; |
|
12 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
13 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
14 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
15 |
import org.gvsig.fmap.dal.feature.Feature; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
17 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
20 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
21 |
import org.gvsig.tools.evaluator.Evaluator; |
|
22 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
23 |
import org.gvsig.tools.evaluator.EvaluatorException; |
|
24 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
|
25 |
import org.gvsig.tools.persistence.PersistentState; |
|
26 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
27 |
|
|
28 |
public class JoinTransform extends AbstractFeatureStoreTransform { |
|
29 |
|
|
30 |
/** |
|
31 |
* Store from which the join transform will get the additional attributes |
|
32 |
*/ |
|
33 |
private FeatureStore store2; |
|
34 |
|
|
35 |
/** |
|
36 |
* name of the key attr in store1 that will be used to match features in |
|
37 |
* store2 |
|
38 |
*/ |
|
39 |
private String keyAttr1; |
|
40 |
|
|
41 |
/** |
|
42 |
* name of the key attr in store2 that will be used to match features in |
|
43 |
* store1 |
|
44 |
*/ |
|
45 |
private String keyAttr2; |
|
46 |
|
|
47 |
/** |
|
48 |
* names of the attributes to join from store2 to store1 |
|
49 |
*/ |
|
50 |
private String[] attrs; |
|
51 |
|
|
52 |
/** |
|
53 |
* Attribute names may change after transformation if they are repeated in |
|
54 |
* both stores. This map keeps correspondence between store2 original names |
|
55 |
* and their transformed counterparts. |
|
56 |
*/ |
|
57 |
private Map targetNamesMap; |
|
58 |
|
|
59 |
private JoinTransformEvaluator evaluator = null; |
|
60 |
|
|
61 |
private FeatureType originalFeatureType; |
|
62 |
|
|
63 |
private String[] attrsForQuery; |
|
64 |
|
|
65 |
private String prefix1; |
|
66 |
|
|
67 |
private String prefix2; |
|
68 |
|
|
69 |
/** |
|
70 |
* A default constructor |
|
71 |
*/ |
|
72 |
public JoinTransform() { |
|
73 |
targetNamesMap = new HashMap(); |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Initializes all the necessary data for this transform |
|
78 |
* |
|
79 |
* @param store1 |
|
80 |
* store whose default feature type is the target of this |
|
81 |
* transform |
|
82 |
* |
|
83 |
* @param store2 |
|
84 |
* store whose default feature type will provide the new |
|
85 |
* attributes to join |
|
86 |
* |
|
87 |
* @param keyAttr1 |
|
88 |
* key attribute in store1 that matches keyAttr2 in store2 |
|
89 |
* (foreign key), used for joining both stores. |
|
90 |
* |
|
91 |
* @param keyAttr2 |
|
92 |
* key attribute in store2 that matches keyAttr1 in store2 |
|
93 |
* (foreign key), used for joining both stores. |
|
94 |
* |
|
95 |
* @param attrs |
|
96 |
* names of the attributes in store2 that will be joined to |
|
97 |
* store1. |
|
98 |
*/ |
|
99 |
public void initialize(FeatureStore store1, FeatureStore store2, |
|
100 |
String keyAttr1, String keyAttr2, String prefix1, String prefix2, |
|
101 |
String[] attrs) |
|
102 |
throws DataException { |
|
103 |
|
|
104 |
if (store1 == store2) { |
|
105 |
throw new IllegalArgumentException("store1 == store2"); |
|
106 |
} |
|
107 |
|
|
108 |
// Initialize needed data |
|
109 |
this.setFeatureStore(store1); |
|
110 |
this.store2 = store2; |
|
111 |
this.keyAttr1 = keyAttr1; |
|
112 |
this.keyAttr2 = keyAttr2; |
|
113 |
this.prefix1 = prefix1; // TODO |
|
114 |
this.prefix2 = prefix2; // TODO |
|
115 |
this.attrs = attrs; |
|
116 |
|
|
117 |
// calculate this transform resulting feature type |
|
118 |
// by adding all specified attrs from store2 to store1's default |
|
119 |
// feature type |
|
120 |
// FIXME for more than one FTypes ?? |
|
121 |
this.originalFeatureType = this.getFeatureStore() |
|
122 |
.getDefaultFeatureType(); |
|
123 |
|
|
124 |
// TODO tener en cuenta prefix1 |
|
125 |
EditableFeatureType type = this.getFeatureStore().getDefaultFeatureType().getEditable(); |
|
126 |
|
|
127 |
FeatureType type2 = store2.getDefaultFeatureType(); |
|
128 |
|
|
129 |
// TODO tener en cuenta prefix2 |
|
130 |
for (int i = 0; i < attrs.length; i++) { |
|
131 |
String name = attrs[i]; |
|
132 |
|
|
133 |
// If an attribute already exists with the same name in store1's |
|
134 |
// default feature type, |
|
135 |
// calculate an alternate name and add it to our type |
|
136 |
int j = 0; |
|
137 |
while (type.getIndex(name) >= 0) { |
|
138 |
name = attrs[i] + "_" + ++j; |
|
139 |
} |
|
140 |
type.add(name, |
|
141 |
type2.getAttributeDescriptor(attrs[i]).getType()); |
|
142 |
|
|
143 |
// keep correspondence between original name and transformed name |
|
144 |
this.targetNamesMap.put(attrs[i], name); |
|
145 |
} |
|
146 |
if (this.targetNamesMap.containsKey(keyAttr2)) { |
|
147 |
this.attrsForQuery = this.attrs; |
|
148 |
} else { |
|
149 |
ArrayList list = new ArrayList(this.attrs.length + 1); |
|
150 |
list.addAll(Arrays.asList(this.attrs)); |
|
151 |
list.add(keyAttr2); |
|
152 |
this.attrsForQuery = (String[]) list.toArray(new String[] {}); |
|
153 |
} |
|
154 |
|
|
155 |
// assign calculated feature type as this transform's feature type |
|
156 |
FeatureType[] types = new FeatureType[] { type.getNotEditableCopy() }; |
|
157 |
setFeatureTypes(Arrays.asList(types), types[0]); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* |
|
162 |
* |
|
163 |
* @param source |
|
164 |
* |
|
165 |
* @param target |
|
166 |
* |
|
167 |
* @throws DataException |
|
168 |
*/ |
|
169 |
public void applyTransform(Feature source, EditableFeature target) |
|
170 |
throws DataException { |
|
171 |
|
|
172 |
// copy the data from store1 into the resulting feature |
|
173 |
this.copySourceToTarget(source, target); |
|
174 |
|
|
175 |
// ask store2 for the specified attributes, filtering by the key |
|
176 |
// attribute value |
|
177 |
// from the source feature |
|
178 |
JoinTransformEvaluator eval = this.getEvaluator(); |
|
179 |
eval.updateValue(source.get(this.keyAttr1)); |
|
180 |
|
|
181 |
FeatureQuery query = this.getFeatureStore().createFeatureQuery(); |
|
182 |
query.setAttributeNames(attrsForQuery); |
|
183 |
query.setFilter(eval); |
|
184 |
|
|
185 |
FeatureSet set = store2.getFeatureSet(query); |
|
186 |
|
|
187 |
// In this join implementation, we will take only the first matching |
|
188 |
// feature found in store2 |
|
189 |
|
|
190 |
FeatureAttributeDescriptor attr; |
|
191 |
Feature feat; |
|
192 |
String targetName; |
|
193 |
|
|
194 |
Iterator itAttr; |
|
195 |
|
|
196 |
DisposableIterator itFeat = set.iterator(); |
|
197 |
if (itFeat.hasNext()) { |
|
198 |
feat = (Feature) itFeat.next(); |
|
199 |
|
|
200 |
// copy all attributes from joined feature to target |
|
201 |
this.copyJoinToTarget(feat, target); |
|
202 |
} |
|
203 |
itFeat.dispose(); |
|
204 |
set.dispose(); |
Also available in: Unified diff