├── .babelrc ├── .editorconfig ├── .eslintrc ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── release.yml │ └── test.yml ├── .gitignore ├── .jshintrc ├── .nvmrc ├── .prettierrc ├── .yarn └── releases │ └── yarn-3.2.3.cjs ├── .yarnrc.yml ├── CHANGELOG ├── LICENSE ├── README.md ├── demo ├── index.html └── index.js ├── karma.conf.js ├── package.json ├── src ├── api.js ├── gdalDataType.js ├── gdalDataset.js ├── guessFileExtension.js ├── index.js ├── randomKey.js ├── stringParamAllocator.js ├── validation.js ├── worker.js ├── workerCommunication.js └── wrappers │ ├── gdalClose.js │ ├── gdalDatasetGetLayerCount.js │ ├── gdalDemProcessing.js │ ├── gdalGetGeoTransform.js │ ├── gdalGetProjectionRef.js │ ├── gdalGetRasterCount.js │ ├── gdalGetRasterDataType.js │ ├── gdalGetRasterMaximum.js │ ├── gdalGetRasterMinimum.js │ ├── gdalGetRasterNoDataValue.js │ ├── gdalGetRasterStatistics.js │ ├── gdalGetRasterXSize.js │ ├── gdalGetRasterYSize.js │ ├── gdalOpen.js │ ├── gdalRasterize.js │ ├── gdalTranslate.js │ ├── gdalVectorTranslate.js │ ├── gdalWarp.js │ └── reproject.js ├── test ├── assets │ ├── geom.geojson │ ├── not-a-tiff.bytes │ ├── point.dbf │ ├── point.prj │ ├── point.shp │ ├── point.shx │ ├── tiny.tif │ └── tiny_dem.tif └── loam.spec.js ├── webpack.dev.js ├── webpack.prod.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [["@babel/env", { "modules": "commonjs" }]], 3 | "plugins": ["add-module-exports"] 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = LF 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "env": { 4 | "browser": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | 9 | "globals": { 10 | "document": false, 11 | "escape": false, 12 | "navigator": false, 13 | "unescape": false, 14 | "window": false, 15 | "describe": true, 16 | "before": true, 17 | "it": true, 18 | "expect": true, 19 | "sinon": true 20 | }, 21 | 22 | "parser": "@babel/eslint-parser", 23 | 24 | "plugins": [ 25 | 26 | ], 27 | 28 | "rules": { 29 | "block-scoped-var": 2, 30 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 31 | "camelcase": [2, { "properties": "always" }], 32 | "comma-dangle": [2, "always-multiline"], 33 | "comma-spacing": [2, { "before": false, "after": true }], 34 | "comma-style": [2, "last"], 35 | "complexity": 0, 36 | "consistent-return": 2, 37 | "consistent-this": 0, 38 | "curly": [2, "multi-line"], 39 | "default-case": 0, 40 | "dot-location": [2, "property"], 41 | "dot-notation": 0, 42 | "eol-last": 2, 43 | "eqeqeq": [2, "allow-null"], 44 | "func-names": 0, 45 | "func-style": 0, 46 | "generator-star-spacing": [2, "both"], 47 | "guard-for-in": 0, 48 | "handle-callback-err": [2, "^(err|error|anySpecificError)$" ], 49 | "indent": [2, 4, { "SwitchCase": 1 }], 50 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 51 | "keyword-spacing": [2, {"before": true, "after": true}], 52 | "linebreak-style": 0, 53 | "max-depth": 0, 54 | "max-len": [2, 100, 4], 55 | "max-nested-callbacks": 0, 56 | "max-params": 0, 57 | "max-statements": 0, 58 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 59 | "newline-after-var": [2, "always"], 60 | "new-parens": 2, 61 | "no-alert": 0, 62 | "no-array-constructor": 2, 63 | "no-bitwise": 0, 64 | "no-caller": 2, 65 | "no-catch-shadow": 0, 66 | "no-cond-assign": 2, 67 | "no-console": 0, 68 | "no-constant-condition": 0, 69 | "no-continue": 0, 70 | "no-control-regex": 2, 71 | "no-debugger": 2, 72 | "no-delete-var": 2, 73 | "no-div-regex": 0, 74 | "no-dupe-args": 2, 75 | "no-dupe-keys": 2, 76 | "no-duplicate-case": 2, 77 | "no-else-return": 2, 78 | "no-empty": 0, 79 | "no-empty-character-class": 2, 80 | "no-eq-null": 0, 81 | "no-eval": 2, 82 | "no-ex-assign": 2, 83 | "no-extend-native": 2, 84 | "no-extra-bind": 2, 85 | "no-extra-boolean-cast": 2, 86 | "no-extra-parens": 0, 87 | "no-extra-semi": 0, 88 | "no-extra-strict": 0, 89 | "no-fallthrough": 2, 90 | "no-floating-decimal": 2, 91 | "no-func-assign": 2, 92 | "no-implied-eval": 2, 93 | "no-inline-comments": 0, 94 | "no-inner-declarations": [2, "functions"], 95 | "no-invalid-regexp": 2, 96 | "no-irregular-whitespace": 2, 97 | "no-iterator": 2, 98 | "no-label-var": 2, 99 | "no-labels": 2, 100 | "no-lone-blocks": 0, 101 | "no-lonely-if": 0, 102 | "no-loop-func": 0, 103 | "no-mixed-requires": 0, 104 | "no-mixed-spaces-and-tabs": [2, false], 105 | "no-multi-spaces": 2, 106 | "no-multi-str": 2, 107 | "no-multiple-empty-lines": [2, { "max": 1 }], 108 | "no-native-reassign": 2, 109 | "no-negated-in-lhs": 2, 110 | "no-nested-ternary": 0, 111 | "no-new": 2, 112 | "no-new-func": 2, 113 | "no-new-object": 2, 114 | "no-new-require": 2, 115 | "no-new-wrappers": 2, 116 | "no-obj-calls": 2, 117 | "no-octal": 2, 118 | "no-octal-escape": 2, 119 | "no-path-concat": 0, 120 | "no-plusplus": 0, 121 | "no-process-env": 0, 122 | "no-process-exit": 0, 123 | "no-proto": 2, 124 | "no-redeclare": 2, 125 | "no-regex-spaces": 2, 126 | "no-reserved-keys": 0, 127 | "no-restricted-modules": 0, 128 | "no-return-assign": 2, 129 | "no-script-url": 0, 130 | "no-self-compare": 2, 131 | "no-sequences": 2, 132 | "no-shadow": 0, 133 | "no-shadow-restricted-names": 2, 134 | "no-spaced-func": 2, 135 | "no-sparse-arrays": 2, 136 | "no-sync": 0, 137 | "no-ternary": 0, 138 | "no-throw-literal": 2, 139 | "no-trailing-spaces": 2, 140 | "no-undef": 2, 141 | "no-undef-init": 2, 142 | "no-undefined": 0, 143 | "no-underscore-dangle": 0, 144 | "no-unneeded-ternary": 2, 145 | "no-unreachable": 2, 146 | "no-unused-expressions": 0, 147 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 148 | "no-use-before-define": 2, 149 | "no-var": 0, 150 | "no-void": 0, 151 | "no-warning-comments": 0, 152 | "no-with": 2, 153 | "one-var": 0, 154 | "operator-assignment": 0, 155 | "operator-linebreak": [2, "after"], 156 | "padded-blocks": 0, 157 | "quote-props": 0, 158 | "quotes": [2, "single", {"allowTemplateLiterals": true, "avoidEscape": true}], 159 | "radix": 2, 160 | "semi": [2, "always"], 161 | "semi-spacing": 0, 162 | "sort-vars": 0, 163 | "space-before-blocks": [2, "always"], 164 | "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], 165 | "space-in-brackets": 0, 166 | "space-in-parens": [2, "never"], 167 | "space-infix-ops": 2, 168 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 169 | "spaced-comment": [2, "always"], 170 | "strict": 0, 171 | "use-isnan": 2, 172 | "valid-jsdoc": 0, 173 | "valid-typeof": 2, 174 | "vars-on-top": 2, 175 | "wrap-iife": [2, "any"], 176 | "wrap-regex": 0, 177 | "yoda": [2, "never"] 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | Brief description of what this PR does and why it is needed. 4 | 5 | 6 | ### Demo 7 | 8 | Optional. Screenshots, `curl` examples, etc. 9 | 10 | 11 | ### Notes 12 | 13 | Optional. Ancillary topics, caveats, alternative strategies that didn't work out, anything else. 14 | 15 | 16 | ## Testing Instructions 17 | 18 | * How to test this PR 19 | * Prefer bulleted description 20 | * Start after checking out this branch 21 | * Include any setup required, such as bundling scripts, restarting services, etc. 22 | * Include test case and expected output 23 | 24 | 25 | ## Checklist 26 | 27 | - [ ] Add entry to CHANGELOG.md 28 | - [ ] Update the README with any function signature changes 29 | 30 | Resolves #XXX 31 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | # Sequence of patterns matched against refs/tags 6 | tags: 7 | - '[0-9]+.[0-9]+.[0-9]+*' # Push events to tags starting with numbers 8 | 9 | jobs: 10 | build: 11 | name: Create Release 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Check out commit 15 | uses: actions/checkout@v2 16 | 17 | - name: Use Node.js 18 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: 18.x 21 | registry-url: 'https://registry.npmjs.org' 22 | 23 | - name: Install dependencies 24 | run: yarn install --frozen-lockfile 25 | 26 | - name: Build project 27 | run: yarn build 28 | 29 | - name: Create release 30 | id: create_release 31 | uses: actions/create-release@v1 32 | env: 33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token 34 | with: 35 | tag_name: ${{ github.ref }} 36 | release_name: Release ${{ github.ref }} 37 | body: | 38 | Changes in this Release 39 | - TODO 40 | draft: true 41 | prerelease: false 42 | 43 | - name: Publish to NPM 44 | run: npm publish 45 | env: 46 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 47 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | # Triggers the workflow on push or pull request 4 | # events but only for the master, develop branches 5 | on: 6 | push: 7 | branches: [ master, develop ] 8 | pull_request: 9 | branches: [ master, develop ] 10 | 11 | jobs: 12 | test: 13 | runs-on: ubuntu-latest 14 | 15 | strategy: 16 | matrix: 17 | node-version: [14.x, 16.x, 18.x] 18 | 19 | steps: 20 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 21 | - name: Check out commit 22 | uses: actions/checkout@v2 23 | 24 | - name: Use Node.js ${{ matrix.node-version }} 25 | uses: actions/setup-node@v1 26 | with: 27 | node-version: ${{ matrix.node-version }} 28 | 29 | - name: Install dependencies 30 | run: yarn install --frozen-lockfile 31 | 32 | - name: Run tests 33 | run: 'yarn test:ci' 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | lib/* 3 | 4 | logs 5 | *.log 6 | 7 | # Runtime data 8 | pids 9 | *.pid 10 | *.seed 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/Release 26 | 27 | # Dependency directory 28 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 29 | node_modules 30 | 31 | # Remove some common IDE working directories 32 | .idea 33 | .vscode 34 | 35 | .DS_Store 36 | 37 | # https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored 38 | .yarn/* 39 | !.yarn/patches 40 | !.yarn/plugins 41 | !.yarn/releases 42 | !.yarn/versions 43 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esversion": 6 3 | } 4 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v18 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "tabWidth": 4, 4 | "useTabs": false, 5 | "semi": true, 6 | "singleQuote": true, 7 | } 8 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | yarnPath: .yarn/releases/yarn-3.2.3.cjs 4 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | ## UPCOMING 2 | 3 | ## 1.2.0 (2022-12-12) 4 | - Add support for opening vector datasets 5 | - Add GDALDataset.layerCount() to wrap GDALDatasetGetLayerCount() 6 | - Add GDALDataset.vectorConvert() to wrap GDALVectorTranslate() 7 | - Add wrappers for GDALGetRasterMinimum, GDALGetRasterMaximum, GDALGetRasterDataType, GDALGetRasterStatistics, and GDALGetRasterNoDataValue 8 | 9 | ## 1.1.2 (2022-10-12) 10 | - Allow users to specify a valid absolute URL when the default URL is invalid 11 | 12 | ## 1.1.1 (2022-09-30) 13 | - Document bytes() method 14 | - Fix production bundle not including unminified assets. 15 | - Add Node versions 16 and 18 to testing matrix (this library currently targets browser environments only) 16 | - Drop testing on Node 12 (this library currently targets browser environments only) 17 | - Update to latest stable version of Yarn 18 | 19 | ## 1.1.0 (2021-09-29) 20 | - Improve documentation for integrating with build tools 21 | - Add a reset() function that allows tearing down the Loam worker 22 | - Allow initializing Loam from a CDN 23 | - Add a demo page for local development 24 | 25 | ## 1.0.0 (2021-03-17) 26 | - No changes from RC.2 except dependency updates 27 | 28 | ## 1.0.0-rc.2 (2020-10-30) 29 | - Add information on contributing to the README 30 | - Apply code auto-formatting 31 | - Improve error messages with originating function names 32 | - Add GDALDataset.render() to provide gdaldem functionality 33 | 34 | ## 1.0.0-rc.1 (2020-07-24) 35 | - Add loam.rasterize() wrapper for GDALRasterize() 36 | - Add pathPrefix parameter to loam.initialize() 37 | - Remove closeAndReadBytes(), flushFS(), and convert close() to a no-op. 38 | - Set up CI and automatic releases via GitHub Actions 39 | - Package updates to resolve security alerts 40 | - Validate that parameters to `warp()` and `convert()` are strings 41 | - Add CHANGELOG, PR template 42 | 43 | ## 1.0.0-alpha.10 (2019-02-13) 44 | - Add `reproject()` utility function 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Azavea, Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A wrapper for running GDAL in the browser using [gdal-js](https://github.com/ddohler/gdal-js/) 2 | 3 |  4 | 5 | # Installation 6 | ``` 7 | npm install loam 8 | ``` 9 | 10 | Assuming you are using a build system, the main `loam` library should integrate into your build the same as any other library might. However, in order to correctly initialize the Emscripten environment for running GDAL, there are other assets that need to be accessible via HTTP request at runtime, but which should _not_ be included in the main application bundle. Specifically, these are: 11 | 12 | - `loam-worker.js`: This is the "backend" of the library; it initializes the Web Worker and translates between the Loam "frontend" and GDAL. 13 | - [`gdal.js`](https://www.npmjs.com/package/gdal-js): This initializes the Emscripten runtime and loads the GDAL WebAssembly. 14 | - [`gdal.wasm`](https://www.npmjs.com/package/gdal-js): The GDAL binary, compiled to WebAssembly. 15 | - [`gdal.data`](https://www.npmjs.com/package/gdal-js): Contains configuration files that GDAL expects to find on the host filesystem. 16 | 17 | All of these files will be included in the `node_modules` folder after running `npm install loam`, but it is up to you to integrate them into your development environment and deployment processes. Unfortunately, support for WebAssembly and Web Workers is still relatively young, so many build tools do not yet have a straightforward out-of-the-box solution that will work. However, in general, treating the four files above similarly to static assets (e.g. images, videos, or PDFs) tends to work fairly well. An example for Create React App is given below. 18 | 19 | ## Create React App 20 | When integrating Loam with a React app that was initialized using Create React App, the simplest thing to do is probably to copy the assets above into [the `/public` folder](https://create-react-app.dev/docs/using-the-public-folder#adding-assets-outside-of-the-module-system), like so: 21 | 22 | ``` 23 | cp node_modules/gdal-js/gdal.* node_modules/loam/lib/loam-worker.js public/ 24 | ``` 25 | 26 | This will cause the CRA build system to copy these files into the build folder untouched, where they can then be accessed by URL (e.g. `http://localhost:3000/gdal.wasm`). 27 | However, this has the disadvantage that you will need to commit the copied files to source control, and they won't be updated if you update Loam. A way to work around this is to put symlinks in `/public` instead: 28 | 29 | ``` 30 | ln -s ../node_modules/loam/lib/loam-worker.js public/loam-worker.js 31 | ln -s ../node_modules/gdal-js/gdal.wasm public/gdal.wasm 32 | ln -s ../node_modules/gdal-js/gdal.data public/gdal.data 33 | ln -s ../node_modules/gdal-js/gdal.js public/gdal.js 34 | 35 | ``` 36 | 37 | # API Documentation 38 | ## Basic usage 39 | 40 | ```javascript 41 | import loam from "loam"; 42 | 43 | // Load WebAssembly and data files asynchronously. Will be called automatically by loam.open() 44 | // but it is often helpful for responsiveness to pre-initialize because these files are fairly large. Returns a promise. 45 | loam.initialize(); 46 | 47 | // Assuming you have a `Blob` object from somewhere. `File` objects also work. 48 | loam.open(blob).then((dataset) => { 49 | dataset.width() 50 | .then((width) => /* do stuff with width */); 51 | ``` 52 | 53 | ## Functions 54 | ### `loam.initialize(pathPrefix, gdalPrefix)` 55 | Manually set up web worker and initialize Emscripten runtime. This function is called automatically by other functions on `loam`. Returns a promise that is resolved when Loam is fully initialized. 56 | 57 | Although this function is called automatically by other functions, such as `loam.open()`, it is often beneficial for user experience to manually call `loam.initialize()`, because it allows pre-fetching Loam's WebAssembly assets (which are several megabytes uncompressed) at a time when the latency required to download them will be least perceptible by the user. For example, `loam.initialize()` could be called when the user clicks a button to open a file-selection dialog, allowing the WebAssembly to load in the background while the user selects a file. 58 | 59 | This function is safe to call multiple times. 60 | #### Parameters 61 | - `pathPrefix` (optional): The path or URL that Loam should use as a prefix when fetching its Web Worker. If left undefined, Loam will make a best guess based on the source path of its own ` 6 | 7 | 8 |
9 |10 | Select a file using the Source file input and then click "Display metadata". Metadata 11 | about the file will be displayed below. GeoTIFFs work best, but GeoJSON and Shapefiles 12 | will work to some extent as well. Make sure to select sidecar files when relevant (e.g. 13 | .prj, .dbf, .shx, etc. for Shapefiles). 14 |
15 | 26 | 27 | 28 | 29 | 30 |