Revision 38388

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/util/Converter.java
49 49
import java.lang.reflect.Array;
50 50
import java.util.ArrayList;
51 51

  
52
import org.gvsig.fmap.geom.Geometry;
53
import org.gvsig.fmap.geom.GeometryLocator;
54
import org.gvsig.fmap.geom.GeometryManager;
55
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
56
import org.gvsig.fmap.geom.Geometry.TYPES;
57
import org.gvsig.fmap.geom.aggregate.MultiCurve;
58
import org.gvsig.fmap.geom.aggregate.MultiPoint;
59
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
60
import org.gvsig.fmap.geom.aggregate.MultiSurface;
61
import org.gvsig.fmap.geom.exception.CreateGeometryException;
62
import org.gvsig.fmap.geom.primitive.GeneralPathX;
63
import org.gvsig.fmap.geom.primitive.Surface;
64
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
66

  
52 67
import com.vividsolutions.jts.algorithm.CGAlgorithms;
53 68
import com.vividsolutions.jts.algorithm.RobustCGAlgorithms;
54 69
import com.vividsolutions.jts.geom.Coordinate;
......
62 77
import com.vividsolutions.jts.geom.Point;
63 78
import com.vividsolutions.jts.geom.Polygon;
64 79

  
65
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
67

  
68
import org.gvsig.fmap.geom.Geometry;
69
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
70
import org.gvsig.fmap.geom.Geometry.TYPES;
71
import org.gvsig.fmap.geom.GeometryLocator;
72
import org.gvsig.fmap.geom.GeometryManager;
73
import org.gvsig.fmap.geom.aggregate.MultiCurve;
74
import org.gvsig.fmap.geom.aggregate.MultiPoint;
75
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
76
import org.gvsig.fmap.geom.aggregate.MultiSurface;
77
import org.gvsig.fmap.geom.exception.CreateGeometryException;
78
import org.gvsig.fmap.geom.primitive.GeneralPathX;
79
import org.gvsig.fmap.geom.primitive.Surface;
80

  
81 80
/**
82 81
 * Clase con varios m�todos est�ticos utilizados para pasar de java2d a jts
83 82
 * y viceversa.
......
152 151
				shpNew = geomManager.createPoint(((Point) geo).getX(),
153 152
						((Point) geo).getY(), SUBTYPES.GEOM2D);
154 153
			}
154
			
155
			if (geo instanceof com.vividsolutions.jts.geom.MultiPoint) {
156
				shpNew = (MultiPoint)geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
157
				Coordinate[] coord = ((com.vividsolutions.jts.geom.MultiPoint)geo).getCoordinates();
158
				for (int i = 0; i < coord.length; i++) {
159
					((MultiPoint)shpNew).addPoint(geomManager.createPoint(coord[i].x, coord[i].y, SUBTYPES.GEOM2D));
160
				}
161
			}
155 162

  
156 163
			if (geo.isEmpty()) {
157 164
				shpNew = null;
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/tojts/Surface2DToJTSLineString.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
package org.gvsig.fmap.geom.operation.tojts;
24

  
25
import java.awt.geom.PathIterator;
26
import java.util.ArrayList;
27

  
28
import org.gvsig.fmap.geom.Geometry;
29
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
30
import org.gvsig.fmap.geom.operation.GeometryOperationException;
31

  
32
import com.vividsolutions.jts.geom.Coordinate;
33
import com.vividsolutions.jts.geom.CoordinateArrays;
34
import com.vividsolutions.jts.geom.LinearRing;
35
import com.vividsolutions.jts.geom.MultiLineString;
36

  
37
/**
38
 * Converts a Surface2D into a MultiLineString object
39
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
40
 */
