|
Post by alexfish on Mar 10, 2021 9:05:15 GMT 1
Dear Alex, I'll now have a look. Incidentally, the "p1" format might, for some purposes, be easier to parse: curl wttr.in/Vienna?format=p1
With kind regards, vovchik Hi vovchik looking at bits. 1. the actual minimal parse is readable as is 2. minimal parsing , should be able to convert as text + some of the geo like moon phase, easy to put into various image formats + possible compass like feature for the Wind direction + a Barometer did a conversion of minutes passed # HELP observation_time Minutes since start of the day the observation happened observation_time{forecast="current"} 402 : the conversion = 06:42:00 BR Alex
|
|
|
Post by alexfish on Mar 10, 2021 12:43:22 GMT 1
can run same from BaCon Server localhost ' Define HTTP Weather CONST New$ = CHR$(13) & NL$ CONST Sep$ = CHR$(13) & NL$ & CHR$(13) & NL$ CONST Msg$ = "<html><head></head><body ><script type='text/javascript'>var width='100%'; var height='300'; var latitude='22.232';var longitude='-97.89'; var zoom='13'; </script><script type='text/javascript' src='https://www.vesselfinder.com/aismap.js'> </script> </body> </html>" ' openplotter.local:3000/signalk/v1/api/ ' Get our IP Ip$ = "localhost" PRINT "Connect from browser '", Ip$, ":8080'."
' Ignore child signals to avoid zombie processes SIGNAL SIG_IGN, SIGCHLD
' Open listening port OPEN Ip$ & ":8080" FOR SERVER AS mynet
' Keep receiving requests WHILE TRUE
' Handle for newly incoming connection fd = ACCEPT(mynet)
' Incoming connection -> create background process spawn = FORK
' We are in the child IF spawn = 0 THEN
' Get the request REPEAT RECEIVE dat$ FROM fd PRINT dat$ UNTIL RIGHT$(dat$, 4) = Sep$
' Reply that we're OK SEND "HTTP/1.1 200 Ok" & New$ & "Content-Length: " & STR$(LEN(Msg$)) & Sep$ & Msg$ TO fd
' Close connection CLOSE SERVER fd
' End this process ENDFORK ENDIF WEND terminal Connect from browser 'localhost:8080'. GET / HTTP/1.1 Host: localhost:8080 Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.197 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Sec-Fetch-Site: none Sec-Fetch-Mode: navigate Sec-Fetch-Dest: document Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9
GET /favicon.ico HTTP/1.1 Host: localhost:8080 Connection: keep-alive User-Agent: Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.197 Safari/537.36 Accept: image/avif,image/webp,image/apng,image/*,*/*;q=0.8 Sec-Fetch-Site: same-origin Sec-Fetch-Mode: no-cors Sec-Fetch-Dest: image Referer: http://localhost:8080/ Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 point here been , we can use Peter's 'server' + 'webkit widgets' etc with in same app , no need for separate Apps BR Alex ADDED : Food for Thought One can get this image as png . then We have the resources as in Talent Here to overlay that image With What Ever & Vice Versa Attachments:
|
|
|
Post by vovchik on Mar 10, 2021 16:51:13 GMT 1
Dear Alex and Rik, And this tiny bit of code will do the png2svg conversion (using the png in my previous post): header$ = CONCAT$("<svg width='256' height='256' viewBox='0 0 3 3'", NL$, \ " preserveAspectRatio='none'>" , NL$, \ "<image x='0' y='0' width='3' height='3'" , NL$, \ " xlink:href='data:image/png;base64,", NL$) footer$ = CONCAT$("'/>", NL$, "</svg>") img$ = CHOP$(ALIGN$(B64ENC$(BLOAD("23.png"), FILELEN("23.png")), 64, 0)) svg$ = header$ & img$ & footer$ SAVE svg$ TO "test.svg" In order to get the dimensions needed for the svg and subsequent scaling, we have to modify the header$ var to reflect real png dimensions. The linux "file" command will do this for us: png$ = "23.png" size$ = CHOP$(TOKEN$(EXEC$("file " & png$), 2, ",")) org_w$ = TOKEN$(size$, 1, " ") org_h$ = TOKEN$(size$, 3, " ") new_w$ = "300" new_h$ = "200"
PRINT "Dimensions: ", org_w$, " x ", org_h$ header$ = CONCAT$("<svg width='", new_w$, "' height='", new_h$, "'", NL$, \ " viewBox='0 0 ", org_w$, " ", org_h$, "'", NL$, \ " xmlns='http://www.w3.org/2000/svg' ", NL$, \ " xmlns:xlink='http://www.w3.org/1999/xlink' ", NL$, \ " preserveAspectRatio='none'>" , NL$, \ "<g transform='scale(100%, 100%)'>", NL$, \ "<image x='0' y='0' width='", org_w$, "' height='", org_h$, "'" , NL$, \ " xlink:href='data:image/png;base64,", NL$) footer$ = CONCAT$("'/>", NL$, "</g>", NL$, "</svg>") img$ = CHOP$(ALIGN$(B64ENC$(BLOAD("23.png"), FILELEN("23.png")), 64, 0)) svg$ = header$ & img$ & footer$ SAVE svg$ TO "test.svg" The image is now 300x200, courtesy of svg scaling. With kind regards, vovchik
|
|
|
Post by rikky on Mar 11, 2021 18:19:43 GMT 1
So Openstreetmap uses the png format for their charts. SVG would indeed be better I suppose. For the openstreetpap there is a format for how to find the charts : /zoom/x/y.png conversion: SLIPPY_MAP.bac 'format is /zoom/x/y.png
FUNCTION X2LON$(xtile,zoom) 'n = 2 ^ zoom 'lon_deg = xtile / n * 360.0 - 180.0 LOCAL result$ PRINT xtile / POW(2,zoom) *360 - 180 FORMAT "%.9f" TO result$ RETURN result$
END FUNCTION
FUNCTION Y2LAT$(ytile,zoom) 'n = 2 ^ zoom 'lat_rad = arctan(sinh(π * (1 - 2 * ytile / n))) 'lat_deg = lat_rad * 180.0 / π LOCAL n$ LOCAL result$ PRINT PI - 2 * PI * ytile / POW(2,zoom) FORMAT "%.9f" TO n$ PRINT 180.0 / PI * ATN2(0.5 * (EXP(VAL(n$)) - EXP(VAL("-" & n$))),1) FORMAT "%.9f" TO result$ RETURN result$ END FUNCTION
FUNCTION LON2X$(lon$,zoom$) /* n = 2 ^ zoom xtile = n * ((lon_deg + 180) / 360) */ LOCAL result$ PRINT (VAL(lon$) + 180) / 360 * POW(2,VAL(zoom$)) FORMAT "%.1f" TO result$ result$ = STR$(FLOOR(VAL(result$))) RETURN result$ END FUNCTION
FUNCTION LAT2Y$(lat$,zoom$)
/* n = 2 ^ zoom ytile = n * (1 - (log(tan(lat_rad) + sec(lat_rad)) / π)) / 2 */ LOCAL result$ PRINT (1 - LOG(TAN(VAL(lat$) * PI/180) + 1 / COS(VAL(lat$) * PI/180)) / PI) / 2 * POW(2,VAL(zoom$)) FORMAT "%.1f" TO result$ result$ = STR$(FLOOR(VAL(result$))) RETURN result$ END FUNCTION X2LON.bac : INCLUDE SLIPPY_MAP.bac
FOR word$ IN "-h --help help ?" IF ISTOKEN(ARGUMENT$,word$) THEN PRINT PRINT BASENAME$(TOKEN$(ARGUMENT$,1)) & " xtile zoom" PRINT PRINT "example: " & BASENAME$(TOKEN$(ARGUMENT$,1)) & " 70406 17" PRINT "Result should be 13.375854492" PRINT END END IF NEXT word$
xtile$ = TOKEN$(ARGUMENT$,2) zoom$ = TOKEN$(ARGUMENT$,3)
PRINT X2LON$(VAL(xtile$),VAL(zoom$))
Y2LAT.bac : INCLUDE SLIPPY_MAP.bac
FOR word$ IN "-h --help help ?" IF ISTOKEN(ARGUMENT$,word$) THEN PRINT PRINT BASENAME$(TOKEN$(ARGUMENT$,1)) & " ytile zoom" PRINT PRINT "example: " & BASENAME$(TOKEN$(ARGUMENT$,1)) & " 42987 17" PRINT "Result should be 52.517892228" PRINT END END IF NEXT word$
ytile$ = TOKEN$(ARGUMENT$,2) zoom$ = TOKEN$(ARGUMENT$,3)
PRINT Y2LAT$(VAL(ytile$),VAL(zoom$))
LON2X.bac : INCLUDE SLIPPY_MAP.bac
FOR word$ IN "-h --help help ?" IF ISTOKEN(ARGUMENT$,word$) THEN PRINT PRINT BASENAME$(TOKEN$(ARGUMENT$,1)) & " longitude zoom" PRINT PRINT "example: " & BASENAME$(TOKEN$(ARGUMENT$,1)) & " 13.375854492 17" PRINT "Result should be 70406" PRINT END END IF NEXT word$
longitude$ = TOKEN$(ARGUMENT$,2) zoom$ = TOKEN$(ARGUMENT$,3)
PRINT LON2X$(longitude$,zoom$)
LAT2Y.bac : INCLUDE SLIPPY_MAP.bac
FOR word$ IN "-h --help help ?" IF ISTOKEN(ARGUMENT$,word$) THEN PRINT PRINT BASENAME$(TOKEN$(ARGUMENT$,1)) & " latitude zoom" PRINT PRINT "example: " & BASENAME$(TOKEN$(ARGUMENT$,1)) & " 52.517892228 17" PRINT "Result should be 42987" PRINT END END IF NEXT word$
latitude$ = TOKEN$(ARGUMENT$,2) zoom$ = TOKEN$(ARGUMENT$,3)
PRINT LAT2Y$(latitude$,zoom$)
Well, If they are tested and being approved and bettered, they could be publicized among the other languages on Slippy MapsNext thing is of course find this url from Openseamap where these png files are. Rik
|
|
|
Post by alexfish on Mar 11, 2021 19:53:18 GMT 1
Nice Work Will find rest of bits HERE, use how you see fit it uses Curl , but if can use all Bacon HTTPS request same usage / as mentioned previous links if using openseamaps converted to png that = same Algo then one can fill the missing bits of seamaps with openstreet, IE Can be either or as a Plus Side , openstreetmaps have a directory of Navigation + icons I need to look those up did post them on this forum , somewhere HEREBR Alex PS :: 'Image Compositing' early days yet Plenty of time ,when ready the will do some 'image Compositing' Initially to add layers to a png image I use Cairo :: cairo create from png for insight can read up cairo operators HEREIf have SVG file in path format the make drive like so this is one of my LIBX11(cairo surfact)demos 'svg demo OPTION PARSE FALSE
INCLUDE "toolkit.bac"
DECLARE width=120 TYPE int DECLARE height= 120 TYPE int
DECLARE SVG$ = "M 57.0625,3.53125 L 49.8125,4.28125 L 42.6875,5.9375 L 35.875,8.40625 L 29.53125,11.75 L 23.84375,15.90625 L 18.9375,20.875 L 14.6875,26.4375 L 10.90625,32.46875 L 7.34375,38.6875 L 11.59375,41.15625 L 13.1875,38.5 L 17,32.4375 L 21.125,26.6875 L 25.84375,21.5 L 31.28125,17.0625 L 37.46875,13.53125 L 44.1875,10.90625 L 51.3125,9.25 L 58.65625,8.59375 L 66.03125,8.9375 L 73.28125,10.28125 L 80.1875,12.625 L 86.53125,15.875 L 92.15625,20.03125 L 96.9375,25 L 100.96875,30.6875 L 104.4375,36.8125 L 107.53125,43.34375 L 110.46875,50 L 116.125,54.28125 L 114.875,47.6875 L 113.0625,40.84375 L 110.34375,34.21875 L 106.71875,28 L 102.28125,22.3125 L 97.09375,17.1875 L 91.34375,12.8125 L 85.0625,9.21875 L 78.40625,6.5 L 71.46875,4.625 L 64.3125,3.65625 L 57.0625,3.53125 z M 6.28125,42.21875 L 4.71875,49.375 L 3.65625,56.375 L 3.5,63.34375 L 4.40625,70.3125 L 5.90625,77.3125 L 32.15625,62.78125 L 38.21875,66.34375 L 44.40625,69.875 L 50.75,73 L 57.40625,75.4375 L 64.34375,76.9375 L 71.4375,77.59375 L 78.625,77.53125 L 85.78125,76.6875 L 92.6875,74.96875 L 99.21875,72.3125 L 105.28125,68.71875 L 110.96875,64.5 L 116.5,59.9375 L 111.1875,55.5625 L 105.5,51.375 L 99.40625,47.875 L 92.84375,45.28125 L 85.90625,43.59375 L 78.75,42.6875 L 71.5625,42.53125 L 64.4375,43.09375 L 57.5,44.5625 L 50.90625,47 L 44.5625,50.25 L 38.34375,53.6875 L 32.15625,57.125 L 6.28125,42.21875 z M 94.5,55 C 97.26,55 99.5,57.24 99.5,60 C 99.5,62.76 97.26,65 94.5,65 C 91.74,65 89.5,62.76 89.5,60 C 89.5,57.24 91.74,55 94.5,55 z M 116.5,65.28125 L 110.46875,69.875 L 109.15625,73.59375 L 106.59375,80.28125 L 103.59375,86.6875 L 99.8125,92.5625 L 95.0625,97.78125 L 89.4375,102.28125 L 83.15625,105.9375 L 76.40625,108.65625 L 69.4375,110.40625 L 62.34375,111.1875 L 55.1875,111 L 48.125,109.8125 L 41.21875,107.71875 L 34.625,104.6875 L 28.5625,100.8125 L 23.28125,96.125 L 18.8125,90.65625 L 15.03125,84.65625 L 11.59375,78.375 L 7.34375,80.84375 L 7.75,81.71875 L 11.03125,88.03125 L 14.78125,94.03125 L 19.28125,99.46875 L 24.59375,104.25 L 30.53125,108.3125 L 36.9375,111.625 L 43.71875,114.0625 L 50.71875,115.75 L 57.84375,116.46875 L 65,116.3125 L 72.03125,115.25 L 78.875,113.25 L 85.40625,110.40625 L 91.625,106.78125 L 97.34375,102.4375 L 102.46875,97.40625 L 106.84375,91.8125 L 110.21875,85.65625 L 112.78125,79.09375 L 114.78125,72.25 L 116.5,65.28125 z" TYPE STRING 'C 97.26, 55 99.5, 57.24 99.5, 60
SUB RENDER_PATH(Window win,STRING svg$,int xpos,int ypos,char r,char g,char b, char a) LOCAL dimention , dim2
SPLIT svg$ BY NL$ TO SVGARRAY$ SIZE dimention LOCAL c1 TYPE cairo_t * LOCAL c TYPE cairo_t * c1=cairo_create(bac_widget_context(STR$(win)))
c=cairo_create(bac_widget_drawable(STR$(win))) 'start drawing xpos ypos using translate : Not cairo_move_to for start of drawing pos cairo_translate (c, xpos, ypos) FOR t = 0 TO dimention -1 A$ = CHOP$(SVGARRAY$[t]) SELECT A$
CASE "M" INCR t A$ = CHOP$(SVGARRAY$[t]) SPLIT A$ BY "," TO BITS$ SIZE dim2 IF dim2 =2 THEN cairo_move_to (c,VAL(BITS$[0]),VAL(BITS$[1])) END IF
CASE "L" INCR t A$ = CHOP$(SVGARRAY$[t]) SPLIT A$ BY "," TO BITS$ SIZE dim2 IF dim2 =2 THEN cairo_set_rgba(c,255,255,255,255) cairo_line_to(c,VAL(BITS$[0]),VAL(BITS$[1])) cairo_set_rgba(c,r,g,b,a) cairo_line_to(c,VAL(BITS$[0]),VAL(BITS$[1])) END IF
CASE "C" INCR t A$ = CHOP$(SVGARRAY$[t]) A$ = REPLACE$(A$," ",",") SPLIT A$ BY "," TO BITS$ SIZE dim2 IF dim2 =6 THEN cairo_set_rgba(c,255,255,255,255) cairo_curve_to (c,VAL(BITS$[0]),VAL(BITS$[1]),VAL(BITS$[2]),VAL(BITS$[3]),VAL(BITS$[4]),VAL(BITS$[5])) cairo_set_rgba(c,r,g,b,a) cairo_curve_to (c,VAL(BITS$[0]),VAL(BITS$[1]),VAL(BITS$[2]),VAL(BITS$[3]),VAL(BITS$[4]),VAL(BITS$[5])) END IF
CASE "z" cairo_close_path (c)
END SELECT
NEXT
cairo_fill (c) cairo_set_source_surface (c1,bac_widget_drawable(STR$(win)),0,0) cairo_paint(c1) cairo_show_page(c1) bac_widget_render(STR$(win))=0 cairo_destroy(c) cairo_destroy(c1)
END SUB
IF INSTR(SVG$," ") THEN SVG$=REPLACE$(SVG$," "," ") END IF IF INSTR(SVG$," ") THEN SVG$=REPLACE$(SVG$," "," ") END IF IF INSTR(SVG$," ") THEN SVG$=REPLACE$(SVG$," "," ") END IF SVG$= SVG$ & "0" SVG$=REPLACE$(SVG$,"M",NL$ & "M" & NL$) SVG$=REPLACE$(SVG$,"L",NL$ & "L" & NL$) SVG$=REPLACE$(SVG$,"C",NL$ & "C" & NL$) SVG$=REPLACE$(SVG$,"z",NL$ & "z" & NL$)
DECLARE window,container,layout TYPE Window window = WINDOW("test",640,400)
' default window is RESIZEWIN(*,*,FALSE) RESIZEWIN(window,640,400,TRUE) layout = LAYOUT(window,1,1,636,396,1) ' container for widgets this one is fixed , but here going to draw on it container = FIXED(layout,10,10,616,376,1)
WHILE (1) XNextEvent(d, &e)
IF (e.type == Expose) THEN expose = (XExposeEvent *)&(e) IF expose->count = 0 THEN Geometry(bac_widget_window(STR$(expose->window))) Check_Expose() RENDER_PATH(container,SVG$,5,5,163,0,117,150) RENDER_PATH(container,SVG$,200,5,0,163,117,150)
END IF
END IF
IF (e.type == ClientMessage) THEN client_message = (XClientMessageEvent *)&(e) 'PRINT "Closing Down" IF bac_widget_window_delete(STR$(client_message->window))=1 THEN IF ((Atom)e.xclient.data.l[0] == wm_delete_window) THEN PRINT "EXIT" FREE_SURFACES() XFlush(d) XCloseDisplay(d) BREAK END IF END IF END IF
WEND
|
|