Skip to content

Assignment 10 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added exit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
168 changes: 168 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@

<!DOCTYPE html>
<head>


<meta http-equiv="content-type" content="text/html; charset=UTF-8" />



<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>





<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>





<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>





<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.min.js"></script>





<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"></script>





<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"></script>





<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />





<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />





<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" />





<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" />





<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css" />





<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css" />





<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css" />





<link rel="stylesheet" href="https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css" />




<style>

html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}

#map {
position:absolute;
top:0;
bottom:0;
right:0;
left:0;
}
</style>



<style> #map_d679cdfe31684aa7a59e819ed92f5011 {
position : relative;
width : 100.0%;
height: 100.0%;
left: 0.0%;
top: 0.0%;
}
</style>



</head>
<body>



<div class="folium-map" id="map_d679cdfe31684aa7a59e819ed92f5011" ></div>



</body>
<script>




var southWest = L.latLng(-90, -180);
var northEast = L.latLng(90, 180);
var bounds = L.latLngBounds(southWest, northEast);

var map_d679cdfe31684aa7a59e819ed92f5011 = L.map('map_d679cdfe31684aa7a59e819ed92f5011', {
center:[33.4484,-112.074],
zoom: 10,
maxBounds: bounds,
layers: [],
crs: L.CRS.EPSG3857
});




var tile_layer_208be8042bd44a41a836f7f736aa0569 = L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
maxZoom: 18,
minZoom: 1,
attribution: 'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.',
detectRetina: false
}
).addTo(map_d679cdfe31684aa7a59e819ed92f5011);




</script>

28 changes: 28 additions & 0 deletions io_geojson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
# from urllib.request import urlopen

def read_tweets(input_file):
with open(input_file, 'r') as f:
tweets = json.load(f)
return tweets

def read_geojson(input_file):
"""
Read a geojson file

Parameters
----------
input_file : str
The PATH to the data to be read

Returns
-------
gj : dict
An in memory version of the geojson
"""
gj = None

with open(input_file, 'r') as f:
gj = json.load(f)

return gj
Binary file added open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions tweet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import random
import utils

class Tweet(object):

def __init__(self, tweet):

self.tweet_id = tweet['id']
self.date = tweet['created_at']
self.tweet = tweet['text']
self.username = tweet['user']['name']
self.user_description = tweet['user']['description']
self.followers_count = tweet['user']['followers_count']
self.bounds = tweet['place']['bounding_box']['coordinates'][0]

def find_lat(self, n):
return self.bounds[n][1]

def find_lng(self, n):
return self.bounds[n][0]

def bounds(self):
lat = random.uniform(self.find_lat(0), self.find_lat(1))
lng = random.uniform(self.find_lng(0), self.find_lng(1))
return lat, lng
159 changes: 159 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import math
import random

def manhattan_distance(a, b):
"""
Compute the Manhattan distance between two points

Parameters
----------
a : tuple
A point in the form (x,y)

b : tuple
A point in the form (x,y)

Returns
-------
distance : float
The Manhattan distance between the two points
"""
distance = abs(a[0] - b[0]) + abs(a[1] - b[1])
return distance



def euclidean_distance(a, b):
"""
Compute the Euclidean distance between two points

Parameters
----------
a : tuple
A point in the form (x,y)

b : tuple
A point in the form (x,y)

Returns
-------

distance : float
The Euclidean distance between the two points
"""
distance = math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
return distance


def shift_point(point, x_shift, y_shift):
"""
Shift a point by some amount in the x and y directions

Parameters
----------
point : tuple
in the form (x,y)

x_shift : int or float
distance to shift in the x direction

y_shift : int or float
distance to shift in the y direction

Returns
-------
new_x : int or float
shited x coordinate

new_y : int or float
shifted y coordinate

Note that the new_x new_y elements are returned as a tuple

Example
-------
>>> point = (0,0)
>>> shift_point(point, 1, 2)
(1,2)
"""
x = getx(point)
y = gety(point)

x += x_shift
y += y_shift

return x, y


def check_coincident(a, b):
"""
Check whether two points are coincident
Parameters
----------
a : tuple
A point in the form (x,y)

b : tuple
A point in the form (x,y)

Returns
-------
equal : bool
Whether the points are equal
"""
return a == b


def check_in(point, point_list):
"""
Check whether point is in the point list

Parameters
----------
point : tuple
In the form (x,y)

point_list : list
in the form [point, point_1, point_2, ..., point_n]
"""
return point in point_list


def getx(point):
"""
A simple method to return the x coordinate of
an tuple in the form(x,y). We will look at
sequences in a coming lesson.

Parameters
----------
point : tuple
in the form (x,y)

Returns
-------
: int or float
x coordinate
"""

return point.x


def gety(point):
"""
A simple method to return the x coordinate of
an tuple in the form(x,y). We will look at
sequences in a coming lesson.

Parameters
----------
point : tuple
in the form (x,y)

Returns
-------
: int or float
y coordinate
"""

return point.y
Loading