Skip to content

Commit f00e83d

Browse files
committed
CRS class
1 parent 10cbf09 commit f00e83d

File tree

1 file changed

+169
-0
lines changed
  • src/main/java/mil/nga/oapi/features/json

1 file changed

+169
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package mil.nga.oapi.features.json;
2+
3+
import java.util.regex.Matcher;
4+
import java.util.regex.Pattern;
5+
6+
/**
7+
* Coordinate Reference System
8+
*
9+
* http://www.opengis.net/def/crs/{authority}/{version}/{code}
10+
*
11+
* @author osbornb
12+
*/
13+
public class Crs {
14+
15+
/**
16+
* CRS pattern
17+
*/
18+
public static final Pattern PATTERN = Pattern
19+
.compile("http.+/([^/]+)/([^/]+)/([^/]+)$");
20+
21+
/**
22+
* CRS pattern authority group
23+
*/
24+
public static final int PATTERN_AUTHORITY_GROUP = 1;
25+
26+
/**
27+
* CRS pattern code group
28+
*/
29+
public static final int PATTERN_VERSION_GROUP = 2;
30+
31+
/**
32+
* CRS pattern code group
33+
*/
34+
public static final int PATTERN_CODE_GROUP = 3;
35+
36+
/**
37+
* Base CRS URL
38+
*/
39+
public static final String BASE_URL = "http://www.opengis.net/def/crs";
40+
41+
/**
42+
* CRS Authority
43+
*/
44+
private String authority;
45+
46+
/**
47+
* CRS Version
48+
*/
49+
private String version;
50+
51+
/**
52+
* CRS Code
53+
*/
54+
private String code;
55+
56+
/**
57+
* Constructor
58+
*/
59+
public Crs() {
60+
61+
}
62+
63+
/**
64+
* Constructor
65+
*
66+
* @param crs
67+
* CRS URL
68+
*/
69+
public Crs(String crs) {
70+
setCrs(crs);
71+
}
72+
73+
/**
74+
* Set the CRS
75+
*
76+
* @param crs
77+
* CRS URL
78+
* @return true if a valid CRS and values were set
79+
*/
80+
public boolean setCrs(String crs) {
81+
82+
boolean valid = false;
83+
84+
Matcher matcher = PATTERN.matcher(crs);
85+
if (matcher.find()) {
86+
authority = matcher.group(PATTERN_AUTHORITY_GROUP);
87+
version = matcher.group(PATTERN_VERSION_GROUP);
88+
code = matcher.group(PATTERN_CODE_GROUP);
89+
valid = true;
90+
}
91+
92+
return valid;
93+
}
94+
95+
/**
96+
* Get the authority
97+
*
98+
* @return authority
99+
*/
100+
public String getAuthority() {
101+
return authority;
102+
}
103+
104+
/**
105+
* Set the authority
106+
*
107+
* @param authority
108+
* authority
109+
*/
110+
public void setAuthority(String authority) {
111+
this.authority = authority;
112+
}
113+
114+
/**
115+
* Get the version
116+
*
117+
* @return version
118+
*/
119+
public String getVersion() {
120+
return version;
121+
}
122+
123+
/**
124+
* Set the version
125+
*
126+
* @param version
127+
* version
128+
*/
129+
public void setVersion(String version) {
130+
this.version = version;
131+
}
132+
133+
/**
134+
* Get the code
135+
*
136+
* @return code
137+
*/
138+
public String getCode() {
139+
return code;
140+
}
141+
142+
/**
143+
* Set the code
144+
*
145+
* @param code
146+
* code
147+
*/
148+
public void setCode(String code) {
149+
this.code = code;
150+
}
151+
152+
/**
153+
* Determine if all parts of the CRS are set
154+
*
155+
* @return true if valid
156+
*/
157+
public boolean isValid() {
158+
return authority != null && version != null && code != null;
159+
}
160+
161+
/**
162+
* {@inheritDoc}
163+
*/
164+
@Override
165+
public String toString() {
166+
return BASE_URL + "/" + authority + "/" + version + "/" + code;
167+
}
168+
169+
}

0 commit comments

Comments
 (0)