def sanitize_aois_html(self, style=None): aois_query = self.hulls_query() aois_query = self.query_generator.without_water_query(aois_query) aois_query = self.query_generator.sanitize_aois_query(aois_query) aois = query_geometries(aois_query) return generate_map_html(self.location, aois, style=style)
def extended_hulls_query(self): aois = query_geometries(self.hulls_query()) aois = aois.to_crs(fiona.crs.from_epsg(4326)) central_nodes = [] start = time.time() for aoi in tqdm(aois.geometry): try: aoi_graph = ox.graph_from_polygon(aoi.buffer(0.001), network_type='all') closeness_centrality = nx.closeness_centrality(aoi_graph) sorted_nodes = sorted(closeness_centrality.items(), key=operator.itemgetter(1), reverse=True) central_nodes += [ node[0] for node in sorted_nodes[:len(sorted_nodes) // 10] ] except KeyboardInterrupt: # leave on ctrl-c sys.exit(0) except: logging.debug("fetching graph failed for {}".format(aoi)) central_nodes_ids = ', '.join([f'{key}' for key in central_nodes]) logging.debug( "calculating most central nodes for aois took {}s".format( time.time() - start)) return """ WITH hulls AS ({hulls_query}), intersecting_lines AS ( SELECT hulls.cid, ST_Intersection(way, ST_Buffer(hulls.geometry, 50)) AS geometry FROM planet_osm_line, hulls WHERE osm_id = ANY( SELECT id FROM planet_osm_ways WHERE nodes && ARRAY[{central_nodes_ids}]::bigint[] ) AND ST_DWithin(planet_osm_line.way, hulls.geometry, 50) ) SELECT 1 AS color, ST_ConcaveHull(ST_Union(geometry), 0.99) AS geometry FROM ( SELECT cid, geometry FROM hulls UNION SELECT cid, geometry FROM intersecting_lines ) AS tmp GROUP BY cid """.format(hulls_query=self.hulls_query(), central_nodes_ids=central_nodes_ids)
def without_water_html(self): query = self.query_generator.without_water_query(self.hulls_query()) hulls = query_geometries(query) return generate_map_html(self.location, hulls, style=None)
def extended_hulls_html(self): hulls = query_geometries(self.query_generator.extended_hulls_query()) return generate_map_html(self.location, hulls, style=None)
def network_centrality_html(self): network_centrality = query_geometries( self.query_generator.network_centrality_query()) return generate_map_html(self.location, network_centrality, style='network')
def clusters_and_hulls_html(self): clusters_and_hulls = query_geometries( self.query_generator.clusters_and_hulls_query()) return generate_map_html(self.location, clusters_and_hulls)
def polygons_html(self): polygons = query_geometries(self.query_generator.polygons_query()) return generate_map_html(self.location, polygons, style=None)
def any_aoi(self): clusters = query_geometries(self.query_generator.clusters_query()) return clusters.size > 0