Skip to content

Commit f8be0e1

Browse files
committed
pretty utility
1 parent 5f69a4f commit f8be0e1

8 files changed

Lines changed: 254 additions & 6 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build & Test
33
on:
44
push:
55
branches:
6-
- master
6+
- develop
77
pull_request:
88

99
jobs:
@@ -25,6 +25,14 @@ jobs:
2525
run: |
2626
mkdir target/release
2727
cp pom.xml target/*.jar target/release/
28+
- name: Create Pretty
29+
run: |
30+
mkdir pretty
31+
cp script/pretty/* pretty/
32+
find target -regex '.*crs-.*[0-9]\.jar' > CRSJAR
33+
cp $(cat CRSJAR) pretty/pretty.jar
34+
zip -r pretty.zip pretty
35+
cp pretty.zip release/
2836
- name: Upload Artifacts
2937
uses: actions/upload-artifact@v1
3038
with:

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Adheres to [Semantic Versioning](http://semver.org/).
44

55
---
66

7-
## 1.1.2 (TBD)
7+
## [1.1.2](https://github.com/ngageoint/coordinate-reference-systems-java/releases/tag/1.1.2) (02-08-2022)
88

9-
* TBD
9+
* Pretty Well-Known Text and PROJ params main class and command line utility
1010

1111
## [1.1.1](https://github.com/ngageoint/coordinate-reference-systems-java/releases/tag/1.1.1) (02-03-2022)
1212

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ String projTextFromWKT = ProjParser.paramsText(wkt);
132132

133133
### Installation ###
134134

135-
Pull from the [Maven Central Repository](http://search.maven.org/#artifactdetails|mil.nga|crs|1.1.1|jar) (JAR, POM, Source, Javadoc)
135+
Pull from the [Maven Central Repository](http://search.maven.org/#artifactdetails|mil.nga|crs|1.1.2|jar) (JAR, POM, Source, Javadoc)
136136

137137
```xml
138138

139139
<dependency>
140140
<groupId>mil.nga</groupId>
141141
<artifactId>crs</artifactId>
142-
<version>1.1.1</version>
142+
<version>1.1.2</version>
143143
</dependency>
144144

145145
```
@@ -151,3 +151,13 @@ Pull from the [Maven Central Repository](http://search.maven.org/#artifactdetail
151151
Build this repository using Eclipse and/or Maven:
152152

153153
mvn clean install
154+
155+
### Pretty ###
156+
157+
The jar includes a pretty Well-Known Text main class utility that can be run from command line.
158+
159+
Parse OGC Coordinate Reference System Well-Known Text (1|2) and pretty print Coordinate Reference System Well-Known Text 2 and PROJ params. Download [pretty.zip](https://github.com/ngageoint/coordinate-reference-systems-java/releases/latest/download/pretty.zip) and follow the [instructions](script/pretty/).
160+
161+
Or run against the jar:
162+
163+
java -jar crs-*.jar well-known_text

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h2 class="project-tagline">by the National Geospatial-Intelligence Agency</h2>
1717
<a href="http://ngageoint.github.io/coordinate-reference-systems-java/docs/api/" class="btn">API</a>
1818
<a href="https://github.com/ngageoint/coordinate-reference-systems-java/zipball/master" class="btn">.zip</a>
1919
<a href="https://github.com/ngageoint/coordinate-reference-systems-java/tarball/master" class="btn">.tar.gz</a>
20-
<a href="http://search.maven.org/#artifactdetails|mil.nga|crs|1.1.1|jar" class="btn">The Central Repository</a>
20+
<a href="http://search.maven.org/#artifactdetails|mil.nga|crs|1.1.2|jar" class="btn">The Central Repository</a>
2121
</section>
2222

2323
<section class="main-content">

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@
5353

5454
<build>
5555
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-jar-plugin</artifactId>
59+
<version>3.2.2</version>
60+
<configuration>
61+
<archive>
62+
<manifest>
63+
<mainClass>mil.nga.crs.wkt.CRSPretty</mainClass>
64+
</manifest>
65+
</archive>
66+
</configuration>
67+
</plugin>
5668
<plugin>
5769
<groupId>org.apache.maven.plugins</groupId>
5870
<artifactId>maven-source-plugin</artifactId>

script/pretty/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Pretty
2+
3+
[pretty.zip](https://github.com/ngageoint/projections-java/releases/latest/download/pretty.zip)
4+
5+
Parse OGC Coordinate Reference System Well-Known Text (1|2) and pretty print Coordinate Reference System Well-Known Text 2 and PROJ params
6+
7+
## Run
8+
9+
### Script
10+
11+
./pretty.sh well-known_text
12+
13+
### Jar
14+
15+
java -jar pretty.jar well-known_text
16+
17+
### Alias
18+
19+
Add an alias to your shell to run from any location
20+
21+
alias pretty="~/pretty/pretty.sh"
22+
23+
And run
24+
25+
pretty well-known_text
26+
27+
## Examples
28+
29+
Run using the script, Jar, or alias.
30+
31+
pretty 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0]]'
32+
33+
pretty 'PROJCS["WGS 84 / Pseudo-Mercator",\
34+
GEOGCS["WGS 84",\
35+
DATUM["WGS_1984",\
36+
SPHEROID["WGS 84",6378137,298.257223563,\
37+
AUTHORITY["EPSG","7030"]],\
38+
AUTHORITY["EPSG","6326"]],\
39+
PRIMEM["Greenwich",0,\
40+
AUTHORITY["EPSG","8901"]],\
41+
UNIT["degree",0.0174532925199433,\
42+
AUTHORITY["EPSG","9122"]],\
43+
AUTHORITY["EPSG","4326"]],\
44+
PROJECTION["Mercator_1SP"],\
45+
PARAMETER["central_meridian",0],\
46+
PARAMETER["scale_factor",1],\
47+
PARAMETER["false_easting",0],\
48+
PARAMETER["false_northing",0],\
49+
UNIT["metre",1,\
50+
AUTHORITY["EPSG","9001"]],\
51+
AXIS["X",EAST],\
52+
AXIS["Y",NORTH],\
53+
EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],\
54+
AUTHORITY["EPSG","3857"]]'
55+
56+
## Help
57+
58+
```
59+
USAGE
60+
61+
well-known_text
62+
63+
DESCRIPTION
64+
65+
Parse OGC Coordinate Reference System Well-Known Text (1|2) and pretty print Coordinate Reference System Well-Known Text 2 and PROJ params
66+
67+
well-known_text
68+
Coordinate Reference System Well-Known Text
69+
Example: 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0]]'
70+
```

script/pretty/pretty.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
set -f
3+
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
java -jar ${__dir}/pretty.jar $*
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package mil.nga.crs.wkt;
2+
3+
import java.io.IOException;
4+
5+
import mil.nga.crs.CRS;
6+
import mil.nga.crs.CRSException;
7+
import mil.nga.crs.util.proj.ProjParser;
8+
9+
/**
10+
* Parse a CRS and pretty print the WKT and PROJ params
11+
*
12+
* To run from command line:
13+
*
14+
* java -jar name.jar +usage_arguments
15+
*
16+
* java -classpath name.jar mil.nga.crs.wkt.CRSPretty +usage_arguments
17+
*
18+
* @author osbornb
19+
* @since 1.1.2
20+
*/
21+
public class CRSPretty {
22+
23+
/**
24+
* Help Argument
25+
*/
26+
private static final String HELP_ARG = "-help";
27+
28+
/**
29+
* Main method to generate tiles in a GeoPackage
30+
*
31+
* @param args
32+
* arguments
33+
* @throws IOException
34+
* upon error
35+
*/
36+
public static void main(String[] args) throws IOException {
37+
38+
StringBuilder builder = new StringBuilder();
39+
40+
if (args.length > 0 && !args[0].equalsIgnoreCase(HELP_ARG)) {
41+
42+
for (int i = 0; i < args.length; i++) {
43+
44+
String[] lines = args[i].trim().split("\n");
45+
46+
for (int j = 0; j < lines.length; j++) {
47+
48+
String line = lines[j].trim();
49+
if (line.endsWith("\\") || line.endsWith("/")) {
50+
line = line.substring(0, line.length() - 1);
51+
}
52+
53+
builder.append(line);
54+
55+
}
56+
57+
}
58+
59+
}
60+
61+
if (builder.length() == 0) {
62+
printUsage();
63+
} else {
64+
parseAndPrint(builder.toString());
65+
}
66+
67+
}
68+
69+
/**
70+
* Project coordinates
71+
*
72+
* @param wkt
73+
* well-known text
74+
* @throws IOException
75+
* upon error
76+
*/
77+
public static void parseAndPrint(String wkt) throws IOException {
78+
79+
System.out.println();
80+
System.out.println("---------------");
81+
System.out.println("Well-Known Text");
82+
System.out.println("---------------");
83+
System.out.println();
84+
String wktPretty = CRSWriter.writePretty(wkt);
85+
System.out.println(wktPretty);
86+
87+
try {
88+
89+
CRS crs = CRSReader.read(wkt);
90+
91+
String crsPretty = CRSWriter.writePretty(crs);
92+
if (!wktPretty.equals(crsPretty)) {
93+
System.out.println();
94+
System.out.println("-------------------");
95+
System.out.println("CRS Well-Known Text");
96+
System.out.println("-------------------");
97+
System.out.println();
98+
System.out.println(crsPretty);
99+
}
100+
101+
System.out.println();
102+
System.out.println("-----------");
103+
System.out.println("PROJ Params");
104+
System.out.println("-----------");
105+
System.out.println();
106+
System.out.println(ProjParser.paramsText(crs));
107+
System.out.println();
108+
109+
} catch (CRSException e) {
110+
111+
System.out.println();
112+
System.out.println("-------------------------------------------");
113+
System.out.println("Failed to parse Coordinate Reference System");
114+
System.out.println("-------------------------------------------");
115+
System.out.println();
116+
e.printStackTrace();
117+
System.out.println();
118+
119+
}
120+
121+
}
122+
123+
/**
124+
* Print usage for the main method
125+
*/
126+
private static void printUsage() {
127+
System.out.println();
128+
System.out.println("USAGE");
129+
System.out.println();
130+
System.out.println("\twell-known_text");
131+
System.out.println();
132+
System.out.println("DESCRIPTION");
133+
System.out.println();
134+
System.out.println(
135+
"\tParse OGC Coordinate Reference System Well-Known Text (1|2) and pretty print Coordinate Reference System Well-Known Text 2 and PROJ params");
136+
System.out.println();
137+
System.out.println("\twell-known_text");
138+
System.out.println("\t\tCoordinate Reference System Well-Known Text");
139+
System.out.println(
140+
"\t\t\tExample: 'GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0]]'");
141+
System.out.println();
142+
}
143+
144+
}

0 commit comments

Comments
 (0)