-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshx-reader.js
More file actions
45 lines (37 loc) · 1006 Bytes
/
shx-reader.js
File metadata and controls
45 lines (37 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function() {
var root = this;
var $ = root.jQuery;
/**
* Handles reading data from a shapefile
*/
ShpJS.ShxReader = function(options) {
this.initialize.call(this,arguments);
};
$.extend(ShpJS.ShxReader.prototype, {
_zipFile: null,
_shxBuffer: null,
_shxData: null,
featureIndices: [],
initialize: function() {
},
/**
* Reads features from the supplied content string
*/
read: function(content) {
// Read the content string into an array buffer
this._shxBuffer = new ArrayBuffer(content.length);
this._shxData = new DataView(this._shxBuffer);
for (var i=0; i<content.length; i++)
this._shxData.setUint8(i, content.charCodeAt(i));
// Parse the SHX file to get indexes of all features in the SHP file
for (var i=100; i<this._shxBuffer.byteLength-1; i+=8) {
this.featureIndices.push(
{
offset: this._shxData.getInt32(i) * 2,
length: this._shxData.getInt32(i+4) * 2
}
);
}
}
});
}).call(this);