批量地理位置解析
Posted 不懂事的小男孩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量地理位置解析相关的知识,希望对你有一定的参考价值。
public class GisHelper
{
/// <summary>
/// 批量地理位置解析
/// </summary>
/// <param name="lonlat"></param>
/// <returns>index-->loc</returns>
public static Dictionary<string, string> GetLocation(List<Dictionary<string, string>> lonlat)
{
string posTemplate = "1,{0},{1},{2}";
Dictionary<string, string> lis = new Dictionary<string, string>();
try
{
WebClientEx client = new WebClientEx();
client.Encoding = Encoding.UTF8;
List<string> param = new List<string>();
int index = 0;
lonlat.ForEach(p =>
{
foreach (KeyValuePair<string, string> item in p)
{
string[] temp = item.Value.Split(‘,‘);
param.Add(string.Format(posTemplate, item.Key, temp[0], temp[1]));
index++;
}
});
string url = "http://{0}:{1}/stargis/Openlayers/GetCountrySeatHandler.aspx?requestInfos=";//xxx.xxx.xxx.xxx:10087 //xxx.xxx.xxx.xxx
string locationinfo = client.OpenRead(string.Format(url, "xxx.xxx.xxx.xxx", 10087) + string.Join(";", param.ToArray()));
if (locationinfo.Trim().Length > 0)
{
string[] temp = locationinfo.Trim().TrimStart(‘(‘).TrimEnd(‘)‘).Split(‘;‘);
foreach (var s in temp)
{
string[] ss = s.Split(‘,‘);
if (ss != null && ss.Length >= 3)
{
string sim = ss[1];
string loc = ss[2];
lis[sim] = loc;
}
}
}
}
catch (Exception ex)
{
LogHelper.Error("位置解析失败", ex);
}
return lis;
}
public static string GetLocation(string lon, string lat)
{
string location = string.Empty;
List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
Dictionary<string, string> dic = new Dictionary<string, string>();
dic["0"] = string.Format("{0},{1}", lon, lat);
list.Add(dic);
Dictionary<string, string> o = GetLocation(list);
if (o.ContainsKey("0"))
return o["0"];
return location;
}
}
以上是关于批量地理位置解析的主要内容,如果未能解决你的问题,请参考以下文章
GIS地理处理脚本案例教程——批量栅格分割-批量栅格裁剪-批量栅格掩膜-深度学习样本批量提取
如何使用 PHP 对 MapQuest 地理编码器进行批量地理编码?