Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / operation / fromwkt / FromWKT.java @ 45683

History | View | Annotate | Download (2.44 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 modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.jts.operation.fromwkt;
24

    
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.GeometryLocator;
27
import org.gvsig.fmap.geom.GeometryManager;
28
import org.gvsig.fmap.geom.operation.GeometryOperation;
29
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
30
import org.gvsig.fmap.geom.operation.GeometryOperationException;
31
import org.gvsig.fmap.geom.operation.fromwkt.FromWKTGeometryOperationContext;
32

    
33
/**
34
 * @author jmvivo
35
 *
36
 */
37
@SuppressWarnings("UseSpecificCatch")
38
public class FromWKT extends GeometryOperation {
39

    
40
    public static final String NAME = GeometryManager.OPERATIONS.FROMWKT;
41
    public static final int CODE = GeometryLocator.getGeometryManager().
42
            getGeometryOperationCode(NAME);
43

    
44
    //  WKTParser parser;
45
    private EWKTParser parser;
46

    
47
    public FromWKT() {
48
//        this.parser = new WKTParser();
49
//        this.parser = new EWKTParser();
50
    }
51
    
52
    @Override
53
    public int getOperationIndex() {
54
        return CODE;
55
    }
56

    
57
    @Override
58
    public Object invoke(Geometry geom, GeometryOperationContext ctx)
59
            throws GeometryOperationException {
60
        try {
61
            String wkt = (String) ctx.getAttribute(FromWKTGeometryOperationContext.TEXT);
62
            this.parser = new EWKTParser();
63
            Geometry g = this.parser.read(wkt);
64
            return g;
65
        } catch (Exception e) {
66
            int type = geom == null ? Geometry.TYPES.UNKNOWN : geom.getType();
67
            throw new GeometryOperationException(type, CODE, e);
68
        }
69
    }
70

    
71
}