0

I have a series of Lat/Long points in a SQL Server database. I would like to be able to find shapes. By that I mean if in the mess of coordinates there are 8 coordinates making a perfect circle, or 7 coordinates making a triangle I would like to know.

I'd be surprised if there is already something out there which does this already, especially in C# (the language I'm using). But My question is really, how should I approach this?

I probably have 200k, but their timestamped, so I should only be working with maybe 1k at a time...

Faraday
  • 2,904
  • 3
  • 23
  • 46
  • 1
    How many Lat/Long coordinates do you have to work with? – Nate Sep 14 '12 at 19:19
  • Mechanical turk? Shape finding is not necessarily an easy task. – user7116 Sep 14 '12 at 19:20
  • @sixlettervariables - Mechanical turk??? – Faraday Sep 14 '12 at 19:21
  • @Nate - Edited question to include information on number of points. – Faraday Sep 14 '12 at 19:21
  • https://www.mturk.com/mturk/welcome – Nate Sep 14 '12 at 19:22
  • 1
    Note that any 3 points (as long as none of them are equal) will make a triangle. – Servy Sep 14 '12 at 19:22
  • 2
    I think you're gonna have a hard time with this if you don't know anything about the data. A circle could be a series of 8 points or it could just as easily be two points (one center, one to find the radius). You could just make polygons out of any set of points as well. – Porco Sep 14 '12 at 19:22
  • @Vijay: show a bounding box of some size to a user with all of the points in it and ask them to find shapes. Compare runs of multiple users. – user7116 Sep 14 '12 at 19:23
  • @Servy - Yes, that's why for the triangle it would take 7 points to say "This is a triangle" – Faraday Sep 14 '12 at 19:24
  • @Porco - I'd be looking for specific patterns (7 point triangle, 8 point circle, 12 point square etc) – Faraday Sep 14 '12 at 19:25
  • @sixlettervariables - I could show a box to the user, but how would you approach actually sifting through the data? How would you establish a shape using coordinates efficiently? – Faraday Sep 14 '12 at 19:26
  • Do they need to be *exactly* on the line for the shape, or just within some margin of error? – Servy Sep 14 '12 at 19:27
  • @Servy: ...also the three points cannot be on the same longitude or latitude. Then it's just a line. – Sani Huttunen Sep 14 '12 at 19:27
  • @Nate - Whilst I like the idea and will bookmark that for later... I'd really like to do this with some good ole codin' ! :) – Faraday Sep 14 '12 at 19:27
  • @Servy - Within a margin of error... – Faraday Sep 14 '12 at 19:28
  • @Vijay: I had a large database of GIS data with intersections, etc. One of the tasks was to ensure the lane configurations were correct. It ended up being a nightmare programatically. Instead, I picked some arbitrary zoom factor and served up areas randomly and had myself and a few other folks "correct" the lanes. It took 2-3 days, but was far more accurate than programming the conceptualization of the idea. – user7116 Sep 14 '12 at 19:32
  • @sixlettervariables - The issue is that in a few months there will be more data, then more again, then more, it will never stop. This has to be automated... The data is never ending! :) – Faraday Sep 14 '12 at 19:34

2 Answers2

0

What you're trying to do is called least squares fitting.

Basically, you pick a shape. Let's pick a straight line for now.

You calculate the sum of the squares of the offsets ("the residuals") of the points from the line. You do this with different lines until you've minimized the sum of the squares.

I have no idea how you would automate this for several types of shapes.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • How would you automate this for a single type of shape? – Faraday Sep 14 '12 at 19:38
  • [Least Squares C# library](http://stackoverflow.com/questions/350852/least-squares-c-sharp-library) – Scott Chamberlain Sep 14 '12 at 19:40
  • @ScottChamberlain - That doesn't appear to help with the finding of shapes. The Least Squares Fitting (from my understanding) is a way of averaging. I know I make it sound rather crude, it will likely help with the error margins, but I can't see how I could use it to find a shape... I'm probably missing something, I usually do! :) – Faraday Sep 14 '12 at 19:43
  • @Vijay: As I said, you have to pick the shape first. There's no automated way to find patterns in data. Humans can find patterns. Least squares fitting helps you to determine the shape of the data, as no set of data points are going to fit perfectly to a shape. – Gilbert Le Blanc Sep 17 '12 at 13:08
  • @GilbertLeBlanc - I'm not sure I understand. If I were looking for a square, or a circle how would I approach this. Your solution appears to be heading in the right direction... So if I have a lot of x y coords and I want to find all the squares how would I do it? Least squares seems to find the average... I'm a little confused as to how that would find a shape... – Faraday Sep 17 '12 at 13:21
  • @Vijay: You cannot find arbitrary shapes in an automated manner. It is impossible. You must first pick a shape, and then use least squares fitting to see how well your data fits the shape. From your comments, you would first try a square. You can try a large finite numbers of squares with different side lengths. Then you could try a large finite number of circles with different radii. But you would always be looking for squares and circles. You must pick the shape first. There is no other way. – Gilbert Le Blanc Sep 17 '12 at 13:27
  • @GilbertLeBlanc - OK, so let's say I want to find squares, how would I find a square using least squares fitting? That's the part I don't understand... – Faraday Sep 17 '12 at 14:27
  • @Vijay: Pick one data point as the origin of the square. Start with a square of 10 meters on a side. Calculate the least squares. Increase the size of the square to 15 meters on a side. calculate the least squares. Continue until you have a square of 3,000 meters on a side. Then move the origin point to another data point. Repeat with squares from 10 meters to 3,000 meters incrementing by 5 meters. Repeat until you've used all your data points as origins. The smallest least squares represents the square that has the best fit. – Gilbert Le Blanc Sep 17 '12 at 14:32
  • @GilbertLeBlanc - Sorry for being a little (or very!) dumb on this one. You say start with a square of 10 meters on a side, how? I don't have a square, I'm looking for a square. Increase size and recalculate, move recalculate (fine if question 1 is answered). The main question I have is that you say "start with a square", how? Again apologies for being a dumb-ass on this, it's all quite new to me! Are you saying plot a square myself and calculate least squares (LS) from each point in the square to all other non-square points? If so how do I relate the LS of one point to the others? – Faraday Sep 17 '12 at 14:43
  • @GilbertLeBlanc - Also, assuming my last presumption is correct, is it possible to handle rotation? – Faraday Sep 17 '12 at 14:50
  • @Vijay: This is not a discussion board. I can't teach you least squares in a few comments. – Gilbert Le Blanc Sep 17 '12 at 14:53
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16785/discussion-between-vijay-and-gilbert-le-blanc) – Faraday Sep 17 '12 at 15:12
0

You need to find a library, or develop your self, a way to calculate Least Squares over shapes.

If the error margin is over a threshold level of R2 then you do not have that "Shape". You will need to define a formula for the shape you test against (For example a circle: x2+y2=r2).

For things that do not have curves (triangle,square, ect.) it will be harder to do as they do not have a "Formula". You can use the least square for finding each side of the shape for a line (y=mX+b) and then building those lines together to make shapes.

Community
  • 1
  • 1
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • I get that I need to find something, or make something ;) The issue is that even the stuff of 2D point-cloud image recognition seems to be based on visuals rather than xy. I'm sure there will be something out there, it's just tricky trying to find it... I've been googling for hours and although I've learnt a lot, none of it has been that helpful to the task at hand! :) Thanks though, any and all help is always appreciated! – Faraday Sep 14 '12 at 20:05