This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Imports a GPX file into the canonical KML file.""" | |
import os | |
import sys | |
import traceback | |
import gpxpy | |
import simplekml | |
from datetime import datetime, timezone | |
from dateutil.parser import parse | |
from lxml import etree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Calculates demographic gravitation for a spreadsheet of city data. | |
This script is specifically designed to work with the basic US cities | |
spreadsheet at https://simplemaps.com/data/us-cities. However, it could | |
be made to work with any spreadsheet of cities, latitudes, longitudes, | |
and populations as long as the sheet name and column names are updated | |
appropriately. | |
""" | |
import pandas as pd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns | |
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"> | |
<graph edgedefault="directed"> | |
<node id="99"/> | |
<node id="bottles"/> | |
<node id="of"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output = "" | |
bottles = 99 | |
def bottle_str(bottles): | |
if bottles == 0: | |
return "No bottles" | |
elif bottles == 1: | |
return "1 bottle" | |
else: | |
return f"{bottles} bottles" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/config/routes.rb | |
get "/flights/flights.gpx" => "flights#show_flight_gpx", as: :show_flight_gpx | |
get "/flights/flights.kml" => "flights#show_flight_kml", as: :show_flight_kml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/app/flights_controller.rb | |
def show_flight_gpx | |
flights = flyer.flights(current_user) | |
render xml: FlightsMap.new(flights).gpx | |
end | |
def show_flight_kml | |
flights = flyer.flights(current_user) | |
render xml: FlightsMap.new(flights).kml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/app/classes/map.rb | |
def kml | |
@airport_details ||= airport_details | |
used_airports = @airport_details.keys | |
output = %Q(<?xml version="1.0" encoding="UTF-8" ?>).html_safe | |
output += content_tag(:kml, xmlns: "http://www.opengis.net/kml/2.2") do | |
content_tag(:Document) do | |
concat content_tag(:name, map_name) | |
concat content_tag(:description, map_description) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/app/classes/map.rb | |
def kml_routes(routes, name) | |
return nil unless routes.any? | |
routes = routes.map{|r| r.sort_by{|x| @airport_details[x][:iata]}}.uniq.sort_by{|y| [@airport_details[y[0]][:iata], @airport_details[y[1]][:iata]]} | |
return content_tag(:Folder) do | |
concat content_tag(:name, name) | |
concat safe_join(routes.map{|r| kml_route(r)}) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/app/classes/map.rb | |
def kml_airports(airports) | |
airports = airports.sort_by{|a| @airport_details[a][:iata]} | |
return content_tag(:Folder) do | |
concat content_tag(:name, "Airports") | |
concat safe_join(airports.map{|a| kml_airport(a)}) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/app/classes/map.rb | |
def kml_styles | |
output = content_tag(:Style, id: "airportMarker") do | |
content_tag(:Icon) do | |
content_tag(:href, "http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png") | |
end | |
end | |
output += content_tag(:Style, id: "flightPath") do | |
content_tag(:LineStyle) do |
NewerOlder