Recent work needs to be smoothed vector spot extraction (shp format), so I was here for a little research, mainly on the Chaikin-curve algorithm is improved, in fact, there are many excellent algorithms can make use of, forced time, it did not continue in-depth,
This blog, right when the initiate would really like to engage smoothing algorithm of "comrades", able to show their true good algorithm. We know that when the number of polygons into hundreds, thousands, possibly cpu serial and parallel computing is not the efficiency gap, but when the number exceeded one trillion months, hundreds of thousands, millions of it?
Serial obvious to die, so I am here to explore the parallel vector smoothing algorithm. . . I was in the back of open source code, if you have questions or need to understand the code, qq: 1044625113, Remarks: vector parallel processing
I calculate 120 000 polygons, computational efficiency comparison, the following table:
Computing model | Calculation time (sec) |
Serial | 70 |
Parallel (quad) | 20 |
Save for a whole three times ah, brothers, this was great!
Vector drawing original spot
Figure smoothed vector patch
The following vectors smooth paste main function codes:
% chaikin-curve ???????????????? % written by Mr zhipan Wang,Email:[email protected],BeiJing,2019-10-21 % Remake: https: //www.cnblogs.com/hongru/archive/2011/10/27/2226946.html clear tic %% read shape file ShpFileName = '????????????. Shp'; [shp,attribute] = shaperead(ShpFileName); Scale = 3; % ?????????????????? Iter = 6; % ???????????????? % figure,mapshow(shp),title('original shapefile!') %% curve smooth numPolygon = length(shp); STR = 'struct(''Geometry'',values ,''X'', values,''Y'', values,''ID'',values)'; values = cell(numPolygon, 1); % ????????帳??????,??????????????????????????????????,????????????????dbf??????,?????????????????????? newSHP = eval(STR); parfor i = 1:numPolygon % ?????????????? Latitude_arrary = shp(i).Y; Longitude_array = shp(i).X; [Smooth_Lati, Smooth_Longi] = ChaikinCurve_Smooth(Latitude_arrary, Longitude_array, Scale, Iter); newSHP(i).X = Smooth_Longi; newSHP(i).Y = Smooth_Lati; newSHP(i).ID = i-1; newSHP(i).Geometry = 'Polygon'; fprintf(['??????????',num2str(numPolygon),'??????????????, ','????', num2str(i), '??????????????????????????...\n']); end clear shp % figure,mapshow(newSHP),title('smooth shpfile!') % ????????????ν??????????????????????,???????????????????????????????? %% export shape file shapewrite(newSHP,'smoothSHP.shp'); toc
贴上实现的函数代码:
function [Smooth_Lati, Smooth_Longi] = ChaikinCurve_Smooth(Latitude_arrary, Longitude_array, Scale, Iter) % CK 曲线平滑算法的核心实现, Email:[email protected],BeiJing,2019-10-21! % Latitude_arrary: 纬度数组 % Longitude_array: 经度数组 % Scale: 尺度参数, 正整数 % Iter: 迭代次数,一般四次即可! if length(Latitude_arrary) ~= length(Longitude_array) fprintf('数组大小不一致...\n'); return; end if Scale < 1 fprintf('尺度参数应该大于1...\n'); return; end % 迭代实现 for i = 1:Iter [Latitude_arrary, Longitude_array] = addPoint(Latitude_arrary, Longitude_array, Scale); end Smooth_Lati = Latitude_arrary; Smooth_Longi = Longitude_array; end
总的来说,只需要设置迭代次数就可以了,平滑度参数默认3即可,迭代次数设置成3-6次基本上够用了,先写到这里吧