01: /*
02: * Created on Jan 6, 2005
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package net.refractions.udig.project.ui.internal;
08:
09: import java.io.IOException;
10: import java.util.ArrayList;
11: import java.util.HashMap;
12: import java.util.Iterator;
13: import java.util.List;
14: import java.util.Map;
15:
16: import net.refractions.udig.catalog.CatalogPlugin;
17: import net.refractions.udig.catalog.IGeoResource;
18: import net.refractions.udig.catalog.IService;
19:
20: import org.opengis.referencing.crs.CoordinateReferenceSystem;
21:
22: /**
23: * @author jones TODO To change the template for this generated type comment go to Window -
24: * Preferences - Java - Code Style - Code Templates
25: */
26: public class UDIGCRSService {
27:
28: /**
29: * @return an array containing all the names of the CRS obtained from the georesources in the
30: * local catalog.
31: */
32: public static String[] getLocalCatalogCRSNamesAsArray() {
33: List<String> list = getLocalCatalogCRSNamesAsList();
34: return list.toArray(new String[list.size()]);
35: }
36:
37: public static List<String> getLocalCatalogCRSNamesAsList() {
38: List<String> list = new ArrayList<String>();
39: try {
40: for (Iterator iter = CatalogPlugin.getDefault()
41: .getLocalCatalog().members(null).iterator(); iter
42: .hasNext();) {
43: for (Iterator iter2 = ((IService) iter.next()).members(
44: null).iterator(); iter2.hasNext();) {
45: try {
46: CoordinateReferenceSystem crs = ((IGeoResource) iter2
47: .next()).getInfo(null).getCRS();
48: if (crs != null) {
49: String name = crs.getName().toString()
50: .trim();
51: if (!list.contains(name))
52: list.add(name);
53: }
54: } catch (Exception e) {
55: // fall through
56: }
57: }
58: }
59: } catch (Exception e) {
60: // // fall through
61: }
62: return list;
63: }
64:
65: public static Map<String, CoordinateReferenceSystem> getLocalCatalogCRSNameMap() {
66: Map<String, CoordinateReferenceSystem> map = new HashMap<String, CoordinateReferenceSystem>();
67:
68: try {
69: for (Iterator iter = CatalogPlugin.getDefault()
70: .getLocalCatalog().members(null).iterator(); iter
71: .hasNext();) {
72:
73: try {
74: for (Iterator iter2 = ((IService) iter.next())
75: .members(null).iterator(); iter2.hasNext();) {
76: try {
77: CoordinateReferenceSystem crs = ((IGeoResource) iter2
78: .next()).getInfo(null).getCRS();
79: if (crs != null) {
80: String name = crs.getName().toString()
81: .trim();
82: map.put(name, crs);
83: }
84: } catch (Exception e) {
85: // fall through
86: }
87: }
88: } catch (IOException e) {
89: // fall through
90: }
91: }
92: } catch (IOException e) {
93: // fall through
94: }
95: return map;
96: }
97:
98: }
|