Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.operation / src / main / java / org / gvsig / fmap / geom / operation / towkb / ToWKB.java @ 40559

History | View | Annotate | Download (2.38 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.geom.operation.towkb;
25

    
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.fmap.geom.GeometryLocator;
28
import org.gvsig.fmap.geom.operation.GeometryOperation;
29
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
30
import org.gvsig.fmap.geom.util.Converter;
31

    
32
import com.vividsolutions.jts.io.WKBWriter;
33

    
34
public class ToWKB extends GeometryOperation {
35
    public static final String NAME       = "toWKB";
36
        public static final int    CODE       =  GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);
37
        private static WKBWriter   writer     = null;
38
        private static int         dimension  = 2;
39

    
40
        public Object invoke(Geometry geom, GeometryOperationContext ctx) {
41
                int subType = geom.getGeometryType().getSubType();
42
                boolean is3D = subType == 1 || subType == 3;
43
                
44
                if(writer == null) {
45
                        if(is3D) {
46
                                dimension = 3;
47
                                writer = new WKBWriter(3);
48
                        } else {
49
                                dimension = 2;
50
                                writer = new WKBWriter();
51
                        }
52
                } else {
53
                        if(is3D && dimension == 2) {
54
                                dimension = 3;
55
                                writer = new WKBWriter(3);
56
                        }
57
                        if(!is3D && dimension == 3) {
58
                                dimension = 2;
59
                                writer = new WKBWriter();
60
                        }
61
                }
62
                
63
                if (ctx == null) {
64
                        return writer.write(Converter.geometryToJts(geom));
65
                }
66
                return writer.write(Converter.geometryToJtsWithSRID(geom,
67
                                ((ToWKBOperationContext) ctx).getSrID()));
68
        }
69

    
70
        public int getOperationIndex() {
71
                return CODE;
72
        }
73

    
74
}