-
Notifications
You must be signed in to change notification settings - Fork 18
Code added #15
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
pkadambi
wants to merge
3
commits into
Geospatial-Python:master
Choose a base branch
from
pkadambi: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
Code added #15
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Assignment 4</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.python.pydev.PyDevBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.python.pydev.pythonNature</nature> | ||
</natures> | ||
</projectDescription> |
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<?eclipse-pydev version="1.0"?><pydev_project> | ||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> | ||
<path>/${PROJECT_DIR_NAME}</path> | ||
</pydev_pathproperty> | ||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property> | ||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> | ||
</pydev_project> |
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 |
---|---|---|
|
@@ -15,12 +15,14 @@ | |
7. Compute the area of a MBR | ||
8. Compute the expected mean distance for a given point pattern | ||
""" | ||
from pyexpat import features | ||
from math import sqrt | ||
|
||
|
||
def read_geojson(input_file): | ||
""" | ||
Read a geojson file | ||
|
||
Parameters | ||
---------- | ||
input_file : str | ||
|
@@ -31,9 +33,13 @@ def read_geojson(input_file): | |
gj : dict | ||
An in memory version of the geojson | ||
""" | ||
|
||
with open(input_file, 'r') as f: | ||
gj=json.load(f) | ||
|
||
# Please use the python json module (imported above) | ||
# to solve this one. | ||
gj = None | ||
|
||
return gj | ||
|
||
|
||
|
@@ -56,10 +62,14 @@ def find_largest_city(gj): | |
population : int | ||
The population of the largest city | ||
""" | ||
city = None | ||
max_population = 0 | ||
|
||
return city, max_population | ||
maximum=0; | ||
features=gj['features'] | ||
|
||
for i in features: | ||
if (i['properties']['pop_max']>maximum): | ||
maximum=i['properties']['pop_max'] | ||
city=i['properties']['nameascii'] | ||
return city, maximum | ||
|
||
|
||
def write_your_own(gj): | ||
|
@@ -74,7 +84,14 @@ def write_your_own(gj): | |
Do not forget to write the accompanying test in | ||
tests.py! | ||
""" | ||
return | ||
#Calculate the number of citues with two-word names | ||
features=gj['features'] | ||
count = 0 | ||
for i in features: | ||
if(' ' in i['properties']['name']): | ||
count= count+1 | ||
|
||
return count | ||
|
||
def mean_center(points): | ||
""" | ||
|
@@ -93,8 +110,15 @@ def mean_center(points): | |
y : float | ||
Mean y coordinate | ||
""" | ||
x = None | ||
y = None | ||
x_tot=0 | ||
y_tot=0 | ||
|
||
for i in points: | ||
x_tot+=i[0] | ||
y_tot+=i[1] | ||
|
||
x = x_tot/len(points) | ||
y = y_tot/len(points) | ||
|
||
return x, y | ||
|
||
|
@@ -120,7 +144,16 @@ def average_nearest_neighbor_distance(points): | |
p. 445-453. | ||
""" | ||
mean_d = 0 | ||
|
||
for i in points: | ||
dist_nearest=1e9 | ||
for j in points: | ||
dist = euclidean_distance(i, j) | ||
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. Check out |
||
continue | ||
elif dist < dist_nearest: | ||
dist_nearest = dist; | ||
mean_d += dist_nearest; | ||
mean_d=mean_d/(len(points)) | ||
return mean_d | ||
|
||
|
||
|
@@ -138,8 +171,25 @@ def minimum_bounding_rectangle(points): | |
: list | ||
Corners of the MBR in the form [xmin, ymin, xmax, ymax] | ||
""" | ||
|
||
mbr = [0,0,0,0] | ||
#set initial params | ||
xmin=points[1][0] | ||
ymin=points[1][1] | ||
xmax=points[1][0] | ||
ymax=points[1][1] | ||
|
||
for i in points: | ||
curr_x=i[0] | ||
curr_y=i[1] | ||
if curr_x < xmin: | ||
xmin= curr_x | ||
elif curr_x > xmax: | ||
xmax= curr_x | ||
|
||
if curr_y < ymin: | ||
ymin= curr_y | ||
elif curr_y > ymax: | ||
ymax= curr_y | ||
mbr = [xmin,ymin,xmax,ymax] | ||
|
||
return mbr | ||
|
||
|
@@ -148,9 +198,7 @@ def mbr_area(mbr): | |
""" | ||
Compute the area of a minimum bounding rectangle | ||
""" | ||
area = 0 | ||
|
||
return area | ||
return (mbr[3]-mbr[1])*(mbr[2]-mbr[0]) | ||
|
||
|
||
def expected_distance(area, n): | ||
|
@@ -172,9 +220,8 @@ def expected_distance(area, n): | |
n : int | ||
The number of points | ||
""" | ||
|
||
expected = 0 | ||
return expected | ||
|
||
return 0.5*(sqrt(area/n)) | ||
|
||
|
||
""" | ||
|
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.
What if
euclidean_distance
were an expensive call. Would you keep it here?