最佳匹配位置数据
2次观看(最近30天)
显示较旧的评论
你好
I have location data (longitude and latitude) for certain sites and I want to compare these two with a national databse to know the
当地政府
这些站点 +他们
邮政编码
。
I have two tables:
Sitename纬度经度
14182-Pembroke Refinery51.686081-5.0271217
8059-New Rugby52.376283-1.2860374
8037-Ketton 52.636537 -0.54737666
And
Postcode当地政府经度纬度
CV212RY橄榄球-1.28855552.376856
TR262JQ康沃尔郡-5.49094450.207428
SY107rn什罗普郡-3.06770352.917641
SA715SJPembrokeshire-5.0271351.686093
PE93SX拉特兰-0.546252.636828
By best matching
both
the latitude and longitude data from the first table with the second, the postcode and local authority will be known.
Output: Sitename, Postcode, Local authority,
感谢您的帮助。
接受的答案
艾米·哈斯金斯(Amy Haskins)
2021年6月9日
The following appoach might not scale well if you have a very large number of sites / postcodes to deal with, but might help you get started in the right direction.
%我完全复制您的示例数据,如平面文本文件所示。
%可读取也可以处理Excel文件,但是如果您拆分,它将更容易
% the tables into separate sheets.
sites = readtable(“ sites.txt”)
邮政编码= readtable(“ Postcodes.txt”)
%初始化变量
numsites =高度(站点);
Mindist = Nan([Numsites,1]);
purativeIndex = nan([[numsites,1]);
为了ii = 1:numSites
% Find the distance in meters from the current site to each of
% the post code lat/lons using a Mapping Toolbox function.
% This is important since at high latitudes, 2 points a degree apart in
百分比的经度比每个度相距2点要近得多
%纬度。
%d的大小为numsites x 1。
D = distance(sites.Latitude(ii),sites.Longitude(ii),codes.Latitude,codes.Longitude,wgs84Ellipsoid,“学位”);
%呼叫使用可选输出arg的最小功能,以便给您
距离站点最小距离的权威索引%。
% Store for each site in the loop.
[minDist(ii),authorityIndex(ii)] = min(D);
结尾
% I added the authority info back to the original sites table, but you could make
%的一个新表,而只是带有所需字段。
sites.authority = codes.authority(pertionalIndex);
sites.PostCode = codes.Postcode(authorityIndex);
sites.Local = codes.Local(authorityIndex);
sites.distance_meters = Mindist