Skip to content

Commit d54bee2

Browse files
committedApr 3, 2021
replaced 3 xml packages with xml-utils
1 parent a369c22 commit d54bee2

File tree

4 files changed

+10
-23
lines changed

4 files changed

+10
-23
lines changed
 

‎package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@
4444
"georaster-to-canvas": "0.2.0",
4545
"geotiff": "1.0.0-beta.13",
4646
"geotiff-palette": "0.0.0",
47-
"simple-xml-dom": "1.0.0",
4847
"threads": "^1.4.0",
4948
"tiny-worker": "^2.3.0",
5049
"ts-node": "^8.8.2",
5150
"txml": "3.1.2",
5251
"underscore": "^1.8.3",
5352
"worker-loader": "^2.0.0",
54-
"xmldom": "0.1.27",
55-
"xpath": "0.0.27"
53+
"xml-utils": "^0.2.0"
5654
},
5755
"devDependencies": {
5856
"@babel/types": "^7.9.5",
@@ -65,7 +63,6 @@
6563
"eslint": "^5.7.0",
6664
"eslint-config-google": "^0.11.0",
6765
"mocha": "^6.2.0",
68-
"replace-in-files-cli": "^0.3.1",
6966
"threads-plugin": "^1.3.1",
7067
"webpack": "^4.12.0",
7168
"webpack-bundle-analyzer": "^3.6.0",

‎src/parse_metadata.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
1-
const xml = require('simple-xml-dom');
2-
const xpath = require('xpath');
1+
const findTagByPath = require('xml-utils/src/find-tag-by-path');
2+
33

44
const parseISO = metadata => {
55
const results = {};
66

7-
const dom = xml.parse(metadata);
8-
9-
const select = xpath.useNamespaces({
10-
gco: 'http://www.isotc211.org/2005/gco',
11-
gmd: 'http://www.isotc211.org/2005/gmd',
12-
});
13-
147
try {
15-
results.projection = parseFloat(select('string(//gmd:RS_Identifier//gmd:code//gco:CharacterString/text())', dom));
8+
results.projection = parseFloat(findTagByPath(metadata, ['gmd:RS_Identifier', 'gmd:code', 'gco:CharacterString']).inner);
169
} catch (error) {
1710
console.error(error);
1811
}
1912

2013
try {
21-
results.xmin = parseFloat(select('string(//gmd:westBoundLongitude//gco:Decimal/text())', dom));
22-
results.xmax = parseFloat(select('string(//gmd:eastBoundLongitude//gco:Decimal/text())', dom));
23-
results.ymin = parseFloat(select('string(//gmd:southBoundLatitude//gco:Decimal/text())', dom));
24-
results.ymax = parseFloat(select('string(//gmd:northBoundLatitude//gco:Decimal/text())', dom));
14+
results.xmin = parseFloat(findTagByPath(metadata, ['gmd:westBoundLongitude', 'gco:Decimal']).inner);
15+
results.xmax = parseFloat(findTagByPath(metadata, ['gmd:eastBoundLongitude', 'gco:Decimal']).inner);
16+
results.ymin = parseFloat(findTagByPath(metadata, ['gmd:southBoundLatitude', 'gco:Decimal']).inner);
17+
results.ymax = parseFloat(findTagByPath(metadata, ['gmd:northBoundLatitude', 'gco:Decimal']).inner);
2518
} catch (error) {
2619
console.error(error);
2720
}
2821

29-
console.log('results:', results);
30-
3122
return results;
3223
};
3324

‎test/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<script src="https://unpkg.com/georaster"></script>
4+
<script src="../dist/georaster.browser.bundle.js"></script>
55
</head>
66
<body>
77
<div id="container"></div>

‎test/test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let parseMetadata = require('../src/parse_metadata.js');
77
let parseISO = parseMetadata.parseISO;
88
let countIn2D = require('../src/utils.js').countIn2D;
99

10+
1011
describe('Parsing Data Object', function() {
1112
describe('Parsing Simple Examples', function() {
1213
it('should create raster correctly', function(done) {
@@ -76,7 +77,6 @@ describe('Checking Error Catching', function() {
7677
});
7778
});
7879

79-
8080
describe('Parsing Metadata', function() {
8181
describe('if you pass in iso xml text', function() {
8282
it('should parse metadata', function(done) {
@@ -93,7 +93,6 @@ describe('Parsing Metadata', function() {
9393
});
9494
});
9595

96-
9796
// Using tiff created from http://geomap.arpa.veneto.it/geoserver/wcs?crs=EPSG%3A4326&service=WCS&format=GeoTIFF&request=GetCoverage&height=329&width=368&version=1.0.0&BBox=9.679858245722988%2C13.951082737884812%2C44.183855724634675%2C47.38727409375604&Coverage=geonode%3Aatlanteil
9897
describe('Parsing Geonode Files', function() {
9998
describe('if you pass in tiff from geoserver', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.