Revision 38004

View differences:

tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/tojts/toJTSTest.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
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.geom.operation.tojts;
29

  
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
34
import org.gvsig.fmap.geom.Geometry.TYPES;
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.aggregate.MultiCurve;
38
import org.gvsig.fmap.geom.aggregate.MultiPoint;
39
import org.gvsig.fmap.geom.aggregate.MultiSurface;
40
import org.gvsig.fmap.geom.exception.CreateGeometryException;
41
import org.gvsig.fmap.geom.operation.GeometryOperationException;
42
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
43
import org.gvsig.fmap.geom.primitive.Curve;
44
import org.gvsig.fmap.geom.primitive.GeneralPathX;
45
import org.gvsig.fmap.geom.primitive.Point;
46
import org.gvsig.fmap.geom.primitive.Surface;
47
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
48

  
49
/**
50
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
51
 */
52
public class toJTSTest extends AbstractLibraryAutoInitTestCase {
53
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
54
	private GeometryManager manager;
55

  
56
    protected void doSetUp() throws Exception {
57
		manager = GeometryLocator.getGeometryManager();
58
		manager.registerGeometryOperation(ToJTS.NAME, new Point2DToJTS(), TYPES.POINT, SUBTYPES.GEOM2D);
59
		manager.registerGeometryOperation(ToJTS.NAME, new Curve2DToJTS(), TYPES.CURVE, SUBTYPES.GEOM2D);
60
		manager.registerGeometryOperation(ToJTS.NAME, new Curve2DToJTS(), TYPES.ARC, SUBTYPES.GEOM2D);
61

  
62
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.SURFACE, SUBTYPES.GEOM2D);
63
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.CIRCLE, SUBTYPES.GEOM2D);
64
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.ELLIPSE, SUBTYPES.GEOM2D);
65
		
66
		manager.registerGeometryOperation(ToJTS.NAME, new MultiPointToJTS(), TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
67

  
68
		manager.registerGeometryOperation(ToJTS.NAME, new MultiCurveToJTS(), TYPES.MULTICURVE, SUBTYPES.GEOM2D);
69

  
70
		manager.registerGeometryOperation(ToJTS.NAME, new MultiSurfaceToJTS(), TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
71
	}
72

  
73
	public void testPoint() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
74
		Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
75
		point.setCoordinateAt(0, 1.0);
76
		point.setCoordinateAt(1, 2.0);
77

  
78
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
79

  
80
		Object obj = point.invokeOperation(ToJTS.CODE, ctx);
81
		assertNotNull(obj);
82
		assertTrue(obj instanceof com.vividsolutions.jts.geom.Point);
83
		assertEquals(1.0, ((com.vividsolutions.jts.geom.Point)obj).getX(), 0.0);
84
		assertEquals(2.0, ((com.vividsolutions.jts.geom.Point)obj).getY(), 0.0);
85
	}
86
	
87
	public void testMultiPoint() throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
88
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
89
		point1.setCoordinateAt(0, 1.0);
90
		point1.setCoordinateAt(1, 2.0);
91
		point1.setCoordinateAt(2, 3.0);
92
		
93
		Point point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM3D);
94
		point2.setCoordinateAt(0, 4.0);
95
		point2.setCoordinateAt(1, 5.0);
96
		point2.setCoordinateAt(2, 6.0);
97
		
98
		MultiPoint multiPoint = (MultiPoint)manager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
99
		multiPoint.addPoint(point1);
100
		multiPoint.addPoint(point2);
101
		
102
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
103

  
104
		Object obj = multiPoint.invokeOperation(ToJTS.CODE, ctx);
105
		assertNotNull(obj);
106
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiPoint);
107
		com.vividsolutions.jts.geom.MultiPoint gtMultiPoint = (com.vividsolutions.jts.geom.MultiPoint)obj;
108
		assertEquals(2, (int)gtMultiPoint.getNumGeometries());
109
	}
110

  
111
	public void testLineString() throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
112
		Curve lineString = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
113
		GeneralPathX generalPathX = new GeneralPathX();
114
		generalPathX.moveTo(0, 0);
115
		generalPathX.lineTo(1, 1);
116
		generalPathX.lineTo(2, 1);		
117
		lineString.setGeneralPath(generalPathX);	
118

  
119
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
120

  
121
		Object obj = lineString.invokeOperation(ToJTS.CODE, ctx);
122
		assertNotNull(obj);
123
		assertTrue(obj instanceof com.vividsolutions.jts.geom.LineString);
124
		com.vividsolutions.jts.geom.LineString gtLineString = (com.vividsolutions.jts.geom.LineString)obj;
125
		assertEquals(0, gtLineString.getCoordinates()[0].x, 0.0);
126
		assertEquals(0, gtLineString.getCoordinates()[0].y, 0.0);
127
		assertEquals(0, gtLineString.getCoordinates()[1].x, 1.0);
128
		assertEquals(0, gtLineString.getCoordinates()[1].y, 1.0);
129
		assertEquals(0, gtLineString.getCoordinates()[2].x, 2.0);
130
		assertEquals(0, gtLineString.getCoordinates()[2].y, 2.0);
131
	}
132

  
133
	public void testPolygon() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
134
		Surface polygon = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
135
		GeneralPathX generalPathX = new GeneralPathX();
136
		generalPathX.moveTo(0, 0);
137
		generalPathX.lineTo(1, 1);
138
		generalPathX.lineTo(2, 1);
139
		polygon.setGeneralPath(generalPathX);	
140

  
141
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
142

  
143
		Object obj = polygon.invokeOperation(ToJTS.CODE, ctx);
144
		assertNotNull(obj);
145
		assertTrue(obj instanceof com.vividsolutions.jts.geom.Polygon);
146
		com.vividsolutions.jts.geom.Polygon gtPolygon = (com.vividsolutions.jts.geom.Polygon)obj;
147
		assertEquals(0, gtPolygon.getCoordinates()[0].x, 0.0);
