-
Notifications
You must be signed in to change notification settings - Fork 18
Completed all test cases! #11
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
tphan5
wants to merge
1
commit into
Geospatial-Python:master
Choose a base branch
from
tphan5: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
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,8 @@ 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 jFile: | ||
| gj = json.load(jFile) | ||
| return gj | ||
|
|
||
|
|
||
|
|
@@ -56,9 +57,19 @@ def find_largest_city(gj): | |
| population : int | ||
| The population of the largest city | ||
| """ | ||
| city = None | ||
|
|
||
| listOfFeatures = gj['features'] | ||
|
|
||
| #city = None | ||
|
|
||
| max_population = 0 | ||
|
|
||
| for i in listOfFeatures: | ||
| popMax = i['properties']['pop_max'] | ||
| if popMax > max_population: | ||
| max_population = popMax | ||
| city = i['properties']['name'] | ||
|
|
||
| return city, max_population | ||
|
|
||
|
|
||
|
|
@@ -74,7 +85,16 @@ def write_your_own(gj): | |
| Do not forget to write the accompanying test in | ||
| tests.py! | ||
| """ | ||
| return | ||
|
|
||
| listOfFeatures2 = gj['features'] | ||
|
|
||
| #going through the list and print the last entry of the city, population, and coordinates | ||
| for i in listOfFeatures2: | ||
| city = i['properties']['name'] | ||
| population = i['properties']['pop_max'] | ||
| coordinates = i['geometry']['coordinates'] | ||
|
|
||
| return city, population, coordinates | ||
|
|
||
| def mean_center(points): | ||
| """ | ||
|
|
@@ -93,8 +113,17 @@ def mean_center(points): | |
| y : float | ||
| Mean y coordinate | ||
| """ | ||
| x = None | ||
| y = None | ||
| #x = None | ||
| #y = None | ||
|
|
||
| x = [i[0] for i in points] | ||
| y = [i[1] for i in points] | ||
|
|
||
| sumX = (sum(x) / len(points)) | ||
| sumY = (sum(y) / len(points)) | ||
|
|
||
| x = sumX | ||
| y = sumY | ||
|
|
||
| return x, y | ||
|
|
||
|
|
@@ -121,6 +150,20 @@ def average_nearest_neighbor_distance(points): | |
| """ | ||
| mean_d = 0 | ||
|
|
||
| shortDistanceList = [] | ||
|
|
||
| for firstPoint in points: | ||
| pointInList = 500 | ||
| for secondPoint in points: | ||
| if firstPoint is not secondPoint: | ||
|
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. What if the points are coincident? Check out |
||
| distance = euclidean_distance(firstPoint, secondPoint) | ||
| if (pointInList > distance): | ||
| pointInList = distance | ||
|
|
||
| shortDistanceList.append(pointInList) | ||
|
|
||
| mean_d = sum(shortDistanceList) / len(points) | ||
|
|
||
| return mean_d | ||
|
|
||
|
|
||
|
|
@@ -141,6 +184,24 @@ def minimum_bounding_rectangle(points): | |
|
|
||
| mbr = [0,0,0,0] | ||
|
|
||
| xmin = 0 | ||
| ymin = 0 | ||
| xmax = 0 | ||
| ymax = 0 | ||
|
|
||
| for i in points: | ||
| if i[0] < xmin: | ||
| xmin = i[0] | ||
| if i[1] < ymin: | ||
| ymin = i[1] | ||
| if i[0] > xmax: | ||
| xmax = i[0] | ||
| if i[1] > ymax: | ||
| ymax = i[1] | ||
|
|
||
| mbr = [xmin,ymin,xmax,ymax] | ||
|
|
||
|
|
||
| return mbr | ||
|
|
||
|
|
||
|
|
@@ -150,6 +211,10 @@ def mbr_area(mbr): | |
| """ | ||
| area = 0 | ||
|
|
||
| length = mbr[3] - mbr[1] | ||
| width = mbr[2] - mbr [0] | ||
| area = length * width | ||
|
|
||
| return area | ||
|
|
||
|
|
||
|
|
@@ -174,6 +239,9 @@ def expected_distance(area, n): | |
| """ | ||
|
|
||
| expected = 0 | ||
|
|
||
| expected = (math.sqrt(area/n)) * (0.5) | ||
|
|
||
| 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.
I would swap in
math.infhere, so that you have a really big starting distance.