parameters: (self, projection, minlat=46.5062, minlon=6.5506, maxlat=46.5264, maxlon=6.5903, useGoogle=True,
                   googleAPIKey='')
docstring: Initialize the projection.
docstring_summary: Initialize the projection.
docstring_tokens: Initialize the projection .
function: def __init__(self, projection, minlat=46.5062, minlon=6.5506, maxlat=46.5264, maxlon=6.5903, useGoogle=True,
                   googleAPIKey=''):
          """Initialize the projection."""
          x1, y1 = projection(minlon, minlat)
          x2, y2 = projection(maxlon, maxlat)
  
          Xmin = min(x1, x2)
          Xmax = max(x1, x2)
          Ymin = min(y1, y2)
          Ymax = max(y1, y2)
  
          Xdiff = Xmax - Xmin
          Ydiff = Ymax - Ymin
  
          xDiv = int(Xdiff / 30) + 1
          yDiv = int(Ydiff / 30) + 1
  
          self.xStep = Xdiff / xDiv
          self.yStep = Ydiff / yDiv
  
          # generate all the locations (lat and long array) in function of the X, Y grid
          locations = []
          for y in range(0, yDiv + 1):
              for x in range(0, xDiv + 1):
                  long, lat = projection(Xmax - x * self.xStep, y * self.yStep + Ymin, inverse=True)
                  long = float(format(long, '.7f'))  # we want to reduce precision in order to reduce the request url
                  lat = float(format(lat, '.7f'))
                  locations.append([lat, long])
  
          result = []
          if useGoogle and googleAPIKey:
              result = Elevation.get_elevation_from_google(locations, key=googleAPIKey)
          else:
              result = Elevation.get_elevation_from_geonames(locations, "cyberbotics")
  
          if not result:
              sys.stderr.write("Warning: the acquisition of the elevation data failed.\n")
              return
  
          # shift the height to have the minimum height been at altitude 0
          offset = min(result)
          for index in range(len(result)):
              result[index] = result[index] - offset
  
          self.floorString = ""
          self.floorString += "DEF FLOOR Solid {\n"
          self.floorString += "  translation %.2f %.2f 0\n" % (-Ydiff / 2, -Xdiff / 2)
          self.floorString += "  children [\n"
          self.floorString += "    DEF FLOOR_SHAPE Shape {\n"
          self.floorString += "      appearance PBRAppearance {\n"
          self.floorString += "        baseColorMap ImageTexture {\n"
          self.floorString += "          url [\n"
          self.floorString += f"            \"{GRASS_TEXTURE}\"\n"
          self.floorString += "          ]\n"
          self.floorString += "        }\n"
          self.floorString += "        roughness 1\n"
          self.floorString += "        metalness 0\n"
          scale = max(Xdiff, Ydiff)
          self.floorString += "        textureTransform TextureTransform {\n"
          self.floorString += "          scale %.2f %.2f\n" % (scale, scale)
          self.floorString += "        }\n"
          self.floorString += "      }\n"
          self.floorString += "      geometry ElevationGrid {\n"
          self.floorString += "        height [\n"
          for x in reversed(range(0, xDiv + 1)):
              self.floorString += "        "
              for y in reversed(range(0, yDiv + 1)):
                  self.floorString += str(result[x + y * (xDiv + 1)]) + " "
              self.floorString += "\n"
          self.floorString += "        ]\n"
          self.floorString += "        xDimension " + str(yDiv + 1) + "\n"
          self.floorString += "        xSpacing " + str(self.yStep) + "\n"
          self.floorString += "        yDimension " + str(xDiv + 1) + "\n"
          self.floorString += "        ySpacing " + str(self.xStep) + "\n"
          self.floorString += "      }\n"
          self.floorString += "    }\n"
          self.floorString += "  ]\n"
          self.floorString += "  boundingObject USE FLOOR_SHAPE\n"
          self.floorString += "}\n"
  
          self.elevationArray = []
          for x in range(0, xDiv + 1):
              for y in range(0, yDiv + 1):
                  self.elevationArray.append({
                      'x': Xmax - x * self.xStep,
                      'y': Ymin + y * self.yStep,
                      'height': result[x + y * (xDiv + 1)]
                  })
