Revision 33789

View differences:

tags/v2_0_0_Build_2020/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/DummyPoint2D.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
* 2008 {{Company}}   {{Task}}
26
*/
27
 
28
package org.gvsig.fmap.geom;
29

  
30
import org.gvsig.fmap.geom.primitive.Point;
31
import org.gvsig.fmap.geom.primitive.impl.Point2D;
32
import org.gvsig.fmap.geom.type.GeometryType;
33

  
34

  
35
public class DummyPoint2D extends Point2D implements Point {
36

  
37
	/**
38
	 * @param geometryType
39
	 */
40
	public DummyPoint2D(GeometryType geometryType) {
41
		super(geometryType);
42
		// TODO Auto-generated constructor stub
43
	}
44

  
45
	private static final long serialVersionUID = 4449552637882072964L;
46

  
47
	
48

  
49
}
tags/v2_0_0_Build_2020/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.gvsig.fmap.geom.GeometryLocator;
31
import org.gvsig.fmap.geom.GeometryManager;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.aggregate.MultiCurve;
35
import org.gvsig.fmap.geom.aggregate.MultiPoint;
36
import org.gvsig.fmap.geom.aggregate.MultiSurface;
37
import org.gvsig.fmap.geom.exception.CreateGeometryException;
38
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
39
import org.gvsig.fmap.geom.operation.GeometryOperationException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
41
import org.gvsig.fmap.geom.operation.impl.DefaultGeometryOperationLibrary;
42
import org.gvsig.fmap.geom.operation.println.PrintMultiPoint;
43
import org.gvsig.fmap.geom.operation.println.PrintPoint;
44
import org.gvsig.fmap.geom.primitive.Curve;
45
import org.gvsig.fmap.geom.primitive.GeneralPathX;
46
import org.gvsig.fmap.geom.primitive.Point;
47
import org.gvsig.fmap.geom.primitive.Surface;
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

  
51
import junit.framework.TestCase;
52

  
53
/**
54
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
55
 */
56
public class toJTSTest extends TestCase {
57
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
58
	private GeometryManager manager;
59

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

  
63
		DefaultGeometryLibrary lib = new DefaultGeometryLibrary();		
64
		lib.initialize();
65
		lib.postInitialize();
66

  
67
		DefaultGeometryOperationLibrary opLib = new DefaultGeometryOperationLibrary();
68
		opLib.initialize();
69
		opLib.postInitialize();			
70

  
71
		manager = GeometryLocator.getGeometryManager();
72
		manager.registerGeometryOperation(ToJTS.NAME, new Point2DToJTS(), TYPES.POINT, SUBTYPES.GEOM2D);
73
		manager.registerGeometryOperation(ToJTS.NAME, new Curve2DToJTS(), TYPES.CURVE, SUBTYPES.GEOM2D);
74
		manager.registerGeometryOperation(ToJTS.NAME, new Curve2DToJTS(), TYPES.ARC, SUBTYPES.GEOM2D);
75

  
76
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.SURFACE, SUBTYPES.GEOM2D);
77
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.CIRCLE, SUBTYPES.GEOM2D);
78
		manager.registerGeometryOperation(ToJTS.NAME, new Surface2DToJTS(), TYPES.ELLIPSE, SUBTYPES.GEOM2D);
79
		
80
		manager.registerGeometryOperation(ToJTS.NAME, new MultiPointToJTS(), TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
81

  
82
		manager.registerGeometryOperation(ToJTS.NAME, new MultiCurveToJTS(), TYPES.MULTICURVE, SUBTYPES.GEOM2D);
83

  
84
		manager.registerGeometryOperation(ToJTS.NAME, new MultiSurfaceToJTS(), TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
85
	}
86

  
87
	public void testPoint() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
88
		Point point = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
89
		point.setCoordinateAt(0, 1.0);
90
		point.setCoordinateAt(1, 2.0);
91

  
92
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
93

  
94
		Object obj = point.invokeOperation(ToJTS.CODE, ctx);
95
		assertNotNull(obj);
96
		assertTrue(obj instanceof com.vividsolutions.jts.geom.Point);
97
		assertEquals(1.0, ((com.vividsolutions.jts.geom.Point)obj).getX(), 0.0);
98
		assertEquals(2.0, ((com.vividsolutions.jts.geom.Point)obj).getY(), 0.0);
99
	}
100
	
101
	public void testMultiPoint() throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
102
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2DZ);
103
		point1.setCoordinateAt(0, 1.0);
104
		point1.setCoordinateAt(1, 2.0);
105
		point1.setCoordinateAt(2, 3.0);
106
		
107
		Point point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2DZ);
108
		point2.setCoordinateAt(0, 4.0);
109
		point2.setCoordinateAt(1, 5.0);
110
		point2.setCoordinateAt(2, 6.0);
111
		
112
		MultiPoint multiPoint = (MultiPoint)manager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
113
		multiPoint.addPoint(point1);
114
		multiPoint.addPoint(point2);
115
		
116
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
117

  
118
		Object obj = multiPoint.invokeOperation(ToJTS.CODE, ctx);
119
		assertNotNull(obj);
120
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiPoint);
121
		com.vividsolutions.jts.geom.MultiPoint gtMultiPoint = (com.vividsolutions.jts.geom.MultiPoint)obj;
122
		assertEquals(2, (int)gtMultiPoint.getNumGeometries());
123
	}
124

  
125
	public void testLineString() throws GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
126
		Curve lineString = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
127
		GeneralPathX generalPathX = new GeneralPathX();
128
		generalPathX.moveTo(0, 0);
129
		generalPathX.lineTo(1, 1);
130
		generalPathX.lineTo(2, 1);		
131
		lineString.setGeneralPath(generalPathX);	
132

  
133
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
134

  
135
		Object obj = lineString.invokeOperation(ToJTS.CODE, ctx);
136
		assertNotNull(obj);
137
		assertTrue(obj instanceof com.vividsolutions.jts.geom.LineString);
138
		com.vividsolutions.jts.geom.LineString gtLineString = (com.vividsolutions.jts.geom.LineString)obj;
139
		assertEquals(0, gtLineString.getCoordinates()[0].x, 0.0);
140
		assertEquals(0, gtLineString.getCoordinates()[0].y, 0.0);
141
		assertEquals(0, gtLineString.getCoordinates()[1].x, 1.0);
142
		assertEquals(0, gtLineString.getCoordinates()[1].y, 1.0);
143
		assertEquals(0, gtLineString.getCoordinates()[2].x, 2.0);
144
		assertEquals(0, gtLineString.getCoordinates()[2].y, 2.0);
145
	}
146

  
147
	public void testPolygon() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
148
		Surface polygon = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
149
		GeneralPathX generalPathX = new GeneralPathX();
150
		generalPathX.moveTo(0, 0);
151
		generalPathX.lineTo(1, 1);
152
		generalPathX.lineTo(2, 1);
153
		polygon.setGeneralPath(generalPathX);	
154

  
155
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
156

  
157
		Object obj = polygon.invokeOperation(ToJTS.CODE, ctx);
158
		assertNotNull(obj);
159
		assertTrue(obj instanceof com.vividsolutions.jts.geom.Polygon);
160
		com.vividsolutions.jts.geom.Polygon gtPolygon = (com.vividsolutions.jts.geom.Polygon)obj;
161
		assertEquals(0, gtPolygon.getCoordinates()[0].x, 0.0);
162
		assertEquals(0, gtPolygon.getCoordinates()[0].y, 0.0);
163
		assertEquals(0, gtPolygon.getCoordinates()[1].x, 1.0);
164
		assertEquals(0, gtPolygon.getCoordinates()[1].y, 1.0);
165
		assertEquals(0, gtPolygon.getCoordinates()[2].x, 2.0);
166
		assertEquals(0, gtPolygon.getCoordinates()[2].y, 2.0);
167
	}
168

  
169
	public void testMultiLineString() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
170
		Curve curve1 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
171
		GeneralPathX generalPathX1 = new GeneralPathX();
172
		generalPathX1.moveTo(0, 0);
173
		generalPathX1.lineTo(1, 1);
174
		generalPathX1.lineTo(2, 1);		
175
		curve1.setGeneralPath(generalPathX1);	
176

  
177
		Curve curve2 = (Curve)manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
178
		GeneralPathX generalPathX2 = new GeneralPathX();
179
		generalPathX2.moveTo(0, 0);
180
		generalPathX2.lineTo(1, 1);
181
		generalPathX2.lineTo(2, 1);		
182
		curve2.setGeneralPath(generalPathX2);	
183

  
184
		MultiCurve multiCurve = (MultiCurve)manager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
185
		multiCurve.addCurve(curve1);
186
		multiCurve.addCurve(curve2);
187

  
188
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
189

  
190
		Object obj = multiCurve.invokeOperation(ToJTS.CODE, ctx);
191
		assertNotNull(obj);
192
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiLineString);
193
		com.vividsolutions.jts.geom.MultiLineString gtMultiLineString = (com.vividsolutions.jts.geom.MultiLineString)obj;
194
		assertEquals(2, (int)gtMultiLineString.getNumGeometries());
195
	}
196
	
