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 / DefaultGeometryType.java @ 42267
History | View | Annotate | Download (6.09 KB)
1 | 42260 | fdiaz | /**
|
---|---|---|---|
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
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | |||
25 | package org.gvsig.fmap.geom.jts; |
||
26 | |||
27 | import java.lang.reflect.Constructor; |
||
28 | |||
29 | import org.gvsig.fmap.geom.Geometry; |
||
30 | import org.gvsig.fmap.geom.GeometryManager; |
||
31 | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
||
32 | import org.gvsig.fmap.geom.type.AbstractGeometryType; |
||
33 | import org.gvsig.fmap.geom.type.GeometryType; |
||
34 | |||
35 | /**
|
||
36 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
37 | */
|
||
38 | public class DefaultGeometryType extends AbstractGeometryType { |
||
39 | |||
40 | /**
|
||
41 | * Geometry type name
|
||
42 | */
|
||
43 | private String name; |
||
44 | |||
45 | /** Class that implements this class type */
|
||
46 | private Class geometryClass; |
||
47 | |||
48 | /**
|
||
49 | * The type of the geometry. The type is an abstract representation
|
||
50 | * of the object (Point, Curve...) but it is not a concrete
|
||
51 | * representation (Point2D, Point3D...). To do that comparation
|
||
52 | * the id field is used.
|
||
53 | */
|
||
54 | private int type; |
||
55 | |||
56 | /**
|
||
57 | * The subtype of the geometry. The subtype represents a set of
|
||
58 | * geometries with a dimensional relationship (2D, 3D, 2DM...)
|
||
59 | */
|
||
60 | private int subType; |
||
61 | |||
62 | /**
|
||
63 | * Super types of a geometry. e.g: the super type of an
|
||
64 | * arc is a curve, the super type of a circle is a surface...
|
||
65 | * The supertypes are defined in the ISO 19107
|
||
66 | *
|
||
67 | * @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012"
|
||
68 | * >ISO 19107< /a>
|
||
69 | */
|
||
70 | private int[] superTypes = null; |
||
71 | |||
72 | /**
|
||
73 | * Super SubTypes of a geometry. e.g: the super SubType of a
|
||
74 | * geometry 3D is a geometry 2D, because the 3D extends the
|
||
75 | * behavior of a geometry 2D
|
||
76 | */
|
||
77 | private int[] superSubTypes = null; |
||
78 | |||
79 | private Constructor constructor; |
||
80 | private final Object[] parameters = { this }; |
||
81 | |||
82 | /**
|
||
83 | * This constructor is used by the {@link GeometryManager} when it
|
||
84 | * register a new GeometryType. It has not be used from other
|
||
85 | * parts.
|
||
86 | * @param geomClass
|
||
87 | * Geometry class (e.g: Point2D.class)
|
||
88 | * @param name
|
||
89 | * Symbolic Geometry name that is used to persist the geometry type. In some
|
||
90 | * cases, it is better to use this name because the id can change for different
|
||
91 | * application executions.
|
||
92 | * @param id
|
||
93 | * Geometry id
|
||
94 | * @param typeName
|
||
95 | * The geometry type name
|
||
96 | * @param type
|
||
97 | * The geometry abstract type
|
||
98 | * @param superTypes
|
||
99 | * The superTypes of the geometry type
|
||
100 | * @param superSubTypes
|
||
101 | * The superSubtypes of the geometry type
|
||
102 | */
|
||
103 | public DefaultGeometryType(Class geomClass, String name, int type, int subType, |
||
104 | int[] superTypes, int[] superSubTypes) { |
||
105 | this.geometryClass = geomClass;
|
||
106 | if (name == null) { |
||
107 | this.name = geomClass.getName();
|
||
108 | } else {
|
||
109 | this.name = name;
|
||
110 | } |
||
111 | this.type = type;
|
||
112 | this.subType = subType;
|
||
113 | this.superTypes = superTypes;
|
||
114 | this.superSubTypes = superSubTypes;
|
||
115 | |||
116 | Class[] parameterTypes = { GeometryType.class }; |
||
117 | try {
|
||
118 | constructor = geometryClass.getConstructor(parameterTypes); |
||
119 | } catch (NoSuchMethodException e) { |
||
120 | throw new RuntimeException( |
||
121 | "Error constructor of the geometry class " + geomClass
|
||
122 | + " with one parameter of type GeometryType not found", e);
|
||
123 | } |
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * This constructor is used by the {@link GeometryManager} when it
|
||
128 | * register a new GeometryType. It has not be used from other
|
||
129 | * parts.
|
||
130 | * @param geomClass
|
||
131 | * Geometry class (e.g: Point2D.class)
|
||
132 | * @param name
|
||
133 | * Symbolic Geometry name that is used to persist the geometry type. In some
|
||
134 | * cases, it is better to use this name because the id can change for different
|
||
135 | * application executions.
|
||
136 | * @param id
|
||
137 | * Geometry id
|
||
138 | * @param typeName
|
||
139 | * The geometry type name
|
||
140 | * @param type
|
||
141 | * The geometry abstract type
|
||
142 | */
|
||
143 | public DefaultGeometryType(Class geomClass, String name, int type, int subType) { |
||
144 | this(geomClass, name, type, subType, new int[0], new int[0]); |
||
145 | } |
||
146 | |||
147 | /**
|
||
148 | * This method creates a {@link Geometry} with the type specified
|
||
149 | * by this GeometryType. The geometry has to have a constructor
|
||
150 | * without arguments.
|
||
151 | *
|
||
152 | * @return A new geometry
|
||
153 | * @throws CreateGeometryException
|
||
154 | */
|
||
155 | public Geometry create() throws CreateGeometryException{ |
||
156 | try {
|
||
157 | return (Geometry) constructor.newInstance(parameters);
|
||
158 | } catch (Exception e) { |
||
159 | throw new CreateGeometryException(type, subType, e); |
||
160 | } |
||
161 | } |
||
162 | |||
163 | public Class getGeometryClass() { |
||
164 | return geometryClass;
|
||
165 | } |
||
166 | |||
167 | public String getName() { |
||
168 | return name;
|
||
169 | } |
||
170 | |||
171 | public int getType() { |
||
172 | return type;
|
||
173 | } |
||
174 | |||
175 | public int getSubType() { |
||
176 | return subType;
|
||
177 | } |
||
178 | |||
179 | public boolean isTypeOf(int geometryType) { |
||
180 | if (type == geometryType){
|
||
181 | return true; |
||
182 | } |
||
183 | for (int i=0 ; i<superTypes.length ; i++){ |
||
184 | if(superTypes[i] == geometryType){
|
||
185 | return true; |
||
186 | } |
||
187 | } |
||
188 | return Geometry.TYPES.GEOMETRY == geometryType;
|
||
189 | } |
||
190 | |||
191 | public boolean isSubTypeOf(int geometrySubType) { |
||
192 | if (subType == geometrySubType){
|
||
193 | return true; |
||
194 | } |
||
195 | for (int i=0 ; i<superSubTypes.length ; i++){ |
||
196 | if(superSubTypes[i] == geometrySubType){
|
||
197 | return true; |
||
198 | } |
||
199 | } |
||
200 | return false; |
||
201 | } |
||
202 | |||
203 | } |