function_tokens: def __init__ ( self , projection , minlat = 46.5062 , minlon = 6.5506 , maxlat = 46.5264 , maxlon = 6.5903 , useGoogle = True , googleAPIKey = '' ) : x1 , y1 = projection ( minlon , minlat ) x2 , y2 = projection ( maxlon , maxlat ) Xmin = min ( x1 , x2 ) Xmax = max ( x1 , x2 ) Ymin = min ( y1 , y2 ) Ymax = max ( y1 , y2 ) Xdiff = Xmax - Xmin Ydiff = Ymax - Ymin xDiv = int ( Xdiff / 30 ) + 1 yDiv = int ( Ydiff / 30 ) + 1 self . xStep = Xdiff / xDiv self . yStep = Ydiff / yDiv # generate all the locations (lat and long array) in function of the X, Y grid locations = [ ] for y in range ( 0 , yDiv + 1 ) : for x in range ( 0 , xDiv + 1 ) : long , lat = projection ( Xmax - x * self . xStep , y * self . yStep + Ymin , inverse = True ) long = float ( format ( long , '.7f' ) ) # we want to reduce precision in order to reduce the request url lat = float ( format ( lat , '.7f' ) ) locations . append ( [ lat , long ] ) result = [ ] if useGoogle and googleAPIKey : result = Elevation . get_elevation_from_google ( locations , key = googleAPIKey ) else : result = Elevation . get_elevation_from_geonames ( locations , "cyberbotics" ) if not result : sys . stderr . write ( "Warning: the acquisition of the elevation data failed.\n" ) return # shift the height to have the minimum height been at altitude 0 offset = min ( result ) for index in range ( len ( result ) ) : result [ index ] = result [ index ] - offset self . floorString = "" self . floorString += "DEF FLOOR Solid {\n" self . floorString += "  translation %.2f %.2f 0\n" % ( - Ydiff / 2 , - Xdiff / 2 ) self . floorString += "  children [\n" self . floorString += "    DEF FLOOR_SHAPE Shape {\n" self . floorString += "      appearance PBRAppearance {\n" self . floorString += "        baseColorMap ImageTexture {\n" self . floorString += "          url [\n" self . floorString += f"            \"{GRASS_TEXTURE}\"\n" self . floorString += "          ]\n" self . floorString += "        }\n" self . floorString += "        roughness 1\n" self . floorString += "        metalness 0\n" scale = max ( Xdiff , Ydiff ) self . floorString += "        textureTransform TextureTransform {\n" self . floorString += "          scale %.2f %.2f\n" % ( scale , scale ) self . floorString += "        }\n" self . floorString += "      }\n" self . floorString += "      geometry ElevationGrid {\n" self . floorString += "        height [\n" for x in reversed ( range ( 0 , xDiv + 1 ) ) : self . floorString += "        " for y in reversed ( range ( 0 , yDiv + 1 ) ) : self . floorString += str ( result [ x + y * ( xDiv + 1 ) ] ) + " " self . floorString += "\n" self . floorString += "        ]\n" self . floorString += "        xDimension " + str ( yDiv + 1 ) + "\n" self . floorString += "        xSpacing " + str ( self . yStep ) + "\n" self . floorString += "        yDimension " + str ( xDiv + 1 ) + "\n" self . floorString += "        ySpacing " + str ( self . xStep ) + "\n" self . floorString += "      }\n" self . floorString += "    }\n" self . floorString += "  ]\n" self . floorString += "  boundingObject USE FLOOR_SHAPE\n" self . floorString += "}\n" self . elevationArray = [ ] for x in range ( 0 , xDiv + 1 ) : for y in range ( 0 , yDiv + 1 ) : self . elevationArray . append ( { 'x' : Xmax - x * self . xStep , 'y' : Ymin + y * self . yStep , 'height' : result [ x + y * ( xDiv + 1 ) ] } )