Plot GPS positions over an image

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Plot GPS positions over an image

Post by dave_probertGA6e24 » Mon Apr 22, 2013 11:50 am

Hi Nakia,

Ok, this might be a little long-winded, but it hopefully shows the process better.

I took your original code (from your last post) and used it to create the mouse location function.

Your function does basically this - (for x values) where qx is the plot point, vx is the incoming NE coord, cx is the orig, sx is the scale factor and ox is the offset.
That gives us these equations:
qx = ((vx - cx) * sx) + ox
qy = ((cy - vy) * sy) - oy

Reworking these equations to use qx as the mouse loc and getting vx out (for the NE coord):
qx - ox = (vx - cx) * sx
. (qx - ox) / sx = vx - cx
. ( (qx-ox) / sx ) + cx = vx

and (. at the start of the line means "is the same as"):
qy + oy = (cy - vy) * sy
. (qy + oy) / sy = cy - vy
. (qy + oy) / sy = -vy + cy
. -(((qy + oy) / sy) - cy) = vy

Gives us:

Code: Select all

  vx = ( (mouseX - tXOffset) / GXFactor) + tXOrig
  vy = (( (mouseY + tYOffset) / GYFactor) - tYOrig) * -1

or

 put ( (mouseX - tXOffset) / GXFactor) + tXOrig into vx
 put (( (mouseY + tYOffset) / GYFactor) - tYOrig) * -1  into vy
Looking at your code you might want to adjust the GYFactor to be negative so that you are only then adding values. This would give more consistency in the code and get rid of the nasty * -1 in the last line above. In theory both the X and Y calculations should use the same structure - you just scale into the other quadrant (i.e. scale by -GYFactor will give an upside down value - which I think is what you want)

In most cases you will find that just playing with the equations will give you the results - then it's just a case of wrapping them into code.

Hope that helps again,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Plot GPS positions over an image

Post by Nakia » Tue Apr 23, 2013 12:21 am

Dave,

Firstly let me thank you for all your help.
I will get back to this tonight and see how the changes you suggested work.

Thanks again

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Plot GPS positions over an image

Post by Nakia » Fri May 03, 2013 4:51 am

Back looking for help again..

After implementing your fucntion above it has highlighted that I still have an issue with the Plotting Algorithm, I never thought I would have so mouch trouble with this.
Any way, I am certian it is because of the difference in conventions between LC and Easting and Northings in terms of the screen etc.

I have been staring at the screen all afternoon trying multiple permatations of the code I posted on the last page and seem to be getting no where.

The issue is coming from having to Plot "Down to Up" meaning that as Northing's rise the Plotted Point will rise on the screen but LC Convetion has the the Y Axis working opposite.
I know this is a simple math problem but for the life of me I just cant figure it out.

Does anyone have any suggestions?

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Plot GPS positions over an image

Post by Nakia » Fri May 03, 2013 7:33 am

So I have modified it a bit and have got to here.
What I have changed is I have made the Y Axis work the same as the X Axis (Subtract Coord Value from Origin Point " Origin Point for Y is now the lower Number, same theory as X")

So theoretically this part should work but the thing I cant get to work from here is how to calculate the Plot point as this number needs to be calculated in reverse.
I.e. the starting point will be the bottom of the image

Gee I hope this makes sense?

Code: Select all

 put line 4 of gPrefs into tXOrig
   put line 5 of gPrefs into tYOrig
   set the itemdel to comma
   put item 1 of the rect of img "imageHolder" into tXOffset
   put item 4 of the  rect of img "imageHolder" into tYOffset
   ## Now we should be able to plot an Event
   set the itemdel to tab
   repeat with x = 1 to the number of lines in lValidEvents
      ## Calculate the LOC
      put (item 25 of line x of lValidEvents - tXOrig) * GXFactor into tXLoc
      add tXOffset to tXLoc
      
      put (item 26 of line x of lValidEvents - tYOrig) * GYFactor into tYLoc
      put (tYOffset - tYLoc) into tYLoc

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Plot GPS positions over an image

Post by bn » Fri May 03, 2013 10:04 am

Nakia,

from what I understand is you want to plot into a given area values that have bottomLeft as their 0,0 coordinate as opposed the Livecode that uses topLeft of the card as 0,0

I made a little stack that simulates data that is in bottomLeft 0,0 of given area format and is transformed into LiveCode format.

You have to use the height of the display rectangle to invert your Y values.

I hope I got your problem right.

Kind regards
Bernd
Attachments
NakiaInvertY.livecode.zip
(1.59 KiB) Downloaded 241 times

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Plot GPS positions over an image

Post by dave_probertGA6e24 » Fri May 03, 2013 11:39 am

Hi Nakia,

I too have made a little stack which might help a little with your problem.

You can enter the North and East settings and have a play. Try various values from your actual datasets and see what happens. You will probably want to drop in an actual map in place of the dummy I used, and adjust the locations of the input boxes - everything is calculated - so there should be no need to hardcode any values.

All the code is on the Card level script (the buttons only call handlers in there) - The mousemove handler over the image you might need to copy to another image if you import one - it's only a single line calling a handler in the script.

Let me know if it works for you (or not!)

Cheers,
Dave
Attachments
Mapping Example.livecode.zip
(21.67 KiB) Downloaded 240 times
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Plot GPS positions over an image

Post by bn » Fri May 03, 2013 12:16 pm

Hi Dave,

that is a very nice stack.

You might want to add

Code: Select all

on preOpenCard
   initScaling
   pass preOpenCard
end preOpenCard
otherwise it goes right into the debugger because on opening the stack the globals are not yet initialized. It crashed LC once.

Kind regards
Bernd

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Plot GPS positions over an image

Post by dave_probertGA6e24 » Fri May 03, 2013 1:21 pm

Good catch Bernd,

Ooops, I forgot to mention that you need to click the "initScaling" button first. I was in a bit of a hurry. :)

I'll add that to the stack here, but I'll wait for Nakia to have a look before uploading any changes. Then I can add other stuff too ;)

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Plot GPS positions over an image

Post by Nakia » Sun May 05, 2013 11:52 pm

Thankyou both for the helper Stacks, and the best news is it was able to show me where I was going wrong!!
I was not calculating the YScaleFactor into a negative number which caused all the issues..

Thankyou both so much for your help with this...

Post Reply