svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / operation / towkb / ToWKB.java @ 40416
History | View | Annotate | Download (1.42 KB)
1 |
package org.gvsig.fmap.geom.operation.towkb; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.geom.Geometry; |
4 |
import org.gvsig.fmap.geom.GeometryLocator; |
5 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
6 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
7 |
import org.gvsig.fmap.geom.util.Converter; |
8 |
|
9 |
import com.vividsolutions.jts.io.WKBWriter; |
10 |
|
11 |
public class ToWKB extends GeometryOperation { |
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; |
16 |
|
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 |
|
40 |
if (ctx == null){ |
41 |
return writer.write(Converter.geometryToJts(geom));
|
42 |
} |
43 |
return writer.write(Converter.geometryToJtsWithSRID(geom,
|
44 |
((ToWKBOperationContext) ctx).getSrID())); |
45 |
} |
46 |
|
47 |
public int getOperationIndex() { |
48 |
return CODE;
|
49 |
} |
50 |
|
51 |
} |