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 @ 42579

History | View | Annotate | Download (2.54 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
import com.vividsolutions.jts.io.ParseException;
34

    
35
/**
36
 * @author jmvivo
37
 *
38
 */
39
public class FromWKT extends GeometryOperation {
40

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

    
45
    private static final WKTParser parser = new WKTParser();
46
    /*
47
     * (non-Javadoc)
48
     *
49
     * @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
50
     */
51

    
52
    @Override
53
    public int getOperationIndex() {
54
        return CODE;
55
    }
56

    
57
    /* (non-Javadoc)
58
     * @see org.gvsig.fmap.geom.operation.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
59
     */
60
    @Override
61
    public Object invoke(Geometry geom, GeometryOperationContext ctx)
62
            throws GeometryOperationException {
63
        try {
64
            return parser.read((String) ctx.getAttribute(FromWKTGeometryOperationContext.TEXT));
65
        } catch (ParseException e) {
66
            int type = geom==null? Geometry.TYPES.NULL : geom.getType(); 
67
            throw new GeometryOperationException(type, CODE, e);
68
        }
69
    }
70

    
71
}