148
		assertEquals(0, gtPolygon.getCoordinates()[0].y, 0.0);
149
		assertEquals(0, gtPolygon.getCoordinates()[1].x, 1.0);
150
		assertEquals(0, gtPolygon.getCoordinates()[1].y, 1.0);
151
		assertEquals(0, gtPolygon.getCoordinates()[2].x, 2.0);
152
		assertEquals(0, gtPolygon.getCoordinates()[2].y, 2.0);
153
	}
154

  
155
	public void testMultiLineString() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
156
		Curve curve1 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
157
		GeneralPathX generalPathX1 = new GeneralPathX();
158
		generalPathX1.moveTo(0, 0);
159
		generalPathX1.lineTo(1, 1);
160
		generalPathX1.lineTo(2, 1);		
161
		curve1.setGeneralPath(generalPathX1);	
162

  
163
		Curve curve2 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
164
		GeneralPathX generalPathX2 = new GeneralPathX();
165
		generalPathX2.moveTo(0, 0);
166
		generalPathX2.lineTo(1, 1);
167
		generalPathX2.lineTo(2, 1);		
168
		curve2.setGeneralPath(generalPathX2);	
169

  
170
		MultiCurve multiCurve = (MultiCurve)manager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
171
		multiCurve.addCurve(curve1);
172
		multiCurve.addCurve(curve2);
173

  
174
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
175

  
176
		Object obj = multiCurve.invokeOperation(ToJTS.CODE, ctx);
177
		assertNotNull(obj);
178
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiLineString);
179
		com.vividsolutions.jts.geom.MultiLineString gtMultiLineString = (com.vividsolutions.jts.geom.MultiLineString)obj;
180
		assertEquals(2, (int)gtMultiLineString.getNumGeometries());
181
	}
182
	
183
	public void testMultiPlygon() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
184
		Surface surface1 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
185
		GeneralPathX generalPathX1 = new GeneralPathX();
186
		generalPathX1.moveTo(0, 0);
187
		generalPathX1.lineTo(1, 1);
188
		generalPathX1.lineTo(2, 1);		
189
		surface1.setGeneralPath(generalPathX1);	
190
		
191
		Surface surface2 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);		
192
		GeneralPathX generalPathX2 = new GeneralPathX();
193
		generalPathX2.moveTo(0, 0);
194
		generalPathX2.lineTo(1, 1);
195
		generalPathX2.lineTo(2, 1);		
196
		surface2.setGeneralPath(generalPathX2);	
197
		
198
		MultiSurface multiPolygon = (MultiSurface)manager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
199
		multiPolygon.addSurface(surface1);
200
		multiPolygon.addSurface(surface2);
201

  
202
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
203

  
204
		Object obj = multiPolygon.invokeOperation(ToJTS.CODE, ctx);
205
		assertNotNull(obj);
206
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiPolygon);
207
		com.vividsolutions.jts.geom.MultiPolygon gtMultiPolygon = (com.vividsolutions.jts.geom.MultiPolygon)obj;
208
		assertEquals(2, (int)gtMultiPolygon.getNumGeometries());
209
		assertEquals(0, gtMultiPolygon.getCoordinates()[0].x, 0.0);
210
		assertEquals(0, gtMultiPolygon.getCoordinates()[0].x, 0.0);
211
	}
212

  
213
}
214

  
0 215

  
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/println/PrintMultiPoint.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
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.operation.println;
29

  
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.GeometryLocator;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.aggregate.MultiPoint;
35
import org.gvsig.fmap.geom.operation.GeometryOperation;
36
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
37
import org.gvsig.fmap.geom.operation.GeometryOperationException;
38
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
39
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
40
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
41
import org.gvsig.tools.locator.LocatorException;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class PrintMultiPoint extends GeometryOperation {
47

  
48
	public PrintMultiPoint() {
49
		super();
50
		// TODO Auto-generated constructor stub
51
	}
52

  
53
	/* (non-Javadoc)
54
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
55
	 */
56
	public int getOperationIndex() {
57
		try {
58
			return GeometryLocator.getGeometryManager()
59
			.registerGeometryOperation("println", new PrintPoint(), TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
60
		} catch (LocatorException e) {
61
			// TODO Auto-generated catch block
62
			e.printStackTrace();
63
		} catch (GeometryTypeNotSupportedException e) {
64
			// TODO Auto-generated catch block
65
			e.printStackTrace();
66
		} catch (GeometryTypeNotValidException e) {
67
			// TODO Auto-generated catch block
68
			e.printStackTrace();
69
		}
70
		return -1;
71
	}
72

  
73
	/* (non-Javadoc)
74
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
75
	 */
76
	public Object invoke(Geometry geom, GeometryOperationContext ctx)
77
			throws GeometryOperationException {
78
		MultiPoint multiPoint = (MultiPoint)geom;
79
		System.out.println("MultiPoint");
80
		for (int i=0 ; i<multiPoint.getPrimitivesNumber() ; i++){
81
			try {
82
				System.out.print(" - ");
83
				multiPoint.getPointAt(i).invokeOperation(getOperationIndex(), ctx);
84
			} catch (GeometryOperationNotSupportedException e) {
85
				// TODO Auto-generated catch block
86
				e.printStackTrace();
87
			}
88
		}
89
		return "println-multipoint";
90
	}	
91
	
92
	
93
}
94

  
95

  
96

  
0 97

  
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/println/PrintPoint.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
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.operation.println;
29

  
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.GeometryLocator;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.operation.GeometryOperation;
35
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
39
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
40
import org.gvsig.tools.locator.LocatorException;
41

  
42
/**
43
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
44
 */
45
public class PrintPoint extends GeometryOperation {
46
	
47
	
48
	/* (non-Javadoc)
49
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
50
	 */
51
	public int getOperationIndex() {
52
		try {
53
			return GeometryLocator.getGeometryManager()
54
			.registerGeometryOperation("println", new PrintPoint(), TYPES.POINT, SUBTYPES.GEOM2D);
55
		} catch (LocatorException e) {
56
			// TODO Auto-generated catch block
57
			e.printStackTrace();
58
		} catch (GeometryTypeNotSupportedException e) {
59
			// TODO Auto-generated catch block
60
			e.printStackTrace();
61
		} catch (GeometryTypeNotValidException e) {
62
			// TODO Auto-generated catch block
63
			e.printStackTrace();
64
		}
65
		return -1;
66
	}
67

  
68
	/* (non-Javadoc)
69
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
70
	 */
71
	public Object invoke(Geometry geom, GeometryOperationContext ctx)
72
			throws GeometryOperationException {
73
		Point point = (Point)geom;
74
		System.out.println("Point, X=" + point.getX() + " Y=" + point.getY());
75
		return "println-point";
76
	}
77
	
78
}
79

  
0 80

  
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/println/PrintlnOperationTest.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
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.operation.println;
29

  
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
34
import org.gvsig.fmap.geom.Geometry.TYPES;
35
import org.gvsig.fmap.geom.GeometryLocator;
36
import org.gvsig.fmap.geom.GeometryManager;
37
import org.gvsig.fmap.geom.aggregate.MultiPoint;
38
import org.gvsig.fmap.geom.exception.CreateGeometryException;
39
import org.gvsig.fmap.geom.operation.GeometryOperationException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
41
import org.gvsig.fmap.geom.primitive.Point;
42
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
43

  
44
/**
45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
46
 */
47
public class PrintlnOperationTest extends AbstractLibraryAutoInitTestCase {
48
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
49
	private GeometryManager manager;
50
	
51
    protected void doSetUp() throws Exception {
52
		manager = GeometryLocator.getGeometryManager();
53
		manager.registerGeometryOperation("println", new PrintPoint(), TYPES.POINT, SUBTYPES.GEOM2D);
54
		manager.registerGeometryOperation("println", new PrintMultiPoint(), TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
55
	}
56
	
57
	public void testPoint() throws InstantiationException, IllegalAccessException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
58
		Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);		
59
		assertEquals((String)manager.invokeOperation("println", point, null), "println-point");		
60
	}
61
	
62
	public void testMultiPoint() throws InstantiationException, IllegalAccessException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
63
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
64
		point1.setCoordinateAt(0, 1.0);
65
		point1.setCoordinateAt(1, 2.0);
66
		
67
		Point point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
68
		point2.setCoordinateAt(0, 4.0);
69
		point2.setCoordinateAt(1, 5.0);
70
			
71
		MultiPoint multiPoint = (MultiPoint)manager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
72
		multiPoint.addPoint(point1);
73
		multiPoint.addPoint(point2);
74
		
75
		assertEquals((String)manager.invokeOperation("println", multiPoint, null), "println-multipoint");	
76
		assertEquals((String)manager.invokeOperation("println", point1, null), "println-point");	
77
		assertEquals((String)manager.invokeOperation("println", point2, null), "println-point");			
78
						
79
		assertEquals((String)point1.invokeOperation("println", null), "println-point");	
80
		
81
	}
82
}
83

  
84

  
85

  
0 86

  
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/towkb/WKBNativeTest.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
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.geom.operation.towkb;
29

  
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
32
import org.gvsig.fmap.geom.Geometry.TYPES;
33
import org.gvsig.fmap.geom.GeometryLocator;
34
import org.gvsig.fmap.geom.GeometryManager;
35
import org.gvsig.fmap.geom.operation.GeometryOperation;
36
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB;
37
import org.gvsig.fmap.geom.operation.fromwkb.FromWKBGeometryOperationContext;
38
import org.gvsig.fmap.geom.primitive.Curve;
39
import org.gvsig.fmap.geom.primitive.GeneralPathX;
40
import org.gvsig.fmap.geom.primitive.Point;
41
import org.gvsig.fmap.geom.primitive.Surface;
42
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
43

  
44
/**
45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
46
 */
