-
Notifications
You must be signed in to change notification settings - Fork 18
Winging it. #10
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
erico637
wants to merge
14
commits into
Geospatial-Python:master
Choose a base branch
from
erico637:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Winging it. #10
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
51ed36e
Update analytics.py
erico637 381e05e
Update functional_test.py
erico637 8e7bbc8
Update test_io_geojson.py
erico637 6d66598
Update test_analytics.py
erico637 ecc75ab
Update test_utils.py
erico637 2fa5c4e
Update analytics.py
erico637 690dd04
Update test_analytics.py
erico637 b8ea946
Update test_io_geojson.py
erico637 bc979c0
Update test_utils.py
erico637 145f899
Update analytics.py
erico637 eaf56e7
Update io_geojson.py
erico637 acc8a42
Update utils.py
erico637 92beb34
Update utils.py
erico637 0d2b83a
Update functional_test.py
erico637 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
""" | ||
created feb 29th, 2016 | ||
By Eric Friesenhahn | ||
|
||
|
||
List of stuff to do | ||
|
||
compute_critical(p) | ||
Find_largest_city(gj) | ||
check_significant(lower,upper,observed) | ||
euclidean_distance(a, b) | ||
mean_center(points) | ||
average_nearest_neighbor_distance(points) | ||
minimum_bounding_rectangle(points) | ||
mbr_area(mbr) | ||
expected_distance(area, n) | ||
check_significant(lower,upper,observed) | ||
...among other things | ||
|
||
""" | ||
|
||
import math | ||
|
||
|
||
def compute_critical(p): | ||
lower = min(p) | ||
upper = max(p) | ||
|
||
return lower, upper | ||
|
||
def check_significant(lower, upper, observed): | ||
|
||
return observed < lower or observed > upper | ||
|
||
def euclidean_distance(a, b): | ||
|
||
distance = math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2) | ||
|
||
return distance | ||
|
||
def find_largest_city(gj): | ||
|
||
max_population = 0 | ||
for feat in gj['features']: | ||
test_max_pop = feat['properties']['pop_max'] | ||
if test_max_pop > max_population: | ||
max_population = test_max_pop | ||
city = feat['properties']['name'] | ||
|
||
return city, max_population | ||
|
||
def mean_center(points): | ||
sumx= 0.0 | ||
sumy= 0.0 | ||
for coord in points: | ||
sumx+=coord[0] | ||
sumy+=coord[1] | ||
x= sumx/len(points) | ||
y=sumy/len(points) | ||
|
||
return x, y | ||
|
||
def average_nearest_neighbor_distance(points): | ||
min_dist_sum = 0 | ||
for coord_x in points: | ||
first = True | ||
for coord_y in points: | ||
if coord_x == coord_y: | ||
continue | ||
else: | ||
d = euclidean_distance(coord_x, coord_y) | ||
if first: | ||
min_dist = d | ||
first = False | ||
else: | ||
if d < min_dist: | ||
min_dist = d | ||
min_dist_sum += min_dist | ||
|
||
mean_d = min_dist_sum / len(points) | ||
|
||
return mean_d | ||
|
||
def minimum_bounding_retangle(points): | ||
xmin = 0 | ||
xmax = 0 | ||
ymin = 0 | ||
ymax = 0 | ||
for coord in points: | ||
if coord[0] < xmin: | ||
xmin = coord[0] | ||
elif coord[0] > xmax: | ||
xmax = coord[0] | ||
|
||
if coord[1] < ymin: | ||
ymin = coord[1] | ||
elif coord[1] > ymax: | ||
ymax = coord[1] | ||
|
||
xcorner = xmax - xmin | ||
ycorner = ymax - ymin | ||
mbr = [0,0,xcorner,ycorner] | ||
|
||
return mbr | ||
|
||
def mbr_area(mbr): | ||
length = mbr[3] - mbr[1] | ||
width = mbr[2] - mbr[0] | ||
area = length * width | ||
|
||
return area | ||
|
||
def expected_distance(area, n): | ||
expected = .5 * math.sqrt(area/n) | ||
|
||
return expected | ||
|
||
|
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import json | ||
|
||
def read_geojson(input_file): | ||
|
||
with open(input_file, 'r') as fp: | ||
gj = json.load(fp) | ||
return gj |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
same date as other, | ||
same guy as other. | ||
y'know, german last name? | ||
|
||
Stuff to do here | ||
|
||
manhattan_distance | ||
euclidean_distance | ||
getx | ||
gety | ||
shift_point | ||
check_coincident | ||
check_in | ||
create_random | ||
permutations | ||
|
||
...at least, I hope | ||
|
||
""" | ||
import math | ||
import random | ||
from .analytics import average_nearest_neighbor_distance | ||
|
||
def manhattan_distance(a, b): | ||
distance = abs(a[0] - b[0]) + abs(a[1] - b[1]) | ||
|
||
return distance | ||
|
||
def euclidian_distance(a, b): | ||
distance = math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2) | ||
|
||
return distance | ||
|
||
def getx(point): | ||
|
||
return point[0] | ||
|
||
def gety(point): | ||
|
||
return point[1] | ||
|
||
def shift_point(point, x_shift, y_shift): | ||
|
||
x = getx(point) | ||
y = gety(point) | ||
|
||
x += x_shift | ||
y += y_shift | ||
|
||
return x, y | ||
|
||
def check_coincident(a, b): | ||
|
||
return a == b | ||
|
||
def check_in(point, point_list): | ||
|
||
return point in point_list | ||
|
||
def create_random(n, seed=None): | ||
random.seed(seed) | ||
points = [(random.uniform(0,1), random.uniform(0,1)) for i in range(n)] | ||
|
||
return points | ||
|
||
def permutations(p=99, n=100): | ||
|
||
perm = [] | ||
for x in range(p): | ||
points = create_random(n, None) | ||
avg_nnd = average_nearest_neighbor_distance(points) | ||
perm.append(avg_nnd) | ||
|
||
return perm |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A doc string would be a great addition here: