-
Notifications
You must be signed in to change notification settings - Fork 18
Completed #14
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
maalmaz3
wants to merge
1
commit into
Geospatial-Python:master
Choose a base branch
from
maalmaz3: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
Completed #14
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -33,7 +33,11 @@ def read_geojson(input_file): | |
""" | ||
# Please use the python json module (imported above) | ||
# to solve this one. | ||
|
||
gj = None | ||
|
||
with open(input_file, 'r') as f: | ||
gj = json.load(f) | ||
return gj | ||
|
||
|
||
|
@@ -59,6 +63,12 @@ def find_largest_city(gj): | |
city = None | ||
max_population = 0 | ||
|
||
features = gj['features'] | ||
for i in features: | ||
if(i['properties']['pop_max']>max_population): | ||
max_population = i['properties']['pop_max'] | ||
city = i['properties']['name'] | ||
|
||
return city, max_population | ||
|
||
|
||
|
@@ -74,7 +84,18 @@ def write_your_own(gj): | |
Do not forget to write the accompanying test in | ||
tests.py! | ||
""" | ||
return | ||
|
||
#I chose the least creative route of finding the average population among all cities | ||
|
||
sum_population = 0 | ||
n = 0 | ||
|
||
features = gj['features'] | ||
for i in features: | ||
sum_population = i['properties']['pop_max']+sum_population | ||
n = n+1 | ||
|
||
return sum_population/n | ||
|
||
def mean_center(points): | ||
""" | ||
|
@@ -93,9 +114,17 @@ def mean_center(points): | |
y : float | ||
Mean y coordinate | ||
""" | ||
x = None | ||
y = None | ||
x = 0 | ||
y = 0 | ||
n = 0 | ||
|
||
for i in points: | ||
x = x+i[0] | ||
y = y+i[1] | ||
n = n+1 | ||
|
||
x = x/n | ||
y = y/n | ||
return x, y | ||
|
||
|
||
|
@@ -119,9 +148,26 @@ def average_nearest_neighbor_distance(points): | |
Measure of Spatial Relationships in Populations. Ecology. 35(4) | ||
p. 445-453. | ||
""" | ||
|
||
#create empty list of distances | ||
shortestDistList = [] | ||
|
||
for i in points: | ||
shortest = 9999999999 | ||
for j in points: | ||
if i!=j: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checkout |
||
current = euclidean_distance(i,j) | ||
if(current<shortest): | ||
shortest = current | ||
shortestDistList.append(shortest) | ||
|
||
n = 0 | ||
mean_d = 0 | ||
for i in shortestDistList: | ||
mean_d = mean_d+i | ||
n = n+1 | ||
|
||
return mean_d | ||
return mean_d/n | ||
|
||
|
||
def minimum_bounding_rectangle(points): | ||
|
@@ -141,14 +187,31 @@ def minimum_bounding_rectangle(points): | |
|
||
mbr = [0,0,0,0] | ||
|
||
x_max = -99999999999 | ||
x_min = 999999999999 | ||
y_max = -99999999999 | ||
y_min = 999999999999 | ||
|
||
for i in points: | ||
if i[0] > x_max: | ||
x_max = i[0] | ||
if i[0] < x_min: | ||
x_min = i[0] | ||
if i[1] > y_max: | ||
y_max = i[1] | ||
if i[1] < y_min: | ||
y_min = i[1] | ||
|
||
mbr = [x_min,y_min,x_max,y_max] | ||
|
||
return mbr | ||
|
||
|
||
def mbr_area(mbr): | ||
""" | ||
Compute the area of a minimum bounding rectangle | ||
""" | ||
area = 0 | ||
area = (mbr[3] - mbr[1]) * (mbr[2] - mbr[0]) | ||
|
||
return area | ||
|
||
|
@@ -173,7 +236,7 @@ def expected_distance(area, n): | |
The number of points | ||
""" | ||
|
||
expected = 0 | ||
expected = 0.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
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.
You could swap this for
math.inf
to get a really large number.