197
	public void testMultiPlygon() throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException{
198
		Surface surface1 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
199
		GeneralPathX generalPathX1 = new GeneralPathX();
200
		generalPathX1.moveTo(0, 0);
201
		generalPathX1.lineTo(1, 1);
202
		generalPathX1.lineTo(2, 1);		
203
		surface1.setGeneralPath(generalPathX1);	
204
		
205
		Surface surface2 = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);		
206
		GeneralPathX generalPathX2 = new GeneralPathX();
207
		generalPathX2.moveTo(0, 0);
208
		generalPathX2.lineTo(1, 1);
209
		generalPathX2.lineTo(2, 1);		
210
		surface2.setGeneralPath(generalPathX2);	
211
		
212
		MultiSurface multiPolygon = (MultiSurface)manager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
213
		multiPolygon.addSurface(surface1);
214
		multiPolygon.addSurface(surface2);
215

  
216
		JTSGeometryOperationContext ctx = new JTSGeometryOperationContext(-1);
217

  
218
		Object obj = multiPolygon.invokeOperation(ToJTS.CODE, ctx);
219
		assertNotNull(obj);
220
		assertTrue(obj instanceof com.vividsolutions.jts.geom.MultiPolygon);
221
		com.vividsolutions.jts.geom.MultiPolygon gtMultiPolygon = (com.vividsolutions.jts.geom.MultiPolygon)obj;
222
		assertEquals(2, (int)gtMultiPolygon.getNumGeometries());
223
		assertEquals(0, gtMultiPolygon.getCoordinates()[0].x, 0.0);
224
		assertEquals(0, gtMultiPolygon.getCoordinates()[0].x, 0.0);
225
	}
226

  
227
}
228

  
0 229

  
tags/v2_0_0_Build_2020/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_2020/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 junit.framework.TestCase;
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.aggregate.MultiPoint;
37
import org.gvsig.fmap.geom.exception.CreateGeometryException;
38
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
39
import org.gvsig.fmap.geom.operation.GeometryOperationException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
41
import org.gvsig.fmap.geom.operation.impl.DefaultGeometryOperationLibrary;
42
import org.gvsig.fmap.geom.primitive.Point;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

  
46
/**
47
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
48
 */
49
public class PrintlnOperationTest extends TestCase {
50
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
51
	private GeometryManager manager;
52
	
53
	protected void setUp() throws Exception {
54
		super.setUp();
55

  
56
		DefaultGeometryLibrary lib = new DefaultGeometryLibrary();		
57
		lib.initialize();
58
		lib.postInitialize();
59
		
60
		DefaultGeometryOperationLibrary opLib = new DefaultGeometryOperationLibrary();
61
		opLib.initialize();
62
		opLib.postInitialize();			
63
		
64
		manager = GeometryLocator.getGeometryManager();
65
		manager.registerGeometryOperation("println", new PrintPoint(), TYPES.POINT, SUBTYPES.GEOM2D);
66
		manager.registerGeometryOperation("println", new PrintMultiPoint(), TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
67
	}
68
	
69
	public void testPoint() throws InstantiationException, IllegalAccessException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
70
		Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);		
71
		assertEquals((String)manager.invokeOperation("println", point, null), "println-point");		
72
	}
73
	
74
	public void testMultiPoint() throws InstantiationException, IllegalAccessException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
75
		Point point1 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
76
		point1.setCoordinateAt(0, 1.0);
77
		point1.setCoordinateAt(1, 2.0);
78
		
79
		Point point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
80
		point2.setCoordinateAt(0, 4.0);
81
		point2.setCoordinateAt(1, 5.0);
82
			
83
		MultiPoint multiPoint = (MultiPoint)manager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
84
		multiPoint.addPoint(point1);
85
		multiPoint.addPoint(point2);
86
		
87
		assertEquals((String)manager.invokeOperation("println", multiPoint, null), "println-multipoint");	
88
		assertEquals((String)manager.invokeOperation("println", point1, null), "println-point");	
89
		assertEquals((String)manager.invokeOperation("println", point2, null), "println-point");			
90
						
91
		assertEquals((String)point1.invokeOperation("println", null), "println-point");	
92
		
93
	}
94
}
95

  
96

  
97

  
0 98

  
tags/v2_0_0_Build_2020/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_2020/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 junit.framework.TestCase;
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.impl.DefaultGeometryLibrary;
38
import org.gvsig.fmap.geom.operation.GeometryOperationException;
39
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
40
import org.gvsig.fmap.geom.operation.impl.DefaultGeometryOperationLibrary;
41
import org.gvsig.fmap.geom.primitive.Point;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

  
45
/**
46
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
47
 */
