简体   繁体   English

如何从GeoJSON文件获取边界框值?

[英]How to get the Bounding box values from a GeoJSON file?

I have of GeoJSON file. 我有GeoJSON文件。 But problem is, I do not know the projection of this file. 但是问题是,我不知道这个文件的投影。 Now, I want to overlay on my base map(OSM). 现在,我想在我的基本地图(OSM)上叠加。 How should I do it? 我该怎么办? This GeoJSON file contains features around Stockholm area. 该GeoJSON文件包含斯德哥尔摩地区的功能。 How can i set the bounding box for this? 我如何为此设置边界框? I tried with couple of openlayers example from hosting sites. 我尝试了来自托管站点的几个openlayers示例。 But, those do not work for me. 但是,这些对我不起作用。 I got one example which is very similar with what i want, from (http://dev.openlayers.org/releases/OpenLayers-2.11/examples/all-overlays.html). 我从(http://dev.openlayers.org/releases/OpenLayers-2.11/examples/all-overlays.html)得到了一个与我想要的例子非常相似的例子。 I checked the source code he used bounding box. 我检查了他使用边界框的源代码。 But problem is, if I remove bounding box this example does not work(I tied with given data with this). 但是问题是,如果我删除边界框,此示例将不起作用(我将给定数据与此绑定)。 I do not know, is there anything wrong with my json file? 我不知道,我的json文件有什么问题吗? Bellow, I have given some sample data. 贝娄,我提供了一些示例数据。 Is the format OK? 格式可以吗? As I told, I tried with different way. 正如我所说,我尝试了不同的方法。 Some time i read the json file just fine from script. 有一段时间我从脚本中读取了json文件。 But, It can not show the featured overlay ed map. 但是,它无法显示精选的覆盖版地图。 Bellow, I gave sample code, that shows how I tried. 贝娄,我给出了示例代码,显示了我如何尝试的。

{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "FNODE_": 387603, "TNODE_": 387603, "LPOLY_": 0, "RPOLY_": 0, "LENGTH": 89.206900, "ROADS_SWER": 519006, "ROADS_SW_1": 519006, "REF": "", "TYPE": "residential", "ONEWAY": 8224, "BRIDGE": 8224, "MAXSPEED": 0, "LENGTH_M": 89.500000, "ID": 0, "dist_fnode": 13655.200000, "dist_tnode": 13655.200000 }, "geometry": { "type": "LineString", "coordinates": [ [ 676868.875000, 6569872.000000 ], [ 676882.437500, 6569861.000000 ], [ 676894.062500, 6569851.500000 ], [ 676894.500000, 6569844.500000 ], [ 676891.812500, 6569840.500000 ], [ 676887.312500, 6569841.000000 ], [ 676882.187500, 6569843.000000 ], [ 676875.250000, 6569850.000000 ], [ 676868.125000, 6569858.500000 ], [ 676866.500000, 6569867.000000 ], [ 676868.875000, 6569872.000000 ] ] } }
,

{ "type": "Feature", "properties": { "FNODE_": 387723, "TNODE_": 387724, "LPOLY_": 0, "RPOLY_": 0, "LENGTH": 9.581310, "ROADS_SWER": 519163, "ROADS_SW_1": 519163, "REF": "", "TYPE": "service", "ONEWAY": 8224, "BRIDGE": 8224, "MAXSPEED": 0, "LENGTH_M": 9.500000, "ID": 1, "dist_fnode": 13705.100000, "dist_tnode": 13695.600000 }, "geometry": { "type": "LineString", "coordinates": [ [ 677125.375000, 6569906.500000 ], [ 677133.437500, 6569911.500000 ] ] } }
, 
..
..
]
}

Code Sample---- 代码示例----

//OSM Layer-----------------------------------------------
var layer = new OpenLayers.Layer.OSM( "Simple OSM Map");

//GeoJSON Layer-------------------------------------------
var vector_format = new OpenLayers.Format.GeoJSON({}); 
var vector_protocol = new OpenLayers.Protocol.HTTP({
    url: 'ml/roads.json',
    format: vector_format
});
var vector_strategies = [new OpenLayers.Strategy.Fixed()];
var vector_layer = new OpenLayers.Layer.Vector('More Advanced Vector Layer',{
    protocol: vector_protocol,
    strategies: vector_strategies,
    isBaseLayer: false
});

var options = {
    layers: [layer, vector_layer]
};
var map = new OpenLayers.Map("map", options);
//Projection-----------------------------------------------
map.setCenter(
    new OpenLayers.LonLat(18.068611, 59.329444).transform(
        new OpenLayers.Projection("EPSG:4326"),
            map.getProjectionObject()
    ), 10
);

Thanks, in advance. 提前致谢。

vector_layer.events.on({
    loadend: function() {
        map.zoomToExtent(vector_layer.getDataExtent());
    }
});

I still think you should set your projection in the map constructor… 我仍然认为您应该在地图构造函数中设置投影…

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM