01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.support;
16:
17: import com.vividsolutions.jts.geom.Geometry;
18: import com.vividsolutions.jts.geom.LineString;
19: import com.vividsolutions.jts.geom.LinearRing;
20: import com.vividsolutions.jts.geom.MultiLineString;
21: import com.vividsolutions.jts.geom.MultiPoint;
22: import com.vividsolutions.jts.geom.MultiPolygon;
23: import com.vividsolutions.jts.geom.Point;
24: import com.vividsolutions.jts.geom.Polygon;
25:
26: /**
27: * Enumerates the different types of Geometry types that a EditGeom can be.
28: *
29: * @author jones
30: * @since 1.1.0
31: */
32: public enum ShapeType {
33: UNKNOWN, POINT, LINE, POLYGON;
34:
35: public static ShapeType valueOf(Geometry geom) {
36: if (geom instanceof Point || geom instanceof MultiPoint)
37: return POINT;
38: if (geom instanceof LineString || geom instanceof LinearRing
39: || geom instanceof MultiLineString)
40: return LINE;
41: if (geom instanceof Polygon || geom instanceof MultiPolygon)
42: return POLYGON;
43:
44: return UNKNOWN;
45: }
46:
47: public static ShapeType valueOf(Class type) {
48: if (Point.class.isAssignableFrom(type)
49: || MultiPoint.class.isAssignableFrom(type))
50: return POINT;
51: if (LineString.class.isAssignableFrom(type)
52: || LinearRing.class.isAssignableFrom(type)
53: || MultiLineString.class.isAssignableFrom(type))
54: return LINE;
55: if (Polygon.class.isAssignableFrom(type)
56: || MultiPolygon.class.isAssignableFrom(type))
57: return POLYGON;
58:
59: return UNKNOWN;
60: }
61: }
|