Skip to content

Commit 7b184d2

Browse files
authored
Merge pull request #6 from OpenIndexMaps/add-converter
add a basic browser based converter
2 parents 9c98a8b + 2d32f98 commit 7b184d2

9 files changed

Lines changed: 5575 additions & 3 deletions

File tree

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"browser": true
4+
},
5+
"extends": "airbnb"
6+
}

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ sass:
3030
load_paths:
3131
- _sass
3232
- node_modules
33+
keep_files:
34+
- assets/javascripts/bundle.js

_layouts/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</div>
1111
</main>
1212
</div>
13-
13+
<script type="text/javascript" src="{{ '/assets/javascripts/bundle.js' | relative_url }}" charset="utf-8"></script>
1414
</body>
1515

1616
</html>

assets/javascripts/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import shp from 'shpjs';
2+
import prettyJSONStringify from 'pretty-json-stringify';
3+
4+
const fileInput = document.getElementById('shapefile-file');
5+
6+
fileInput.addEventListener('change', (e) => {
7+
const reader = new FileReader();
8+
reader.onload = (event) => {
9+
shp(event.target.result).then((data) => {
10+
const convertedData = JSON.parse(JSON.stringify(data));
11+
convertedData.features = convertedData.features.map((f, i) => {
12+
// Caution: not a deep copy
13+
const featureCopy = Object.assign({}, f);
14+
const propCopy = f.properties;
15+
// Converts "available" strings to Boolean values
16+
if (Object.prototype.hasOwnProperty.call(f.properties, 'available') && (typeof f.properties.available) === 'string') {
17+
propCopy.available = (f.properties.available === 'true');
18+
}
19+
featureCopy.properties = propCopy;
20+
return featureCopy;
21+
});
22+
23+
const output = document.getElementById('converted');
24+
const formatted = `<pre><code>${prettyJSONStringify(convertedData)}</code></pre>`;
25+
output.innerHTML = formatted;
26+
});
27+
};
28+
reader.readAsArrayBuffer(e.target.files[0]);
29+
});

assets/main.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44

55
@import 'variables';
66
@import '../node_modules/bootstrap/scss/bootstrap.scss';
7+
8+
#converted {
9+
max-height: 800px;
10+
overflow-y: scroll;
11+
}

converter.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
# You don't need to edit this file, it's empty on purpose.
3+
# Edit theme's home layout instead if you wanna make some changes
4+
# See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults
5+
layout: home
6+
---
7+
8+
This is a basic Shapefile index map to OpenIndexMaps GeoJSON converter. Index maps are often created in desktop GIS software that may not have full support of GeoJSON features. This converter is useful to convert to GeoJSON. Conversion steps happening:
9+
10+
- Shapefile -> GeoJSON
11+
- Feature property "available" converted to `Boolean` type.
12+
13+
<div class="form-group">
14+
<label for="shapefile-file"> Upload index map shapefile</label>
15+
<input type="file" id="shapefile-file" class="form-control">
16+
</div>
17+
18+
19+
<div id="converted" class="bg-light"></div>

0 commit comments

Comments
 (0)