コード例 #1
0
ファイル: amap.py プロジェクト: vctcn93/gibbon_lib
    def pois_by_keyword_lnglat_radius(self,
                                      keywords: str,
                                      lnglat: tuple,
                                      radius: int,
                                      types: str = '',
                                      city: str = '',
                                      sortrule: str = 'distance',
                                      offset: int = 20,
                                      page: int = 1,
                                      extensions: str = 'all') -> pd.DataFrame:
        """
        :param lnglat: 中心点坐标。规则: 经度和纬度用","分割,经度在前,纬度在后,经纬度小数点后不得超过6位
        :param keywords: 查询关键字。规则: 多个关键字用“|”分割
        :param types: 查询POI类型
        :param city: 查询城市
        :param radius: 查询半径。取值范围:0-50000。规则:大于50000按默认值,单位:米
        :param sortrule: 排序规则。按距离排序:distance;综合排序:weight
        :param offset: 每页记录数据,强烈建议不超过25,若超过25可能造成访问报错
        :param page: 当前页数
        :param extensions: 此项默认返回基本地址信息;取值为 'all' 返回地址信息、附近POI、道路以及道路交叉口信息。
        :return: pd.DataFrame
        """
        results = list()
        gcj02 = Convert.wgs84togcj02(lnglat)
        str_lnglat = Convert.to_string(gcj02)

        url = 'https://restapi.amap.com/v3/place/around?'
        params = {
            'key': self.key,
            'location': str_lnglat,
            'keywords': keywords,
            'types': types,
            'city': city,
            'radius': radius,
            'sortrule': sortrule,
            'offset': offset,
            'page': page,
            'extensions': extensions
        }

        response = requests.get(url, params=params)
        content = json.loads(response.content)
        results += content['pois']

        turns = int(eval(content['count']) / offset)

        for i in range(1, turns + 1):
            params['page'] = i + 1
            response = requests.get(url, params=params)
            content = json.loads(response.content)
            results += content['pois']

        df = pd.DataFrame(results)
        df['coord_sys'] = 'gcj02'

        return df
コード例 #2
0
ファイル: bmap.py プロジェクト: vctcn93/gibbon_lib
    def driving_path_by_origin_destination(
            self,
            origin: tuple,
            destination: tuple,
            waypoints: str = '',
            tactics: int = 0,
            coord_type: str = 'wgs84',
            ret_coordtype: str = 'gcj02') -> list:
        """
        根据起终点坐标规划驾车出行路线和耗时
        :param origin: 起点
        :param destination: 终点
        :param waypoints: 途经点。支持5个以内的有序途径点。多个途径点坐标按顺序以英文竖线符号分隔
        :param tactics: 路线偏好。
                0:常规路线,即多数用户常走的一条经验路线,满足大多数场景需求,是较推荐的一个策略
                1:不走高速
                2:躲避拥堵
        :param coord_type: 输入坐标类型
                bd09ll:百度经纬度坐标
                bd09mc:百度墨卡托坐标
                gcj02:国测局加密坐标
                wgs84:gps设备获取的坐标
        :param ret_coordtype: 输出坐标类型
                bd09ll:百度经纬度坐标
                gcj02:国测局加密坐标
        :return: pd.DataFrame
        """
        s_e = list()
        for item in [origin.copy(), destination.copy()]:
            item.reverse()
            s_e.append(Convert.to_string(item))

        url = 'http://api.map.baidu.com/directionlite/v1/driving?'
        params = {
            'ak': self.key,
            'origin': s_e[0],
            'destination': s_e[1],
            'waypoints': waypoints,
            'tactics': tactics,
            'coord_type': coord_type,
            'ret_coordtype': ret_coordtype
        }

        response = requests.get(url, params)
        content = json.loads(response.content)

        routes = content['result']['routes']
        results = list()

        for route in routes:
            results += route['steps']

        return pd.DataFrame(results)
コード例 #3
0
ファイル: bmap.py プロジェクト: vctcn93/gibbon_lib
    def reverse_geocoding(self,
                          lnglat: tuple,
                          coordtype: str = 'wgs84ll',
                          ret_coordtype: str = 'gcj02ll',
                          radius: int = 1000,
                          sn: str = '',
                          output='json',
                          callback='',
                          extensions_poi: int = 0,
                          extensions_road: str = 'flase',
                          extensions_town: str = 'true',
                          language: str = 'zh-CN',
                          language_auto: int = 1) -> str:
        """
        :param lnglat: 根据经纬度坐标获取地址。
        :param coordtype: 发送的坐标的类型
        :param ret_coordtype: 后返回国测局经纬度坐标或百度米
        :param radius: poi召回半径,允许设置区间为0-1000米,超过1000米按1000米召回
        :param sn: 若用户所用ak的校验方式为sn校验时该参数必须
        :param output: 输出格式为json或者xml
        :param callback: 将json格式的返回值通过callback函数返回以实现jsonp功能
        :param extensions_poi: extensions_poi=0,不召回pois数据
                                extensions_poi=1,返回pois数据,默认显示周边1000米内的poi。
        :param extensions_road: 当取值为true时,召回坐标周围最近的3条道路数据。
                                区别于行政区划中的street参数(street参数为行政区划中的街道,和普通道路不对应)。
        :param extensions_town: 当取值为true时,行政区划返回乡镇级数据(仅国内召回乡镇数据)。默认不访问。
        :param language: 指定召回的新政区划语言类型。
        :param language_auto: 是否自动填充行政区划,1填充,0不填充。
        :return:
        """
        lnglat = Convert.to_string(lnglat.copy().reverse())

        url = 'http://api.map.baidu.com/reverse_geocoding/v3/?'
        params = {
            'ak': self.key,
            'location': lnglat,
            'coordtype': coordtype,
            'ret_coordtype': ret_coordtype,
            'radius': radius,
            'sn': sn,
            'output': output,
            'callback': callback,
            'extensions_poi': extensions_poi,
            'extensions_road': extensions_road,
            'extensions_town': extensions_town,
            'language': language,
            'language_auto': language_auto
        }

        response = requests.get(url, params)
        content = json.loads(response.content)
        return content['result']['formatted_address']
コード例 #4
0
ファイル: _map_sensor.py プロジェクト: vctcn93/gibbon_lib
 def calculate_bounds(self):
     extremums = [
         np.min(self._indices, axis=(0, 1)),
         np.max(self._indices, axis=(0, 1))
     ]
     diss = extremums - self._center_index
     bounds = diss * self._tile_size
     fix = [[-self._tile_size, -self._tile_size, 0],
            [self._tile_size, self._tile_size, 0]]
     bounds += fix
     self._bounds = np.delete(bounds, -1, axis=1)
     self._llbounds = list(
         map(lambda x: Convert.mercator_to_lnglat(x, self.origin),
             self._bounds / 1000))
コード例 #5
0
ファイル: bmap.py プロジェクト: vctcn93/gibbon_lib
    def static_image(self,
                     lnglat: tuple,
                     width: int = '',
                     height: int = '',
                     scale: int = '',
                     bbox: str = '',
                     zoom: float = '',
                     coordtype: str = 'wgs84ll',
                     show: bool = False):
        """
        返回百度申请的静态地图
        :param lnglat: 地图中心点位置,参数可以为经纬度坐标或名称。坐标格式:lng<经度>,lat<纬度>,[116.43213,38.76623]。
        :param width: 图片宽度。取值范围:(0, 1024]。Scale=2,取值范围:(0, 512]。
        :param height: 图片高度。取值范围:(0, 1024]。Scale=2,取值范围:(0, 512]。
        :param scale: 返回图片大小会根据此标志调整。取值范围为1或2:
                    1表示返回的图片大小为size= width * height;
                    2表示返回图片为(width*2)*(height *2),且zoom加1
                    注:如果zoom为最大级别,则返回图片为(width*2)*(height*2),zoom不变。
        :param bbox: 地图视野范围。格式:minX,minY;maxX,maxY。
        :param zoom: 地图级别。高清图范围[3, 18];低清图范围[3,19]
        :param coordtype: 静态图的坐标类型。
                    支持wgs84ll(wgs84坐标)/gcj02ll(国测局坐标)/bd09ll(百度经纬度)/bd09mc(百度墨卡托)。默认bd09ll(百度经纬度)
        :param show: 是否临时显示图片
        :return: 区域的静态地图图片
        """
        # 官方API,经前纬后
        lnglat = Convert.to_string(lnglat)

        url = 'http://api.map.baidu.com/staticimage/v2?'
        params = {
            'ak': self.key,
            'center': lnglat,
            'width': width,
            'height': height,
            'scale': scale,
            'bbox': bbox,
            'zoom': zoom,
            'coordtype': coordtype
        }

        response = requests.get(url, params=params)
        img = Image.open(BytesIO(response.content))

        if show:
            img.show()

        rgb = img.convert('RGB')
        return np.array(rgb).astype(int)
コード例 #6
0
ファイル: bmap.py プロジェクト: vctcn93/gibbon_lib
    def walking_path_by_origin_destination(
            self,
            origin: tuple,
            destination: tuple,
            coord_type: str = 'wgs84',
            ret_coordtype: str = 'gcj02') -> list:
        """
        根据起终点坐标规划步行出行路线和耗时
        :param origin: 起点
        :param destination: 终点
        :param coord_type: 输入坐标类型
                bd09ll:百度经纬度坐标
                bd09mc:百度墨卡托坐标
                gcj02:国测局加密坐标
                wgs84:gps设备获取的坐标
        :param ret_coordtype: 输出坐标类型
                bd09ll:百度经纬度坐标
                gcj02:国测局加密坐标
        :return: pd.DataFrame
        """
        s_e = list()
        for item in [origin.copy(), destination.copy()]:
            item.reverse()
            s_e.append(Convert.to_string(item))

        url = 'http://api.map.baidu.com/directionlite/v1/walking?'
        params = {
            'ak': self.key,
            'origin': s_e[0],
            'destination': s_e[1],
            'coord_type': coord_type,
            'ret_coordtype': ret_coordtype
        }

        response = requests.get(url, params)
        content = json.loads(response.content)

        routes = content['result']['routes']
        results = list()

        for route in routes:
            results += route['steps']

        return pd.DataFrame(results)
コード例 #7
0
                [-91011.301433665678, -165898.26749964245],
                [135656.22394360788, -165898.26749976166],
                [135656.22394360788, -115189.30818407424],
                [126656.22394360788, -106189.30821271427],
                [126686.89403142221, -97189.308212356642],
                [57662.24364461191, -97189.308212356642],
                [57461.112780706026, 32315.40416692337],
                [135645.11278065387, 32315.40416692337]]

    project = Project(boundary, origin=[113.520280, 22.130790])
    path = r'C:\Users\wenhs\Desktop'
    project.fem_red_line.dump_mesh(path + r'\fem_red_line.json')
    project.fem_site.dump_mesh(path + r'\fem_site.json')
    project.fem_map.dump_mesh(path + r'\fem_map.json')

    dfs = list()
    kinds = ['公交车站', '住宅']

    for k in kinds:
        pois = project.pois_by_keyword(k)
        location, names = pois['location'], pois['name']
        lnglats = location.apply(lambda x: [x['lng'], x['lat']])
        coords = lnglats.apply(
            lambda x: Convert.lnglat_to_mercator(x, project.sensor.origin))

        rst = pd.DataFrame()
        rst['names'] = names
        rst['lnglat'] = lnglats
        rst['coords'] = coords
        rst.to_json(path + f'/{k}.json')
