0

I have a shapefile with several links that I open in matlab, that produce a structure with geometries for each line containing a cell of Xs and a cell of Ys described as follows:

geo(1,1).X = [X1 X2 ... Xn NaN]
geo(1,1).Y = [Y1 Y2 ... Yn NaN]

Then, I have some points described by (X,Y) pairs (matrix myPoints) for each one of which I would like to create a candidate array cand that is simply described by a boolean, indicating that if distance from one of my points to the random line i is less that R then cand(i)= 1. And of course if cand(i)== 1 then geo(i,1) is a candidate line.

An illustrative example is presented in the following picture. As illustrated L2 can be considered as a candidate line for point with coordinates (x0,y0)

Example

In order to define this array (or matrix in case of many points), what I do is that I use the polyxpoly function, and I check for intersection of each line to the circle.

ii=zeros(size(Geo,1),size(myPoints,1))';
for i =1:size(myPoints,1)
    [latc, lonc] = scircle1(myPoints(i,1), myPoints(i,2), km2deg(rad));

   parfor j = 1:size(Geo,1)
        [~, ~, index] = polyxpoly(lonc, latc, ...
            Geo(j,1).X', Geo(j,1).Y');
        if isempty(index)~=1
            ii(i,j) =1;
        end
    end
end

However this take too much time even with a parfor loop; ~9 seconds for 200 points and 94 lines, which is too much only for this candidate links array, given the fact that I need to apply this for thousands of points (~5000 points per 15 minutes) and for thousands of lines (160,000 lines).

Is there any idea on what to do so that I could speed this up?

Other functions or approaches are welcomed.

Thanks

Manos C
  • 333
  • 4
  • 16
  • Can you just use the standard way of determining if a point is within a circle: http://math.stackexchange.com/a/198769 – Suever Apr 07 '16 at 14:09
  • Not really, imagine you have a straight line which starts and ends far away from the point in question. One way to do this might be to interpolate the line, with points, however I am not sure this is a more efficient way to do it. – Manos C Apr 07 '16 at 14:17
  • There seems to be a fairly simple equation here: http://stackoverflow.com/a/1084899/670206 – Suever Apr 07 '16 at 14:20
  • Thanks for that, I will try to see if there is any performance improvement, however I would prefer a matlab function (for which I feel more comfortable concerning its performance) ;) – Manos C Apr 07 '16 at 14:41
  • You can vectorize the above solution and it is guaranteed to be faster. – Suever Apr 07 '16 at 17:52

0 Answers0