Skip to content

Commit 8aa3b4b

Browse files
committed
include definition parsed crs in the projections
1 parent 6318e20 commit 8aa3b4b

2 files changed

Lines changed: 77 additions & 16 deletions

File tree

src/main/java/mil/nga/proj/Projection.java

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.locationtech.proj4j.units.Unit;
55
import org.locationtech.proj4j.units.Units;
66

7+
import mil.nga.crs.CRS;
8+
79
/**
810
* Single Projection for an authority and code
911
*
@@ -22,7 +24,7 @@ public class Projection {
2224
private final String code;
2325

2426
/**
25-
* Coordinate Reference System
27+
* Projection Coordinate Reference System
2628
*/
2729
private final CoordinateReferenceSystem crs;
2830

@@ -31,6 +33,11 @@ public class Projection {
3133
*/
3234
private final String definition;
3335

36+
/**
37+
* Definition parsed Coordinate Reference System
38+
*/
39+
private final CRS definitionCRS;
40+
3441
/**
3542
* Constructor
3643
*
@@ -39,7 +46,7 @@ public class Projection {
3946
* @param code
4047
* coordinate code
4148
* @param crs
42-
* crs
49+
* projection coordinate reference system
4350
*/
4451
public Projection(String authority, long code,
4552
CoordinateReferenceSystem crs) {
@@ -54,7 +61,7 @@ public Projection(String authority, long code,
5461
* @param code
5562
* coordinate code
5663
* @param crs
57-
* crs
64+
* projection coordinate reference system
5865
*/
5966
public Projection(String authority, String code,
6067
CoordinateReferenceSystem crs) {
@@ -69,13 +76,13 @@ public Projection(String authority, String code,
6976
* @param code
7077
* coordinate code
7178
* @param crs
72-
* crs
79+
* projection coordinate reference system
7380
* @param definition
7481
* well-known text coordinate definition
7582
*/
7683
public Projection(String authority, long code,
7784
CoordinateReferenceSystem crs, String definition) {
78-
this(authority, String.valueOf(code), crs, definition);
85+
this(authority, code, crs, definition, null);
7986
}
8087

8188
/**
@@ -86,12 +93,52 @@ public Projection(String authority, long code,
8693
* @param code
8794
* coordinate code
8895
* @param crs
89-
* crs
96+
* projection coordinate reference system
9097
* @param definition
9198
* well-known text coordinate definition
9299
*/
93100
public Projection(String authority, String code,
94101
CoordinateReferenceSystem crs, String definition) {
102+
this(authority, code, crs, definition, null);
103+
}
104+
105+
/**
106+
* Constructor
107+
*
108+
* @param authority
109+
* coordinate authority
110+
* @param code
111+
* coordinate code
112+
* @param crs
113+
* projection coordinate reference system
114+
* @param definition
115+
* well-known text coordinate definition
116+
* @param definitionCRS
117+
* definition parsed coordinate reference system
118+
*/
119+
public Projection(String authority, long code,
120+
CoordinateReferenceSystem crs, String definition,
121+
CRS definitionCRS) {
122+
this(authority, String.valueOf(code), crs, definition, definitionCRS);
123+
}
124+
125+
/**
126+
* Constructor
127+
*
128+
* @param authority
129+
* coordinate authority
130+
* @param code
131+
* coordinate code
132+
* @param crs
133+
* projection coordinate reference system
134+
* @param definition
135+
* well-known text coordinate definition
136+
* @param definitionCRS
137+
* definition parsed coordinate reference system
138+
*/
139+
public Projection(String authority, String code,
140+
CoordinateReferenceSystem crs, String definition,
141+
CRS definitionCRS) {
95142
if (authority == null || code == null || crs == null) {
96143
throw new IllegalArgumentException(
97144
"All projection arguments are required. authority: "
@@ -101,6 +148,7 @@ public Projection(String authority, String code,
101148
this.code = code;
102149
this.crs = crs;
103150
this.definition = definition;
151+
this.definitionCRS = definitionCRS;
104152
}
105153

106154
/**
@@ -124,7 +172,7 @@ public String getCode() {
124172
/**
125173
* Get the Coordinate Reference System
126174
*
127-
* @return Coordinate Reference System
175+
* @return coordinate reference system
128176
*/
129177
public CoordinateReferenceSystem getCrs() {
130178
return crs;
@@ -139,6 +187,15 @@ public String getDefinition() {
139187
return definition;
140188
}
141189

190+
/**
191+
* Get the definition parsed Coordinate Reference System
192+
*
193+
* @return coordinate reference system
194+
*/
195+
public CRS getDefinitionCRS() {
196+
return definitionCRS;
197+
}
198+
142199
/**
143200
* Get the transformation from this Projection to the EPSG code. Each thread
144201
* of execution should have it's own transformation.

src/main/java/mil/nga/proj/ProjectionFactory.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,21 @@ public static Projection getProjectionByDefinition(String definition) {
298298

299299
if (definition != null && !definition.isEmpty()) {
300300

301-
CRS crsObject = null;
301+
CRS definitionCRS = null;
302302
try {
303-
crsObject = CRSReader.read(definition);
303+
definitionCRS = CRSReader.read(definition);
304304
} catch (IOException e) {
305305
throw new ProjectionException(
306306
"Failed to parse definition: " + definition, e);
307307
}
308308

309-
if (crsObject != null) {
309+
if (definitionCRS != null) {
310310

311311
String authority = null;
312312
String code = null;
313313

314-
if (crsObject.hasIdentifiers()) {
315-
Identifier identifier = crsObject.getIdentifier(0);
314+
if (definitionCRS.hasIdentifiers()) {
315+
Identifier identifier = definitionCRS.getIdentifier(0);
316316
authority = identifier.getName();
317317
code = identifier.getUniqueIdentifier();
318318
}
@@ -347,10 +347,10 @@ public static Projection getProjectionByDefinition(String definition) {
347347
if (projection == null) {
348348

349349
CoordinateReferenceSystem crs = CRSParser
350-
.convert(crsObject);
350+
.convert(definitionCRS);
351351
if (crs != null) {
352352
projection = new Projection(authority, code, crs,
353-
definition);
353+
definition, definitionCRS);
354354
if (cache) {
355355
projections.addProjection(projection);
356356
}
@@ -451,10 +451,14 @@ private static Projection fromDefinition(String authority, String code,
451451
if (definition != null && !definition.isEmpty()) {
452452

453453
try {
454-
CoordinateReferenceSystem crs = CRSParser.parse(definition);
454+
CoordinateReferenceSystem crs = null;
455+
CRS definitionCRS = CRSReader.read(definition);
456+
if (definitionCRS != null) {
457+
crs = CRSParser.convert(definitionCRS);
458+
}
455459
if (crs != null) {
456460
projection = new Projection(authority, code, crs,
457-
definition);
461+
definition, definitionCRS);
458462
projections.addProjection(projection);
459463
}
460464
} catch (Exception e) {

0 commit comments

Comments
 (0)