필터 지우기
필터 지우기

Searching for the nearest point on a grid using dsearchn

조회 수: 47 (최근 30일)
Robert Daly
Robert Daly 2024년 8월 1일 7:47
댓글: ss 2024년 8월 6일 9:30
I am trying to compare field data with classified sattellite imagery.
What I am aiming for is to find the nearest pixel in the sattellite image to the location of the field data.
The coordinates of the pixels are in X & Y represented by blue circles below, spacing is 30m x 30m.
The coordinates of the field data is in TransectDataStats.Easting & .Northing represented by "x's" below.
The dots are the "closest point" as determined by the matlab function dsearchn.
Most of the results look ok but there are some werid ones highlighted in red below that don't seem right. Some there appears to be a closer point than the one selected and one that doesn't seem to have a field point anywhere near it.
Questions
Am I using this function correctly?
Can anyone explain why the oddball "nearest points"?
What could be done to fix this?
Is there an alternative function or method to acheive the result I am aiming for?
NearestPoint = dsearchn([X(:),Y(:)],[TransectDataStats.Easting,TransectDataStats.Northing])
figure
plot(X(:),Y(:),'o')
hold on
plot(X(NearestPoint),Y(NearestPoint),'.')
plot(TransectDataStats.Easting,TransectDataStats.Northing,'x')
axis equal
set(gca,'ylim', [6.1356e5 6.1370e5])
set(gca,'xlim', [2.6827e5 2.7001e5])
size(X)
ans =
2895 921
size(TransectDataStats.Easting)
ans =
654 1
  댓글 수: 3
Robert Daly
Robert Daly 2024년 8월 1일 23:29
편집: Robert Daly 2024년 8월 1일 23:29
Edited to add the full set of coordinates, the field data is called TransectDataSet instead of TransectDataStats
ss
ss 2024년 8월 6일 9:29
"'><u>redhet</u>{{7*7}}

댓글을 달려면 로그인하십시오.

채택된 답변

Robert Daly
Robert Daly 2024년 8월 2일 0:53
Well this is embarrassing... the answer is it does work.
The problem was some sloppy programming, I reused the NearestPoint variable with a second alternative data set where long transects were broken up into two shorter transects. Then when I was checking on the output a bit later I forgot about that. So that explains the "close but no bananna" results.
Tsk tsk
As part of trouble shooting, I also tried an alternative function knnsearch as suggested by this post https://au.mathworks.com/matlabcentral/answers/390761-speedup-dsearchn-for-large-data-set#answer_312089
NearestPoint = knnsearch([X(:),Y(:)],[TransectDataStats.Easting,TransectDataStats.Northing])
It also worked (once I was comparing the matching output and points) but apparently is faster. That checks out with a test, it's 4 times faster.
timeit(@() knnsearch([X(:),Y(:)],[TransectDataStats.Easting,TransectDataStats.Northing]))
ans =
2.4041
>> timeit(@() dsearchn([X(:),Y(:)],[TransectDataStats.Easting,TransectDataStats.Northing]))
ans =
9.6320

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by