嗨,我正在尝试使用GeoJson.Net将OSM webservice的响应解析为要素集合。
我对GeoJSON不熟悉,无法确定如何做到这一点:
可以在这里找到Json响应。我编写的代码是:
System.IO.StreamReader file = new System.IO.StreamReader(filepath);
string content = file.ReadToEnd();
file.Close();
dynamic deserialized = JsonConvert.DeserializeObject(content);
List<Feature> lstGeoLocation = new List<Feature>();
foreach (JObject item in deserialized.features)
{
//var feature = new Feature();
var geom = item.Property("geometry").Value;
}
但这只是普通的JSON解析,可能有更好的解析方式。
我还尝试了NetTopologySuite JSON扩展,但当我使用以下代码时它会给我异常:
"Expected token 'type' not found."
System.IO.StreamReader file = new System.IO.StreamReader(filepath);
string content = file.ReadToEnd();
file.Close();
var reader = new NetTopologySuite.IO.GeoJsonReader();
var featureCollection = reader.Read <NetTopologySuite.Features.FeatureCollection>(content);