svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / test / java / org / gvsig / fmap / dal / store / shp / Bug15642Test.java @ 40559
History | View | Annotate | Download (4.68 KB)
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 |
} |