コード例 #1
0
 def test_mapper(self):
     latlons = np.array([
         [46.0555, 14.5083],  # Ljubljana
         [40.7127, -74.0059],  # NYC
         [32.775833, -96.796667],  # Dallas
         (49.761667, -77.802778),  # Quebec, Ontario
         (31.814700, 79.886838),  # Tibet
         (52.818925, 92.567674),  # Krasnoyarsk
         [64.295556, -15.227222],  # Austurland, Iceland
         [61.760153, -121.236525],  # Canada
         [0, -1],  # "middle of the ocean"
         [40, np.nan],
     ])
     self.assertEqual([i.get('name') for i in latlon2region(latlons, 2)], [
         'Ljubljana', 'New York, New York', 'Dallas, Texas', 'Québec',
         'Xizang', 'Krasnoyarsk', 'Austurland', 'Northwest Territories',
         None, None
     ])
     self.assertEqual([i.get('_id') for i in latlon2region(latlons, 0)], [
         'SVN', 'USA', 'USA', 'CAN', 'CHN', 'RUS', 'ISL', 'CAN', None, None
     ])
     self.assertEqual([i.get('_id') for i in latlon2region(latlons, 1)], [
         'SVN-962', 'USA-3559', 'USA-3536', 'CAN-683', 'CHN-1662',
         'RUS-2603', 'ISL-695', 'CAN-635', None, None
     ])
     self.assertEqual([i.get('_id') for i in latlon2region(latlons, 2)], [
         'SVN-962', 'USA-NY-36061', 'USA-TX-48113', 'CAN-683', 'CHN-1662',
         'RUS-2603', 'ISL-695', 'CAN-635', None, None
     ])
コード例 #2
0
    def get_regions(self, lat_attr, lon_attr, admin):
        """
        Map points to regions and get regions information.
        Returns:
            ndarray of ids corresponding to points,
            dict of region ids matched to their additional info,
            dict of region ids matched to their polygon
        """
        latlon = np.c_[self.data.get_column_view(lat_attr)[0],
                       self.data.get_column_view(lon_attr)[0]]
        region_info = latlon2region(latlon, admin)
        ids = np.array([region.get('_id') for region in region_info])
        region_info = {info.get('_id'): info for info in region_info}

        self.data_ids = np.array(ids)
        no_region = np.sum(self.data_ids == None)
        if no_region:
            self.Warning.no_region(no_region)

        unique_ids = list(set(ids) - {None})
        polygons = {
            _id: poly
            for _id, poly in zip(unique_ids, get_shape(unique_ids))
        }
        return ids, region_info, polygons
コード例 #3
0
ファイル: owgeocoding.py プロジェクト: astaric/orange3-geo
 def decode(self):
     if (self.data is None or not len(self.data)
             or self.lat_attr not in self.data.domain
             or self.lon_attr not in self.data.domain):
         return None
     latlon = np.c_[self.data.get_column_view(self.lat_attr)[0],
                    self.data.get_column_view(self.lon_attr)[0]]
     assert isinstance(self.admin, int)
     regions = pd.DataFrame(latlon2region(latlon, self.admin))
     return self._to_addendum(regions, ['name'])
コード例 #4
0
 def get_regions(self, lat_attr, lon_attr, admin):
     latlon = np.c_[self.data.get_column_view(lat_attr)[0],
                    self.data.get_column_view(lon_attr)[0]]
     regions = latlon2region(latlon, admin)
     adm0 = ({'0'} if admin == 0 else
             {'1-' + a3 for a3 in (i.get('adm0_a3') for i in regions) if a3} if admin == 1 else
             {('2-' if a3 in ADMIN2_COUNTRIES else '1-') + a3
              for a3 in (i.get('adm0_a3') for i in regions) if a3})
     ids = [i.get('_id') for i in regions]
     self.ids = pd.Series(ids)
     regions = set(ids) - {None}
     bounds = get_bounding_rect(regions) if regions else None
     return regions, ids, adm0, bounds
コード例 #5
0
 def decode(self):
     self.setMainAreaVisibility(False)
     if (self.data is None or not len(self.data)
             or self.lat_attr not in self.data.domain
             or self.lon_attr not in self.data.domain):
         return None
     latlon = np.c_[self.data.get_column_view(self.lat_attr)[0],
                    self.data.get_column_view(self.lon_attr)[0]]
     assert isinstance(self.admin, int)
     with self.progressBar(2) as progress:
         progress.advance()
         regions = pd.DataFrame(latlon2region(latlon, self.admin))
     return self._to_addendum(regions, ['name'])