Skip to content

Commit ebd9c99

Browse files
committed
Implement proj:code #26
1 parent 57fd728 commit ebd9c99

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ The most important methods are:
132132
import { Formatters } from '@radiantearth/stac-fields';
133133
Formatters.allowHtmlInCommonMark = false;
134134
```
135+
* CrsCode (CRS Codes such as `EPSG:1234`)
135136
* CSV (array to comma-separated values)
136137
* Date
137138
* DOI (generate a link for a DOI)
138139
* Duration (ISO 8601 duration)
139-
* EPSG (generate a link for an EPSG code)
140+
* EPSG (generate a link for an EPSG code - deprecated in favor of CrsCode)
140141
* Extent (array with two values formatted as range)
141142
* FileDataType (explains the data types defined in the file extension)
142143
* FileSize (formats a number of bytes into kB, MB, ...)

demo/item.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"https://stac-extensions.github.io/file/v1.0.0/schema.json",
77
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
88
"https://stac-extensions.github.io/contacts/v0.1.1/schema.json",
9-
"https://stac-extensions.github.io/themes/v1.0.0/schema.json"
9+
"https://stac-extensions.github.io/themes/v1.0.0/schema.json",
10+
"https://stac-extensions.github.io/projection/v2.0.0/schema.json"
1011
],
1112
"id": "LC08_L1TP_107018_20181001_20181001_01_RT",
1213
"type": "Feature",
@@ -62,6 +63,7 @@
6263
"language": {
6364
"code": "en"
6465
},
66+
"proj:code": "EPSG:4326",
6567
"file:checksum": "1114a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
6668
"file:data_type": "uint16",
6769
"file:size": 2048,

fields.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,11 @@
11511151
"format": "EPSG",
11521152
"summary": "v"
11531153
},
1154+
"proj:code": {
1155+
"label": "Code",
1156+
"format": "CrsCode",
1157+
"summary": "v"
1158+
},
11541159
"proj:wkt2": {
11551160
"label": "WKT2",
11561161
"explain": "Well-Known Text, version 2",

formatters.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,36 @@ const Formatters = {
325325
});
326326
},
327327

328-
formatEPSG(value) {
329-
// Remove leading 'epsg:' which people sometimes prepend
328+
formatCrsCode(value) {
330329
if (typeof value === 'string') {
331-
value = value.replace(/^epsg:/i, '');
330+
const [authority, code] = value.split(':', 2);
331+
switch(authority.toUpperCase()) {
332+
case 'EPSG':
333+
case 'ESRI':
334+
case 'IAU_2015':
335+
case 'IGNF':
336+
case 'MKG':
337+
case 'OGC':
338+
return _.toLink(`https://spatialreference.org/ref/${authority.toLowerCase()}/${code}/`, value);
339+
default:
340+
return DataTypes.string(value);
341+
}
332342
}
333-
value = parseInt(value, 10);
334-
if (value > 0) {
335-
return _.toLink(`http://epsg.io/${value}`, value);
343+
344+
return DataTypes.null();
345+
},
346+
347+
/**
348+
* @deprecated Use formatCrsCode instead
349+
*/
350+
formatEPSG(value) {
351+
if (typeof value === 'number') {
352+
return Formatters.formatCrsCode(`EPSG:${value}`);
336353
}
337-
else {
338-
return DataTypes.null();
354+
else if (typeof value === 'string') {
355+
return Formatters.formatCrsCode(value);
339356
}
357+
return DataTypes.null();
340358
},
341359

342360
formatExtent(value, field, spec = {}) {

0 commit comments

Comments
 (0)