-
Notifications
You must be signed in to change notification settings - Fork 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
First Commit #9
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
First Commit #9
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 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,234 @@ | ||
from .utils import * | ||
|
||
def find_largest_city(gj): | ||
""" | ||
Iterate through a geojson feature collection and | ||
find the largest city. Assume that the key | ||
to access the maximum population is 'pop_max'. | ||
|
||
Parameters | ||
---------- | ||
gj : dict | ||
A GeoJSON file read in as a Python dictionary | ||
|
||
Returns | ||
------- | ||
city : str | ||
The largest city | ||
|
||
population : int | ||
The population of the largest city | ||
""" | ||
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 | ||
|
||
def write_your_own(gj): | ||
""" | ||
Here you will write your own code to find | ||
some attribute in the supplied geojson file. | ||
|
||
Take a look at the attributes available and pick | ||
something interesting that you might like to find | ||
or summarize. This is totally up to you. | ||
|
||
Do not forget to write the accompanying test in | ||
tests.py! | ||
""" | ||
|
||
#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): | ||
""" | ||
Given a set of points, compute the mean center | ||
|
||
Parameters | ||
---------- | ||
points : list | ||
A list of points in the form (x,y) | ||
|
||
Returns | ||
------- | ||
x : float | ||
Mean x coordinate | ||
|
||
y : float | ||
Mean y coordinate | ||
""" | ||
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 | ||
|
||
|
||
# def average_nearest_neighbor_distance(points): | ||
# """ | ||
# Given a set of points, compute the average nearest neighbor. | ||
|
||
# Parameters | ||
# ---------- | ||
# points : list | ||
# A list of points in the form (x,y) | ||
|
||
# Returns | ||
# ------- | ||
# mean_d : float | ||
# Average nearest neighbor distance | ||
|
||
# References | ||
# ---------- | ||
# Clark and Evan (1954 Distance to Nearest Neighbor as a | ||
# 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: | ||
# 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/(n) | ||
|
||
def minimum_bounding_rectangle(points): | ||
""" | ||
Given a set of points, compute the minimum bounding rectangle. | ||
|
||
Parameters | ||
---------- | ||
points : list | ||
A list of points in the form (x,y) | ||
|
||
Returns | ||
------- | ||
: list | ||
Corners of the MBR in the form [xmin, ymin, xmax, ymax] | ||
""" | ||
|
||
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 = (mbr[3] - mbr[1]) * (mbr[2] - mbr[0]) | ||
|
||
return area | ||
|
||
def expected_distance(area, n): | ||
""" | ||
Compute the expected mean distance given | ||
some study area. | ||
|
||
This makes lots of assumptions and is not | ||
necessarily how you would want to compute | ||
this. This is just an example of the full | ||
analysis pipe, e.g. compute the mean distance | ||
and the expected mean distance. | ||
|
||
Parameters | ||
---------- | ||
area : float | ||
The area of the study area | ||
|
||
n : int | ||
The number of points | ||
""" | ||
|
||
expected = 0.5 * math.sqrt(area / n) | ||
return expected | ||
|
||
def compute_critical(points): | ||
""" | ||
Compute the "critical" points for the Monte Carlo | ||
simulation as the minimum and maximum of the points | ||
|
||
Parameters | ||
---------- | ||
points : float | ||
The area of the study area | ||
|
||
(min,max) : int | ||
The minimum and maximum list | ||
""" | ||
|
||
return min(points), max(points) | ||
|
||
def check_significant(input_min,input_max,X): | ||
""" | ||
Compute the "critical" points for the Monte Carlo | ||
simulation as the minimum and maximum of the points | ||
|
||
Parameters | ||
---------- | ||
area : float | ||
The area of the study area | ||
|
||
n : int | ||
The number of points | ||
""" | ||
|
||
flag = False; | ||
|
||
if X>input_max: | ||
flag = True | ||
elif X<input_min: | ||
flag = True | ||
|
||
return flag |
This file contains 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,25 @@ | ||
import json # I would like you to use the JSON module for reading geojson (for now) | ||
|
||
|
||
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 | ||
""" | ||
# 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 |
This file contains 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,20 @@ | ||
#from utils import check_coincident | ||
#import utils | ||
from .utils import * | ||
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. While |
||
|
||
class Point(object): | ||
|
||
#Create a point class with three attributes, x, y, and a keyword argument mark. Please place the point pattern class in point.py. | ||
def __init__(self, x, y, mark={}): | ||
self.x = x | ||
self.y = y | ||
self.mark = mark | ||
|
||
#Add a method to the Point class to chec if another point, passed as an argument, is coincident. Remember that you already wrote this logic. | ||
def check_coincident(self,other): | ||
return check_coincident((self.x, self.y), (other.x, other.y)) | ||
|
||
#Add a method to shift the point in some direction. This logic is also already written. | ||
def shift_point(self, dx, dy): | ||
return shift_point((self.x,self.y),dx,dy) | ||
|
This file contains 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
Oops, something went wrong.
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 can not assume that these numbers are large enough. What if my point pattern are cities and my units are millimeters?