proj4 2.16.2 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -146,6 +146,7 @@ WKT1 definitions can contain a `TOWGS84` parameter. For proj strings, `towgs84`
146
146
 
147
147
  ## Grid Based Datum Adjustments
148
148
 
149
+ ### NTV2 format (.gsb)
149
150
  To use `+nadgrids=` in a proj definition or a WKT2/PROJJSON `ABRIDGEDTRANSFORM` with an `NTv2` method, first read your NTv2 `.gsb` file (e.g. from https://github.com/OSGeo/proj-datumgrid) into an ArrayBuffer, then pass it to `proj4.nadgrid`. E.g:
150
151
 
151
152
  ```javascript
@@ -164,6 +165,17 @@ proj4.nadgrid('key', buffer, {includeErrorFields:false});
164
165
 
165
166
  If the options argument is omitted, `includeErrorFields` is assumed to be true.
166
167
 
168
+
169
+ ### GeoTIFF format (.tif)
170
+ To use `+nadgrids=` in a proj definition or a WKT2/PROJJSON `ABRIDGEDTRANSFORM` with a `GeoTIFF` method, first read your `.tif` file (e.g. from https://github.com/OSGeo/PROJ-data or https://cdn.proj.org/) into a GeoTIFF instance from the [GeoTIFF.js library](https://github.com/geotiffjs/geotiff.js/), then pass it to `proj4.nadgrid`. E.g:
171
+ ```javascript
172
+ import { fromUrl} from "geotiff";
173
+ const tiff = await fromUrl('ca_nrc_NA83SCRS.tif');
174
+ await proj4.nadgrid('ca_nrc_NA83SCRS.tif', tiff).ready;
175
+ ```
176
+
177
+ Then use the given key in your definition, e.g. `proj4.defs("EPSG:32188","+proj=tmerc +lat_0=0 +lon_0=-73.5 +k=0.9999 +x_0=304800 +y_0=0 +ellps=GRS80 +nadgrids=ca_nrc_NA83SCRS.tif +units=m +no_defs +type=crs");` noting the `+nadgrids=ca_nrc_NA83SCRS.tif` parameter.
178
+
167
179
  ## TypeScript
168
180
 
169
181
  TypeScript implementation was added to the [DefinitelyTyped repository](https://github.com/DefinitelyTyped/DefinitelyTyped).
package/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proj4",
3
- "version": "2.16.2",
3
+ "version": "2.17.0",
4
4
  "description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
5
5
  "homepage": "https://github.com/proj4js/proj4js",
6
6
  "main": "dist/proj4.js",
package/component.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proj4",
3
- "version": "2.16.2",
3
+ "version": "2.17.0",
4
4
  "description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
5
5
  "repo": "proj4js/proj4js",
6
6
  "keywords": [
package/dist/proj4-src.js CHANGED
@@ -3349,10 +3349,17 @@
3349
3349
  var loadedNadgrids = {};
3350
3350
 
3351
3351
  /**
3352
- * Load a binary NTv2 file (.gsb) to a key that can be used in a proj string like +nadgrids=<key>. Pass the NTv2 file
3353
- * as an ArrayBuffer.
3352
+ * Load either a NTv2 file (.gsb) or a Geotiff (.tif) to a key that can be used in a proj string like +nadgrids=<key>. Pass the NTv2 file
3353
+ * as an ArrayBuffer. Pass Geotiff as a GeoTIFF instance from the geotiff.js library.
3354
3354
  */
3355
3355
  function nadgrid(key, data, options) {
3356
+ if (data instanceof ArrayBuffer) {
3357
+ return readNTV2Grid(key, data, options);
3358
+ }
3359
+ return { ready: readGeotiffGrid(key, data) };
3360
+ }
3361
+
3362
+ function readNTV2Grid(key, data, options) {
3356
3363
  var includeErrorFields = true;
3357
3364
  if (options !== undefined && options.includeErrorFields === false) {
3358
3365
  includeErrorFields = false;
@@ -3366,6 +3373,50 @@
3366
3373
  return nadgrid;
3367
3374
  }
3368
3375
 
3376
+ async function readGeotiffGrid(key, tiff) {
3377
+ var subgrids = [];
3378
+ var subGridCount = await tiff.getImageCount();
3379
+ // proj produced tiff grid shift files appear to organize lower res subgrids first, higher res/ child subgrids last.
3380
+ for (var subgridIndex = subGridCount - 1; subgridIndex >= 0; subgridIndex--) {
3381
+ var image = await tiff.getImage(subgridIndex);
3382
+
3383
+ var rasters = await image.readRasters();
3384
+ var data = rasters;
3385
+ var lim = [image.getWidth(), image.getHeight()];
3386
+ var imageBBoxRadians = image.getBoundingBox().map(degreesToRadians);
3387
+ var del = [image.fileDirectory.ModelPixelScale[0], image.fileDirectory.ModelPixelScale[1]].map(degreesToRadians);
3388
+
3389
+ var maxX = imageBBoxRadians[0] + (lim[0] - 1) * del[0];
3390
+ var minY = imageBBoxRadians[3] - (lim[1] - 1) * del[1];
3391
+
3392
+ var latitudeOffsetBand = data[0];
3393
+ var longitudeOffsetBand = data[1];
3394
+ var nodes = [];
3395
+
3396
+ for (let i = lim[1] - 1; i >= 0; i--) {
3397
+ for (let j = lim[0] - 1; j >= 0; j--) {
3398
+ var index = i * lim[0] + j;
3399
+ nodes.push([-secondsToRadians(longitudeOffsetBand[index]), secondsToRadians(latitudeOffsetBand[index])]);
3400
+ }
3401
+ }
3402
+
3403
+ subgrids.push({
3404
+ del: del,
3405
+ lim: lim,
3406
+ ll: [-maxX, minY],
3407
+ cvs: nodes
3408
+ });
3409
+ }
3410
+
3411
+ var tifGrid = {
3412
+ header: {
3413
+ nSubgrids: subGridCount
3414
+ },
3415
+ subgrids: subgrids
3416
+ };
3417
+ loadedNadgrids[key] = tifGrid;
3418
+ return tifGrid;
3419
+ }
3369
3420
  /**
3370
3421
  * Given a proj4 value for nadgrids, return an array of loaded grids
3371
3422
  */
@@ -3397,6 +3448,10 @@
3397
3448
  };
3398
3449
  }
3399
3450
 
3451
+ function degreesToRadians(degrees) {
3452
+ return (degrees) * Math.PI / 180;
3453
+ }
3454
+
3400
3455
  function secondsToRadians(seconds) {
3401
3456
  return (seconds / 3600) * Math.PI / 180;
3402
3457
  }
@@ -3457,6 +3512,10 @@
3457
3512
  return grids;
3458
3513
  }
3459
3514
 
3515
+ /**
3516
+ * @param {*} nodes
3517
+ * @returns Array<Array<number>>
3518
+ */
3460
3519
  function mapNodes(nodes) {
3461
3520
  return nodes.map(function (r) {
3462
3521
  return [secondsToRadians(r.longitudeShift), secondsToRadians(r.latitudeShift)];
@@ -9454,7 +9513,7 @@
9454
9513
  proj4.nadgrid = nadgrid;
9455
9514
  proj4.transform = transform;
9456
9515
  proj4.mgrs = mgrs;
9457
- proj4.version = '2.16.2';
9516
+ proj4.version = '2.17.0';
9458
9517
  includedProjections(proj4);
9459
9518
 
9460
9519
  return proj4;