Skip to content

Instantly share code, notes, and snippets.

@n1n9-jp
Last active February 2, 2016 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1n9-jp/4fc4121b0a977680e065 to your computer and use it in GitHub Desktop.
Save n1n9-jp/4fc4121b0a977680e065 to your computer and use it in GitHub Desktop.
WKT形式をGeoJSON形式に変換する ref: http://qiita.com/yuichy/items/14f2cb7d4ed113eca727
<script src="terraformer.min.js"></script>
<script src="terraformer-wkt-parser.min.js"></script>
var geoJSONSingle = Terraformer.WKT.parse( wktSingle );
MULTIPOINT ((10 40), (40 30), (20 20), (30 10))
{"type":"MultiPoint","coordinates":[[10,40],[40,30],[20,20],[30,10]],"bbox":[10,10,40,40]}
//wktObj...変換前のWKTデータ、geoJSONObj...変換後のGeoJsonデータ
var _geoArray = new Array();
for (var i=0; i<wktObj.length; i++) {
var _o = new Object();
_o["type"] = "Feature";
_o["geometry"] = Terraformer.WKT.parse( wktObj[i] );
_o["properties"] = {"country_id": "some_id",
"count": "some_count"};
_geoArray[i] = _a;
};
var geoJSONObj = {
"type": "FeatureCollection"
};
geoJSONObj["features"] = _geoArray;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment