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 | 20962 | jiyarza | package org.gvsig.fmap.geom.operation.towkb; |
---|---|---|---|
2 | |||
3 | import org.gvsig.fmap.geom.Geometry; |
||
4 | 26328 | jpiera | import org.gvsig.fmap.geom.GeometryLocator; |
5 | 20962 | jiyarza | import org.gvsig.fmap.geom.operation.GeometryOperation; |
6 | import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
||
7 | 20964 | jiyarza | import org.gvsig.fmap.geom.util.Converter; |
8 | 20962 | jiyarza | |
9 | 22207 | jmvivo | import com.vividsolutions.jts.io.WKBWriter; |
10 | |||
11 | 20962 | jiyarza | public class ToWKB extends GeometryOperation { |
12 | 40416 | nbrodin | 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 | 22207 | jmvivo | |
17 | 20962 | jiyarza | public Object invoke(Geometry geom, GeometryOperationContext ctx) { |
18 | 40416 | nbrodin | 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 | 28396 | jmvivo | if (ctx == null){ |
41 | return writer.write(Converter.geometryToJts(geom));
|
||
42 | } |
||
43 | return writer.write(Converter.geometryToJtsWithSRID(geom,
|
||
44 | ((ToWKBOperationContext) ctx).getSrID())); |
||
45 | 20962 | jiyarza | } |
46 | |||
47 | public int getOperationIndex() { |
||
48 | 21081 | jiyarza | return CODE;
|
49 | 20962 | jiyarza | } |
50 | |||
51 | } |