48
public class WKBTest extends TestCase {
49
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
50
	private GeometryManager manager;
51
	
52
	protected void setUp() throws Exception {
53
		super.setUp();
54

  
55
		DefaultGeometryLibrary lib = new DefaultGeometryLibrary();		
56
		lib.initialize();
57
		lib.postInitialize();
58
		
59
		DefaultGeometryOperationLibrary opLib = new DefaultGeometryOperationLibrary();
60
		opLib.initialize();
61
		opLib.postInitialize();	
62
		
63
		manager = GeometryLocator.getGeometryManager();
64
	}
65
	
66
	public void testPoint() throws InstantiationException, IllegalAccessException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException{
67
		Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);		
68
		manager.invokeOperation("toWKB", point, null);		
69
	}
70
}
71

  
0 72

  
tags/v2_0_0_Build_2020/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 junit.framework.TestCase;
31

  
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.GeometryLocator;
34
import org.gvsig.fmap.geom.GeometryManager;
35
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
36
import org.gvsig.fmap.geom.Geometry.TYPES;
37
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
38
import org.gvsig.fmap.geom.operation.GeometryOperation;
39
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB;
40
import org.gvsig.fmap.geom.operation.fromwkb.FromWKBGeometryOperationContext;
41
import org.gvsig.fmap.geom.operation.impl.DefaultGeometryOperationLibrary;
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.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

  
49
/**
50
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
51
 */
52
public class WKBNativeTest extends TestCase {
53
	final static private Logger logger = LoggerFactory.getLogger("org.gvsig");
54
	private GeometryManager manager;
55
	private GeometryOperation toWkb2d;
56
	private GeometryOperation fromWkb2d;
57
	private FromWKBGeometryOperationContext fromWkbContext;
58

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

  
62
		DefaultGeometryLibrary lib = new DefaultGeometryLibrary();
63
		lib.initialize();
64
		lib.postInitialize();
65

  
66
		DefaultGeometryOperationLibrary opLib = new DefaultGeometryOperationLibrary();
67
		opLib.initialize();
68
		opLib.postInitialize();
69

  
70
		manager = GeometryLocator.getGeometryManager();
71
		toWkb2d = manager.getGeometryOperation(ToWKBNative.CODE,
72
				Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D);
73
		fromWkb2d = manager.getGeometryOperation(FromWKB.CODE,
74
				Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D);
75
		fromWkbContext = new FromWKBGeometryOperationContext();
76
	}
77

  
78
	public void testPoint() throws Exception{
79
		Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
80
		point.setX(1);
81
		point.setY(2);
82
		byte[] wkb = (byte[]) toWkb2d.invoke(point,
83
				null);
84
		fromWkbContext.setData(wkb);
85
		Geometry geom = (Geometry) fromWkb2d.invoke(null,
86
				fromWkbContext);
87

  
88
		assertEquals(point, geom);
89
	}
90

  
91
	public void testCurve() throws Exception {
92

  
93
		GeneralPathX gp = new GeneralPathX();
94

  
95
		gp.moveTo(0.0, 0.0);
96
		gp.lineTo(1.0, 1.0);
97
		gp.lineTo(2.0, 2.0);
98
		gp.lineTo(3.0, 3.0);
99
		Curve curve = (Curve) manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
100
		curve.setGeneralPath(gp);
101
		byte[] wkb = (byte[]) toWkb2d.invoke(curve,
102
				null);
103
		fromWkbContext.setData(wkb);
104
		Geometry geom = (Geometry) fromWkb2d.invoke(null,
105
				fromWkbContext);
106
		assertTrue(curve.equals(geom));
107
	}
108

  
109
	public void testPolygon() throws Exception {
110
		GeneralPathX gp = new GeneralPathX();
111
		gp.moveTo(1.0, 1.0);
112
		gp.lineTo(2.0, 2.0);
113
		gp.lineTo(3.0, 3.0);
114
		gp.lineTo(4.0, 4.0);
115
		gp.lineTo(5.0, 5.0);
116
		gp.closePath();
117

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

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

  
125
	}
126

  
127
}
128

  
0 129

  
tags/v2_0_0_Build_2020/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
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.fmap.geom.handler.Handler;
41
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
42
import org.gvsig.fmap.geom.operation.GeometryOperationException;
43
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
44
import org.gvsig.fmap.geom.primitive.Envelope;
45
import org.gvsig.fmap.geom.primitive.GeneralPathX;
46
import org.gvsig.fmap.geom.primitive.Point;
47
import org.gvsig.fmap.geom.type.GeometryType;
48

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

  
56
	private DefaultGeometryManager manager;
57

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

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

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

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

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

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

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

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

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

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

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

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

  
126
	public static class TestGeometry implements Geometry {
127

  
128
		private final GeometryType geometryType;
129

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
220
		}
221

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

  
225
		}
226

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
380
	}
381
}
tags/v2_0_0_Build_2020/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.GEOM2DZ);
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_2020/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
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff