Statistics
| Revision:

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 / Bug15617Test.java @ 40559

History | View | Annotate | Download (5.25 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.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
}