Salut, je me réponds à moi-même.
J'ai donc réussi (grâce à mes pérégrinations sur ce forum et à partir de ce code (voir ci-après)) à créer un programme qui travaille en deux temps:
1er temps : préparation
- Récupération par api des communes situées dans un quadrilatère (via openstreetmap)
- mise en forme du fichier jason
- création d'un fichier de travail qui contient les coordonnées lat et long, nom, code postal, population, référence insee (année du recensement).
2eme temps : calcul
- a partir du fichier de travail, récupération des informations injectées via api googlemap avec création d'un fichier json (obligation d'ajouter un délai car si cela va trop vite, le serveur bloque devant des requêtes trop proches les unes des autres).
- extraction des données temps et distance de ce fichier
- élaboration d'un fichier csv qui contient la ville de départ puis les temps/distance à partir de cette ville vers toutes les communes référencées dans le quadrilatère défini en phase 1.
Suivant la taille du quadrilatère et donc des communes à calculer, cela peut prendre quelques minutes pour finaliser l'action de la phase 2 (à cause du délai imposé). Il y a aussi un probleme de limite de requêtes journalière car je n'ai pas de key... (à voir).
Il me reste à peaufiner tout cela, optimiser le code et créer une carte anamorphe à partir de ces données. Il est possible qu'il y ait plus facile ou plus simple, mais j'ai beaucoup cherché et pas trouvé d'autres pistes sur cette recherche particulière.
Code qui m'a servi à dénouer fa faisabilité de mon projet :
Ce n'est pas mon code (mais celui trouvé dans un package intitulé
HTTPGetFromWeb mais la base (je mettrai le mien dès que j'aurai fait le ménage):
Code : Tout sélectionner
IncludeFile #PB_Compiler_FilePath + "..\HTTPGetFromWeb.pb"
Define tHTTP.T_HTTP_GET
Define Temp1.String, Temp2.String
Define iRetVal
Procedure MyCallStart (*tHTTP.T_HTTP_GET, hRequest)
Protected Text$, iCount
Protected Buffer$ = Space(1024), iStringBufferSize = 1024
Text$ = "-> MyCallStart() called ... this means the download is about to start."
Debug Text$
Debug ""
Text$ = "You can access all params stored in *tHTTP here."
Debug Text$
Text$ = "And you can access the handle of the HTTP request using HttpQueryInfo(), if you care."
Debug Text$
Debug ""
; *** Example of querying various info ***
Debug "#HTTP_QUERY_RAW_HEADERS_CRLF = "
If (HttpQueryInfo_(hRequest, #HTTP_QUERY_RAW_HEADERS_CRLF, @Buffer$, @iStringBufferSize, #Null))
Repeat
iCount + 1
Text$ = StringField(Buffer$, iCount, #CR$)
If Left(Text$, 1) = #LF$
Text$ = Right(Text$, Len(Text$) - 1)
EndIf
Debug Text$
If Len(Text$) = 0: Break: EndIf
ForEver
EndIf
If (HttpQueryInfo_(hRequest, #HTTP_QUERY_CONTENT_TYPE, @Buffer$, @iStringBufferSize, #Null))
Debug "HTTP_QUERY_CONTENT_TYPE = " + Buffer$
EndIf
If (HttpQueryInfo_(hRequest, #HTTP_QUERY_CONTENT_LENGTH , @Buffer$, @iStringBufferSize, #Null))
Debug "HTTP_QUERY_CONTENT_LENGTH = " + Buffer$
EndIf
If (HttpQueryInfo_(hRequest, #HTTP_QUERY_STATUS_CODE, @Buffer$, @iStringBufferSize, #Null))
Debug "HTTP_QUERY_STATUS_CODE = " + Buffer$
EndIf
If (HttpQueryInfo_(hRequest, #HTTP_QUERY_STATUS_TEXT, @Buffer$, @iStringBufferSize, #Null))
Debug "HTTP_QUERY_STATUS_TEXT = " + Buffer$
EndIf
Debug ""
Text$ = "-> MyCallStart() ends here"
Debug Text$
Debug ""
EndProcedure
Procedure MyCallEnd (*tHTTP.T_HTTP_GET, iRetVal, iBytesReceived, iSize, iElapsedTime)
Protected Text$
Text$ = "-> MyCallEnd (ErrCode = " + Str(iRetVal) + ", Bytes = " + Str(iBytesReceived) + ", Size = " + Str(iSize) + ", Elapsed = " + Str(iElapsedTime) + ")"
Debug ""
Debug Text$
EndProcedure
Procedure.i MyCallWorking (*tHTTP.T_HTTP_GET, iBytesReceived, iSize, iElapsedTime)
Protected Text$
Text$ = "-> MyCallBack (Bytes = " + Str(iBytesReceived) + ", Size = " + Str(iSize) + ", Elapsed = " + Str(iElapsedTime) + ")"
If (iElapsedTime > 0)
Text$ + " - Speed = " + Str (iBytesReceived / iElapsedTime / 1024) + " KB/sec"
EndIf
Debug Text$
ProcedureReturn #True ; return #False to abort download
EndProcedure
; error 404 example
; tHTTP\URL$ = "http://www.somedomain.com/foo/bar.zip"
; content length unknown and automatic redirection enabled example
; tHTTP\URL$ = "http://finance.yahoo.com/d/quotes.csv?s=MVC+MIDD+BWLD+AAPL&f=sl1d1t1"
; try to test again the above URL but this time disabling redirection with
; tHTTP\iFlags = #INTERNET_FLAG_NO_UI | #INTERNET_FLAG_RELOAD | #INTERNET_FLAG_NO_AUTO_REDIRECT
tHTTP\URL$ = "http://www.purebasic.com/download/PureBasic_Demo.exe"
tHTTP\iThreadID = 0
tHTTP\iDestination = #WEB_WRITE_TO_FILE
tHTTP\iChunkSize = 512*1024 ; 512 KB
tHTTP\fpCB_Start = @MyCallStart()
tHTTP\fpCB_Working = @MyCallWorking()
tHTTP\fpCB_End = @MyCallEnd()
tHTTP\FullFileName$ = GetTemporaryDirectory() + "PureBasic_Demo.exe"
URLGetDomain (tHTTP\URL$, @Temp1)
Debug "URLGetDomain = " + Temp1\s
URLGetFullPath (tHTTP\URL$, @Temp1)
Debug "URLGetFullPath = " + Temp1\s
URLGetBasicAuth (tHTTP\URL$, @Temp1, @Temp2)
Debug "URLGetBasicAuth = " + Temp1\s + ":" + Temp2\s
Debug ""
iRetVal = HTTPGetFromWeb (@tHTTP)
Debug ""
Select iRetVal
Case #WEB_OK
Debug "HTTPGetFromWeb() successful."
Debug Str(tHTTP\iTotBytesRead) + " bytes read from Internet."
Select tHTTP\iDestination
Case #WEB_WRITE_TO_MEMORY
Debug Str(MemorySize(tHTTP\DestBuffer)) + " bytes currently allocated in memory."
Case #WEB_WRITE_TO_FILE
Debug Str(tHTTP\iTotBytesRead) + " bytes written to " + tHTTP\FullFileName$
EndSelect
Case #WEB_ERR_HTTP_OPEN
Debug "Error initializing the WININET.DLL API."
Case #WEB_ERR_HTTP_CONNECT
Debug "Error opening the session to the given site."
Case #WEB_ERR_HTTP_SET_PROXY
Debug "Error setting the options for the proxy server."
Case #WEB_ERR_HTTP_HTTP_OPEN
Debug "Error creating the HTTP request handle."
Case #WEB_ERR_HTTP_HTTP_SEND
Debug "Error sending the HTTP request to the server."
Case #WEB_ERR_HTTP_HTTP_QUERY_STATUS
Debug "Error retrieving the HTTP status code."
Case #WEB_ERR_HTTP_READ
Debug "Error reading data from the opened session."
Case #WEB_ERR_HTTP_CLOSE
Debug "Error closing the Internet handle."
Case #WEB_ERR_HTTP_BASIC_AUTH
Debug "Error setting the options for basic authentication."
Case #WEB_ERR_HTTP_STATUS
Debug "HTTP status code = " + Str(tHTTP\iErrorCodeEx)
Case #WEB_ERR_FILE_CREATION
Debug "Cannot create the file " + tHTTP\FullFileName$
Case #WEB_ERR_FILE_IO
Debug "Error writing to the file " + tHTTP\FullFileName$
Case #WEB_ERR_INVALID_PARAMETERS
Debug "Check procedure parameters."
Case #WEB_ERR_OUT_OF_MEMORY
Debug "Out of memory."
Case #WEB_ERR_USER_ABORT
Debug "Download aborted."
Default
Debug "Unexpected error = " + Str(iRetVal)
EndSelect
; IDE Options = PureBasic 5.10 Beta 5 (Windows - x86)
; Folding = -
; EnableThread
; CPU = 1
; CompileSourceDirectory
; EnableBuildCount = 0