Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / operation / fromjts / FromJTS.java @ 32386

History | View | Annotate | Download (2.07 KB)

1
package org.gvsig.fmap.geom.operation.fromjts;
2

    
3
import org.gvsig.fmap.geom.Geometry;
4
import org.gvsig.fmap.geom.GeometryLocator;
5
import org.gvsig.fmap.geom.GeometryManager;
6
import org.gvsig.fmap.geom.exception.CreateGeometryException;
7
import org.gvsig.fmap.geom.operation.GeometryOperation;
8
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
9
import org.gvsig.fmap.geom.operation.GeometryOperationException;
10
import org.gvsig.fmap.geom.util.Converter;
11

    
12
/**
13
 * <p>
14
 * Converts a geometry from JTS to DAL format. This is a special geometry operation
15
 * because don't use the Geometry parameter and returns a JTS geometry. This kind
16
 * of operation can be called from the {@link GeometryManager} using invokeOperation.
17
 * </p>
18
 * <p>
19
 * This operation needs a JTS geometry loaded in the context. The only attribute
20
 * of the {@link GeometryOperation} have to be a geometry of this type and the ID 
21
 * of this attribute will be JTSGeometry.
22
 * </p>
23
 * 
24
 * @author Nacho Brodin (nachobrodin@gmail.com)
25
 *
26
 */
27
public class FromJTS extends GeometryOperation {
28
    public static final String NAME  = "fromJTS";
29
    public static final String PARAM = "JTSGeometry";
30
        protected static GeometryManager geomManager = GeometryLocator.getGeometryManager();
31
    public static final int CODE = geomManager.getGeometryOperationCode(NAME);        
32
        protected final static com.vividsolutions.jts.geom.GeometryFactory geomFactory = new com.vividsolutions.jts.geom.GeometryFactory();
33

    
34
        public int getOperationIndex() {
35
                return CODE;
36
        }
37
        
38
        /*
39
         * (non-Javadoc)
40
         * @see org.gvsig.fmap.geom.operation.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
41
         */
42
        public Object invoke(Geometry geom, GeometryOperationContext ctx)
43
                        throws GeometryOperationException {
44
                Object obj = ctx.getAttribute("JTSGeometry");
45
                if(obj instanceof com.vividsolutions.jts.geom.Geometry) {
46
                        try {
47
                                return Converter.jtsToGeometry((com.vividsolutions.jts.geom.Geometry)obj);
48
                        } catch (CreateGeometryException e) {
49
                                throw new GeometryOperationException(e); 
50
                        }
51
                }
52
                return null;
53
        }
54

    
55
}