项目作者: DanielJDufour

项目描述 :
Super Low-Level Raster Reprojection and Resampling Library
高级语言: JavaScript
项目地址: git://github.com/DanielJDufour/geowarp.git
创建时间: 2021-05-10T03:08:21Z
项目社区:https://github.com/DanielJDufour/geowarp

开源协议:Creative Commons Zero v1.0 Universal

下载


geowarp

Super Low-Level Raster Reprojection and Resampling Library

install

  1. npm install -S geowarp

usage

  1. const geowarp = require("geowarp");
  2. const proj4 = require("proj4-fully-loaded");
  3. const result = geowarp({
  4. // control the level of console log output
  5. // set debug_level to zero to turn off console logging
  6. debug_level: 2,
  7. // reproject from an [x, y] point in the input spatial reference system
  8. // to an [x, y] point in the output spatial reference system
  9. forward: proj4("EPSG:" + in_srs, "EPSG:3857").forward,
  10. // reproject from an [x, y] point in the output spatial reference system
  11. // to an [x, y] point in the input spatial reference system
  12. inverse: proj4("EPSG:" + in_srs, "EPSG:3857").inverse,
  13. // two-dimensional array of pixel data organized by band
  14. // usually [ r, g, b ] or [ r, g, b, a ]
  15. // pixel data for each band is usually flattened,
  16. // so the end of one row is immediately followed by the next row
  17. in_data: [
  18. [0, 123, 123, 162, ...],
  19. [213, 41, 62, 124, ...],
  20. [84, 52, 124, 235, ...]
  21. ],
  22. // bounding box of input data (in_data)
  23. // in [xmin, ymin, xmax, ymax] format
  24. in_bbox: [ -122.51, 40.97, -122.34, 41.11 ],
  25. // layout of the in_data using xdim layout syntax
  26. // see: https://github.com/danieljdufour/xdim
  27. in_layout: "[band][row,column]",
  28. // a number or array of numbers
  29. in_no_data: -99,
  30. // a number or string representing the spatial reference system of the input data
  31. // could be 4326 or "EPSG:4326"
  32. in_srs: 4326,
  33. // only necessary when in_data is skewed or rotated
  34. // 6-parameter geotransform using the order from https://gdal.org/tutorials/geotransforms_tut.html
  35. in_geotransform: [337934.48363, -0.142999, -0.576775, 7840518.4648, -0.57677, 0.14299],
  36. // how many pixels wide the input data is
  37. in_width: 1032,
  38. // how many pixels tall the input data is
  39. in_height: 1015,
  40. // optional array of constructor names for each array level
  41. // default is to use Array (untyped) for everything
  42. out_array_types: ["Array", "Array", "Uint8Array"],
  43. // optional array for sampling and/or changing band order
  44. // array is the order of the bands in the output with numbers
  45. // indicating the band index in the input (starting at zero)
  46. // for example, [13, 12, 11] skips the first 11 bands,
  47. // and takes the 12th, 13th, and 14th in reverse order
  48. out_bands: [13, 12, 11],
  49. // bounding box of output
  50. // this is the space that you want to paint
  51. // in same format as in_bbox
  52. out_bbox: [-13638811.83098057, 5028944.964938315, -13619243.951739563, 5028944.964938315],
  53. // optional
  54. // single or multi-dimensional array that will hold the output
  55. out_data: [[[[],[],[],...],[[],[],[],...],[[],[],[],...],[[],[],[],...],...]],
  56. // optional, default is null
  57. // the no data value for your output data
  58. out_no_data: -99,
  59. // layout of the result using xdim layout syntax
  60. // see: https://github.com/danieljdufour/xdim
  61. out_layout: "[row][column][band]",
  62. // a number or string representing the spatial reference system of the input data
  63. // could be 4326 or "EPSG:4326"
  64. out_srs: 3857,
  65. // optional
  66. // number of bands in the output
  67. out_pixel_depth: 3,
  68. // height of the output image in pixels
  69. out_height: 256,
  70. // width of the output image in pixels
  71. out_width: 256,
  72. // horizontal and vertical resolution
  73. // resolution of [0.25, 0.25] (i.e. 25%) means that you sample once for every 4 x 4 pixels
  74. // this is useful if you need your output to be a certain height or width (like 256 x 256)
  75. // but don't necessarily want to render data at that high resolution
  76. out_resolution: [0.5, 0.5],
  77. // method for sampling pixels
  78. // current supported methods are:
  79. // "near", "vectorize", "near-vectorize", "bilinear", "max", "mean", "median", "min", "mode", "mode-max", "mode-mean", "mode-median", and "mode-min"
  80. // you can also pass in a custom function that takes in ({ values }) and returns a number
  81. method: 'median',
  82. // round output pixel values to closest integer
  83. // do this if you will convert your output to a PNG or JPG
  84. round: true,
  85. // optional
  86. // the lowest possible pixel value considering the bit-depth of the data
  87. // this is used to speed up the min and mode-min resampling
  88. // if in_data is an array of typed arrays, this will be automatically calculated
  89. theoretical_min: 0,
  90. // optional
  91. // the highest possible pixel value considering the bit-depth of the data
  92. // this is used to speed up the max and mode-max resampling
  93. // if in_data is an array of typed arrays, this will be automatically calculated
  94. theoretical_max: 255,
  95. // optional
  96. // band math expression that maps a pixel from the read bands to the output
  97. // if expr is async (i.e. returns a promise), geowarp will return a promise
  98. expr: ({ pixel }) => {
  99. // clamp values above 100
  100. return pixel.map(value => Math.min(value, 100));
  101. },
  102. // optional
  103. // whether to insert or skip null values
  104. // "skip" - default, don't insert null values
  105. // "insert" - try to insert null values into output data
  106. insert_null_strategy: "skip",
  107. // optional
  108. // array of band indexes to read from
  109. // use this if your expr function only uses select bands
  110. read_bands: [0, 1, 2],
  111. // optional
  112. // polygon or multi-polygons defining areas to cut out (everything outside becomes no data)
  113. // terminology taken from https://gdal.org/programs/gdalwarp.html
  114. cutline: geojson,
  115. // if you specify a cutline, this is required
  116. cutline_srs: 4326,
  117. // function to reproject [x, y] point from cutline_srs to out_srs
  118. // required if you specify a cutline and the cutline is a different srs than out_srs,
  119. cutline_forward: proj4("EPSG:4326", "EPSG:3857").forward,
  120. // optional, default is "outside"
  121. // cut out the pixels "inside" or "outside" the cutline
  122. // in other words, if your cutline_strategy is "inside",
  123. // geowarp will set every pixel inside your cutline geometry to out_no_data
  124. cutline_strategy: "inside",
  125. // optional, default is false
  126. // enable experimental turbocharging via proj-turbo
  127. turbo: true,
  128. // completely optional and not recommended
  129. // you don't want this in most cases
  130. // over-ride the default function for inserting data into the output multidimensional array
  131. // useful if writing to an alternative object like a canvas
  132. insert_pixel: ({ row, column, pixel }) => {
  133. context.fillStyle = toColor(pixel);
  134. context.fillRect(column, row, 1, 1);
  135. },
  136. // completely optional and not recommended in most cases
  137. // take pixel values for a given sample located by sample row and column
  138. // and insert into the output multidimensional array
  139. // by default, this will call insert_pixel
  140. insert_sample: ({ row, column, pixel }) => {
  141. const [xmin, ymin, xmax, ymax] = scalePixel([column, row], [x_scale, y_scale]);
  142. for (let y = ymin; y < ymax; y++) {
  143. for (let x = xmin; x < xmax; x++) {
  144. insert_pixel({ row: y, column: x, pixel });
  145. }
  146. }
  147. },
  148. // skip writing a pixel if "any" or "all" its values are no data
  149. // default is undefined, meaning don't skip no data values
  150. skip_no_data_strategy: "any"
  151. });

result is

  1. {
  2. // a multi-dimensional array of pixel values with the structure defined by out_layout
  3. data: [
  4. [ [...], [...], [...] ], // band 1
  5. // ...
  6. ]
  7. }