41
public class Surface2DToJTSLineString extends ToJTS {
42
	public static final String NAME = "toJTSLineString";
43
	public static final int CODE = geomManager.getGeometryOperationCode(NAME);
44
	
45
	/*
46
	 * (non-Javadoc)
47
	 * @see org.gvsig.fmap.geom.operation.tojts.ToJTS#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
48
	 */
49
	public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException {
50
		int srid = -1;
51
		if (ctx != null){
52
			srid = ((JTSGeometryOperationContext)ctx).getSrid();
53
		}
54
		PathIterator theIterator = geom.getPathIterator(null, geomManager.getFlatness());
55
		int theType;
56
		double[] theData = new double[6];
57
		ArrayList arrayCoords = null;
58
		Coordinate[] points = null;
59
		ArrayList listRings = new ArrayList();
60
		theIterator = geom.getPathIterator(null, geomManager.getFlatness());
61

  
62
		while (!theIterator.isDone()) {
63
			theType = theIterator.currentSegment(theData);
64

  
65
			switch (theType) {
66
			case PathIterator.SEG_MOVETO:
67
				if (arrayCoords == null) {
68
					arrayCoords = new ArrayList();
69
				} else
70
					arrayCoords.clear();
71
				arrayCoords.add(new Coordinate(theData[0], theData[1]));
72
				break;
73

  
74
			case PathIterator.SEG_LINETO:
75
				arrayCoords.add(new Coordinate(theData[0],theData[1]));
76
				break;
77
			case PathIterator.SEG_QUADTO:
78
				System.out.println("SEG_QUADTO Not supported here");
79
				break;
80
			case PathIterator.SEG_CUBICTO:
81
				System.out.println("SEG_CUBICTO Not supported here");
82
				break;
83
			case PathIterator.SEG_CLOSE:
84
				Coordinate firstCoord = (Coordinate) arrayCoords.get(0);
85
				Coordinate lastCoord = (Coordinate) arrayCoords.get(arrayCoords.size() - 1);
86
				if (!isClosed(firstCoord, lastCoord)) {
87
					arrayCoords.add(firstCoord);
88
				}
89
				points = CoordinateArrays.toCoordinateArray(arrayCoords);
90
				listRings.add(geomFactory.createLinearRing(points));
91
				break;
92
			}
93
			theIterator.next();
94
		} 
95
		
96
		LinearRing[] list = (LinearRing[])listRings.toArray(new LinearRing[listRings.size()]);
97
		MultiLineString lineStr = new com.vividsolutions.jts.geom.GeometryFactory().createMultiLineString(list);
98
		lineStr.setSRID(srid);
99
		return lineStr;
100
	}
101
}
0 102

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/impl/DefaultGeometryOperationLibrary.java
58 58
import org.gvsig.fmap.geom.operation.tojts.MultiSurfaceToJTS;
59 59
import org.gvsig.fmap.geom.operation.tojts.Point2DToJTS;
60 60
import org.gvsig.fmap.geom.operation.tojts.Surface2DToJTS;
61
import org.gvsig.fmap.geom.operation.tojts.Surface2DToJTSLineString;
61 62
import org.gvsig.fmap.geom.operation.tojts.ToJTS;
62 63
import org.gvsig.fmap.geom.operation.towkb.ToWKB;
63 64
import org.gvsig.fmap.geom.operation.towkb.ToWKBNative;
......
117 118
        geometryManager.registerGeometryOperation(ToJTS.NAME, new MultiPointToJTS(), TYPES.MULTIPOINT);
118 119
        geometryManager.registerGeometryOperation(ToJTS.NAME, new MultiCurveToJTS(), TYPES.MULTICURVE);
119 120
        geometryManager.registerGeometryOperation(ToJTS.NAME, new MultiSurfaceToJTS(), TYPES.MULTISURFACE);
120
        
121
        geometryManager.registerGeometryOperation(Surface2DToJTSLineString.NAME, new Surface2DToJTSLineString(), TYPES.SURFACE);
122
        geometryManager.registerGeometryOperation(Surface2DToJTSLineString.NAME, new Surface2DToJTSLineString(), TYPES.MULTISURFACE);
121 123
    }	
122 124
}

Also available in: Unified diff