コード例 #1
0
 def _handle_polyfill(self, base_shape, resolution):
     if isinstance(base_shape, MultiPolygon):
         temporary_hexagons = base_shape.explode().apply(
             lambda x: self._get_hexagons(x, resolution))
         hexagons = list(
             set(
                 np.concatenate(temporary_hexagons[
                     temporary_hexagons.notna()].to_list())))
     else:
         hexagons = h3.polyfill(
             self._extract_geometry(base_shape),
             resolution,
             geo_json_conformant=True,
         )
     return hexagons
コード例 #2
0
 def __init__(self, geoJson, resolution=9):
     self.geoJson = geoJson
     self.resolution = resolution
     self.polyline = self.geoJson['coordinates'][0]
     self.polyline.append(self.polyline[0])
     self.hexagons = list(h3.polyfill(geoJson, resolution))
     self.lookup_table = pd.read_pickle(
         os.path.abspath('data/lookup_table.pkl'))
     self.valid_nodes = list(self.lookup_table.index.levels[0])  #[50:60]
     self.nodes = [Node(node_id) for node_id in self.valid_nodes]  #[50:60]
     self.city_time = 0
     self.orders = np.load(os.path.abspath('data/prep_data.npy'))
     self.max_timesteps = 143
     self.days = 2
     #self.num_taxis = 5
     self.taxis = None  #[Taxi(_id) for _id in range(self.num_taxis)]
     self.set_node_neighbors()
コード例 #3
0
ファイル: tilers.py プロジェクト: valreds/scikit-mobility
    def _handle_polyfill(self, base_shape, res):
        def get_hex(x):
            h = h3.polyfill(x.__geo_interface__, res, geo_json_conformant=True)
            if len(h) > 0:
                return h
            else:
                return None

        if base_shape.type[0] == "MultiPolygon":
            tmp_hexs = base_shape.explode().apply(lambda x: get_hex(x))
            hexs = list(
                set(np.concatenate(tmp_hexs[tmp_hexs.notna()].to_list())))
        else:
            hexs = h3.polyfill(
                base_shape.geometry.__geo_interface__['features'][0]
                ['geometry'],
                res,
                geo_json_conformant=True)

        return hexs
コード例 #4
0
 def _get_hexagons(self, x, resolution):
     hexagons = h3.polyfill(x.__geo_interface__,
                            resolution,
                            geo_json_conformant=True)
     if hexagons.all():
         return hexagons
コード例 #5
0
ファイル: tilers.py プロジェクト: valreds/scikit-mobility
 def get_hex(x):
     h = h3.polyfill(x.__geo_interface__, res, geo_json_conformant=True)
     if len(h) > 0:
         return h
     else:
         return None