Revision 41431
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.fmap.dal.file</artifactId> |
|
7 |
<packaging>pom</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>org.gvsig.fmap.dal</artifactId> |
|
12 |
<version>2.0.40</version> |
|
13 |
</parent> |
|
14 |
|
|
15 |
<dependencies> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
19 |
<scope>compile</scope> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
24 |
<scope>compile</scope> |
|
25 |
</dependency> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
|
|
32 |
</dependencies> |
|
33 |
|
|
34 |
<modules> |
|
35 |
<module>org.gvsig.fmap.dal.file.lib</module> |
|
36 |
<module>org.gvsig.fmap.dal.file.dbf</module> |
|
37 |
<module>org.gvsig.fmap.dal.file.shp</module> |
|
38 |
<module>org.gvsig.fmap.dal.file.csv</module> |
|
39 |
</modules> |
|
40 |
<description>This library has the implementation of the provider of te Data Access Library for accesing to file resources, like SHP, DBF or CSV.</description> |
|
41 |
</project> |
|
42 |
|
|
0 | 43 |
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/test/java/org/gvsig/fmap/dal/store/shp/Bug15597Test.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.shp; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import junit.framework.TestCase; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DALLocator; |
|
31 |
import org.gvsig.fmap.dal.DataManager; |
|
32 |
import org.gvsig.fmap.dal.DataTypes; |
|
33 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
35 |
import org.gvsig.fmap.dal.feature.Feature; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
41 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
42 |
import org.gvsig.fmap.geom.GeometryManager; |
|
43 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
44 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
45 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
46 |
|
|
47 |
/** |
|
48 |
* Code to test bug gvsig-desktop#15597. 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 Bug15597Test extends TestCase { |
|
55 |
private static final String TEMP_PATH = System.getProperty("java.io.tmpdir") + File.separator; |
|
56 |
|
|
57 |
public void testBug15642() throws Exception { |
|
58 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
59 |
DataManager manager = DALLocator.getDataManager(); |
|
60 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
61 |
|
|
62 |
//Create a store |
|
63 |
NewFeatureStoreParameters destParams = |
|
64 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
65 |
"FilesystemExplorer", "Shape"); |
|
66 |
|
|
67 |
//Create a feature type with two fields: "geom" and "field1" |
|
68 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
|
69 |
GeometryType geometryType = |
|
70 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
71 |
Geometry.SUBTYPES.GEOM2D); |
|
72 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
73 |
.setGeometryType(geometryType); |
|
74 |
type.setDefaultGeometryAttributeName("geom"); |
|
75 |
type.add("field1", DataTypes.STRING).setSize(2); |
|
76 |
|
|
77 |
destParams.setDynValue("shpfile", TEMP_PATH + "mySHP.shp"); |
|
78 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
79 |
destParams.setDefaultFeatureType(type); |
|
80 |
|
|
81 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
82 |
FeatureStore store = |
|
83 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
84 |
|
|
85 |
|
|
86 |
//Edit the store and add a new Feature. |
|
87 |
store.edit(); |
|
88 |
|
|
89 |
EditableFeature feature1 = store.createNewFeature().getEditable(); |
|
90 |
feature1.setGeometry(type.getDefaultGeometryAttributeIndex(), |
|
91 |
geometryManager.createPoint(0, 0, SUBTYPES.GEOM2D)); |
|
92 |
feature1.set("field1", "Hi"); |
|
93 |
|
|
94 |
store.insert(feature1); |
|
95 |
|
|
96 |
//Finish the edition |
|
97 |
store.finishEditing(); |
|
98 |
|
|
99 |
//Edit the feature type and add a new field: "field2" |
|
100 |
store.edit(); |
|
101 |
|
|
102 |
EditableFeatureType type2 = |
|
103 |
store.getDefaultFeatureType().getEditable(); |
|
104 |
type2.add("field2", DataTypes.STRING).setSize(10); |
|
105 |
store.update(type2); |
|
106 |
|
|
107 |
assertEquals(store.getDefaultFeatureType().getAttributeDescriptors().length, 3); |
|
108 |
|
|
109 |
//Add a second feature |
|
110 |
EditableFeature feature2 = store.createNewFeature().getEditable(); |
|
111 |
feature2.setGeometry(type2.getDefaultGeometryAttributeIndex(), |
|
112 |
geometryManager.createPoint(1, 1, SUBTYPES.GEOM2D)); |
|
113 |
feature2.set("field1", "Hi"); |
|
114 |
feature2.set("field2", "Max"); |
|
115 |
|
|
116 |
store.insert(feature2); |
|
117 |
|
|
118 |
//The edition is not finished. Check if all the features have the two fields |
|
119 |
FeatureSet featureSet = store.getFeatureSet(); |
|
120 |
DisposableIterator it = featureSet.fastIterator(); |
|
121 |
|
|
122 |
it.hasNext(); |
|
123 |
Feature feature = (Feature)it.next(); |
|
124 |
assertNotNull(feature.getDefaultGeometry()); |
|
125 |
assertEquals("Hi", feature.get("field1")); |
|
126 |
assertNull(feature.get("field2")); |
|
127 |
|
|
128 |
it.hasNext(); |
|
129 |
feature = (Feature)it.next(); |
|
130 |
assertNotNull(feature.getDefaultGeometry()); |
|
131 |
assertEquals("Hi", feature.get("field1")); |
|
132 |
assertEquals("Max", feature.get("field2")); |
|
133 |
|
|
134 |
it.dispose(); |
|
135 |
store.finishEditing(); |
|
136 |
|
|
137 |
//Edit the feature type and remove the field: "field1" |
|
138 |
store.edit(); |
|
139 |
|
|
140 |
EditableFeatureType type3 = |
|
141 |
store.getDefaultFeatureType().getEditable(); |
|
142 |
type3.remove("field1"); |
|
143 |
store.update(type3); |
|
144 |
|
|
145 |
assertEquals(store.getDefaultFeatureType().getAttributeDescriptors().length, 2); |
|
146 |
|
|
147 |
//Finish the edition |
|
148 |
store.finishEditing(); |
|
149 |
|
|
150 |
//Check if all the features have one field |
|
151 |
featureSet = store.getFeatureSet(); |
|
152 |
it = featureSet.fastIterator(); |
|
153 |
|
|
154 |
it.hasNext(); |
|
155 |
feature = (Feature)it.next(); |
|
156 |
assertNotNull(feature.getDefaultGeometry()); |
|
157 |
assertEquals("", feature.get("field2")); |
|
158 |
|
|
159 |
it.hasNext(); |
|
160 |
feature = (Feature)it.next(); |
|
161 |
assertNotNull(feature.getDefaultGeometry()); |
|
162 |
assertEquals("Max", feature.get("field2")); |
|
163 |
|
|
164 |
it.dispose(); |
|
165 |
store.dispose(); |
|
166 |
} |
|
167 |
} |
|
0 | 168 |
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/test/java/org/gvsig/fmap/dal/store/shp/TestSHP.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.fmap.dal.store.shp; |
|
26 |
|
|
27 |
import java.io.File; |
|
28 |
import java.util.Iterator; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
31 |
import org.gvsig.fmap.dal.exception.DataException; |
|
32 |
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
|
33 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
35 |
import org.gvsig.fmap.dal.feature.Feature; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
40 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
41 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
42 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
43 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
|
44 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
|
45 |
|
|
46 |
public class TestSHP extends BaseTestEditableFeatureStore { |
|
47 |
|
|
48 |
private FilesystemServerExplorer myExplorer; |
|
49 |
|
|
50 |
public static final File file_prueba = new File(TestSHP.class.getResource( |
|
51 |
"data/prueba.shp").getFile()); |
|
52 |
public static final File file_prueba_destino = new File(file_prueba |
|
53 |
.getParent() |
|
54 |
+ File.separatorChar + "pruebaTemp.shp"); |
|
55 |
public static final File file_pruebaNull = new File(TestSHP.class |
|
56 |
.getResource("data/pruebaNull.shp").getFile()); |
|
57 |
|
|
58 |
public static final File file_poly_valencia = new File(TestSHP.class |
|
59 |
.getResource("data/poly-valencia.shp").getFile()); |
|
60 |
|
|
61 |
public void testSimpleIteration() throws Exception { |
|
62 |
|
|
63 |
FeatureStore store = null; |
|
64 |
SHPStoreParameters shpParameters = null; |
|
65 |
|
|
66 |
shpParameters = (SHPStoreParameters) dataManager |
|
67 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
68 |
|
|
69 |
// shpParameters.setFile(file_poly_valencia); |
|
70 |
shpParameters.setFile(file_prueba); |
|
71 |
|
|
72 |
shpParameters.setCRS("EPSG:23030"); |
|
73 |
|
|
74 |
store = (FeatureStore) dataManager.createStore(shpParameters); |
|
75 |
FeatureSet set; |
|
76 |
FeatureType type = store.getDefaultFeatureType(); |
|
77 |
set = store.getFeatureSet(); |
|
78 |
|
|
79 |
System.out.println("Num:" + set.getSize()); |
|
80 |
DisposableIterator it = set.iterator(); |
|
81 |
Iterator ftIt; |
|
82 |
FeatureAttributeDescriptor desc; |
|
83 |
|
|
84 |
int i = 0; |
|
85 |
Feature feature; |
|
86 |
while (it.hasNext()) { |
|
87 |
ftIt = type.iterator(); |
|
88 |
|
|
89 |
feature = (Feature) it.next(); |
|
90 |
// while (ftIt.hasNext()) { |
|
91 |
// desc = (FeatureAttributeDescriptor) ftIt.next(); |
|
92 |
// System.out.println(desc.getName() + ":" |
|
93 |
// + feature.get(desc.getIndex())); |
|
94 |
// |
|
95 |
// } |
|
96 |
// System.out.println(feature.get("NOMBRE")); |
|
97 |
System.out.print(feature.getDefaultEnvelope() + "\t"); |
|
98 |
// System.out.print(feature.getDefaultGeometry() + "\t"); |
|
99 |
// System.out.println(feature.get("NOMBRE")); |
|
100 |
System.out.println("row:" + i); |
|
101 |
i++; |
|
102 |
|
|
103 |
|
|
104 |
} |
|
105 |
|
|
106 |
it.dispose(); |
|
107 |
set.dispose(); |
|
108 |
|
|
109 |
store.dispose(); |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
public void testEditing(Object x) throws Exception { |
|
114 |
FeatureStore store = null; |
|
115 |
SHPStoreParameters shpParameters = null; |
|
116 |
|
|
117 |
shpParameters = (SHPStoreParameters) dataManager |
|
118 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
119 |
|
|
120 |
shpParameters.setFile(file_poly_valencia); |
|
121 |
|
|
122 |
store = (FeatureStore) dataManager.createStore(shpParameters); |
|
123 |
FeatureSet set; |
|
124 |
FeatureType type = store.getDefaultFeatureType(); |
|
125 |
System.err.println("Antes de la edici?n"); |
|
126 |
set = store.getFeatureSet(); |
|
127 |
System.out.println("Num:" + set.getSize()); |
|
128 |
DisposableIterator it = set.iterator(); |
|
129 |
Iterator ftIt; |
|
130 |
FeatureAttributeDescriptor desc; |
|
131 |
|
|
132 |
int i = 0; |
|
133 |
Feature feature; |
|
134 |
while (it.hasNext()) { |
|
135 |
ftIt = type.iterator(); |
|
136 |
|
|
137 |
feature = (Feature) it.next(); |
|
138 |
// while (ftIt.hasNext()) { |
|
139 |
// desc = (FeatureAttributeDescriptor) ftIt.next(); |
|
140 |
// System.out.println(desc.getName() + ":" |
|
141 |
// + feature.get(desc.getIndex())); |
|
142 |
// |
|
143 |
// } |
|
144 |
// System.out.println(feature.get("NOMBRE")); |
|
145 |
System.out.print(feature.getDefaultEnvelope() + "\t"); |
|
146 |
// System.out.print(feature.getDefaultGeometry() + "\t"); |
|
147 |
// System.out.println(feature.get("NOMBRE")); |
|
148 |
System.out.println("row:" + i); |
|
149 |
i++; |
|
150 |
|
|
151 |
|
|
152 |
} |
|
153 |
|
|
154 |
it.dispose(); |
|
155 |
set.dispose(); |
|
156 |
store.edit(); |
|
157 |
EditableFeature ef = store.createNewFeature(); |
|
158 |
store.insert(ef); |
|
159 |
store.finishEditing(); |
|
160 |
System.err.println("Despu?s de la edici?n"); |
|
161 |
set = store.getFeatureSet(); |
|
162 |
System.out.println("Num:" + set.getSize()); |
|
163 |
it = set.iterator(); |
|
164 |
|
|
165 |
i = 0; |
|
166 |
while (it.hasNext()) { |
|
167 |
ftIt = type.iterator(); |
|
168 |
|
|
169 |
feature = (Feature) it.next(); |
|
170 |
// while (ftIt.hasNext()) { |
|
171 |
// desc = (FeatureAttributeDescriptor) ftIt.next(); |
|
172 |
// System.out.println(desc.getName() + ":" |
|
173 |
// + feature.get(desc.getIndex())); |
|
174 |
// |
|
175 |
// } |
|
176 |
// System.out.println(feature.get("NOMBRE")); |
|
177 |
System.out.print(feature.getDefaultEnvelope() + "\t"); |
|
178 |
// System.out.print(feature.getDefaultGeometry() + "\t"); |
|
179 |
// System.out.println(feature.get("NOMBRE")); |
|
180 |
System.out.println("row:" + i); |
|
181 |
i++; |
|
182 |
|
|
183 |
|
|
184 |
} |
|
185 |
|
|
186 |
it.dispose(); |
|
187 |
set.dispose(); |
|
188 |
|
|
189 |
store.dispose(); |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
public void testExport(Object x) throws Exception { |
|
194 |
DBFStoreParameters dbfParameters = null; |
|
195 |
|
|
196 |
dbfParameters = (DBFStoreParameters) dataManager |
|
197 |
.createStoreParameters(DBFStoreProvider.NAME); |
|
198 |
|
|
199 |
dbfParameters.setFile(file_prueba); |
|
200 |
|
|
201 |
FeatureStore store = (FeatureStore) dataManager |
|
202 |
.createStore(dbfParameters); |
|
203 |
FilesystemServerExplorerParameters explorerParams = (FilesystemServerExplorerParameters) dataManager |
|
204 |
.createServerExplorerParameters(FilesystemServerExplorerParameters.DYNCLASS_NAME); |
|
205 |
explorerParams.setRoot(file_prueba.getParent()); |
|
206 |
|
|
207 |
FilesystemServerExplorer explorer = (FilesystemServerExplorer) dataManager |
|
208 |
.createServerExplorer(explorerParams); |
|
209 |
|
|
210 |
NewFeatureStoreParameters newParams = (NewFeatureStoreParameters) explorer |
|
211 |
.getAddParameters(file_prueba_destino); |
|
212 |
|
|
213 |
store.export(explorer, DBFStoreProvider.NAME, newParams); |
|
214 |
|
|
215 |
FeatureStore result = (FeatureStore) dataManager.createStore(newParams); |
|
216 |
|
|
217 |
FeatureSet set = result.getFeatureSet(); |
|
218 |
FeatureSet originalSet = store.getFeatureSet(); |
|
219 |
assertEquals(set.getSize(), originalSet.getSize()); |
|
220 |
|
|
221 |
DisposableIterator originalIter = originalSet.iterator(); |
|
222 |
DisposableIterator iter = set.iterator(); |
|
223 |
while (iter.hasNext()) { |
|
224 |
assertEquals(originalIter.next(), iter.next()); |
|
225 |
} |
|
226 |
|
|
227 |
originalIter.dispose(); |
|
228 |
iter.dispose(); |
|
229 |
result.dispose(); |
|
230 |
explorer.remove(newParams); |
|
231 |
|
|
232 |
} |
|
233 |
|
|
234 |
/* |
|
235 |
* (non-Javadoc) |
|
236 |
* |
|
237 |
* @see |
|
238 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters |
|
239 |
* () |
|
240 |
*/ |
|
241 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
242 |
throws DataException { |
|
243 |
SHPStoreParameters shpParameters = (SHPStoreParameters) dataManager |
|
244 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
245 |
|
|
246 |
// shpParameters.setFile(file_poly_valencia); |
|
247 |
shpParameters.setFile(file_prueba); |
|
248 |
shpParameters.setCRS("EPSG:23030"); |
|
249 |
return shpParameters; |
|
250 |
} |
|
251 |
|
|
252 |
/* |
|
253 |
* (non-Javadoc) |
|
254 |
* |
|
255 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer() |
|
256 |
*/ |
|
257 |
public boolean hasExplorer() { |
|
258 |
return true; |
|
259 |
} |
|
260 |
|
|
261 |
/* |
|
262 |
* (non-Javadoc) |
|
263 |
* |
|
264 |
* @seeorg.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore# |
|
265 |
* getDefaultNewDataStoreParameters() |
|
266 |
*/ |
|
267 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters() |
|
268 |
throws Exception { |
|
269 |
SHPStoreParameters parameters = (SHPStoreParameters) this |
|
270 |
.getDefaultDataStoreParameters(); |
|
271 |
|
|
272 |
if (this.myExplorer == null) { |
|
273 |
FeatureStore store = (FeatureStore) dataManager |
|
274 |
.createStore(parameters); |
|
275 |
myExplorer = (FilesystemServerExplorer) store.getExplorer(); |
|
276 |
store.dispose(); |
|
277 |
} |
|
278 |
|
|
279 |
SHPNewStoreParameters result = (SHPNewStoreParameters) myExplorer |
|
280 |
.getAddParameters(file_prueba_destino); |
|
281 |
|
|
282 |
result.setCRS(parameters.getCRS()); |
|
283 |
return result; |
|
284 |
} |
|
285 |
|
|
286 |
public boolean usesResources() { |
|
287 |
return true; |
|
288 |
} |
|
289 |
|
|
290 |
public boolean resourcesNotifyChanges() { |
|
291 |
return true; |
|
292 |
} |
|
293 |
|
|
294 |
} |
|
0 | 295 |
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/test/java/org/gvsig/fmap/dal/store/shp/Bug15642Test.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.shp; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import com.vividsolutions.jts.geom.Coordinate; |
|
29 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.DALLocator; |
|
32 |
import org.gvsig.fmap.dal.DataManager; |
|
33 |
import org.gvsig.fmap.dal.DataTypes; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
41 |
import org.gvsig.fmap.geom.GeometryManager; |
|
42 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
|
43 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
44 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
45 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
46 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
47 |
|
|
48 |
/** |
|
49 |
* Code to test bug gvsig-desktop#15642. This is based on the code provided by |
|
50 |
* the bug reporter (see ticket), thanks to him!! |
|
51 |
* |
|
52 |
* @author gvSIG Team |
|
53 |
* @version $Id$ |
|
54 |
*/ |
|
55 |
public class Bug15642Test extends TestCase { |
|
56 |
|
|
57 |
public void testBug15642() throws Exception { |
|
58 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
59 |
DataManager manager = DALLocator.getDataManager(); |
|
60 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
61 |
|
|
62 |
NewFeatureStoreParameters destParams = |
|
63 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
64 |
"FilesystemExplorer", "Shape"); |
|
65 |
|
|
66 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
|
67 |
GeometryType geometryType = |
|
68 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
69 |
Geometry.SUBTYPES.GEOM2D); |
|
70 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
71 |
.setGeometryType(geometryType); |
|
72 |
type.setDefaultGeometryAttributeName("geom"); |
|
73 |
type.add("float", DataTypes.FLOAT).setSize(5); |
|
74 |
type.add("long", DataTypes.LONG).setSize(5); |
|
75 |
|
|
76 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
77 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
78 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
79 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
80 |
destParams.setDefaultFeatureType(type); |
|
81 |
|
|
82 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
83 |
FeatureStore store = |
|
84 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
85 |
|
|
86 |
store.edit(); |
|
87 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
88 |
com.vividsolutions.jts.geom.Geometry g = |
|
89 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
|
90 |
|
|
91 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME); |
|
92 |
GeometryOperation converter = |
|
93 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
|
94 |
Geometry.SUBTYPES.GEOM2D); |
|
95 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
96 |
ctx.setAttribute(FromJTS.PARAM, g); |
|
97 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx); |
|
98 |
feature.setGeometry(feature.getType() |
|
99 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
|
100 |
feature.setFloat("float", 34.0f); |
|
101 |
feature.setLong("long", 34l); |
|
102 |
store.insert(feature); |
|
103 |
store.finishEditing(); |
|
104 |
|
|
105 |
FeatureAttributeDescriptor defaultGeometryAttribute = |
|
106 |
store.getDefaultFeatureType().getDefaultGeometryAttribute(); |
|
107 |
|
|
108 |
geometryType = defaultGeometryAttribute.getGeomType(); |
|
109 |
assertEquals(Geometry.TYPES.POINT, geometryType.getType()); |
|
110 |
assertEquals(Geometry.SUBTYPES.GEOM2D, geometryType.getSubType()); |
|
111 |
|
|
112 |
store.dispose(); |
|
113 |
} |
|
114 |
|
|
115 |
} |
|
0 | 116 |
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/test/java/org/gvsig/fmap/dal/store/shp/Bug15643Test.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.shp; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import com.vividsolutions.jts.geom.Coordinate; |
|
29 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.DALLocator; |
|
32 |
import org.gvsig.fmap.dal.DataManager; |
|
33 |
import org.gvsig.fmap.dal.DataTypes; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
36 |
import org.gvsig.fmap.dal.feature.Feature; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
41 |
import org.gvsig.fmap.geom.GeometryManager; |
|
42 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
|
43 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
44 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
45 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
46 |
import org.gvsig.tools.exception.BaseException; |
|
47 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
48 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
49 |
import org.gvsig.tools.visitor.Visitor; |
|
50 |
|
|
51 |
/** |
|
52 |
* Code to test bug gvsig-desktop#15643. This is based on the code provided by |
|
53 |
* the bug reporter (see ticket), thanks to him!! |
|
54 |
* |
|
55 |
* @author gvSIG Team |
|
56 |
* @version $Id$ |
|
57 |
*/ |
|
58 |
public class Bug15643Test extends TestCase { |
|
59 |
|
|
60 |
public void testBug15643() throws Exception { |
|
61 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
62 |
DataManager manager = DALLocator.getDataManager(); |
|
63 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
64 |
|
|
65 |
NewFeatureStoreParameters destParams = |
|
66 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
67 |
"FilesystemExplorer", "Shape"); |
|
68 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
|
69 |
GeometryType geometryType = |
|
70 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
71 |
Geometry.SUBTYPES.GEOM2D); |
|
72 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
73 |
.setGeometryType(geometryType); |
|
74 |
type.setDefaultGeometryAttributeName("geom"); |
|
75 |
type.add("float", DataTypes.FLOAT).setSize(5); |
|
76 |
type.add("double", DataTypes.DOUBLE).setSize(5); |
|
77 |
type.add("int", DataTypes.INT).setSize(5); |
|
78 |
type.add("long", DataTypes.LONG).setSize(5); |
|
79 |
|
|
80 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
81 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
82 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
83 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
84 |
destParams.setDefaultFeatureType(type); |
|
85 |
|
|
86 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
87 |
FeatureStore store = |
|
88 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
89 |
|
|
90 |
store.edit(); |
|
91 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
92 |
com.vividsolutions.jts.geom.Geometry g = |
|
93 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
|
94 |
|
|
95 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME); |
|
96 |
GeometryOperation converter = |
|
97 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
|
98 |
Geometry.SUBTYPES.GEOM2D); |
|
99 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
100 |
ctx.setAttribute(FromJTS.PARAM, g); |
|
101 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx); |
|
102 |
feature.setGeometry(feature.getType() |
|
103 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
|
104 |
feature.setFloat("float", 34.0f); |
|
105 |
feature.setDouble("double", 34.0d); |
|
106 |
feature.setInt("int", 34); |
|
107 |
feature.setLong("long", 34l); |
|
108 |
store.insert(feature); |
|
109 |
store.finishEditing(); |
|
110 |
|
|
111 |
store.accept(new Visitor() { |
|
112 |
|
|
113 |
public void visit(Object obj) throws VisitCanceledException, |
|
114 |
BaseException { |
|
115 |
Feature feature = (Feature) obj; |
|
116 |
assertEquals(34.0f, feature.getFloat("float")); |
|
117 |
assertEquals(34.0d, feature.getDouble("double")); |
|
118 |
assertEquals(34, feature.getInt("int")); |
|
119 |
assertEquals(34l, feature.getLong("long")); |
|
120 |
} |
|
121 |
}); |
|
122 |
|
|
123 |
store.dispose(); |
|
124 |
} |
|
125 |
|
|
126 |
} |
|
0 | 127 |
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/test/java/org/gvsig/fmap/dal/store/shp/Bug15670Test.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.shp; |
|
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.feature.EditableFeature; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
32 |
import org.gvsig.fmap.dal.feature.Feature; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
34 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
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.Point; |
|
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#15670. 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 Bug15670Test extends TestCase { |
|
53 |
|
|
54 |
public void testBug15670() throws Exception { |
|
55 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
56 |
DataManager manager = DALLocator.getDataManager(); |
|
57 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
58 |
|
|
59 |
NewFeatureStoreParameters destParams = |
|
60 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
61 |
"FilesystemExplorer", "Shape"); |
|
62 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
|
63 |
GeometryType geometryType = |
|
64 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
65 |
Geometry.SUBTYPES.GEOM2D); |
|
66 |
type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
67 |
.setGeometryType(geometryType); |
|
68 |
type.setDefaultGeometryAttributeName("GEOMETRY"); |
|
69 |
|
|
70 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
71 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
72 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
73 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
74 |
destParams.setDefaultFeatureType(type); |
|
75 |
|
|
76 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
77 |
FeatureStore store = |
|
78 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
79 |
|
|
80 |
store.edit(); |
|
81 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
82 |
final Point geom = |
|
83 |
geometryManager.createPoint(10.0, 10.0, Geometry.SUBTYPES.GEOM2D); |
|
84 |
feature.setGeometry("GEOMETRY", geom); |
|
85 |
store.insert(feature); |
|
86 |
store.finishEditing(); |
|
87 |
|
|
88 |
store.accept(new Visitor() { |
|
89 |
|
|
90 |
public void visit(Object obj) throws VisitCanceledException, |
|
91 |
BaseException { |
|
92 |
Feature feature = (Feature) obj; |
|
93 |
assertEquals(geom, feature.getGeometry("GEOMETRY")); |
|
94 |
} |
|
95 |
}); |
|
96 |
store.dispose(); |
|
97 |
} |
|
98 |
} |
|
0 | 99 |
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/test/java/org/gvsig/fmap/dal/store/shp/Bug15617Test.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.shp; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import com.vividsolutions.jts.geom.Coordinate; |
|
29 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.DALLocator; |
|
32 |
import org.gvsig.fmap.dal.DataManager; |
|
33 |
import org.gvsig.fmap.dal.DataTypes; |
|
34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
36 |
import org.gvsig.fmap.dal.feature.Feature; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
41 |
import org.gvsig.fmap.geom.GeometryManager; |
|
42 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
|
43 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
44 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
45 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
46 |
import org.gvsig.tools.exception.BaseException; |
|
47 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
48 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
49 |
import org.gvsig.tools.visitor.Visitor; |
|
50 |
|
|
51 |
/** |
|
52 |
* Code to test bug gvsig-desktop#15617. |
|
53 |
* |
|
54 |
* @author gvSIG Team |
|
55 |
* @version $Id$ |
|
56 |
*/ |
|
57 |
public class Bug15617Test extends TestCase { |
|
58 |
|
|
59 |
public void testBug15617() throws Exception { |
|
60 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
61 |
DataManager manager = DALLocator.getDataManager(); |
|
62 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
63 |
|
|
64 |
NewFeatureStoreParameters destParams = |
|
65 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
66 |
"FilesystemExplorer", "Shape"); |
|
67 |
|
|
68 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
|
69 |
GeometryType geometryType = |
|
70 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
71 |
Geometry.SUBTYPES.GEOM2D); |
|
72 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
73 |
.setGeometryType(geometryType); |
|
74 |
type.setDefaultGeometryAttributeName("geom"); |
|
75 |
// type.add("float", DataTypes.FLOAT).setSize(5); |
|
76 |
// type.add("double", DataTypes.DOUBLE).setSize(5); |
|
77 |
type.add("int", DataTypes.INT).setSize(5); |
|
78 |
// type.add("long", DataTypes.LONG).setSize(5); |
|
79 |
type.add("bool", DataTypes.BOOLEAN); |
|
80 |
|
|
81 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
82 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
83 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
84 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
85 |
destParams.setDefaultFeatureType(type); |
|
86 |
|
|
87 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
88 |
FeatureStore store = |
|
89 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
90 |
|
|
91 |
store.edit(); |
|
92 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
93 |
com.vividsolutions.jts.geom.Geometry g = |
|
94 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
|
95 |
|
|
96 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME); |
|
97 |
GeometryOperation converter = |
|
98 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
|
99 |
Geometry.SUBTYPES.GEOM2D); |
|
100 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
101 |
ctx.setAttribute(FromJTS.PARAM, g); |
|
102 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx); |
|
103 |
|
|
104 |
feature.setGeometry(feature.getType() |
|
105 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
|
106 |
// feature.setFloat("float", 34.0f); |
|
107 |
// feature.setDouble("double", 34.0d); |
|
108 |
feature.setInt("int", 25); |
|
109 |
// feature.setLong("long", 34l); |
|
110 |
feature.setBoolean("bool", true); |
|
111 |
assertEquals(true, feature.getBoolean("bool")); |
|
112 |
store.insert(feature); |
|
113 |
store.finishEditing(); |
|
114 |
|
|
115 |
store.accept(new Visitor() { |
|
116 |
|
|
117 |
public void visit(Object obj) throws VisitCanceledException, |
|
118 |
BaseException { |
|
119 |
Feature feature = (Feature) obj; |
|
120 |
// assertEquals(34.0f, feature.getFloat("float")); |
|
121 |
// assertEquals(34.0d, feature.getDouble("double")); |
|
122 |
assertEquals(25, feature.getInt("int")); |
|
123 |
// assertEquals(34l, feature.getLong("long")); |
|
124 |
assertEquals(true, feature.getBoolean("bool")); |
|
125 |
} |
|
126 |
}); |
|
127 |
|
|
128 |
store.dispose(); |
|
129 |
} |
|
130 |
|
|
131 |
} |
|
0 | 132 |
tags/org.gvsig.desktop-2.0.40/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/test/java/org/gvsig/fmap/dal/store/shp/Bug15671Test.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.shp; |
|
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.FeatureStore; |
|
35 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
36 |
import org.gvsig.fmap.geom.Geometry; |
|
37 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
38 |
import org.gvsig.fmap.geom.GeometryManager; |
|
39 |
import org.gvsig.fmap.geom.primitive.NullGeometry; |
|
40 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
41 |
import org.gvsig.tools.exception.BaseException; |
|
42 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
43 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
44 |
import org.gvsig.tools.visitor.Visitor; |
|
45 |
|
|
46 |
/** |
|
47 |
* Code to test bug gvsig-desktop#15671. 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 Bug15671Test extends TestCase { |
|
54 |
|
|
55 |
public void testBug15671() throws Exception { |
|
56 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
57 |
DataManager manager = DALLocator.getDataManager(); |
|
58 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
59 |
|
|
60 |
|
|
61 |
NewFeatureStoreParameters destParams = |
|
62 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
63 |
"FilesystemExplorer", "Shape"); |
|
64 |
|
|
65 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
|
66 |
GeometryType geometryType = |
|
67 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
|
68 |
Geometry.SUBTYPES.GEOM2D); |
|
69 |
type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
70 |
.setGeometryType(geometryType); |
|
71 |
type.setDefaultGeometryAttributeName("GEOMETRY"); |
|
72 |
type.add("double", DataTypes.DOUBLE); |
|
73 |
|
|
74 |
|
|
75 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
76 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
77 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
78 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
79 |
//destParams.setDefaultFeatureType(type); |
|
80 |
|
|
81 |
|
|
82 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
83 |
FeatureStore store = |
|
84 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
85 |
|
|
86 |
store.edit(); |
|
87 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
88 |
NullGeometry geom = |
|
89 |
geometryManager.createNullGeometry(Geometry.SUBTYPES.GEOM2D); |
|
90 |
feature.setGeometry("GEOMETRY", geom); |
|
91 |
feature.setDouble("double", 42.0d); |
|
92 |
store.insert(feature); |
|
93 |
store.finishEditing(); |
|
94 |
|
|
95 |
store.accept(new Visitor() { |
|
96 |
|
|
97 |
public void visit(Object obj) throws VisitCanceledException, |
|
98 |
BaseException { |
|
99 |
Feature feature = (Feature) obj; |
|
100 |
Geometry geometry = feature.getGeometry("GEOMETRY"); |
|
101 |
assertEquals( |
|
102 |
"Read geometry must be of Null Geometry type instead of " |
|
103 |
+ geometry.getGeometryType().getName(), |
|
104 |
Geometry.TYPES.NULL, geometry.getType()); |
|
105 |
} |
|
106 |
}); |
|
107 |
store.dispose(); |
|
108 |
} |
|
109 |
|
|
110 |
} |
|
0 | 111 |
tags/org.gvsig.desktop-2.0.40/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 | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.fmap.dal.store.shp; |
|
26 |
|
|
27 |
import java.io.File; |
|
28 |
import java.io.IOException; |
|
29 |
import java.util.Iterator; |
|
30 |
|
|
31 |
import org.apache.commons.io.FileUtils; |
|
32 |
import org.cresques.cts.IProjection; |
|
33 |
import org.slf4j.Logger; |
|
34 |
import org.slf4j.LoggerFactory; |
|
35 |
|
|
36 |
import org.gvsig.fmap.dal.DataStore; |
|
37 |
import org.gvsig.fmap.dal.DataTypes; |
|
38 |
import org.gvsig.fmap.dal.FileHelper; |
|
39 |
import org.gvsig.fmap.dal.exception.CloseException; |
|
40 |
import org.gvsig.fmap.dal.exception.DataException; |
|
41 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
42 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
43 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
44 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
45 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
46 |
import org.gvsig.fmap.dal.feature.Feature; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
48 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
51 |
import org.gvsig.fmap.dal.feature.exception.AttributeNameException; |
|
52 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
|
53 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
54 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
|
55 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
|
56 |
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
|
57 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyChangesException; |
|
58 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyCloseException; |
|
59 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException; |
|
60 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
61 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
|
62 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
63 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
64 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
|
65 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
|
66 |
import org.gvsig.fmap.dal.store.shp.utils.SHPFile; |
|
67 |
import org.gvsig.fmap.geom.Geometry; |
|
68 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
69 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
70 |
import org.gvsig.fmap.geom.GeometryManager; |
|
71 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
72 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
73 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
74 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
75 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
|
76 |
import org.gvsig.tools.exception.BaseException; |
|
77 |
|
|
78 |
public class SHPStoreProvider extends DBFStoreProvider { |
|
79 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
80 |
private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class); |
|
81 |
public static String NAME = "Shape"; |
|
82 |
public static String DESCRIPTION = "Shape file"; |
|
83 |
private SHPFile shpFile; |
|
84 |
|
|
85 |
private MultiResource resource; |
|
86 |
|
|
87 |
protected static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY"; |
|
88 |
|
|
89 |
public static final String METADATA_DEFINITION_NAME = NAME; |
|
90 |
|
|
91 |
private SHPFeatureWriter writer = null; |
|
92 |
|
|
93 |
public SHPStoreProvider(SHPStoreParameters params, |
|
94 |
DataStoreProviderServices storeServices) |
|
95 |
throws InitializeException { |
|
96 |
super( |
|
97 |
params, |
|
98 |
storeServices, |
|
99 |
FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
|
100 |
); |
|
101 |
} |
|
102 |
|
|
103 |
protected void init(DBFStoreParameters params, |
|
104 |
DataStoreProviderServices storeServices) throws InitializeException { |
|
105 |
|
|
106 |
this.shpFile = new SHPFile((SHPStoreParameters) params); |
|
107 |
super.init(params, storeServices); |
|
108 |
} |
|
109 |
|
|
110 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
|
111 |
if( DataStore.METADATA_CRS.equalsIgnoreCase(name) ) { |
|
112 |
|
|
113 |
/* |
|
114 |
* String srs = this.shpFile.getSRSParameters(); |
|
115 |
if (srs != null){ |
|
116 |
// This can be non null but not sure how to handle |
|
117 |
} |
|
118 |
*/ |
|
119 |
return this.getShpParameters().getCRS(); |
|
120 |
|
|
121 |
} else if( DataStore.METADATA_ENVELOPE.equalsIgnoreCase(name) ) { |
|
122 |
try { |
|
123 |
return this.shpFile.getFullExtent(); |
|
124 |
} catch (ReadException e) { |
|
125 |
return null; |
|
126 |
} |
|
127 |
} |
|
128 |
return super.getDynValue(name); |
|
129 |
} |
|
130 |
|
|
131 |
protected void initResource(DBFStoreParameters params, |
|
132 |
DataStoreProviderServices storeServices) throws InitializeException { |
|
133 |
|
|
134 |
SHPStoreParameters shpParams = (SHPStoreParameters) params; |
|
135 |
resource = |
|
136 |
(MultiResource) createResource(MultiResource.TYPE_NAME, |
|
137 |
new Object[] { shpParams.getSHPFileName() }); |
|
138 |
|
|
139 |
resource.addResource(FileResource.NAME, |
|
140 |
new Object[] { shpParams.getSHPFileName() }, true); |
|
141 |
resource.addResource(FileResource.NAME, |
|
142 |
new Object[] { shpParams.getSHXFileName() }, true); |
|
143 |
resource.addResource(FileResource.NAME, |
|
144 |
new Object[] { shpParams.getDBFFileName() }, true); |
|
145 |
|
|
146 |
resource.addConsumer(this); |
|
147 |
}; |
|
148 |
|
|
149 |
public ResourceProvider getResource() { |
|
150 |
return resource; |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* |
|
155 |
* @throws ResourceNotifyChangesException |
|
156 |
*/ |
|
157 |
protected void resourcesNotifyChanges() |
|
158 |
throws ResourceNotifyChangesException { |
|
159 |
// super.resourcesNotifyChanges(); |
|
160 |
// this.shpResource.notifyChanges(); |
|
161 |
// this.shxResource.notifyChanges(); |
|
162 |
getResource().notifyChanges(); |
|
163 |
// TODO .prj |
|
164 |
|
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* @throws ResourceNotifyCloseException |
|
169 |
* |
|
170 |
*/ |
|
171 |
protected void resourcesNotifyClose() throws ResourceNotifyCloseException { |
|
172 |
// super.resourcesNotifyClose(); |
|
173 |
// this.shpResource.notifyClose(); |
|
174 |
// this.shxResource.notifyClose(); |
|
175 |
getResource().notifyClose(); |
|
176 |
// TODO .prj |
|
177 |
|
|
178 |
} |
|
179 |
|
|
180 |
@Override |
|
181 |
protected void doDispose() throws BaseException { |
|
182 |
super.doDispose(); |
|
183 |
getResource().removeConsumer(this); |
|
184 |
this.writer = null; |
|
185 |
this.shpFile = null; |
|
186 |
} |
|
187 |
|
|
188 |
protected void disposeResource() { |
|
189 |
getResource().removeConsumer(this); |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* @throws ResourceNotifyOpenException |
|
194 |
* |
|
195 |
*/ |
|
196 |
protected void resourcesOpen() throws ResourceNotifyOpenException { |
|
197 |
// super.resourcesOpen(); |
|
198 |
// this.shpResource.notifyOpen(); |
|
199 |
// this.shxResource.notifyOpen(); |
|
200 |
getResource().notifyOpen(); |
|
201 |
} |
|
202 |
|
|
203 |
protected static EditableFeatureAttributeDescriptor addGeometryColumn( |
|
204 |
EditableFeatureType fType) { |
|
205 |
|
|
206 |
EditableFeatureAttributeDescriptor attrTmp = null; |
|
207 |
EditableFeatureAttributeDescriptor attr = null; |
|
208 |
Iterator iter = fType.iterator(); |
|
209 |
while (iter.hasNext()) { |
|
210 |
attrTmp = (EditableFeatureAttributeDescriptor) iter.next(); |
|
211 |
if (attrTmp.getType() == DataTypes.GEOMETRY) { |
|
212 |
if (attr != null) { |
|
213 |
// Two geom fields not allowed |
|
214 |
fType.remove(attrTmp.getName()); |
|
215 |
} else { |
|
216 |
attr = attrTmp; |
|
217 |
// attr.setName(GEOMETRY_ATTIBUTE_NAME); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
|
|
223 |
if (attr == null){ |
|
224 |
|
|
225 |
String geofield = createGeometryFieldName(fType); |
|
226 |
attr = fType.add(geofield, DataTypes.GEOMETRY); |
|
227 |
try { |
|
228 |
attr.setDefaultValue(geomManager |
|
229 |
.createNullGeometry(SUBTYPES.GEOM2D)); |
|
230 |
} catch (CreateGeometryException e) { |
|
231 |
logger.error("Error creating the envelope", e); |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
attr.setObjectClass(Geometry.class); |
Also available in: Unified diff