01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library 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 GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.gml2.bindings;
17:
18: import com.vividsolutions.jts.geom.CoordinateSequence;
19:
20: public class GMLUtil {
21: /**
22: * Determines the dimension of a coordinate sequence. This is based off of
23: * the first coordinate in the sequence.
24: *
25: * @param seq The coordinate sequence in question.
26: *
27: * @return The best guess at a dimension, -1 if it can not be determined.
28: */
29: public static int getDimension(CoordinateSequence seq) {
30: int dimension = 0;
31:
32: if (seq.size() == 0) {
33: return -1;
34: }
35:
36: for (; dimension < 100; dimension++) {
37: try {
38: double d = seq.getOrdinate(0, dimension);
39:
40: if (Double.isNaN(d)) {
41: return dimension;
42: }
43: } catch (Throwable t) {
44: return dimension;
45: }
46: }
47:
48: //whoever has a coordinate with more then 100 dimensions is not sane
49: return -1;
50: }
51: }
|