01: /*
02: * This file is part of the GeOxygene project source files.
03: *
04: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
05: * the development and deployment of geographic (GIS) applications. It is a open source
06: * contribution of the COGIT laboratory at the Institut Géographique National (the French
07: * National Mapping Agency).
08: *
09: * See: http://oxygene-project.sourceforge.net
10: *
11: * Copyright (C) 2005 Institut Géographique National
12: *
13: * This library is free software; you can redistribute it and/or modify it under the terms
14: * of the GNU Lesser General Public License as published by the Free Software Foundation;
15: * either version 2.1 of the License, or any later version.
16: *
17: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser General Public License along with
22: * this library (see file LICENSE if present); if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: *
25: */
26:
27: package fr.ign.cogit.geoxygene.util.conversion;
28:
29: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPosition;
30: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString;
31: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon;
32: import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_Aggregate;
33: import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Point;
34: import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
35:
36: public class IsEmptyUtil {
37:
38: public static boolean isEmpty(GM_Object geom) {
39: if (geom == null)
40: return true;
41: if (geom instanceof GM_Point)
42: return isEmpty((GM_Point) geom);
43: if (geom instanceof GM_Polygon)
44: return isEmpty((GM_Polygon) geom);
45: if (geom instanceof GM_LineString)
46: return isEmpty((GM_LineString) geom);
47: if (geom instanceof GM_Aggregate)
48: return isEmpty((GM_Aggregate) geom);
49: return false;
50: }
51:
52: public static boolean isEmpty(GM_Point point) {
53: DirectPosition position = point.getPosition();
54: double x = position.getX();
55: double y = position.getY();
56: double z = position.getZ();
57: return (x == Double.NaN || y == Double.NaN || z == Double.NaN);
58: }
59:
60: public static boolean isEmpty(GM_Polygon poly) {
61: return poly.coord().size() == 0;
62: }
63:
64: public static boolean isEmpty(GM_LineString lineString) {
65: return lineString.sizeControlPoint() == 0;
66: }
67:
68: static boolean isEmpty(GM_Aggregate aggr) {
69: if (aggr.size() == 0)
70: return true;
71: else {
72: aggr.initIterator();
73: while (aggr.hasNext()) {
74: GM_Object geom = aggr.next();
75: if (!isEmpty(geom))
76: return false;
77: }
78: return true;
79: }
80: }
81: }
|