47
public class WKBNativeTest extends AbstractLibraryAutoInitTestCase {
48
    private GeometryManager manager;
49
    private GeometryOperation toWkb2d;
50
    private GeometryOperation fromWkb2d;
51
    private FromWKBGeometryOperationContext fromWkbContext;
52

  
53
    protected void doSetUp() throws Exception {
54
        manager = GeometryLocator.getGeometryManager();
55
        fromWkbContext = new FromWKBGeometryOperationContext();
56
    }
57

  
58
    public void testPoint() throws Exception{
59
        Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
60
        point.setX(1);
61
        point.setY(2);
62
        toWkb2d =
63
            manager.getGeometryOperation(ToWKBNative.CODE,
64
                Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D);
65
        fromWkb2d =
66
            manager.getGeometryOperation(FromWKB.CODE, Geometry.TYPES.POINT,
67
                Geometry.SUBTYPES.GEOM2D);
68
        byte[] wkb = (byte[]) toWkb2d.invoke(point,
69
            null);
70
        fromWkbContext.setData(wkb);
71
        Geometry geom = (Geometry) fromWkb2d.invoke(null,
72
            fromWkbContext);
73

  
74
        assertEquals(point, geom);
75
    }
76

  
77
    public void testCurve() throws Exception {
78

  
79
        GeneralPathX gp = new GeneralPathX();
80

  
81
        gp.moveTo(0.0, 0.0);
82
        gp.lineTo(1.0, 1.0);
83
        gp.lineTo(2.0, 2.0);
84
        gp.lineTo(3.0, 3.0);
85
        toWkb2d =
86
            manager.getGeometryOperation(ToWKBNative.CODE,
87
                Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D);
88
        fromWkb2d =
89
            manager.getGeometryOperation(FromWKB.CODE, Geometry.TYPES.CURVE,
90
                Geometry.SUBTYPES.GEOM2D);
91
        Curve curve = (Curve) manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
92
        curve.setGeneralPath(gp);
93
        byte[] wkb = (byte[]) toWkb2d.invoke(curve,
94
            null);
95
        fromWkbContext.setData(wkb);
96
        Geometry geom = (Geometry) fromWkb2d.invoke(null,
97
            fromWkbContext);
98
        assertTrue(curve.equals(geom));
99
    }
100

  
101
    public void testPolygon() throws Exception {
102
        GeneralPathX gp = new GeneralPathX();
103
        gp.moveTo(1.0, 1.0);
104
        gp.lineTo(2.0, 2.0);
105
        gp.lineTo(3.0, 3.0);
106
        gp.lineTo(4.0, 4.0);
107
        gp.lineTo(5.0, 5.0);
108
        gp.closePath();
109

  
110
        toWkb2d =
111
            manager.getGeometryOperation(ToWKBNative.CODE,
112
                Geometry.TYPES.SURFACE, Geometry.SUBTYPES.GEOM2D);
113
        fromWkb2d =
114
            manager.getGeometryOperation(FromWKB.CODE, Geometry.TYPES.SURFACE,
115
                Geometry.SUBTYPES.GEOM2D);
116

  
117
        Surface surface = manager.createSurface(gp, SUBTYPES.GEOM2D);
118

  
119
        byte[] wkb = (byte[]) toWkb2d.invoke(surface, null);
120
        fromWkbContext.setData(wkb);
121
        Geometry geom = (Geometry) fromWkb2d.invoke(null, fromWkbContext);
122
        assertTrue(surface.equals(geom));
123
    }
124

  
125
//    public void testPolygonWithZ() throws Exception {
126
//        Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM3D);
127
//
128
//        Point point = manager.createPoint(1, 1, SUBTYPES.GEOM3D);
129
//        point.setCoordinateAt(DIMENSIONS.Z, 1);
130
//        surface.addMoveToVertex(point);
131
//        
132
//        point = manager.createPoint(2, 2, SUBTYPES.GEOM3D);
133
//        point.setCoordinateAt(DIMENSIONS.Z, 2);
134
//        surface.addVertex(point);
135
//        
136
//        point = manager.createPoint(3, 3, SUBTYPES.GEOM3D);
137
//        point.setCoordinateAt(DIMENSIONS.Z, 3);
138
//        surface.addVertex(point);
139
//        
140
//        point = manager.createPoint(4, 4, SUBTYPES.GEOM3D);
141
//        point.setCoordinateAt(DIMENSIONS.Z, 4);
142
//        surface.addVertex(point);
143
//        
144
//        point = manager.createPoint(5, 5, SUBTYPES.GEOM3D);
145
//        point.setCoordinateAt(DIMENSIONS.Z, 5);
146
//        surface.addVertex(point);       
147
//
148
//        surface.closePrimitive();
149
//        
150
//        byte[] wkb = (byte[]) toWkb2d.invoke(surface, null);
151
//        fromWkbContext.setData(wkb);
152
//        Geometry geom = (Geometry) fromWkb2d.invoke(null, fromWkbContext);
153
//        assertTrue(surface.equals(geom));
154
//    }
155
}
156

  
0 157

  
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/towkb/WKBTest.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
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.operation.towkb;
29

  
30
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
31
import org.gvsig.fmap.geom.Geometry.TYPES;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.exception.CreateGeometryException;
35
import org.gvsig.fmap.geom.operation.GeometryOperationException;
36
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
39

  
40
/**
41
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
42
 */
43
public class WKBTest extends AbstractLibraryAutoInitTestCase {
44
	private GeometryManager manager;
45

  
46
    protected void doSetUp() throws Exception {
47
		manager = GeometryLocator.getGeometryManager();
48
	}
49
	
50
	public void testPoint() throws InstantiationException, IllegalAccessException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
51
		Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);		
52
		manager.invokeOperation("toWKB", point, null);		
53
	}
54
}
55

  
0 56

  
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/impl/DefaultGeometryManagerTest.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
* 2009 {}  {{Task}}
26
*/
27
package org.gvsig.fmap.geom.impl;
28

  
29
import java.awt.Rectangle;
30
import java.awt.Shape;
31
import java.awt.geom.AffineTransform;
32
import java.awt.geom.PathIterator;
33
import java.awt.geom.Point2D;
34
import java.awt.geom.Rectangle2D;
35

  
36
import junit.framework.TestCase;
37

  
38
import org.cresques.cts.ICoordTrans;
39

  
40
import org.gvsig.fmap.geom.Geometry;
41
import org.gvsig.fmap.geom.handler.Handler;
42
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
43
import org.gvsig.fmap.geom.operation.GeometryOperationException;
44
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
45
import org.gvsig.fmap.geom.primitive.Envelope;
46
import org.gvsig.fmap.geom.primitive.GeneralPathX;
47
import org.gvsig.fmap.geom.primitive.Point;
48
import org.gvsig.fmap.geom.type.GeometryType;
49

  
50
/**
51
 * Unit tests for the class {@link DefaultGeometryManager}.
52
 * 
53
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
54
 */
