Created
January 30, 2017 08:42
-
-
Save kudarisenmon/44d034060fb5ca17920b3ff9fb33559d to your computer and use it in GitHub Desktop.
YOLPのJSON出力(yolp.json)をGeoJSONに変換する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| var Obj = function(name, latlon) { | |
| this.name = name; | |
| this.geo = {}; | |
| this.geo.type = "Point"; | |
| this.geo.coordinates = []; | |
| this.geo.coordinates.push(parseFloat(latlon.split(",")[0])); | |
| this.geo.coordinates.push(parseFloat(latlon.split(",")[1])); | |
| } | |
| var GeoJSON = require('geojson'); | |
| var util = require('util'); | |
| var jsonfile = require('jsonfile'); | |
| var shimada = require('./yolp.json'); | |
| var data = []; | |
| shimada.Feature.forEach(function(element, index, array) { | |
| var obj = new Obj(element.Name, element.Geometry.Coordinates); | |
| data.push(obj); | |
| }); | |
| var out = GeoJSON.parse(data, {GeoJSON: 'geo'}); | |
| var json = jsonfile.writeFileSync('yolp.geojson', out, { | |
| encoding: 'utf-8', | |
| replacer: null, | |
| spaces: null | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment