Revision 40416 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/towkb/ToWKB.java

View differences:

ToWKB.java
9 9
import com.vividsolutions.jts.io.WKBWriter;
10 10

  
11 11
public class ToWKB extends GeometryOperation {
12
    public static final String NAME = "toWKB";
13
	public static final int CODE = GeometryLocator.getGeometryManager().
14
    	getGeometryOperationCode(NAME);
15
	
16
	private static WKBWriter writer = new WKBWriter();
12
    public static final String NAME       = "toWKB";
13
	public static final int    CODE       =  GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);
14
	private static WKBWriter   writer     = null;
15
	private static int         dimension  = 2;
17 16

  
18 17
	public Object invoke(Geometry geom, GeometryOperationContext ctx) {
18
		int subType = geom.getGeometryType().getSubType();
19
		boolean is3D = subType == 1 || subType == 3;
20
		
21
		if(writer == null) {
22
			if(is3D) {
23
				dimension = 3;
24
				writer = new WKBWriter(3);
25
			} else {
26
				dimension = 2;
27
				writer = new WKBWriter();
28
			}
29
		} else {
30
			if(is3D && dimension == 2) {
31
				dimension = 3;
32
				writer = new WKBWriter(3);
33
			}
34
			if(!is3D && dimension == 3) {
35
				dimension = 2;
36
				writer = new WKBWriter();
37
			}
38
		}
39
		
19 40
		if (ctx == null){
20 41
			return writer.write(Converter.geometryToJts(geom));
21 42
		}

Also available in: Unified diff