コード例 #1
0
    def test_compare_voronoi_polygons(self):

        files = ['up_in_3_thie_join.shp', 'up_in_11_thie_join.shp']
        out = tempfile.mkdtemp(prefix='voronoi_')

        for f in files:
            voronoi_shp_file = res_mgr.get_resource_path('test/shp/%s' % f)
            area_shp_file = res_mgr.get_resource_path(
                'extraction/shp/kub-wgs84/kub-wgs84.shp')

            shape_df = gpd.GeoDataFrame.from_file(voronoi_shp_file)

            points = {}
            for i in range(len(shape_df)):
                points[shape_df['OBJECTID'][i]] = [
                    shape_df['x'][i], shape_df['y'][i]
                ]

            result = get_voronoi_polygons(points,
                                          area_shp_file, ['OBJECTID', 1],
                                          output_shape_file=os.path.join(
                                              out, '%s_out.shp' % f))

            for i in range(len(shape_df)):
                self.assertAlmostEqual(result['area'][i],
                                       shape_df['Shape_Area'][i],
                                       places=4)
コード例 #2
0
    def test_get_voronoi_polygons_kub(self):
        points = {
            'Colombo': [79.8653, 6.898158],
            'IBATTARA3': [79.86, 6.89],
            'Isurupaya': [79.92, 6.89],
            'Daraniyagala': [80.33805556, 6.924444444],
            'Glencourse': [80.20305556, 6.978055556],
            'Hanwella': [80.08166667, 6.909722222],
            'Holombuwa': [80.26480556, 7.185166667],
            'Kitulgala': [80.41777778, 6.989166667],
            'Borella': [
                79.86,
                6.93,
            ],
            'Kompannaveediya': [79.85, 6.92],
        }

        shp = res_mgr.get_resource_path(
            'extraction/shp/kelani-upper-basin.shp')
        out = tempfile.mkdtemp(prefix='voronoi_')
        print(out)
        result = get_voronoi_polygons(points,
                                      shp, ['OBJECTID', 1],
                                      output_shape_file=os.path.join(
                                          out, 'out.shp'))
        print(result)
コード例 #3
0
def get_thessian_polygon_from_gage_points(shape_file, gage_points):
    shape = res_mgr.get_resource_path(shape_file)
    # calculate the voronoi/thesian polygons w.r.t given station points.
    thessian_df = get_voronoi_polygons(gage_points, shape, ['OBJECTID', 1],
                                       output_shape_file=os.path.join(SUB_CATCHMENT_SHAPE_FILE_DIR,
                                                                      'sub_catchment.shp'))
    return thessian_df
コード例 #4
0
def get_voronoi_polygons_kub(points):
    shp = res_mgr.get_resource_path('kub/kelani-upper-basin.shp')
    result = get_voronoi_polygons(points,
                                  shp, ['OBJECTID', 1],
                                  output_shape_file=os.path.join(
                                      '/home/hasitha/QGis/test', 'out.shp'))
    print(result.iloc[0])
コード例 #5
0
def get_thessian_polygon_from_gage_points(shape_file, gage_points):
    shape = res_mgr.get_resource_path(shape_file)
    # calculate the voronoi/thesian polygons w.r.t given station points.
    thessian_df = get_voronoi_polygons(
        gage_points,
        shape, ['OBJECTID', 1],
        output_shape_file=os.path.join(
            PROJECT_PATH,
            datetime.date.today().strftime('%Y-%m-%d') + '.shp'))
    return thessian_df
コード例 #6
0
    def test_is_inside_polygon(self):
        points = {
            'Colombo': [79.8653, 6.898158],
            'IBATTARA3': [79.86, 6.89],
            'Isurupaya': [79.92, 6.89],
            'Borella': [
                79.86,
                6.93,
            ],
            'Kompannaveediya': [79.85, 6.92],
        }

        shp = res_mgr.get_resource_path(
            'extraction/shp/klb-wgs84/klb-wgs84.shp')
        result = get_voronoi_polygons(points, shp, ['OBJECTID', 1])
        print(result)
        for k in points.keys():
            pp = is_inside_geo_df(result, points[k][0], points[k][1])
            print(points[k], pp)
            self.assertEqual(pp, k)
コード例 #7
0
    def test_get_voronoi_polygons(self):
        points = {
            'Colombo': [79.8653, 6.898158],
            'IBATTARA3': [79.86, 6.89],
            'Isurupaya': [79.92, 6.89],
            'Borella': [
                79.86,
                6.93,
            ],
            'Kompannaveediya': [79.85, 6.92],
        }

        shp = res_mgr.get_resource_path(
            'extraction/shp/klb-wgs84/klb-wgs84.shp')
        out = tempfile.mkdtemp(prefix='voronoi_')
        result = get_voronoi_polygons(points,
                                      shp, ['OBJECTID', 1],
                                      output_shape_file=os.path.join(
                                          out, 'out.shp'))
        print(result)
コード例 #8
0
from resources import manager as res_mgr
import geopandas as gpd


if __name__ == '__main__':
    shape_file = res_mgr.get_resource_path('kub-wgs84/kub-wgs84.shp')
    shape_df = gpd.GeoDataFrame.from_file(shape_file)
    print('shape_df : ', shape_df)
    shape_polygon = shape_df['geometry']
    print('shape_polygon : ', shape_df['geometry'])
    area = shape_polygon.area
    print('kub area : ', area)
    sub_shape_file = res_mgr.get_resource_path('sub_catchments/sub_subcatchments.shp')
    catchment_df = gpd.GeoDataFrame.from_file(sub_shape_file)
    for i, catchment_polygon in enumerate(catchment_df['geometry']):
        print('sub area : ', catchment_polygon.area)
コード例 #9
0
def get_gage_points():
    gage_csv = res_mgr.get_resource_path('gages/CurwRainGauges.csv')
    gage_df = pd.read_csv(gage_csv)[['name', 'longitude', 'latitude']]
    gage_dict = gage_df.set_index('name').T.to_dict('list')
    return gage_dict
コード例 #10
0
def get_catchment_area(catchment_file):
    shape = res_mgr.get_resource_path(catchment_file)
    catchment_df = gpd.GeoDataFrame.from_file(shape)
    return catchment_df