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.gml3.bindings;
17:
18: import java.net.URI;
19: import java.net.URISyntaxException;
20: import java.util.Iterator;
21: import com.vividsolutions.jts.geom.Coordinate;
22: import com.vividsolutions.jts.geom.LineString;
23: import org.opengis.geometry.DirectPosition;
24: import org.opengis.metadata.Identifier;
25: import org.opengis.referencing.crs.CoordinateReferenceSystem;
26: import org.geotools.geometry.DirectPosition2D;
27: import org.geotools.gml2.bindings.GML2EncodingUtils;
28: import org.geotools.referencing.CRS;
29:
30: /**
31: * Utility class for gml3 encoding.
32: *
33: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
34: *
35: */
36: public class GML3EncodingUtils {
37: static DirectPosition[] positions(LineString line) {
38: Coordinate[] coordinates = line.getCoordinates();
39: DirectPosition[] dps = new DirectPosition[coordinates.length];
40:
41: for (int i = 0; i < dps.length; i++) {
42: Coordinate coordinate = coordinates[i];
43: dps[i] = new DirectPosition2D(coordinate.x, coordinate.y);
44: }
45:
46: return dps;
47: }
48:
49: static URI crs(CoordinateReferenceSystem crs) {
50: if (crs == null) {
51: return null;
52: }
53:
54: try {
55: String crsCode = GML2EncodingUtils.crs(crs);
56:
57: if (crsCode != null) {
58: return new URI(crsCode);
59: } else {
60: return null;
61: }
62: } catch (URISyntaxException e) {
63: throw new RuntimeException(e);
64: }
65: }
66: }
|