55
public class DefaultGeometryManagerTest extends TestCase {
56

  
57
	private DefaultGeometryManager manager;
58

  
59
	protected void setUp() throws Exception {
60
		super.setUp();
61
	}
62

  
63
	/**
64
	 * Test method for
65
	 * {@link org.gvsig.fmap.geom.impl.DefaultGeometryManager#registerGeometryType(int, int)}
66
	 * and
67
	 * {@link org.gvsig.fmap.geom.impl.DefaultGeometryManager#getGeometryType(int, int)
68
	 * .
69
	 */
70
	public void testRegisterGetGeometryType() throws Exception {
71
		manager = new DefaultGeometryManager(1, 1);
72
		manager.registerGeometryType(TestGeometry.class,
73
				Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D);
74
		manager.registerGeometryType(TestGeometry.class,
75
				Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM3D);
76
		manager.registerGeometryType(TestGeometry.class,
77
				Geometry.TYPES.MULTISOLID, Geometry.SUBTYPES.GEOM2D);
78
		manager.registerGeometryType(TestGeometry.class, Geometry.TYPES.ARC,
79
				Geometry.SUBTYPES.GEOM3DM);
80

  
81
		assertNotNull(manager.getGeometryType(Geometry.TYPES.GEOMETRY,
82
				Geometry.SUBTYPES.GEOM2D));
83

  
84
		assertNotNull(manager.getGeometryType(Geometry.TYPES.GEOMETRY,
85
				Geometry.SUBTYPES.GEOM3D));
86

  
87
		assertNotNull(manager.getGeometryType(Geometry.TYPES.MULTISOLID,
88
				Geometry.SUBTYPES.GEOM2D));
89

  
90
		assertNotNull(manager.getGeometryType(Geometry.TYPES.ARC,
91
				Geometry.SUBTYPES.GEOM3DM));
92
	}
93

  
94
	/**
95
	 * Test method for
96
	 * {@link org.gvsig.fmap.geom.impl.DefaultGeometryManager#create(int, int)}.
97
	 */
98
	public void testCreateIntInt() throws Exception {
99
		manager = new DefaultGeometryManager();
100
		manager.registerGeometryType(TestGeometry.class,
101
				Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D);
102
		manager.registerGeometryType(TestGeometry.class,
103
				Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM3D);
104
		manager.registerGeometryType(TestGeometry.class,
105
				Geometry.TYPES.MULTISOLID, Geometry.SUBTYPES.GEOM2D);
106
		manager.registerGeometryType(TestGeometry.class, Geometry.TYPES.ARC,
107
				Geometry.SUBTYPES.GEOM3DM);
108

  
109
		assertGeometry(manager.create(Geometry.TYPES.GEOMETRY,
110
				Geometry.SUBTYPES.GEOM2D));
111

  
112
		assertGeometry(manager.create(Geometry.TYPES.GEOMETRY,
113
				Geometry.SUBTYPES.GEOM3D));
114

  
115
		assertGeometry(manager.create(Geometry.TYPES.MULTISOLID,
116
				Geometry.SUBTYPES.GEOM2D));
117

  
118
		assertGeometry(manager.create(Geometry.TYPES.ARC,
119
				Geometry.SUBTYPES.GEOM3DM));
120
	}
121

  
122
	private void assertGeometry(Geometry geom) {
123
		assertNotNull(geom);
124
		assertEquals(TestGeometry.class, geom.getClass());
125
	}
126

  
127
	public static class TestGeometry implements Geometry {
128

  
129
		private final GeometryType geometryType;
130

  
131
		public TestGeometry(GeometryType geometryType) {
132
			this.geometryType = geometryType;
133
		}
134

  
135
		public Geometry cloneGeometry() {
136
			// TODO Auto-generated method stub
137
			return null;
138
		}
139

  
140
		public boolean fastIntersects(double x, double y, double w, double h) {
141
			// TODO Auto-generated method stub
142
			return false;
143
		}
144

  
145
		public Rectangle2D getBounds2D() {
146
			// TODO Auto-generated method stub
147
			return null;
148
		}
149

  
150
		public int getDimension() {
151
			// TODO Auto-generated method stub
152
			return 0;
153
		}
154

  
155
		public Envelope getEnvelope() {
156
			// TODO Auto-generated method stub
157
			return null;
158
		}
159

  
160
		public GeneralPathX getGeneralPath() {
161
			// TODO Auto-generated method stub
162
			return null;
163
		}
164

  
165
		public GeometryType getGeometryType() {
166
			return geometryType;
167
		}
168

  
169
		public Handler[] getHandlers(int type) {
170
			// TODO Auto-generated method stub
171
			return null;
172
		}
173

  
174
		public Shape getInternalShape() {
175
			// TODO Auto-generated method stub
176
			return null;
177
		}
178

  
179
		public PathIterator getPathIterator(AffineTransform at) {
180
			// TODO Auto-generated method stub
181
			return null;
182
		}
183

  
184
		public PathIterator getPathIterator(AffineTransform at, double flatness) {
185
			// TODO Auto-generated method stub
186
			return null;
187
		}
188

  
189
		public int getType() {
190
			return 0;
191
		}
192

  
193
		public boolean intersects(Rectangle2D r) {
194
			// TODO Auto-generated method stub
195
			return false;
196
		}
197

  
198
		public Object invokeOperation(int index, GeometryOperationContext ctx)
199
				throws GeometryOperationNotSupportedException,
200
				GeometryOperationException {
201
			// TODO Auto-generated method stub
202
			return null;
203
		}
204

  
205
		public Object invokeOperation(String opName,
206
				GeometryOperationContext ctx)
207
				throws GeometryOperationNotSupportedException,
208
				GeometryOperationException {
209
			// TODO Auto-generated method stub
210
			return null;
211
		}
212

  
213
		public boolean isSimple() {
214
			// TODO Auto-generated method stub
215
			return false;
216
		}
217

  
218
		public void reProject(ICoordTrans ct) {
219
			// TODO Auto-generated method stub
220

  
221
		}
222

  
223
		public void transform(AffineTransform at) {
224
			// TODO Auto-generated method stub
225

  
226
		}
227

  
228
		public boolean contains(Point2D p) {
229
			// TODO Auto-generated method stub
230
			return false;
231
		}
232

  
233
		public boolean contains(Rectangle2D r) {
234
			// TODO Auto-generated method stub
235
			return false;
236
		}
237

  
238
		public boolean contains(double x, double y) {
239
			// TODO Auto-generated method stub
240
			return false;
241
		}
242

  
243
		public boolean contains(double x, double y, double w, double h) {
244
			// TODO Auto-generated method stub
245
			return false;
246
		}
247

  
248
		public Rectangle getBounds() {
249
			// TODO Auto-generated method stub
250
			return null;
251
		}
252

  
253
		public boolean intersects(double x, double y, double w, double h) {
254
			// TODO Auto-generated method stub
255
			return false;
256
		}
257

  
258
		public int compareTo(Object arg0) {
259
			// TODO Auto-generated method stub
260
			return 0;
261
		}
262

  
263
		public Geometry buffer(double distance)
264
				throws GeometryOperationNotSupportedException,
265
				GeometryOperationException {
266
			// TODO Auto-generated method stub
267
			return null;
268
		}
269

  
270
		public boolean contains(Geometry geometry)
271
				throws GeometryOperationNotSupportedException,
272
				GeometryOperationException {
273
			// TODO Auto-generated method stub
274
			return false;
275
		}
276

  
277
		public byte[] convertToWKB()
278
				throws GeometryOperationNotSupportedException,
279
				GeometryOperationException {
280
			// TODO Auto-generated method stub
281
			return null;
282
		}
283

  
284
		public String convertToWKT()
285
				throws GeometryOperationNotSupportedException,
286
				GeometryOperationException {
287
			// TODO Auto-generated method stub
288
			return null;
289
		}
290

  
291
		public Geometry convexHull()
292
				throws GeometryOperationNotSupportedException,
293
				GeometryOperationException {
294
			// TODO Auto-generated method stub
295
			return null;
296
		}
297

  
298
		public boolean coveredBy(Geometry geometry)
299
				throws GeometryOperationNotSupportedException,
300
				GeometryOperationException {
301
			// TODO Auto-generated method stub
302
			return false;
303
		}
304

  
305
		public boolean crosses(Geometry geometry)
306
				throws GeometryOperationNotSupportedException,
307
				GeometryOperationException {
308
			// TODO Auto-generated method stub
309
			return false;
310
		}
311

  
312
		public Geometry difference(Geometry other)
313
				throws GeometryOperationNotSupportedException,
314
				GeometryOperationException {
315
			// TODO Auto-generated method stub
316
			return null;
317
		}
318

  
319
		public boolean disjoint(Geometry geometry)
320
				throws GeometryOperationNotSupportedException,
321
				GeometryOperationException {
322
			// TODO Auto-generated method stub
323
			return false;
324
		}
325

  
326
		public double distance(Geometry geometry)
327
				throws GeometryOperationNotSupportedException,
328
				GeometryOperationException {
329
			// TODO Auto-generated method stub
330
			return 0;
331
		}
332

  
333
		public Geometry intersection(Geometry other)
334
				throws GeometryOperationNotSupportedException,
335
				GeometryOperationException {
336
			// TODO Auto-generated method stub
337
			return null;
338
		}
339

  
340
		public boolean intersects(Geometry geometry)
341
				throws GeometryOperationNotSupportedException,
342
				GeometryOperationException {
343
			// TODO Auto-generated method stub
344
			return false;
345
		}
346

  
347
		public boolean overlaps(Geometry geometry)
348
				throws GeometryOperationNotSupportedException,
349
				GeometryOperationException {
350
			// TODO Auto-generated method stub
351
			return false;
352
		}
353

  
354
		public boolean touches(Geometry geometry)
355
				throws GeometryOperationNotSupportedException,
356
				GeometryOperationException {
357
			// TODO Auto-generated method stub
358
			return false;
359
		}
360

  
361
		public Geometry union(Geometry other)
362
				throws GeometryOperationNotSupportedException,
363
				GeometryOperationException {
364
			// TODO Auto-generated method stub
365
			return null;
366
		}
367

  
368
		public boolean within(Geometry geometry)
369
				throws GeometryOperationNotSupportedException,
370
				GeometryOperationException {
371
			// TODO Auto-generated method stub
372
			return false;
373
		}
374

  
375
		public Point centroid() throws GeometryOperationNotSupportedException,
376
				GeometryOperationException {
377
			// TODO Auto-generated method stub
378
			return null;
379
		}
380

  
381
        public double area() throws GeometryOperationNotSupportedException,
382
            GeometryOperationException {
383
            // TODO Auto-generated method stub
384
            return 0;
385
        }
386

  
387
        public double perimeter()
388
            throws GeometryOperationNotSupportedException,
389
            GeometryOperationException {
390
            // TODO Auto-generated method stub
391
            return 0;
392
        }
393

  
394
        public Shape getShape() {
395
            // TODO Auto-generated method stub
396
            return null;
397
        }
398

  
399
        public Shape getShape(AffineTransform affineTransform) {
400
            // TODO Auto-generated method stub
401
            return null;
402
        }
403

  
404
	}
405
}
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/GeometryManagerTest.java
1
package org.gvsig.fmap.geom;
2

  
3
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
4
import org.gvsig.fmap.geom.Geometry.TYPES;
5
import org.gvsig.fmap.geom.exception.CreateGeometryException;
6
import org.gvsig.fmap.geom.operation.GeometryOperation;
7
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
8
import org.gvsig.fmap.geom.operation.GeometryOperationException;
9
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
10
import org.gvsig.fmap.geom.operation.ensureOrientation.EnsureOrientation;
11
import org.gvsig.fmap.geom.operation.flip.Flip;
12
import org.gvsig.fmap.geom.operation.isCCW.IsCCW;
13
import org.gvsig.fmap.geom.operation.tojts.ToJTS;
14
import org.gvsig.fmap.geom.operation.towkb.ToWKB;
15
import org.gvsig.fmap.geom.primitive.Arc;
16
import org.gvsig.fmap.geom.primitive.Point;
17
import org.gvsig.fmap.geom.primitive.impl.Arc2D;
18
import org.gvsig.fmap.geom.type.GeometryType;
19
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
20
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
21
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

  
25
public class GeometryManagerTest extends AbstractLibraryAutoInitTestCase {
26

  
27
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
28

  
29
	private GeometryManager manager;
30

  
31
	protected void doSetUp() throws Exception {
32
		manager = GeometryLocator.getGeometryManager();		
33
	}
34

  
35
	public void testRegister() throws Exception {
36
		logger.debug("--------- testRegister() START ----------");
37

  
38
		Point p2d = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
39
		assertNotNull(p2d);
40
		p2d.setCoordinateAt(0, 0);
41
		p2d.setCoordinateAt(1, 0);
42

  
43
		java.awt.geom.Point2D pt1 = new java.awt.geom.Point2D.Float(0,1);
44
		java.awt.geom.Point2D pt2 = new java.awt.geom.Point2D.Float(1,1);
45
		java.awt.geom.Point2D pt3 = new java.awt.geom.Point2D.Float(1,0);
46
		Arc2D c2d = (Arc2D) manager.create(TYPES.ARC, SUBTYPES.GEOM2D);
47
		assertNotNull(c2d);
48
		
49
		GeometryType geomType1 = manager.getGeometryType(TYPES.POINT, SUBTYPES.GEOM2D);
50
		GeometryType geomType2 = manager.getGeometryType(TYPES.ARC, SUBTYPES.GEOM2D);
51

  
52
		assertEquals(p2d.getGeometryType(), geomType1);
53
		assertEquals(c2d.getGeometryType(), geomType2);
54

  
55
//		int op1 = manager.registerGeometryOperation("toJTS", new ToJTS(), geomType1);
56
//		logger.debug("op1=" + op1);
57
//
58
//		int op2 = -1;
59
//		try {
60
//			op2 = manager.registerGeometryOperation("toJTS", new ToJTS(), geomType1);
61
//			logger.debug("op2=" + op2);
62
//		} catch (Exception e) {
63
//			logger.error("Error registrando operaci?n: ", e);
64
//		}
65

  
66
		int op3 = manager.registerGeometryOperation("toWKB", new ToWKB(),geomType1);
67
		int op4 = manager.registerGeometryOperation("toWKB", new ToWKB(),geomType2);
68

  
69
		logger.debug("op3=" + op3);
70

  
71
//		assertTrue("FALLO: op1 != op2", op1 == op2);
72
//		assertTrue("FALLO: op1 == op3", op1 != op3);
73
//		assertFalse("FALLO: op4 == op", op4 == op1);
74

  
75
		//Point p = (Point) factory.createPoint2D(1, 2);
76
		Point p = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
77

  
78
		// TODO: implement again with the needed context for each operation
79

  
80
		// GeometryOperationContext ctx = new GeometryOperationContext();
81
		// ctx.setAttribute("dummy", "DummyValue");
82
		// p.invokeOperation(ToWKB.CODE, ctx);
83
		// p.invokeOperation(ToJTS.CODE, ctx);
84
		// p.invokeOperation(Flip.CODE, ctx);
85

  
86
		Geometry sol = manager.create(TYPES.SOLID, SUBTYPES.GEOM3D);
87
		assertNotNull(sol);
88
		//logger.debug(sol);
89

  
90
		logger.debug("--------- testRegister() END ----------");
91
	}
92

  
93
	public void testGeneralPathXOperations() throws InstantiationException, IllegalAccessException, CreateGeometryException{
94
		logger.debug("--------- Test GeneralPathX Operation START ----------");
95

  
96
		//Registering the operation Flip() to all the geometries...
97
		manager.registerGeometryOperation("flip", new Flip());
98

  
99
		//Registering the operation ensureOrientation() to all the geometries...
100
		manager.registerGeometryOperation("ensureOrientation", new EnsureOrientation());
101

  
102
		//Registering the operation isCCW() to all the geometries...
103
		manager.registerGeometryOperation("isCCW", new IsCCW());
104

  
105
		//Building the Points for a curve...
106
//		java.awt.geom.Point2D p1 = new java.awt.geom.Point2D.Double(1,2);
107
//		java.awt.geom.Point2D p2 = new java.awt.geom.Point2D.Double(2,1);
108
//		java.awt.geom.Point2D p3 = new java.awt.geom.Point2D.Double(3,3);
109

  
110
		Point p1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
111
		p1.setCoordinateAt(0, 1);
112
		p1.setCoordinateAt(1, 2);
113

  
114
		Point p2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
115
		p2.setCoordinateAt(0, 2);
116
		p2.setCoordinateAt(1, 1);
117

  
118
		Point p3 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
119
		p3.setCoordinateAt(0, 3);
120
		p3.setCoordinateAt(1, 3);
121

  
122
		//Build a curve to get the operation invoked with the registered operation.
123
		//Geometry curve = (Curve) factory.createArc(p1, p2, p3);
124
		Arc arc = (Arc) manager.create(TYPES.ARC, SUBTYPES.GEOM2D);
125
        arc.setPoints(p1, p2, p3);
126

  
127
		try {
128
			arc.invokeOperation(Flip.CODE, null);
129
		} catch (GeometryOperationNotSupportedException e) {
130
			logger.error("Operation doesn't be registered for this geometry. \n", e);
131
		} catch (GeometryOperationException e) {
132
			logger.error("An error produced while the Operation was running. \n", e);
133
		}
134
		GeometryOperationContext ctx = new GeometryOperationContext();
135
		ctx.setAttribute("bCCW",new Boolean(true));
136
		Boolean aux1 = null;
137
		try {
138
			aux1 = (Boolean) arc.invokeOperation(EnsureOrientation.CODE, ctx);
139
		} catch (GeometryOperationNotSupportedException e) {
140
			logger.error("Operation doesn't be registered for this geometry. \n", e);
141
		} catch (GeometryOperationException e) {
142
			// TODO Auto-generated catch block
143
			logger.error("An error produced while the Operation was running. \n", e);
144
		}
145
		//True si es exterior, le ha dado la vuelta.
146
		assertTrue(aux1.booleanValue());
147

  
148
		Boolean aux2 = null;
149
		try {
150
			aux2 = (Boolean) arc.invokeOperation(IsCCW.CODE, null);
151
		} catch (GeometryOperationNotSupportedException e) {
152
			logger.error("Operation doesn't be registered for this geometry. \n", e);
153
		} catch (GeometryOperationException e) {
154
			// TODO Auto-generated catch block
155
			logger.error("An error produced while the Operation was running. \n", e);
156
		}
157
		//True si es CCW.
158
		assertTrue(aux2.booleanValue());
159

  
160
		logger.debug("--------- Test GeneralPathX Operation END ----------");
161
	}
162

  
163
	// TODO: implement again with the needed context for each operation
164
	// public void testInvoke() throws InstantiationException,
165
	// IllegalAccessException, CreateGeometryException {
166
	// int size = 100000;
167
	//
168
	// // Fill the operation context with required params
169
	// GeometryOperationContext ctx = new GeometryOperationContext();
170
	// GeometryOperationContext var = new GeometryOperationContext();
171
	// var.setAttribute("bCCW",new Boolean(true));
172
	//
173
	// logger.debug("ToJTS.-");
174
	// indirectInvoke(ToJTS.CODE, ctx, size);
175
	// directInvoke(ToJTS.CODE, ctx, size);
176
	// logger.debug("ToWKB.-");
177
	// indirectInvoke(ToWKB.CODE, null, size);
178
	// directInvoke(ToWKB.CODE, null, size);
179
	// logger.debug("Flip.-");
180
	// indirectInvoke(Flip.CODE, ctx, size);
181
	// directInvoke(Flip.CODE, ctx, size);
182
	// logger.debug("EnsureOrientation.-");
183
	// //indirectInvoke(EnsureOrientation.CODE, var, size);
184
	// directInvoke(EnsureOrientation.CODE, var, size);
185
	// logger.debug("isCCW.-");
186
	// //indirectInvoke(IsCCW.CODE, ctx, size);
187
	// directInvoke(IsCCW.CODE, ctx, size);
188
	//
189
	// }
190

  
191
	private Geometry[] createGeometryArray(int size) throws InstantiationException, IllegalAccessException, CreateGeometryException {
192
		Geometry[] geom = new Geometry[size];
193
		for (int i = 0; i < size; i++) {
194
			//geom[i] = factory.createPoint2D(Math.log(1 - i), Math.log(i + 1));
195
			geom[i] = manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
196
		}
197
		return geom;
198
	}
199

  
200
	private long directInvoke(int opCode, GeometryOperationContext ctx, int size) throws InstantiationException, IllegalAccessException, CreateGeometryException {
201
		Geometry[] geoms = createGeometryArray(size);
202

  
203
		long t0 = System.currentTimeMillis();
204

  
205
		GeometryOperation geomOp = null;
206
		try {
207
			geomOp = manager.getGeometryOperation(ToJTS.CODE, TYPES.POINT, SUBTYPES.GEOM2D);
208
		} catch (GeometryTypeNotSupportedException gtnse) {
209
			logger.error("Error:", gtnse);
210
		} catch (GeometryOperationNotSupportedException gonse) {
211
			logger.error("Error:", gonse);
212
		} catch (GeometryTypeNotValidException e) {
213
			logger.error("Error:", e);
214
		}
215

  
216
		// Here is the main loop where you call the operation
217
		try {
218
			for (int i = 0; i < geoms.length; i++) {
219
				Object result = geomOp.invoke(geoms[i], ctx);
220
				// if(i%100 == 99) logger.debug(result);
221
			}
222

  
223
		} catch (GeometryOperationException goe) {
224
			logger.error("Error:", goe);
225
		}
226
		long t1 = System.currentTimeMillis();
227
		long t = t1 - t0;
228
		logger.debug("Milliseconds (direct): " + t);
229
		return t;
230
	}
231

  
232
	private long indirectInvoke(int opCode, GeometryOperationContext ctx,
233
			int size) throws InstantiationException, IllegalAccessException, CreateGeometryException {
234
		Geometry[] geoms = createGeometryArray(size);
235

  
236
		long t0 = System.currentTimeMillis();
237

  
238
		// Here is the main loop where you call the operation
239
		try {
240
			for (int i = 0; i < geoms.length; i++) {
241
				Object result = (geoms[i]).invokeOperation(opCode,
242
						ctx);
243
				// if(i%100 == 99) logger.debug(result);
244
			}
245
		} catch (GeometryOperationNotSupportedException gonse) {
246
			logger.error("Error:", gonse);
247
		} catch (GeometryOperationException goe) {
248
			logger.error("Error:", goe);
249
		}
250
		long t1 = System.currentTimeMillis();
251
		long t = t1 - t0;
252
		logger.debug("Milliseconds (indirect): " + t);
253
		return t;
254
	}
255

  
256
//	public void testRegisterBasicGeometryType() {
257
//		GeometryType gt = GeometryLocator.getGeometryManager()
258
//		.registerGeometryType(DummyPoint2D.class, "DummyPoint2D", TYPES.ELLIPSE,  SUBTYPES.GEOM2DZ);
259
//
260
//		logger.debug(String.valueOf(gt.getType()));
261
//
262
//		GeometryLocator.getGeometryManager().unregisterGeometryType(DummyPoint2D.class);
263
//
264
//		gt = GeometryLocator.getGeometryManager()
265
//		.registerGeometryType(DummyPoint2D.class, "DummyPoint2D", TYPES.POINT, SUBTYPES.GEOM2D);
266
//
267
//		logger.debug(String.valueOf(gt.getType()));
268
//		GeometryLocator.getGeometryManager().unregisterGeometryType(
269
//				DummyPoint2D.class);
270
//		
271
//	}
272
}
tags/v2_0_0_Build_2045/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/aggregate/MultiCurveTest.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
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.aggregate;
29

  
30
import junit.framework.Assert;
31

  
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.Geometry.TYPES;
36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.fmap.geom.primitive.Curve;
38
import org.gvsig.fmap.geom.primitive.GeneralPathX;
39
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class MultiCurveTest extends AbstractLibraryAutoInitTestCase {
47
	private GeometryManager manager;
48
	
49
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
50

  
51
	protected void doSetUp() throws Exception {
52
		manager = GeometryLocator.getGeometryManager();		
53
	}
54
	
55
	public void testCreateMultiCurve2D() throws InstantiationException, IllegalAccessException, CreateGeometryException{
56
		Curve curve1 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
57
		GeneralPathX generalPathX1 = new GeneralPathX();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff