|
Post by alexfish on Mar 11, 2021 22:28:46 GMT 1
openseamap charts if want png download the mbtiles format and then convert as Posted my link = en can change lang at site HERElook for downloads another link HEREBR Alex
|
|
|
Post by alexfish on Mar 11, 2021 23:15:30 GMT 1
Some Useful Functions
DEF FN DEG2RAD(deg) = (deg * M_PI / 180.0) DEF FN RAD2DEG(rad) = (rad / M_PI * 180.0)
' =================================== FUNCTION LONDEG2LONMIN ( float lon) TYPE STRING ' ===================================
LOCAL lonmin[20] TYPE static char LOCAL degrees TYPE int LOCAL minutes TYPE float degrees = (abs( (lon>0) ? floor(lon) : ceil(lon) )) minutes = ((fabs(lon) - (float)degrees) * 60) sprintf (lonmin,"%d°%.3f' %s",degrees,minutes,(lon>0) ? "E" : "W") RETURN lonmin
END FUNCTION
' ================================= FUNCTION LATDEG2LATMIN (float lat) TYPE STRING ' =================================
LOCAL latmin[20] TYPE static char LOCAL degrees TYPE int LOCAL minutes TYPE float degrees = (abs( (lat>0) ? floor(lat) : ceil(lat) )) minutes = ((fabs(lat) - (float)degrees) * 60) sprintf (latmin,"%d°%.3f' %s", degrees,minutes,(lat>0) ? "N" : "S") RETURN latmin
END FUNCTION
' ================================= FUNCTION LATDEG2LATSEC(float lat) TYPE STRING ' =================================
LOCAL latsec[20] TYPE static char LOCAL degrees, full_minutes TYPE int LOCAL minutes, seconds TYPE float degrees = abs( (lat>0) ? floor(lat) : ceil(lat) ) minutes = (fabs(lat) - (float)degrees) * 60 full_minutes = floor(minutes) seconds = (minutes - (float)full_minutes) * 60 sprintf( latsec,"%d°%d'%.2f\" %s", degrees,full_minutes,seconds,(lat>0) ? "N" : "S") RETURN latsec
END FUNCTION
' ================================== FUNCTION LONDEG2LONSEC ( float lon) TYPE STRING ' ==================================
LOCAL lonmin[20] TYPE static char LOCAL degrees, full_minutes TYPE int LOCAL minutes, seconds TYPE float degrees = (abs( (lon>0) ? floor(lon) : ceil(lon) )) minutes = ((fabs(lon) - (float)degrees) * 60) full_minutes = (floor(minutes)) seconds = ((minutes - (float)full_minutes) * 60)
sprintf(lonmin,"%d°%d'%.2f\" %s",degrees,full_minutes,seconds,(lon>0) ? "E" : "W") RETURN lonmin
END FUNCTION
' ========================================================= FUNCTION GET_DISTANCE (double lat1, double lon1, double lat2, double lon2) TYPE float ' =========================================================
LOCAL distance = 0 TYPE float LOCAL tmp TYPE double tmp = sin(DEG2RAD(lat1)) * sin(DEG2RAD(lat2)) + cos(DEG2RAD(lat1)) * cos(DEG2RAD(lat2)) * cos(DEG2RAD(lon2) - DEG2RAD(lon1)) distance = 6371.0 * acos(tmp) RETURN distance
END FUNCTION
' ======================================================== FUNCTION GET_BEARING(double lat1, double lon1, double lat2, double lon2) TYPE float ' ======================================================== LOCAL bearing, tmp TYPE double
tmp = atan2(sin(DEG2RAD(lon2)-DEG2RAD(lon1)) * cos(DEG2RAD(lat2)), \ cos(DEG2RAD(lat1)) * sin(DEG2RAD(lat2)) - \ sin(DEG2RAD(lat1)) * cos(DEG2RAD(lat2)) * cos(DEG2RAD(lon2)-DEG2RAD(lon1)) )
bearing = ((tmp < 0) ? tmp + M_PI*2 : tmp)
RETURN RAD2DEG(bearing)
END FUNCTION BR Alex
|
|
|
Post by vovchik on Mar 12, 2021 11:23:45 GMT 1
Dear Alex,
Thanks for that collection of useful fucntions. They will come in handy...
With kind regards, vovchik
|
|
|
Post by alexfish on Mar 12, 2021 12:03:04 GMT 1
Dear Alex, Thanks for that collection of useful fucntions. They will come in handy... With kind regards, vovchik Hi Vovchik Most Welcome, as a side note, these function from Known Sources & are implemented in the likes of foxtrot gps & libosm where I did get stuck at the time was the Bacon PRINT TO so, possible someone can try to Baconise , I say that since looking at initial render formats = Libx11 + cairo, here do not need GTK + easy to free the bits GTK2 using cairo, this we know should work with all distro's ,esp looks like we have a problem with X11 Mint Peter's WebKit ToolKit , can comment on that one since previous Pi version's gtk bits were problematic at first stages named as Experimentalso as said busy getting the bits done in that department Posting a link for github.com/nzjrs/osm-gps-mapmay also find interesting , look at example , yet like most gtk pretty much a locked in affair BR Alex
|
|
|
Post by rikky on Mar 12, 2021 16:32:57 GMT 1
Unfortunately bumped into a major problem elsewhere (but related) that needs my attention. Just wanted to mention OpenLayers
|
|
|
Post by alexfish on Mar 13, 2021 2:52:39 GMT 1
Not for me 'J'
This is BaCon = 'C'
. in previous post I touched on Peter's Webkit ToolKit and in a another Post Peter's WebServer.
Joe has a thread going, possible best suited for The 'J' word , there is also a Special forum for such.
BR Alex
|
|
|
Post by rikky on Mar 13, 2021 20:58:03 GMT 1
commandline utility that downloads OpenStreet en OpenSea png's, converts them to one svg and stashes them in $HOME/TILES/etc/etc If no position is given, the location of your ip is used. If no zoom is given all 20 zoom svg's are created. This way you can use your app offline next step is have a boat or car or bike icon on your position Attachments:POS2TILE.bac (6.18 KB)
|
|
|
Post by rikky on Mar 14, 2021 11:42:18 GMT 1
Latitude is the angle between the equatorial plane and the line extending from the center of the Earth to a certain point on its surface. It references the north-south position on the Earth. It's represented by circles of latitude, or parallels - the lines that go around the globe. The central line of latitude is called the Equator. It has a latitude of 0 degrees. The maximum value of latitude is 90 degrees - found at the poles. Longitude, on the other hand, refers to a east-west position on the Earth. Lines of longitude, or meridians connect the North and the South Pole. They extend to the east and west of the Prime Meridian, reaching up to 180 degrees. All meridians have the same length - 12,429.9 miles (20,003.93 km). Latitude = horizontal = φ (phi) Longitude = vertical = λ (lambda) First comes the latitude, then the longitude. (I ALWAYS make this mistake) there are three formats (at least) DD decimal degrees - ° DMS degrees - °, minutes - ', seconds - " DDM degrees (°), decimal minutes (') For latitude, northern directions may be indicated by the letter N or a positive number, and southern directions can be marked with either the letter S or a negative value. For longitude, you can use the letter E or a positive number for the eastern direction, and the western direction can be indicated by the letter W, or a negative number. So mistakes are common. I personally haven't got a clue what to use My AIS gives output in DDM SignalK converts them to DD OpenSeamap shows them in DMS THE international standard is WGS84 , according to the internet. At least it is the standard of the U.S. Department of Offense No wonder they always lose. So the best is probably what3words
|
|
|
Post by alexfish on Mar 14, 2021 11:49:07 GMT 1
Hi Rik
Just finished testing Previous Post , Looking Good
Need to read and Digest ais bits, There are converters about + will look through what I have here
Just Noted Will the above Functions not be suitable These
LONDEG2LONMIN LATDEG2LATMIN LATDEG2LATSEC LONDEG2LONSEC
put the decimals values in,it should works
BR Alex
|
|
|
Post by alexfish on Mar 14, 2021 12:30:36 GMT 1
OPTION PARSE FALSE
DEF FN DEG2RAD(deg) = (deg * M_PI / 180.0) DEF FN RAD2DEG(rad) = (rad / M_PI * 180.0)
' =================================== FUNCTION LONDEG2LONMIN ( float lon) TYPE STRING ' ===================================
LOCAL lonmin[20] TYPE static char LOCAL degrees TYPE int LOCAL minutes TYPE float degrees = (abs( (lon>0) ? floor(lon) : ceil(lon) )) minutes = ((fabs(lon) - (float)degrees) * 60) sprintf (lonmin,"%d°%.3f' %s",degrees,minutes,(lon>0) ? "E" : "W") RETURN lonmin
END FUNCTION
' ================================= FUNCTION LATDEG2LATMIN (float lat) TYPE STRING ' =================================
LOCAL latmin[20] TYPE static char LOCAL degrees TYPE int LOCAL minutes TYPE float degrees = (abs( (lat>0) ? floor(lat) : ceil(lat) )) minutes = ((fabs(lat) - (float)degrees) * 60) sprintf (latmin,"%d°%.3f' %s", degrees,minutes,(lat>0) ? "N" : "S") RETURN latmin
END FUNCTION
' ================================= FUNCTION LATDEG2LATSEC(float lat) TYPE STRING ' =================================
LOCAL latsec[20] TYPE static char LOCAL degrees, full_minutes TYPE int LOCAL minutes, seconds TYPE float degrees = abs( (lat>0) ? floor(lat) : ceil(lat) ) minutes = (fabs(lat) - (float)degrees) * 60 full_minutes = floor(minutes) seconds = (minutes - (float)full_minutes) * 60 sprintf( latsec,"%d°%d'%.2f\" %s", degrees,full_minutes,seconds,(lat>0) ? "N" : "S") RETURN latsec
END FUNCTION
' ================================== FUNCTION LONDEG2LONSEC ( float lon) TYPE STRING ' ==================================
LOCAL lonmin[20] TYPE static char LOCAL degrees, full_minutes TYPE int LOCAL minutes, seconds TYPE float degrees = (abs( (lon>0) ? floor(lon) : ceil(lon) )) minutes = ((fabs(lon) - (float)degrees) * 60) full_minutes = (floor(minutes)) seconds = ((minutes - (float)full_minutes) * 60)
sprintf(lonmin,"%d°%d'%.2f\" %s",degrees,full_minutes,seconds,(lon>0) ? "E" : "W") RETURN lonmin
END FUNCTION
' ========================================================= FUNCTION GET_DISTANCE (double lat1, double lon1, double lat2, double lon2) TYPE float ' =========================================================
LOCAL distance = 0 TYPE float LOCAL tmp TYPE double tmp = sin(DEG2RAD(lat1)) * sin(DEG2RAD(lat2)) + cos(DEG2RAD(lat1)) * cos(DEG2RAD(lat2)) * cos(DEG2RAD(lon2) - DEG2RAD(lon1)) distance = 6371.0 * acos(tmp) RETURN distance
END FUNCTION
' ======================================================== FUNCTION GET_BEARING(double lat1, double lon1, double lat2, double lon2) TYPE float ' ======================================================== LOCAL bearing, tmp TYPE double
tmp = atan2(sin(DEG2RAD(lon2)-DEG2RAD(lon1)) * cos(DEG2RAD(lat2)), \ cos(DEG2RAD(lat1)) * sin(DEG2RAD(lat2)) - \ sin(DEG2RAD(lat1)) * cos(DEG2RAD(lat2)) * cos(DEG2RAD(lon2)-DEG2RAD(lon1)) )
bearing = ((tmp < 0) ? tmp + M_PI*2 : tmp)
RETURN RAD2DEG(bearing)
END FUNCTION
LOCAL A$ TYPE STRING A$ = LATDEG2LATSEC(54.134938)
PRINT A$
Terminal gives
pi@raspberrypi:~/nav $ ./latlon 54°8'5.77" N
&
LOCAL A$ TYPE STRING A$ = LONDEG2LONSEC (-1.580320)
PRINT A$
gives
pi@raspberrypi:~/nav $ ./latlon 1°34'49.15" W
BR Alex
|
|
|
Post by alexfish on Mar 14, 2021 17:01:52 GMT 1
Have Just Managed to get X11 & cairo working on RPI4
change things a bit + using new Xinput 'XIM'for the keyboard etc
so here a very simple setup , hope it shows + type something
Note Special keys like space an arrow keys should not work . may see the in the terminal
BR Alex
OPTION PARSE FALSE
PRAGMA LDFLAGS `pkg-config --libs x11 cairo` PRAGMA OPTIONS `pkg-config --cflags x11 cairo`
PRAGMA INCLUDE <X11/Xlib.h> PRAGMA INCLUDE <X11/Xutil.h> PRAGMA INCLUDE <cairo/cairo.h> PRAGMA INCLUDE <cairo/cairo-pdf.h> PRAGMA INCLUDE <cairo/cairo-ps.h> PRAGMA INCLUDE <cairo/cairo-xlib.h>
DECLARE dpy TYPE Display* DECLARE win TYPE Window DECLARE xim TYPE XIM DECLARE xic TYPE XIC
DECLARE cs TYPE cairo_surface_t * DECLARE wid TYPE cairo_surface_t * DECLARE MSG$ = "OK g " TYPE STRING
SUB cairo_rgba(cairo_t * cr,char r,char g,char b,char a) LOCAL R,G,B,A TYPE double R = r/255.0 G = g/255.0 B = b/255.0 A = a/255.0 PRINT R , ":",G,":",B,":" ,A cairo_set_source_rgba(cr , R ,G ,B,A) END SUB SUB Test(cairo_surface_t * csy, STRING txt$)
LOCAL c TYPE cairo_t * c=cairo_create(csy) cairo_rgba(c,0, 255,238, 255)
cairo_paint(c) cairo_save(c) cairo_restore(c) cairo_set_source_rgb(c,1, 1, 1) cairo_set_font_size(c,20.0) cairo_set_source_rgb(c,0, 0, 0) cairo_move_to(c, 20, 20) cairo_show_text(c, txt$) cairo_save(c) cairo_restore(c) cairo_show_page(c) 'cairo_destroy(c)
END SUB
'setlocale(LC_ALL, "") dpy = XOpenDisplay(NULL) screen_num = DefaultScreen(dpy)
display_width = DisplayWidth(dpy, screen_num) display_height = DisplayHeight(dpy, screen_num) win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 600, 400, 3, BlackPixel(dpy, screen_num),WhitePixel(dpy, screen_num) )
XSetLocaleModifiers("")
xim = XOpenIM(dpy, 0, 0, 0)
IF ( NOT(xim)) THEN ' fallback to internal input method XSetLocaleModifiers("@im=none") xim = XOpenIM(dpy, 0, 0, 0) PRINT "FallBack" END IF
xic = XCreateIC(xim, \ XNInputStyle,XIMPreeditNothing | XIMStatusNothing, \ XNClientWindow, win, \ XNFocusWindow, win, \ NULL)
XSetICFocus (xic) XSelectInput(dpy, win, ExposureMask | KeyPressMask | KeyReleaseMask ) wm_delete_window = XInternAtom (dpy, "WM_DELETE_WINDOW", False) XSetWMProtocols (dpy,win, &wm_delete_window, 1) cs=cairo_xlib_surface_create(dpy, win, DefaultVisual(dpy, 0),display_width, display_height) XMapWindow(dpy, win) 'XMapRaised(dpy, win) 'XSync(dpy , FALSE)
LOCAL prev_ev = {}, ev = {} TYPE XEvent
WHILE (1) DO
XNextEvent(dpy, &ev)
IF (XFilterEvent(&ev, None) == TRUE ) THEN
CONTINUE
END IF
SELECT ev.type
CASE Expose PRINT "Expose :" ,ptr INCR ptr Test(cs,MSG$) expo = (XExposeEvent *)&ev
'@ when protcols are set the have to exit via the protocols if client data[0]=wm_delete_window CASE ClientMessage
PRINT "Closing Down"
IF ((Atom)ev.xclient.data.l[0] == wm_delete_window) THEN PRINT "EXITING"
XFlush(dpy) XClearWindow(dpy, win) cairo_surface_destroy(cs) XCloseDisplay(dpy) 'DESTROY_ALL() BREAK
END IF CASE MapNotify PRINT "MapNotify"
CASE KeyPress
LOCAL status TYPE Status LOCAL keysym TYPE KeySym keysym = NoSymbol LOCAL text [32] TYPE char memset(text,'\0',32) LOCAL is_repeat TYPE int LOCAL txt$ TYPE STRING
' =========================================== is_repeat = prev_ev.type == KeyRelease && \ prev_ev.xkey.time == ev.xkey.time && \ prev_ev.xkey.keycode == ev.xkey.keycode ' ========================================== ev.xkey.state &= ~ControlMask
Xutf8LookupString(xic, &ev.xkey, text, sizeof(text) - 1, &keysym, &status) ' ================================================ IF (status == XBufferOverflow) THEN
' ignore END IF
' ================================================== IF (status == XLookupChars) THEN txt$ = text PRINT "Got String: " , txt$ )
END IF
' ========================================================
IF (status == XLookupBoth) THEN LOCAL sym_name$ TYPE STRING txt$ = text txt$=CHOP$(txt$) sym_name$ = XKeysymToString(keysym) PRINT "Have Two: ", txt$ , " : " , sym_name$ MSG$=MSG$ & txt$ Test(cs,MSG$) END IF
' ================================================ IF (status == XLookupKeySym) THEN
LOCAL sym_name2$ TYPE STRING
sym_name2$ = XKeysymToString(keysym)
PRINT "Have keysym: ", sym_name$
END IF
' ================================================= IF (keysym == XK_Escape) THEN
END
END IF
END SELECT
WEND
|
|
|
Post by alexfish on Mar 14, 2021 21:37:25 GMT 1
nearest api for what3words was based on python wrapper
https://github.com/what3words/w3w-python-wrapper it bemoans at app key KeyError: "'W3W_API_KEY'", so puzzled
rest in popular = 'J'
BR Alex
|
|
|
Post by vovchik on Mar 14, 2021 22:23:44 GMT 1
Dear Alex,
Your keyboard code works on Pi4 and Mint. Thanks....
With kind regards, vovchik
|
|
|
Post by alexfish on Mar 14, 2021 22:29:44 GMT 1
Hi Vovchik
Thanks for testing
BR Alex
|
|
|
Post by alexfish on Mar 14, 2021 22:33:34 GMT 1
What3Words , I can sum up with what2words git fail on V3 and followed instructions HEREon RPI I get res = geocoder.convert_to_3wa(what3words.Coordinates(51.484463, -0.195405)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "build/bdist.linux-armv7l/egg/what3words/what3words.py", line 82, in convert_to_3wa File "build/bdist.linux-armv7l/egg/what3words/what3words.py", line 280, in _request File "/usr/lib/python2.7/dist-packages/requests/api.py", line 75, in get return request('get', url, params=params, **kwargs) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /v3/convert-to-3wa?key=what3words-api-key&language=en&coordinates=51.484463%2C-0.195405&format=json (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xb5d14910>: Failed to establish a new connection: [Errno 111] Connection refused',)) >>> geocoder = what3words.Geocoder("what3words-api-key", end_point='http://localhost:8080/v3')
|
|