Skip to content

Commit

Permalink
Fixing references and aligning the grammar against the spec more accu…
Browse files Browse the repository at this point in the history
…rately.
  • Loading branch information
fikin committed Aug 16, 2023
1 parent b0b7228 commit d9832ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
18 changes: 9 additions & 9 deletions wkt-crs-v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

Grammar for parsing Well Known Text Coordinate Reference System, version 1.

Reference: [Specification](https://docs.ogc.org/is/12-063r5/12-063r5.html)
References:

The grammar tries to adhere to the spec but have not made extensive tests.

This grammar is extended with ability to parse properties file, containing EPSG=WKTCRS type of definitions.
For example one can parse [GeoTools epsg.properties](https://raw.githubusercontent.com/geotools/geotools/main/modules/plugin/epsg-wkt/src/main/resources/org/geotools/referencing/epsg/wkt/epsg.properties) directly.
- [WKT](https://en.wikipedia.org/wiki/Well-known_text_representation_of_coordinate_reference_systems)
- [WKT v1](https://github.com/geotools/geotools/blob/main/modules/library/opengis/src/main/java/org/opengis/referencing/doc-files/WKT.html)

If the input is properties file, use `propsFile` starting rule.
The grammar tries to adhere to the spec but have not made extensive tests.

If the input is pure WKT, use `wkt` starting rule.
This grammar is extended with ability to parse multiple WTK definitions from a properties file of the format EPSG_CODE=WKTCRS.
Specifically it ca parse [GeoTools epsg.properties](https://raw.githubusercontent.com/geotools/geotools/main/modules/plugin/epsg-wkt/src/main/resources/org/geotools/referencing/epsg/wkt/epsg.properties).

## License
Grammar rules:

BSD
- if the input is properties file, use `propsFile` starting rule.
- if the input is pure WKT, use `wkt` starting rule.
28 changes: 13 additions & 15 deletions wkt-crs-v1/wktcrsv1.g4
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* For parsing propeties file (like GeoTools epsg.properties), use starting rule "propsFile".
* For parsing single WKT CRS definition, use starting rule "wkt".
* For parsing propeties file (like GeoTools epsg.properties), use starting rule "propsFile". For parsing single WKT CRS definition, use starting rule "wkt".
*/
grammar wktcrsv1;
options { caseInsensitive = true; }

propsFile: propRow* EOF;

Expand All @@ -35,10 +33,10 @@ datum: 'DATUM' LPAR name COMMA spheroid (COMMA towgs84)? (COMMA authorit
vertdatum: 'VERT_DATUM' LPAR name COMMA type COMMA authority RPAR;
localdatum: 'LOCAL_DATUM' LPAR name COMMA type (COMMA authority)? RPAR;
spheroid: 'SPHEROID' LPAR name COMMA semiMajorAxis COMMA inverseFlattening (COMMA authority)? RPAR;
towgs84: 'TOWGS84' LPAR dXBF COMMA dYBF COMMA dZBF (COMMA rXBF COMMA rYBF COMMA rZBF (COMMA mBF)?)? RPAR;
towgs84: 'TOWGS84' LPAR dx COMMA dy COMMA dz (COMMA ex COMMA ey COMMA ez (COMMA ppm)?)? RPAR;
authority: 'AUTHORITY' LPAR authorityName COMMA code RPAR;
primem: 'PRIMEM' LPAR name COMMA longitude (COMMA authority)? RPAR;
unit: 'UNIT' LPAR name COMMA angularUnit (COMMA authority)? RPAR;
unit: 'UNIT' LPAR name COMMA conversionFactor (COMMA authority)? RPAR;
axis: 'AXIS' LPAR name COMMA axisOrient RPAR;
projection: 'PROJECTION' LPAR name (COMMA authority)? RPAR;
parameter: 'PARAMETER' LPAR name COMMA value RPAR;
Expand All @@ -63,16 +61,16 @@ number: NUMBER;
type: NUMBER;
semiMajorAxis: NUMBER;
inverseFlattening: NUMBER;
dXBF: NUMBER;
dYBF: NUMBER;
dZBF: NUMBER;
rXBF: NUMBER;
rYBF: NUMBER;
rZBF: NUMBER;
mBF: NUMBER;
dx: NUMBER;
dy: NUMBER;
dz: NUMBER;
ex: NUMBER;
ey: NUMBER;
ez: NUMBER;
ppm: NUMBER;
code: TEXT;
longitude: NUMBER;
angularUnit: NUMBER;
conversionFactor: NUMBER;
value: NUMBER;

NUMBER: PM? INT ('.' INT)? EXP?;
Expand All @@ -87,5 +85,5 @@ RPAR: ']' | ')';
EQ: '=';

fragment INT: [0-9]+;
fragment EXP: 'E' PM? INT;
fragment PM: '+' | '-';
fragment EXP: [Ee] PM? INT;
fragment PM: '+' | '-';

0 comments on commit d9832ff

Please sign in to comment.