-
Notifications
You must be signed in to change notification settings - Fork 15
Very Late #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
aciepli
wants to merge
10
commits into
Geospatial-Python:master
Choose a base branch
from
aciepli: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
Very Late #14
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0e6e11b
Update utils.py
aciepli 1ca3148
Update point.py
aciepli 21a6690
Update io_geojson.py
aciepli 126d368
Update analytics.py
aciepli 58d7f40
Update point.py
aciepli ce2b0eb
Update analytics.py
aciepli 8b25dd9
Update analytics.py
aciepli 2bc5d07
Update analytics.py
aciepli e1b5df6
Update analytics.py
aciepli bdeaddd
Update analytics.py
aciepli 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,120 @@ | ||
import math | ||
import sys | ||
import os | ||
|
||
|
||
from .. import point | ||
from .. import utils | ||
|
||
def find_largest_city(gj): | ||
city = None | ||
max_population = 0 | ||
|
||
for i in gj['features']: | ||
if i['properties']['pop_max'] > max_population: | ||
max_population = i['properties']['pop_max'] | ||
city = i['properties']['name'] | ||
|
||
return city, max_population | ||
|
||
|
||
def mean_center(points): | ||
x = 0 | ||
y = 0 | ||
|
||
for i in points: | ||
x += i[0] | ||
y += i[1] | ||
|
||
x /= len(points) | ||
y /= len(points) | ||
|
||
return x, y | ||
|
||
|
||
def average_nearest_neighbor_distance(points): | ||
|
||
mean_d = 0 | ||
nearest_neighbor = math.inf | ||
|
||
for p in points: | ||
for otherPoint in points: | ||
if point.check_coincident(p, otherPoint): | ||
continue | ||
current_distance = utils.euclidean_distance(p, otherPoint) | ||
if nearest_neighbor is None: | ||
nearest_neighbor = current_distance | ||
elif nearest_neighbor > current_distance: | ||
nearest_neighbor = current_distance | ||
|
||
mean_d += nearest_neighbor | ||
nearest_neighbor = None | ||
|
||
mean_d /= len(points) | ||
|
||
return mean_d | ||
|
||
|
||
def minimum_bounding_rectangle(points): | ||
|
||
mbr = [0, 0, 0, 0] | ||
x_min = 0 | ||
x_max = 0 | ||
y_min = 0 | ||
y_max = 0 | ||
|
||
for p in points: | ||
if p[0] < x_min: | ||
x_min = p[0] | ||
if p[0] > x_max: | ||
x_max = p[0] | ||
if p[1] < y_min: | ||
y_min = p[1] | ||
if p[1] > y_max: | ||
y_max = p[1] | ||
mbr = [x_min, y_min, x_max, y_max] | ||
|
||
return mbr | ||
|
||
|
||
def mbr_area(mbr): | ||
|
||
l = mbr[2] - mbr[0] | ||
w = mbr[3] - mbr[1] | ||
area = l * w | ||
|
||
return area | ||
|
||
|
||
def expected_distance(area, n): | ||
|
||
expected = 0.5 * (math.sqrt(area / n)) | ||
|
||
return expected | ||
|
||
|
||
def compute_critical(points): | ||
|
||
lower = min(points) | ||
upper = max(points) | ||
|
||
return lower, upper | ||
|
||
|
||
def check_significant(lower, upper, observed): | ||
|
||
if (lower < observed) or (observed < upper): | ||
result = True | ||
else: | ||
result = False | ||
|
||
return result | ||
|
||
|
||
def permutation(p=99, n=100): | ||
|
||
perm = [] | ||
for x in range(p): | ||
perm.append(average_nearest_neighbor_distance(utils.create_random_points(n))) | ||
|
||
return perm |
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,10 @@ | ||
import json | ||
|
||
|
||
def read_geojson(input_file): | ||
|
||
with open(input_file, 'r') as f: | ||
gj = json.load(f) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import utils | ||
|
||
sys.path.insert(0, os.path.abspath('..')) | ||
|
||
|
||
def __init__(self, x, y, mark=[]): | ||
self.x = x | ||
self.y = y | ||
self.mark = mark | ||
|
||
|
||
def __str__(self): | ||
return "[0], [1]".format(self.x, self.y) | ||
|
||
|
||
def check_coincident(a, b): | ||
return a == b | ||
|
||
|
||
def shift_point(point, x_shift, y_shift): | ||
x = utils.getx(point) | ||
y = utils.gety(point) | ||
|
||
x += x_shift | ||
y += y_shift | ||
|
||
return x, y |
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,42 @@ | ||
import math | ||
import random | ||
|
||
|
||
def create_random_points(n): | ||
rand = random.seed() | ||
random_points = [(rand.randint(0, 100), rand.randint(0, 100))] | ||
return random_points | ||
|
||
|
||
def create_random_marked_points(n, marks=[]): | ||
rand_mp = random.seed() | ||
rand_pts = [] | ||
if marks is None: | ||
for i in range(n): | ||
rand_pts.append(rand_mp.randint(0, 100), rand_mp.randint(0,100), rand_mp.choice(marks)) | ||
else: | ||
for i in range(n): | ||
rand_pts.append(rand_mp.randint(0, 100), rand_mp.randint(0,100), rand_mp.choice(marks)) | ||
return rand_pts | ||
|
||
|
||
def euclidean_distance(a, b): | ||
distance = math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) | ||
return distance | ||
|
||
|
||
def manhattan_distance(a, b): | ||
distance = abs(a[0] - b[0]) + abs(a[1] - b[1]) | ||
return distance | ||
|
||
|
||
def check_in(points, point_list): | ||
return points in point_list | ||
|
||
|
||
def getx(points): | ||
return points[0] | ||
|
||
|
||
def gety(points): | ||
return points[1] |
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.
This should be a class, e.g.