コード例 #8
0
ファイル: bmap.py プロジェクト: vctcn93/gibbon_lib
    def pois_by_lnglat_radius_keyword(self,
                                      lnglat: tuple,
                                      radius: int,
                                      keywords: str,
                                      radius_limit: str = 'true',
                                      types: str = '',
                                      page: int = 0,
                                      offset: int = 20,
                                      extension: int = 2,
                                      ret_coordtype: str = 'wgs84ll',
                                      coord_type: int = 1) -> list:
        """
        设置圆心和半径,检索圆形区域内的地点信息
        :param lnglat: 圆形区域检索中心点,不支持多个点
        :param radius: 圆形区域检索半径,单位为米。(当半径过大,超过中心点所在城市边界时,会变为城市范围检索,检索范围为中心点所在城市)
        :param keywords: 检索关键字。圆形区域检索和矩形区域内检索支持多个关键字并集检索,不同关键字间以$符号分隔,最多支持10个关键字检索。
        :param radius_limit: 是否严格限定召回结果在设置检索半径范围内。
        :param types: 检索分类偏好,与q组合进行检索,多个分类以","分隔
        :param page: 分页页码,默认为0,0代表第一页,1代表第二页,以此类推。
        :param offset: 单次召回POI数量,默认为10条记录,最大返回20条。
        :param extension:  检索结果详细程度。取值为1 或空,则返回基本信息;取值为2,返回检索POI详细信息
        :param ret_coordtype: 可选参数,添加后POI返回wgs84经纬度坐标
        :param coord_type: 坐标类型。
                1(wgs84ll即GPS经纬度)
                2(gcj02ll即国测局经纬度坐标)
                3(bd09ll即百度经纬度坐标)
                4(bd09mc即百度米制坐标)
        :return: pd.DataFrame
        """
        pois = list()
        lnglat.reverse()
        lnglat = Convert.to_string(lnglat)

        url = 'http://api.map.baidu.com/place/v2/search?'
        params = {
            'ak': self.key,
            'query': keywords,
            'location': lnglat,
            'radius': radius,
            'tag': types,
            'radius_limit': radius_limit,
            'page_num': page,
            'page_size': offset,
            'ret_coordtype': ret_coordtype,
            'coord_type': coord_type,
            'scope': extension,
            'output': 'json'
        }

        response = requests.get(url, params)
        content = json.loads(response.content)
        pois += content['results']
        quantity = content['total']
        turns = int(quantity / offset)

        for i in range(1, turns + 1):
            params['page_num'] = i
            response = requests.get(url, params)
            content = json.loads(response.content)
            pois += content['results']

        return pd.DataFrame(pois)
コード例 #9
0
ファイル: _normal_tile.py プロジェクト: vctcn93/gibbon_lib
    def calculate_vertices(self):
        sizes = [[self.tile_size, self.tile_size]] * 4
        marks = np.array([[-1, -1], [1, -1], [1, 1], [-1, 1]])
        change = sizes * marks / 2
        coords = change + self._coords
        heights = np.zeros([len(coords), 1])
        self._vertices = np.concatenate((coords, heights), axis=1)

    def set_colour(self, colour):
        self._colour = np.ones_like(self._vertices)
        self._colour[:, :, :] = colour 

    def create_mesh(self):
        super().create_mesh()
        self.calculate_vertices()
        self._mesh['v'] = self.vertices
        self._mesh['f'] = [[0, 1, 2, 3]]
        # self._mesh['c'] = [[255, 255, 255]] * len(self._vertices)


if __name__ == '__main__':
    cs = [112.970840, 28.198560]
    center_tile_index = Convert.lnglat_to_tile_index(cs, 17)
    tile_index = [106667, 54827, 17]
    tile = NormalTile(center_tile_index, tile_index)
    print(tile.tile_size)
    print(tile.coords)
    print(tile.vertices)
    print(tile.mesh)
コード例 #10
0
 def f(lnglats):
     return [Convert.lnglat_to_mercator(ll, self.sensor.origin) for ll in lnglats]
コード例 #11
0
 def calculate_tile_size(self):
     self._tile_size = Convert.tile_size_by_zoom(self.level)
コード例 #12
0
ファイル: _map_sensor.py プロジェクト: vctcn93/gibbon_lib
 def calculate_center_index(self):
     center_index = Convert.lnglat_to_tile_index(self._lnglat, self._level)
     self._center_index = np.array(center_index)
コード例 #13
0
ファイル: _map_sensor.py プロジェクト: vctcn93/gibbon_lib
 def f(x):
     size = Convert.tile_size_by_zoom(x, 'm')
     quantity = self._radius / size
     return abs(quantity - self.row_limit)