-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.wkb.to.geojson.html
61 lines (40 loc) · 4.08 KB
/
index.wkb.to.geojson.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1,user-scalable=no,maximum-scale=1,width=device-width">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="author" content="">
<title>WKB to GeoJSON</title>
<!-- JavaScript ================================================== -->
<script src="assets/jquery-1.11.1.min.js"></script>
<script src="assets/wkx.js"></script>
</head>
<body>
<script>
var the_geom = '0103000020E6100000010000002900000088B6E6AD0C433840289BAB58393C4840A8B716FC23443840889BCF2E993C484050B83E96CA443840609C8B536C3D484090BA0E5F02473840B49C2F3BC23D4840F0BAD6F467473840C09C6FB3CD3D484050BB96BCC1473840DC9C1F8DE93D484090BB6EA302483840489D8F86523E4840F0BE8E68564B3840909D27789B3E4840D8BF7E193C4C3840F09D679CFA3E484048C5B63D9E5138400C9B1FE21D3C4840E0C8C66F2B553840409B93A4503C4840A8CC467AE8583840AC99B3D9C03A484000D0E67D325C3840309997D9463A4840E8D03E5D185D384080972BC59B38484018D6A685376238408C96ABACAD37484038D666CC5D623840289613144837484060D9FE2578653840DC95AF0CFF36484000DD56E80E693840349537EE5936484060DEBE71676A38404C943F1A72354840C0DD8652CE69384094932B11BD344840C0DA66AFD0663840A09297A6CB33484050D9360165653840A8926F2ED533484070D6A6A78D623840F892979824344840E0D4FE4205613840FC9267C527344840C8D45EAFED603840E4927B080D34484068D4866A9260384078923787A533484000D426252960384074919F30A432484020C7463173533840AC92F35BD833484018C86EB061543840FC92DF3F26344840C0C8F6300D553840CC93FB91F3344840C0C8F6300D5538408894F392AE354840B0C89EBAF9543840B09427B0D535484050C886F19E5438406895E71A8C36484030C586CE885138406496630D8637484078C06649D84C3840189733CA3438484000C11E0A5F4D384084978780A238484008C0EE29704C3840D097F3AAED38484030BEAEA69E4A3840D49793BBF1384840D8BD26C7424A384098983FB7B239484098BC56670A4938402499AFCD3A3A484088B6E6AD0C433840289BAB58393C4840';
var wkx = require('wkx');
var buffer = require('buffer');
// Split WKB into array of integers (necessary to turn it into buffer)
var hexAry = the_geom.match(/.{2}/g);
var intAry = [];
for (var i in hexAry) {
intAry.push(parseInt(hexAry[i], 16));
};
console.log("intAry = " + intAry);
// Generate the buffer
var buf = new buffer.Buffer(intAry);
console.log(buf);
// Parse buffer into geometric object
var geom = wkx.Geometry.parse(buf);
//Error: GeometryType 536870915 not supported
// Should log '-73.700380647'
//console.log(geom.x);
// Should log '40.739754168'
//console.log(geom.y);
//var geojson = '{"type":"Polygon","coordinates":[[[24.2619122207894,48.4705000722809],[24.266174083277,48.4734247697552],[24.2687162306905,48.4798683578199],[24.2773799334487,48.4824899656755],[24.2789299988025,48.482839993952],[24.2802999370572,48.4836899189338],[24.2812902589172,48.4868934823267],[24.294287237978,48.4891195481715],[24.297792046971,48.4920230394308],[24.3188208171098,48.4696619657826],[24.3326940403284,48.4712110253081],[24.3472973273134,48.4590103270487],[24.3601454437739,48.4552871694781],[24.363653018795,48.4422537291384],[24.3836596996608,48.4349876249154],[24.3842437506739,48.4318871589315],[24.396364569396,48.4296584946967],[24.4103837215489,48.4246194621468],[24.4156409350384,48.4175446329542],[24.4133044795287,48.4120198691154],[24.4016217828855,48.404652427683],[24.3960724600705,48.4049432797231],[24.3849739820784,48.4073668232067],[24.3789865371845,48.4074637180074],[24.3786267859003,48.4066477397335],[24.377234132688,48.4034890195225],[24.3756278247638,48.3956356791631],[24.325976447849,48.4050402583428],[24.3296156187499,48.4074172822638],[24.3322325327397,48.4136831739812],[24.3322325327397,48.4193900765759],[24.3319355619103,48.4205837434068],[24.3305502847728,48.4261506682186],[24.318493755248,48.4337784515635],[24.3001752735003,48.4391110183626],[24.3022314381678,48.4424591695852],[24.2985864837538,48.4447530450267],[24.2914833237284,48.4448770971937],[24.2900814504227,48.4507664738205],[24.285314997364,48.4549195392049],[24.2619122207894,48.4705000722809]]]}';
</script>
</body>
</html>