from stl import mesh
import numpy as np
import requests
import math
import time
import json

# Coordonnées GPS (latitude, longitude) du point dont vous souhaitez obtenir l'altitude
latitudeStart = 44.903360
longitudeStart = 5.356751

deplacement_metres = 100

facteur = deplacement_metres

lenX=10
lenY=10

import math

test=[1430.0, 1369.85, 1298.29, 1229.3, 1175.09, 1138.52, 1124.26, 1105.4, 1095.02, 1082.01, 1422.49, 1349.6, 1284.16, 1210.23, 1150.72, 1114.83, 1097.72, 1091.05, 1078.23, 1069.26, 1414.12, 1336.12, 1270.67, 1190.59, 1125.19, 1096.12, 1082.26, 1073.76, 1063.9, 1058.02, 1402.96, 1340.04, 1267.52, 1164.27, 1101.05, 1080.91, 1072.28, 1064.41, 1056.36, 1051.67, 1381.24, 1321.08, 1247.24, 1137.52, 1083.51, 1074.58, 1067.2, 1054.67, 1048.43, 1047.06, 1355.6, 1297.31, 1215.26, 1115.71, 1084.07, 1077.54, 1059.52, 1047.86, 1044.04, 1043.31, 1326.47, 1265.13, 1183.72, 1107.97, 1083.95, 1067.03, 1054.31, 1044.21, 1041.29, 1041.12, 1296.84, 1233.47, 1162.75, 1111.98, 1088.34, 1069.63, 1055.8, 1045.91, 1042.01, 1040.87, 1272.49, 1214.92, 1160.39, 1117.79, 1086.36, 1067.9, 1057.78, 1048.49, 1043.65, 1041.59, 1261.53, 1207.49, 1164.9, 1121.47, 1088.72, 1073.59, 1062.01, 1057.08, 1055.04, 1056.71]
"""
latitude=latitudeStart
for j in range (0,lenX):
	longitude=longitudeStart
	print(j,"/",lenX)
	for i in range (0,lenY):
		altitude = alt(latitude,longitude)
		# print(latitude,",",longitude)
		# print(altitude)
		longitude=longitudePlus(longitude,deplacement_metres)
		test.append(altitude)
		# time.sleep(0.1)
	latitude=latitudePlus(latitude,deplacement_metres)

print(latitude,",",longitude)

print(test)
"""
test = [nombre / facteur for nombre in test]
mini=min(test)-1
test = [nombre - mini for nombre in test]

vertices = np.zeros((lenX*lenY * 2,3) , dtype=float)
y=0
for i in range (0,lenX):
	for j in range (0,lenY):
		vertices[y]= [i,j,0]
		vertices[y+1]= [i,j,test[i*lenY+j]]
		y=y+2



nb=(lenX*2-2)
faces1 = np.zeros((nb, 3), dtype=int)
y=0
for i in range(0,lenX*2-2,2):
	faces1[y] = [i,i+1 ,i+2]
	faces1[y+1] = [i+1 ,i+3,i+2]
	y=y+2



nb=lenY*2-2
faces2 = np.zeros((nb, 3), dtype=int)
y=0
for i in range(0,lenX*2*lenY-lenY*2 ,lenX*2):
	faces2[y] 	= [i,i+1,i+lenX*2]
	faces2[y+1] = [i+1,i+lenX*2+1,i+lenX*2]
	y=y+2

nb=(lenX*2-2)
Start3 = (lenX*2*lenY)-lenX*2
faces3 = np.zeros((nb, 3), dtype=int)
y=0
for i in range(Start3,lenX*2-2+Start3,2):
	print(i)
	faces3[y] = [i,i+1 ,i+2]
	faces3[y+1] = [i+1,i+3 ,i+2]
	y=y+2

nb = lenY*2-2
Start4 = lenX*2-2
faces4 = np.zeros((nb, 3), dtype=int)
y=0
for i in range(Start4,lenX*2*lenY-lenY*2+Start4,lenX*2):
	faces4[y] 	= [i,i+1,i+lenX*2]
	faces4[y+1] = [i+1,i+lenX*2+1,i+lenX*2]
	y=y+2

nb = 2
faces5 = np.zeros((nb,3), dtype=int)
faces5[0] =[0,lenX*2-2,(lenX*2*lenY)-lenX*2]
faces5[1] =[lenX*2-2,lenX*lenY*2-2,(lenX*2*lenY)-lenX*2]


nb=lenX*lenY*2
faces6 = np.zeros((nb,3), dtype=int)
y=0
for j in range(0,lenY-1):
	for i in range(lenX*2*j+1,lenX*2*j+lenX*2-1,2):
		faces6[y]=[i,i+2,lenX*2+i]
		faces6[y+1]=[i+2,lenX*2+i+2,lenX*2+i]
		y=y+2

faces=np.concatenate((faces1, faces2,faces3,faces4,faces5,faces6), axis=0)


# Créez le maillage STL
cube = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))

for i, f in enumerate(faces):
    for j in range(3):
        cube.vectors[i][j] = vertices[f[j], :]

#Sauvegardez le cube au format STL
cube.save('IGN.stl')

#"""
