Revision 44432 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/coerce/CoerceToGeometry.java
CoerceToGeometry.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
/** |
33 | 33 |
* Convert a object to Geometry. |
34 |
* |
|
35 |
* Support convert: |
|
36 |
* - Geometry to Geometry (do nothing) |
|
37 |
* - WKB (byte[]) to Geometry |
|
38 |
* - WKT (String/toString) to Geometry |
|
39 |
* |
|
40 |
* |
|
34 |
* |
|
35 |
* Support convert: - Geometry to Geometry (do nothing) - WKB (byte[]) to |
|
36 |
* Geometry - WKT (String/toString) to Geometry |
|
37 |
* |
|
38 |
* |
|
41 | 39 |
* @author gvSIG Team |
42 | 40 |
* @version $Id$ |
43 |
*
|
|
41 |
* |
|
44 | 42 |
*/ |
43 |
@SuppressWarnings("UseSpecificCatch") |
|
45 | 44 |
public class CoerceToGeometry implements Coercion { |
46 | 45 |
|
47 |
public Object coerce(Object value) throws CoercionException { |
|
48 |
try { |
|
49 |
if( value == null || value instanceof Geometry ) { |
|
50 |
return value; |
|
51 |
} |
|
52 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
53 |
if( value instanceof byte[] ) { |
|
54 |
return manager.createFrom((byte[])value); |
|
55 |
} |
|
56 |
return manager.createFrom(value.toString()); |
|
57 |
} catch (Exception e) { |
|
58 |
throw new CoercionException(e); |
|
59 |
} |
|
46 |
public Object coerce(Object value) throws CoercionException { |
|
47 |
try { |
|
48 |
if (value == null || value instanceof Geometry) { |
|
49 |
return value; |
|
50 |
} |
|
51 |
Geometry geom; |
|
52 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
53 |
if (value instanceof byte[]) { |
|
54 |
geom = manager.createFrom((byte[]) value); |
|
55 |
} else { |
|
56 |
geom = manager.createFrom(value.toString()); |
|
57 |
} |
|
58 |
if (geom == null) { |
|
59 |
throw new CoercionException(); |
|
60 |
} |
|
61 |
return geom; |
|
62 |
} catch (Exception e) { |
|
63 |
throw new CoercionException(e); |
|
64 |
} |
|
60 | 65 |
|
61 |
}
|
|
66 |
}
|
|
62 | 67 |
|
63 | 68 |
} |
Also available in: Unified diff