From 26b47c04ad6d6953e9b621904196db3409752567 Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 12:01:24 -0700 Subject: [PATCH 01/12] First --- point_pattern.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/point_pattern.py b/point_pattern.py index 1b0a5cb..0653117 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -33,6 +33,8 @@ def read_geojson(input_file): """ # Please use the python json module (imported above) # to solve this one. + with open(input_file, 'r') as f: + gj = json.load(f) gj = None return gj @@ -58,6 +60,12 @@ def find_largest_city(gj): """ city = None max_population = 0 + for place in gj["features"]: + thisCity = place["properties"]["pop_max"] + if thisCity > max_population: + max_population = thisCity + city = place["properties"] + return city, max_population @@ -95,6 +103,12 @@ def mean_center(points): """ x = None y = None + for point in points: + x += [0] + y += [1] + + x = x/len(points) + y = y/len(points) return x, y @@ -119,7 +133,19 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ + mean_d = 0 + neighbor = None + for point in points: + if point_a != ponit_b + thisDistance = euclidean_distance(point_a, point_b) + if neighbor = None + neighbor = thisDistance + else neighbor > thisDistance + neighbor = thisDistance + mean_d += neighbor + neighbor = None + mean_d/=len(points) return mean_d From 621e0d5132287f1650885276484052f11ded7b8a Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 12:08:11 -0700 Subject: [PATCH 02/12] Second --- point_pattern.py | 1 + 1 file changed, 1 insertion(+) diff --git a/point_pattern.py b/point_pattern.py index 0653117..fc9d581 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -141,6 +141,7 @@ def average_nearest_neighbor_distance(points): thisDistance = euclidean_distance(point_a, point_b) if neighbor = None neighbor = thisDistance + continue else neighbor > thisDistance neighbor = thisDistance mean_d += neighbor From e45ad322a8b6e90ff7904c4bfeed2cff040505aa Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 12:27:39 -0700 Subject: [PATCH 03/12] Third --- point_pattern.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index fc9d581..57b29d8 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -137,12 +137,15 @@ def average_nearest_neighbor_distance(points): mean_d = 0 neighbor = None for point in points: - if point_a != ponit_b + if: + point_a != point_b thisDistance = euclidean_distance(point_a, point_b) - if neighbor = None + if: + neighbor = None neighbor = thisDistance - continue - else neighbor > thisDistance + + else: + neighbor > thisDistance neighbor = thisDistance mean_d += neighbor neighbor = None From ca768d542ab4b06514ec42882eef85ae235182b8 Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 12:31:37 -0700 Subject: [PATCH 04/12] Fourth --- point_pattern.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 57b29d8..15d7c8d 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -135,21 +135,7 @@ def average_nearest_neighbor_distance(points): """ mean_d = 0 - neighbor = None - for point in points: - if: - point_a != point_b - thisDistance = euclidean_distance(point_a, point_b) - if: - neighbor = None - neighbor = thisDistance - - else: - neighbor > thisDistance - neighbor = thisDistance - mean_d += neighbor - neighbor = None - mean_d/=len(points) + return mean_d From ee4a5752061cb1dca00f21b94e663d0a0f652d76 Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 16:29:08 -0700 Subject: [PATCH 05/12] Fifth --- point_pattern.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 15d7c8d..4a18bd1 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -60,11 +60,7 @@ def find_largest_city(gj): """ city = None max_population = 0 - for place in gj["features"]: - thisCity = place["properties"]["pop_max"] - if thisCity > max_population: - max_population = thisCity - city = place["properties"] + return city, max_population From 23eb580ee4426810d23c22b6090921f239d1792e Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 16:44:21 -0700 Subject: [PATCH 06/12] Do Over --- point_pattern.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 4a18bd1..72446e2 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -33,8 +33,7 @@ def read_geojson(input_file): """ # Please use the python json module (imported above) # to solve this one. - with open(input_file, 'r') as f: - gj = json.load(f) + gj = None return gj @@ -60,7 +59,7 @@ def find_largest_city(gj): """ city = None max_population = 0 - + return city, max_population From 4f48e7fa6c4356f81f1cc38f69b7e4e3cd9f30bf Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 17:15:17 -0700 Subject: [PATCH 07/12] Do Over 1 --- point_pattern.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 72446e2..5e7ad59 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -33,9 +33,9 @@ def read_geojson(input_file): """ # Please use the python json module (imported above) # to solve this one. - - gj = None - return gj +with open('data/us_cities.geojson', 'r') as f: + gj = json.load(f) +return gj def find_largest_city(gj): @@ -57,12 +57,17 @@ def find_largest_city(gj): population : int The population of the largest city """ - city = None - max_population = 0 - +city = None +max_population = 0 +temp = 0 +for i in gj: + if i['pop_max'] < temp: + temp = i['pop_max'] + city = i['city'] + max_population = temp - return city, max_population +return city, max_population def write_your_own(gj): From ae7c7bc2c429c0503efcf4877c42bfe33ed8af2e Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 17:28:40 -0700 Subject: [PATCH 08/12] Do Over 2 --- point_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/point_pattern.py b/point_pattern.py index 5e7ad59..373c73a 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -33,7 +33,7 @@ def read_geojson(input_file): """ # Please use the python json module (imported above) # to solve this one. -with open('data/us_cities.geojson', 'r') as f: +with open(input_file, 'r') as f: gj = json.load(f) return gj From 92eb5bf753977f445ce0144c927427da9b42fea3 Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 17:50:38 -0700 Subject: [PATCH 09/12] Do Over 3 --- point_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 373c73a..4ed5841 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -104,8 +104,8 @@ def mean_center(points): x = None y = None for point in points: - x += [0] - y += [1] + x += point[0] + y += point[1] x = x/len(points) y = y/len(points) From 7c2e24905507aa93d30baa01e0e81da8cba43c4c Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 18:01:11 -0700 Subject: [PATCH 10/12] Do Over4 --- point_pattern.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/point_pattern.py b/point_pattern.py index 4ed5841..624e249 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -36,6 +36,7 @@ def read_geojson(input_file): with open(input_file, 'r') as f: gj = json.load(f) return gj +print(gj) def find_largest_city(gj): @@ -156,6 +157,22 @@ def minimum_bounding_rectangle(points): """ mbr = [0,0,0,0] + mbr = [None,None,None,None] + + for point in points: + + if mbr[0] == None: + + mbr[0] = point[0] + + mbr[1] = point[1] + + mbr[2] = point[0] + + mbr[3] = point[1] + + else: + + if point[0] < mbr[0]: + + mbr[0] = point[0] + + if point[1] < mbr[1]: + + mbr[1] = point[1] + + if point[0] > mbr[2]: + + mbr[2] = point[0] + + if point[1] > mbr[3]: + + mbr[3] = point[1] return mbr From 4b2876fd96f4f5a14677ab004d027f01f5788a93 Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 18:03:09 -0700 Subject: [PATCH 11/12] Do Over4 --- point_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/point_pattern.py b/point_pattern.py index 624e249..2d71d52 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -159,7 +159,7 @@ def minimum_bounding_rectangle(points): mbr = [0,0,0,0] mbr = [None,None,None,None] + for point in points: - + if mbr[0] == None: + + if mbr[0] is None: + mbr[0] = point[0] + mbr[1] = point[1] + mbr[2] = point[0] From c0ce56f03cec99ce84283d4f951a04a603a59130 Mon Sep 17 00:00:00 2001 From: Adam Herczeg Date: Tue, 23 Feb 2016 18:16:57 -0700 Subject: [PATCH 12/12] Again --- point_pattern.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 2d71d52..b68090c 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -157,22 +157,7 @@ def minimum_bounding_rectangle(points): """ mbr = [0,0,0,0] - mbr = [None,None,None,None] - + for point in points: - + if mbr[0] is None: - + mbr[0] = point[0] - + mbr[1] = point[1] - + mbr[2] = point[0] - + mbr[3] = point[1] - + else: - + if point[0] < mbr[0]: - + mbr[0] = point[0] - + if point[1] < mbr[1]: - + mbr[1] = point[1] - + if point[0] > mbr[2]: - + mbr[2] = point[0] - + if point[1] > mbr[3]: - + mbr[3] = point[1] + return mbr