def generate_location(eclipse_path_data): points = eclipse_gis.load_stripped_data( open(eclipse_path_data).readlines()) boundary, center = eclipse_gis.generate_polygon(points) eg = eclipse_gis.EclipseGIS(boundary, center) p = eg.get_random_point_in_polygon() return p
def __init__(self, datastore_client, storage_client): self.datastore = datastore_client self.storage = storage_client times, points = eclipse_gis.load_stripped_data( open("/app/data/eclipse_data.txt").readlines()) boundary, center_line = eclipse_gis.generate_polygon(points) self.eclipse_gis = eclipse_gis.EclipseGIS(boundary, center_line)
def generate_grid(eclipse_path_data, us_map_polygon, outside=False, umbra_boundary_buffer_size=1.5, x_count=75, y_count=125): """Generate a grid of locations within or around the eclipse path. If outside=False, the grid points are within the eclipse path. If outside=True, the grid points are in a buffer region around the eclipse path. umbra_boundary_buffer_size defines the buffer. x_count and y_count define the number of points in the grid (the full grid covers the bounding box of the United states). """ times, points = eclipse_gis.load_stripped_data( open(eclipse_path_data).readlines()) boundary, center = eclipse_gis.generate_polygon(points) eg = eclipse_gis.EclipseGIS(boundary, center) # TODO(dek) use shapely to compute the BB min_x = min([item[0] for item in us_map_polygon.exterior.coords]) min_y = min([item[1] for item in us_map_polygon.exterior.coords]) max_x = max([item[0] for item in us_map_polygon.exterior.coords]) max_y = max([item[1] for item in us_map_polygon.exterior.coords]) # Create a grid of candidate points covering the US x_range = np.linspace(min_x, max_x, x_count) y_range = np.linspace(min_y, max_y, y_count) cp = cartesian_product2([x_range, y_range]) p = [] # Create a buffer around the eclipse path bounding boundary_buffer = boundary.buffer(umbra_boundary_buffer_size) for point in cp: Po = Point(point) inside_umbra = eg.test_point_within_eclipse_boundary(Po) inside_us = us_map_polygon.contains(Po) inside_boundary_buffer = boundary_buffer.contains(Po) # Filter candidate points if not outside and inside_umbra: # User wants point inside the eclipse path and point is inside the # eclipse path p.append(Po) elif outside and not inside_umbra and inside_us and inside_boundary_buffer: # User wants point outside the eclipse path and point is not inside # the eclipse path, is inside the US map boundaries, and inside the boundary buffer p.append(Po) return p
def load_path(eclipse_path_data): times, points = eclipse_gis.load_stripped_data(open(eclipse_path_data).readlines()) boundary, center = eclipse_gis.generate_polygon(points) eg = eclipse_gis.EclipseGIS(boundary, center) return eg
def main(): logging.basicConfig(level=logging.INFO, format=constants.LOG_FMT_S_THREADED) args = get_arguments() times, points = eclipse_gis.load_stripped_data( open(args.eclipse_path_data).readlines()) datastore_client = datastore.Client(project=args.project_id) query = datastore_client.query(kind=ds.DATASTORE_ORIENTED_IMAGE, \ order=[ds.TOTALITY_ORDERING_PROPERTY], \ filters=[("image_type","=", ds.TOTALITY_IMAGE_TYPE)]) results = query.fetch() results = list(results) results.sort(key=cmp_totality_ordering) d = {} keys = [result["original_photo"] for result in results] for key_chunk in chunks(keys, 1000): entities = datastore_client.get_multi(key_chunk) for entity in entities: d[entity.key] = entity map = Basemap(llcrnrlat=22, llcrnrlon=-119, urcrnrlat=49, urcrnrlon=-64, projection='lcc', lat_1=33, lat_2=45, lon_0=-95) base_color = 'white' border_color = 'lightgray' boundary_color = 'gray' map.fillcontinents(color=base_color, lake_color=border_color) map.drawstates(color=border_color) map.drawcoastlines(color=border_color) map.drawcountries(color=border_color) map.drawmapboundary(color=boundary_color) lats = [] lons = [] colors = [] for result in results: photo_key = result["original_photo"] photo = d[photo_key] lat = photo['lat'] lon = -photo['lon'] image_datetime = photo['image_datetime'] colors.append(int(result[ds.TOTALITY_ORDERING_PROPERTY] * 100)) lats.append(lat) lons.append(lon) # Draw photo locations as colored points map.scatter(lons, lats, c=colors, marker='.', edgecolors='none', s=1, latlon=True, zorder=2, cmap=cm.plasma) map.colorbar() y = [points[0][1][0]] x = [points[0][1][1]] # Draw boundary of eclipse path y.extend([point[0][0] for point in points]) x.extend([point[0][1] for point in points]) y.extend([points[-1][1][0]]) x.extend([points[-1][1][1]]) y.extend([point[2][0] for point in points][::-1]) x.extend([point[2][1] for point in points][::-1]) y.extend([points[0][1][0]]) x.extend([points[0][1][1]]) map.plot(x, y, latlon=True, alpha=0.5, zorder=3) # Draw centerline of eclipse path y = [point[1][0] for point in points] x = [point[1][1] for point in points] map.plot(x, y, latlon=True, alpha=0.5, zorder=3) plt.savefig(args.output)
# # Copyright 2017 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from eclipse_gis import eclipse_gis times, points = eclipse_gis.load_stripped_data( open("src/eclipse_gis/data/eclipse_data.txt").readlines()) boundary, center = eclipse_gis.generate_polygon(points) print center eclipse_gis = eclipse_gis.EclipseGIS(boundary, center) from shapely.geometry import Point print eclipse_gis.find_nearest_point_on_line(Point(44.62, -117.13)) print eclipse_gis.interpolate_nearest_point_on_line(Point(44.62, -117.13)) print eclipse_gis.find_nearest_point_on_line(Point(37, -88)) print eclipse_gis.interpolate_nearest_point_on_line(Point(37, -88))