1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > json生成shp_使用JS把shapefile地图数据转换为geojson格式

json生成shp_使用JS把shapefile地图数据转换为geojson格式

时间:2024-07-10 08:12:07

相关推荐

json生成shp_使用JS把shapefile地图数据转换为geojson格式

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

/* /wavded/js-shapefile-to-geojson */

OpenLayers._getScriptLocation = function() {

return "/js/openlayers/2.9.1/";

};

var starttime = +new Date,

map = new OpenLayers.Map("map", {

allOverlays: true

}),

parser = new OpenLayers.Format.GeoJSON(),

vector = new OpenLayers.Layer.Vector("Converted"),

shapefile = new Shapefile({

shp: "/uploads/shpjson/testdata/world.shp",

dbf: "/uploads/shpjson/testdata/world.dbf"

}, function(data) {

var features = parser.read(data.geojson);

vector.addFeatures(features);

map.zoomToExtent(vector.getDataExtent());

console.log("took", new Date - starttime, "milliseconds")

console.log(data);

//export geojson

var str = JSON.stringify(data.geojson);

//Save the file contents as a DataURI

var dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(str);

//Write it as the href for the link

var link = document.getElementById('link').href = dataUri;

})

map.addLayer(vector);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。