try: import bpaTools except ImportError: ### Include local modules/librairies ## import os import sys module_dir = os.path.dirname(__file__) aixmParserLocalSrc = "../../aixmParser/src/" sys.path.append(os.path.join(module_dir, aixmParserLocalSrc)) import bpaTools from frenchConfig import * ### Context applicatif #### appName = bpaTools.getFileName(__file__) appPath = bpaTools.getFilePath(__file__) appVersion = bpaTools.getVersionFile() appId = appName + " v" + appVersion inpPath = appPath + "../input/" outPath = appPath + "../output/" logFile = outPath + "_" + appName + ".log" def createGeoJsonFile(sFileSrc, sCountryName, sCountryCode, sCountryIsoCode, sCountryDepCode, oArea, iIdx=-1) -> None: if iIdx==-1: sName = sCountryName elif iIdx>-1 and sCountryName=="France": sName = oFranceNames.get(str(iIdx), str(iIdx)) else: sName = str(iIdx)
#!/usr/bin/env python3 import sys import bpaTools import aixmReader ### Context applicatif bpaTools.ctrlPythonVersion() __AppName__ = bpaTools.getFileName(__file__) __AppPath__ = bpaTools.getFilePath(__file__) __AppVers__ = bpaTools.getVersionFile() ___AppId___ = __AppName__ + " v" + __AppVers__ __OutPath__ = __AppPath__ + "../out/" __LogFile__ = __OutPath__ + "_" + __AppName__ + ".log" bpaTools.createFolder(__OutPath__) #Init dossier de sortie def syntaxe(): print("Aeronautical Information Exchange Model (AIXM) Converter") print( "Call: " + __AppName__ + " <[drive:][path]filename> <Format> <Type> [<Type2> ... <TypeN>] [<Option(s)>]" ) print("With:") print(" <[drive:][path]filename> AIXM source file") print("") print(" <Format> - Output formats:") print(" " + aixmReader.CONST.frmtGEOJSON + " GeoJSON for GoogleMap") print(" " + aixmReader.CONST.frmtOPENAIR + " OpenAir for aeronautical software")
#!/usr/bin/env python3 import bpaTools import aixm2json from shapely.geometry import Point #Polygon, mapping from pyproj import Proj, transform __ClsName__ = bpaTools.getFileName(__file__) class Aixm2jsonTst: def __init__(self, oCtrl): bpaTools.initEvent(__file__, oCtrl.oLog) self.oCtrl = oCtrl self.oAixm2json = aixm2json.Aixm2json4_5(oCtrl) print() self.oCtrl.oLog.info("Tests de génération Geojson", outConsole=True) return def testAll(self): self.tstGeojsonPosition() self.tstGeojsonArcHorAntihor() self.tstGeojsonZonesCTR_LORIENT() self.tstGeojsonObjects() self.oCtrl.oLog.info("Fin des tests", outConsole=True) return """ Contrôle d'interprétation des positionnements depuis une source 'aixm' """
def getGroundEstimatedHeight(self, oZone) -> list: oCoordinates = self.getCoordinates(oZone) if not isinstance(oCoordinates, list): #self.oLog.critical("float err: No coordinates found {}".format(oZone)) return 0, {} lon = [] lat = [] try: for o in oCoordinates: lat.append(o[0]) lon.append(o[1]) except Exception as e: sHeader = "[" + bpaTools.getFileName( __file__ ) + "." + self.getGroundEstimatedHeight.__name__ + "()] " sMsg = "/!\ Estimated height Error - AreaRef={0}".format(oZone) raise Exception(sHeader + sMsg + " / " + str(e)) #Estimation d'un carré représentatif de la zone latMin = min(lat) #Bottom segment of square latMax = max(lat) #Top segment of square lonMin = min(lon) #Left segment of square lonMax = max(lon) #Right segment of square #self.oLog.info("Data: sZoneUId={} - lonMin={} - lonMax={} - latMin={} - latMax={}\nCoordinate={}".format(sZoneUId, lonMin, lonMax, latMin, latMax, oCoordinates), outConsole=False) #Définition d'une suite de coordonnées pour représenter la surface de la zone carré step = 10 latSerial = np.linspace( latMin, latMax, step) #10 nombres établies entre la valeur mini et maxi lonSerial = np.linspace( lonMin, lonMax, step) #10 nombres établies entre la valeur mini et maxi #self.oLog.info("lonMin={} - lonMax={} - latMin={} - latMax={} \nlonSerial={} \nlatSerial={}".format(lonMin, lonMax, latMin, latMax, lonSerial, latSerial), outConsole=False) #Définition d'une ligne (type serpentin) qui parcours la surface de la zone line = [] switch = True for latIdx in range(0, step): if switch: for lonIdx in range(0, step, 1): line.append([latSerial[latIdx], lonSerial[lonIdx]]) else: for lonIdx in range(step, 0, -1): line.append([latSerial[latIdx], lonSerial[lonIdx - 1]]) switch = not switch #self.oLog.info("line={}\n".format(line), outConsole=False) #Détermination des hauteurs terrain des 100 points (=step*step) qui couvre la zone géographique #srtm library documentation - https://pypi.org/project/SRTM.py/ aElevation = [] lastElevation = 0 lCptNullValue = 0 lCptError = 0 for o in line: #sample: elevation_data.get_elevation(48.694548, 2.333953) lElevation = self.elevation_data.get_elevation(o[1], o[0]) if lElevation == None: lCptError += 1 lElevation = lastElevation if lElevation > 0: lastElevation = lElevation aElevation.append(lElevation) elif lElevation == 0 and lCptNullValue == 0: lCptNullValue += 1 aElevation.append(lElevation) #self.oLog.info("aElevation={}".format(aElevation), outConsole=False) if lCptError > 60: print( "{0} errors in call elevation_data.get_elevation() - name={1}". format(lCptError, oZone[self.sProp]["name"])) self.oLog.warning( "{0} errors in call elevation_data.get_elevation()\nProperties={1}\naElevation{2}" .format(lCptError, oZone[self.sProp], aElevation), outConsole=False) eSortedElevation = sorted(aElevation) idxMedium = int(len(eSortedElevation) / 2) idxRetain = int(idxMedium + (idxMedium * (2 / 3))) lAltMin = eSortedElevation[0] lAltMax = eSortedElevation[len(eSortedElevation) - 1] lAltMed = eSortedElevation[idxMedium] lAltRet = eSortedElevation[ idxRetain] #Valeur retenue pour l'estimation globale de la hauteur sol #¤Contruction d'une description geoJSON de la ligne de calcul d'élévations #self.oLog.info("oZone=\n{}".format(str(oZone).replace(chr(39),chr(34))), outConsole=False) geoJSON = [] geoJSON.append(oZone) prop = {} prop.update({"name": "Square line"}) prop.update({"lAltMin": lAltMin}) prop.update({"lAltMax": lAltMax}) prop.update({"lAltMed": lAltMed}) prop.update({"lAltRet": lAltRet}) prop.update({"elevationArray": aElevation}) prop.update({"sortedElevationArray": eSortedElevation}) geoJSON.append({ "type": "Feature", "properties": prop, "geometry": { "type": "LineString", "coordinates": line } }) #self.oLog.info("geoJSON=\n{}".format(str(geoJSON).replace(chr(39),chr(34))), outConsole=False) return [lAltMin, lAltMed, lAltRet, lAltMax], geoJSON
oLog.info("{}".format(sMsg), outConsole=True) bpaTools.writeTextFile(sOutPath + sOutFile, sAllOpenair) ###(end) Phase 2a - Consolidation de tous les parcs dans un unique fichier pour traitement automatisé via poaff ###(deb) Phase 2b - Construction de l'aixm et des fichiers assimilés sur la base des parcs consolidés sInPath: str = sOutPath sOutPath: str = sInPath + "map/" makeAllFiles(sInPath, sOutFile, sOutPath, cstPoaffInPath) ###(fin) Phase 2b - Construction de l'aixm et des fichiers assimilés sur la base des parcs consolidés return if __name__ == '__main__': ### Context applicatif callingContext: str = "Paragliding-OpenAir-FrenchFiles" #Your app calling context appName: str = bpaTools.getFileName(__file__) appPath: str = bpaTools.getFilePath(__file__) #or your app path appVersion: str = "1.1.2" #or your app version appId: str = appName + " v" + appVersion cstPoaffInPath: str = "../../input/" cstPoaffOutPath: str = "../../output/" logFile: str = cstPoaffOutPath + "_" + appName + ".log" sFilterClass: list = None sFilterType: list = None sFilterName: list = None oLog = bpaTools.Logger(appId, logFile) oLog.resetFile() mOpenairEpsilonReduce: float = -1 epsilonReduce: bool = True #Normaly = True or False for generate without optimization
def getGroundEstimatedHeight(self, oZone) -> list: oCoordinates = self.getCoordinates(oZone) if not isinstance(oCoordinates, list): #self.oLog.critical("float err: No coordinates found {}".format(oZone)) return 0,{} lat = [] lon = [] try: for o in oCoordinates: lat.append(o[0]) lon.append(o[1]) except Exception as e: sHeader = "[" + bpaTools.getFileName(__file__) + "." + self.getGroundEstimatedHeight.__name__ + "()] " sMsg = "/!\ Estimated height Error - AreaRef={0}".format(oZone) raise Exception(sHeader + sMsg + " / " + str(e)) #Estimation d'un carré représentatif de la zone latMin = min(lat) #Bottom segment of square latMax = max(lat) #Top segment of square lonMin = min(lon) #Left segment of square lonMax = max(lon) #Right segment of square #self.oLog.info("Data: sZoneUId={} - lonMin={} - lonMax={} - latMin={} - latMax={}\nCoordinate={}".format(sZoneUId, lonMin, lonMax, latMin, latMax, oCoordinates), outConsole=False) #Définition d'une suite de coordonnées pour représenter la surface de la zone carré step = 10 latSerial = np.linspace(latMin, latMax, step) #10 nombres établies entre la valeur mini et maxi lonSerial = np.linspace(lonMin, lonMax, step) #10 nombres établies entre la valeur mini et maxi #self.oLog.info("lonMin={} - lonMax={} - latMin={} - latMax={} \nlonSerial={} \nlatSerial={}".format(lonMin, lonMax, latMin, latMax, lonSerial, latSerial), outConsole=False) #Définition d'une ligne (type serpentin) qui parcours la surface de la zone line = [] switch=True for latIdx in range(0, step): if switch: for lonIdx in range(0, step, 1): line.append([latSerial[latIdx], lonSerial[lonIdx]]) else: for lonIdx in range(step, 0, -1): line.append([latSerial[latIdx], lonSerial[lonIdx-1]]) switch = not switch #self.oLog.info("line={}\n".format(line), outConsole=False) #Détermination des hauteurs terrain des 100 points (=step*step) qui couvre la zone géographique aElevation:list = [] aRet:list = [] lastElevation = 0 lCptNullValue = 0 lCptError = 0 for o in line: #lElevation:float = self.getElevation(o[1], o[0]) #for map lElevation:float = self.elevation_data.get_elevation(o[1], o[0]) #operational if lElevation==None: lCptError += 1 lElevation = lastElevation elif lElevation>0: lastElevation = lElevation aElevation.append(lElevation) elif lElevation==0 and lCptNullValue==0: lCptNullValue += 1 aElevation.append(lElevation) #self.oLog.info("aElevation={}".format(aElevation), outConsole=False) #if lCptError > 90: # #print("{0} errors in call elevation_data.get_elevation() - name={1}".format(lCptError, oZone[self.sProp]["nameV"])) # self.oLog.warning("{0} errors in call elevation_data.get_elevation()\nProperties={1}\naElevation={2}".format(lCptError, oZone[self.sProp], aElevation), outConsole=False) if not aElevation: #Tableau vide ! --> '100 errors in call elevation_data.get_elevation()' sMsg:str = "{0} errors in call elevation_data.get_elevation() --> Properties={1}".format(lCptError, oZone[self.sProp]) sMsg += "\n(debug) --> Area coordinates={0}".format(line) self.oLog.error(sMsg, outConsole=False) aRet = defEstimHeight else: eSortedElevation = sorted(aElevation) idxMedium = int(len(eSortedElevation)/2) idxRetain = int(idxMedium+(idxMedium*(2/3))) lAltMin = eSortedElevation[0] lAltMax = eSortedElevation[-1] lAltMed = eSortedElevation[idxMedium] lAltRet = eSortedElevation[idxRetain] #Valeur retenue pour l'estimation globale de la hauteur sol aRet = [lAltMin,lAltMed,lAltRet,lAltMax] geoJSON = [] geoJSON.append(oZone) prop = {} prop.update({"nameV":"Square line"}) prop.update({"lAltMin":aRet[0]}) prop.update({"lAltMed":aRet[1]}) prop.update({"lAltRet":aRet[2]}) prop.update({"lAltMax":aRet[3]}) #prop.update({"elevationArray":aElevation}) #prop.update({"sortedElevationArray":eSortedElevation}) geoJSON.append({"type":"Feature", "properties":prop, "geometry":{"type":"LineString", "coordinates":line}}) return aRet, geoJSON