Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extGPE-gvSIG / src-test / org / gvsig / fmap / geom / operation / writegml2 / WriteGmlTest.java @ 34899

History | View | Annotate | Download (7.71 KB)

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.geom.operation.writegml2;
23

    
24
import java.io.ByteArrayOutputStream;
25
import java.io.IOException;
26
import java.io.OutputStream;
27

    
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

    
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.GeometryLocator;
35
import org.gvsig.fmap.geom.GeometryManager;
36
import org.gvsig.fmap.geom.aggregate.MultiCurve;
37
import org.gvsig.fmap.geom.aggregate.MultiPoint;
38
import org.gvsig.fmap.geom.aggregate.MultiSurface;
39
import org.gvsig.fmap.geom.exception.CreateGeometryException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationException;
41
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
42
import org.gvsig.fmap.geom.primitive.Curve;
43
import org.gvsig.fmap.geom.primitive.GeneralPathX;
44
import org.gvsig.fmap.geom.primitive.Point;
45
import org.gvsig.fmap.geom.primitive.Surface;
46
import org.gvsig.gpe.lib.api.GPELocator;
47
import org.gvsig.gpe.lib.api.GPEManager;
48
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerCreationException;
49
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandler;
50
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
51

    
52

    
53
/**
54
 * @author gvSIG Team
55
 * @version $Id$
56
 *
57
 */
58
public class WriteGmlTest extends AbstractLibraryAutoInitTestCase{
59
    private static final Logger LOG = LoggerFactory.getLogger(WriteGmlTest.class);
60
    private GeometryManager geometryManager;
61
    private GPEManager gpeManager;
62
    
63
    protected void doSetUp() throws Exception {
64
        geometryManager = GeometryLocator.getGeometryManager();   
65
        gpeManager = GPELocator.getGPEManager();
66
    }
67
    
68
    private String write(Geometry geometry) throws WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException{      
69
        OutputStream os = new ByteArrayOutputStream();   
70
        IGPEWriterHandler writerHandler = gpeManager.createWriterByMimeType("text/xml; subtype=gml/3.1.2");  
71
        writerHandler.setOutputStream(os);
72
        writerHandler.initialize(); 
73
               
74
        WriteGml2OperationContext operationContext = new WriteGml2OperationContext();
75
        operationContext.setWriterHandler(writerHandler);
76
        operationContext.setId("0");
77
        operationContext.setSrs("EPSG:23030");
78
        
79
        geometry.invokeOperation(WriteGml2Operation.NAME, operationContext);
80
   
81
        writerHandler.close();
82

    
83
        LOG.info("Parsed geometry: " + os.toString());
84
        assertTrue(os.toString().startsWith("<?xml"));
85
        return os.toString();
86
    }
87
    
88
    public void testPoint2D() throws CreateGeometryException, WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException, IOException{
89
        Point point = (Point)geometryManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
90
        point.setCoordinateAt(0, 1.0);
91
        point.setCoordinateAt(1, 2.0);
92
        
93
        write(point);        
94
    }    
95
    
96
    public void testCurve2D() throws CreateGeometryException, WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException, IOException{
97
        Curve curve = (Curve)geometryManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
98
        GeneralPathX generalPathX = new GeneralPathX();
99
        generalPathX.moveTo(0, 0);
100
        generalPathX.lineTo(1, 1);
101
        generalPathX.lineTo(2, 1);      
102
        curve.setGeneralPath(generalPathX); 
103
        
104
        write(curve);
105
    }  
106
    
107
    public void testSurface2D() throws CreateGeometryException, WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException, IOException{
108
        Surface surface = (Surface)geometryManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
109
        GeneralPathX generalPathX = new GeneralPathX();
110
        generalPathX.moveTo(0, 0);
111
        generalPathX.lineTo(1, 1);
112
        generalPathX.lineTo(2, 1);
113
        surface.setGeneralPath(generalPathX);   
114
        
115
        write(surface);
116
    } 
117
    
118
    public void testMultiPoint2D() throws CreateGeometryException, WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException, IOException{
119
        Point point1 = (Point)geometryManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
120
        point1.setCoordinateAt(0, 1.0);
121
        point1.setCoordinateAt(1, 2.0);
122
        point1.setCoordinateAt(2, 3.0);
123
        
124
        Point point2 = (Point)geometryManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
125
        point2.setCoordinateAt(0, 4.0);
126
        point2.setCoordinateAt(1, 5.0);
127
        point2.setCoordinateAt(2, 6.0);
128
        
129
        MultiPoint multiPoint = (MultiPoint)geometryManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
130
        multiPoint.addPoint(point1);
131
        multiPoint.addPoint(point2);
132
        
133
        write(multiPoint);        
134
    }    
135
    
136
    public void testMultiCurve2D() throws CreateGeometryException, WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException, IOException{
137
        Curve curve1 = (Curve)geometryManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
138
        GeneralPathX generalPathX1 = new GeneralPathX();
139
        generalPathX1.moveTo(0, 0);
140
        generalPathX1.lineTo(1, 1);
141
        generalPathX1.lineTo(2, 1);     
142
        curve1.setGeneralPath(generalPathX1);   
143
        
144
        Curve curve2 = (Curve)geometryManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
145
        GeneralPathX generalPathX2 = new GeneralPathX();
146
        generalPathX2.moveTo(0, 0);
147
        generalPathX2.lineTo(1, 1);
148
        generalPathX2.lineTo(2, 1);     
149
        curve2.setGeneralPath(generalPathX2);   
150
        
151
        MultiCurve multiCurve = (MultiCurve)geometryManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
152
        multiCurve.addCurve(curve1);
153
        multiCurve.addCurve(curve2);
154
        
155
        write(multiCurve);
156
    }  
157
    
158
    public void testMultiSurface2D() throws CreateGeometryException, WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException, IOException{
159
        Surface surface1 = (Surface)geometryManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
160
        GeneralPathX generalPathX1 = new GeneralPathX();
161
        generalPathX1.moveTo(0, 0);
162
        generalPathX1.lineTo(1, 1);
163
        generalPathX1.lineTo(2, 1);     
164
        surface1.setGeneralPath(generalPathX1); 
165
        
166
        Surface surface2 = (Surface)geometryManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);     
167
        GeneralPathX generalPathX2 = new GeneralPathX();
168
        generalPathX2.moveTo(0, 0);
169
        generalPathX2.lineTo(1, 1);
170
        generalPathX2.lineTo(2, 1);     
171
        surface2.setGeneralPath(generalPathX2); 
172
        
173
        MultiSurface multiSurface = (MultiSurface)geometryManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
174
        multiSurface.addSurface(surface1);
175
        multiSurface.addSurface(surface2); 
176
        
177
        write(multiSurface);
178
    } 
179
    
180
}