[PYTHON] Find a building on Google Earth that is the same height as Shingodzilla

Shin Godzilla is amazingly powerful. It seems that there is also 118.5m. On the other hand, in Tokyo, where skyscrapers are lined up, there are many buildings that are taller than that. Tokyo Midtown seems to be 248m long, and Shingodzilla is no longer even half that size.

Is Shingodzilla really big or small? I'm not sure what it is, so I used Google Earth API and Selenium to search for a building of the same height in the 23 wards of Tokyo in order to get an idea of how big it is.

Google Earth

midtown.png

The image above is when you hover over Tokyo Midtown on Google Earth. At the bottom, the altitude (269m) is displayed in addition to the latitude and longitude, and the height of the building is obtained by subtracting the sea level altitude from this. Google Earth uses a technology called aerial photogrammetry to determine the altitude of buildings around the world.

Google Earth does not have a Web API, but it does provide a Javascript API that allows you to get information about that location via an event. This API is currently Depricated and will be discontinued at the end of 2016, so those who use the data may want to acquire it early. There is no open data for building altitude information, and I think it is difficult to obtain it outside of Google Earth.

Get the altitude of the clicked point with Javascript API

First of all, use the Javascript API to display Google Earth in the browser so that you can get the information of that point by clicking it. This time, if you specify latitude and longitude in the query parameter like / path / to / index.html? Lat = 35.820 & lon = 139.555, a map of 5km x 5km with that point as the upper left is displayed. I tried to do it. Since this is placed on 1,000px x 1,000px, it is 5m per 1px.

index.html


<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Google Earth API</title>
    <style>
      body { width: 1000px; height: 1000px; margin: 0; }
      #map3d { height: 100%; }
    </style>
  </head>
  <body>
    <div id="map3d" />
    <script src="https://www.google.com/jsapi"></script>
    <script src="map.js"></script>
  </body>
</html>

map.js


google.load('earth', '1', { other_params: 'sensor=false' })

const results = []

google.setOnLoadCallback(() => {
  google.earth.createInstance('map3d', earth => {
    earth.getWindow().setVisibility(true)
    earth.getLayerRoot().enableLayerById(earth.LAYER_BUILDINGS, true)

    //parse query string.g., /path/to/index.html?lat=35.820&lon=139.555
    const params = location.search.split('?')[1].split('&')
    const [lat, lng] = params.map(param => parseFloat(param.split('=')[1]))
    
    const globe = earth.getGlobe()
    const lookAt = earth.createLookAt('')

    //Screen display range(m)
    lookAt.setRange(5000)

    // lat,Fixed lng to be located at the top left of the screen(Center by default)
    lookAt.setLatitude(lat - 0.025844962203145)
    lookAt.setLongitude(lng + 0.03188911376511783)

    earth.getView().setAbstractView(lookAt)

    //Set click event
    google.earth.addEventListener(globe, 'click', event => {
      const info = {
        latitude: event.getLatitude(),
        longitude: event.getLongitude(),
        altitude: event.getAltitude()  //Altitude
      }
      info.groundAltitude = globe.getGroundAltitude(info.latitude, info.longitude)  //Sea level altitude
      console.log(info)
      results.push(info)
    })
  }, () => {
    console.error('fail!')
  })
})

If you install the Google Earth plug-in on your browser and display it, a map starting from the specified latitude and longitude will be displayed as shown in the figure below. Also, if you click somewhere on the map, you can see that the information of that point is output to the console.

スクリーンショット 2016-08-21 0.30.27.png

Automate click events with Selenium

Now that you can get the information by clicking, let's make Selenium pop by 1px. In this case, the altitude will be acquired every 5m, which is 1,000px x 1,000px, so it will be 1 million clicks.

getAltitude.py


#!/usr/bin/env python
# -*- coding:utf-8 -*-

from selenium import webdriver
import argparse
import time

def main():
    url = parse_args()
    browser = webdriver.Firefox()
    browser.get(url)
    map_element = browser.find_element_by_id('map3d')

    time.sleep(20)  # Allow google earth plugin while this time

    for x in xrange(1000):
        for y in xrange(1000):
            print x, y
            action = webdriver.common.action_chains.ActionChains(browser)
            action.move_to_element_with_offset(map_element, x, y).click().perform()
        results = browser.execute_script("return results;")
        with open('{}.csv'.format(url.split('?')[1]), 'a') as f:
            for d in results:
                f.write('{latitude},{longitude},{altitude},{groundAltitude}\n'.format(**d))
        browser.execute_script("results = [];")

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('-u', '--url', type=str, required=True, help='url path')
    args = parser.parse_args()
    return args.url

if __name__ == '__main__':
    main()

If you execute the following, Firefox will start up and Selenium will start clicking after 20 seconds. During this 20 seconds, please allow the Google Earth plugin. I'd really like to run it on the server using a headless browser such as PhantomJS, but I couldn't put the Google Earth plugin in them, so I did my best locally.

python getAltitude.py --url /path/to/index.html?lat=35.820\&lon=139.555

When the execution is completed, the following csv file will be generated, and the columns of latitude, longitude, altitude, and sea level will be lined up in 1 million rows.

35.8201681437,139.554803147,11.4957876807,11.4957887253
35.8201160743,139.55480317,11.495894997,11.4958948098
35.8200640214,139.554803208,11.4960015882,11.4960015454
35.8200119787,139.55480324,11.4961081794,11.4961079175
35.8199599214,139.554803282,11.4962147706,11.4962156907
...

We found that the 23 wards of Tokyo could be covered by 36 5km x 5km squares (30km x 30km squares), so we performed this procedure in each section and obtained a total of 36 million point information (about 2GB).

23wards.png

Acquire a building that is the same height as Shin Godzilla

Finally, the latitude and longitude of the building at the same height (118m to 119m) as Shingodzilla was acquired from the acquired data.

In [1]: import csv

In [2]: for l in csv.reader(open('/path/to/csv')):
   ...:     if 118 < float(l[2]) - float(l[3]) < 119:
   ...:         print l[0], l[1]

We got about 1,000 lines of output. Since they are clicked at 5m intervals, many of them are popping the same building many times, and the number of buildings is much smaller than the number of rows.

35.5497718126 139.67314824
35.5499246984 139.673900422
35.5498233084 139.673962201
35.549719274 139.676315323
35.5498629383 139.676696309
...

I sampled the acquired data and checked some of them on Google Map.

35.6704993 139.7551047:It was the Togoku Seimei Building, a 29-story building in Hibiya. According to Wikipedia, the height is 120m, so it's about the same height as Shingodzilla.




#### **`35.6884934,139.6947538:It was a 30-story building in Shinjuku called the Monolith Building. 123 on Wikipedia.It was written as 35m, which was a little larger than Shingodzilla. In addition, Wikipedia also has the following description, and it seems that it has already been destroyed by Godzilla.`**

In "Godzilla vs King Ghidorah" released in 1991, a scene destroyed by Godzilla was drawn.

It was only a short time since I came to Tokyo, and there were many buildings I didn't know about, so the results didn't really deepen my image, but I knew that it was about the same height as a 30-story building, and Shingodzilla said, "Somewhat. I got the knowledge that it is huge.

Recommended Posts

Find a building on Google Earth that is the same height as Shingodzilla
Note that the Google Maps Android API GoogleMap.getProjection is not a singleton
A program that searches for the same image
Building multiple Python environments on the same system
The Linux emulator "iSH" that runs on the iPad is a hot topic in me
When a local variable with the same name as a global variable is defined in the function
Building a TensorFlow environment that uses GPU on Windows 10
Find the part that is 575 from Wikipedia in Python
Is there a bias in the numbers that appear in the Fibonacci numbers?
Use the graphic LCD as a character LCD that can also display Chinese characters on the Rasberry Pi