Skip to content

Commit 7f373f4

Browse files
committed
projection by name method
1 parent d4d3a5c commit 7f373f4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Adheres to [Semantic Versioning](http://semver.org/).
77
## 3.0.4 (TBD)
88

99
* simple-features-java version 2.0.4
10+
* Projection Factory projection by name method
1011

1112
## [3.0.3](https://github.com/ngageoint/simple-features-proj-java/releases/tag/3.0.3) (07-13-2020)
1213

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,39 @@ public static Projection getProjection(long epsg) {
4444
String.valueOf(epsg));
4545
}
4646

47+
/**
48+
* Get the projection for the projection name, expected as 'authority:code'
49+
* or 'epsg_code'
50+
*
51+
* @param name
52+
* projection name
53+
* @return projection
54+
* @since 3.0.4
55+
*/
56+
public static Projection getProjection(String name) {
57+
58+
String authority = null;
59+
String code = null;
60+
61+
String[] projectionParts = name.split(":");
62+
63+
switch (projectionParts.length) {
64+
case 1:
65+
authority = ProjectionConstants.AUTHORITY_EPSG;
66+
code = projectionParts[0];
67+
break;
68+
case 2:
69+
authority = projectionParts[0];
70+
code = projectionParts[1];
71+
break;
72+
default:
73+
throw new SFException("Invalid projection name '" + name
74+
+ "', expected 'authority:code' or 'epsg_code'");
75+
}
76+
77+
return getProjection(authority, code);
78+
}
79+
4780
/**
4881
* Get the projection for authority and code
4982
*

0 commit comments

Comments
 (0)