def test_geo_boundaries_polygon_response(): response: SuccessResponse = make_success_response() \ .set_geocoded_features( [ NAMED_FEATURE_BUILDER \ .set_boundary( make_polygon_boundary( polygon( ring( point(1, 2), point(3, 4), point(5, 6) ) ) ) ).build_geocoded(), NAMED_FEATURE_BUILDER \ .set_boundary( make_polygon_boundary( polygon( ring( point(11, 11), point(11, 14), point(14, 14), point(14, 11), point(11, 11) ), ring( point(12, 12), point(12, 13), point(13, 13), point(13, 12), point(12, 12) ) ) ) ).build_geocoded() ] ).build() assert_success_response(response) boundary: DataFrame = BoundariesGeoDataFrame().to_data_frame( queries=features_to_queries(response.features), answers=features_to_answers(response.features), level_kind=LevelKind.city) assert_geo_boundary(boundary, index=0, polygon=[[point(1, 2), point(3, 4), point(5, 6)]]) assert_geo_boundary(boundary, index=1, polygon=[[ point(11, 11), point(11, 14), point(14, 14), point(14, 11), point(11, 11) ], [ point(12, 12), point(12, 13), point(13, 13), point(13, 12), point(12, 12) ]])
def test_geo_centroid_response(): response: SuccessResponse = make_success_response() \ .set_geocoded_features( [ NAMED_FEATURE_BUILDER \ .set_centroid(make_centroid_point()) \ .build_geocoded() ] ).build() assert_success_response(response) data_frame: DataFrame = CentroidsGeoDataFrame().to_data_frame( answers=features_to_answers(response.features), queries=features_to_queries(response.features), level_kind=LevelKind.city) assert_geo_centroid(data_frame, 0)
def test_geo_boundaries_point_response(): response: SuccessResponse = make_success_response() \ .set_geocoded_features( [ NAMED_FEATURE_BUILDER \ .set_boundary(make_single_point_boundary(-5, 13)) \ .build_geocoded(), NAMED_FEATURE_BUILDER \ .set_boundary(make_single_point_boundary(7, -3)) \ .build_geocoded(), ] ).build() assert_success_response(response) boundary: DataFrame = BoundariesGeoDataFrame().to_data_frame( queries=features_to_queries(response.features), answers=features_to_answers(response.features), level_kind=LevelKind.city) assert_geo_centroid(boundary, index=0, lon=-5, lat=13) assert_geo_centroid(boundary, index=1, lon=7, lat=-3)
def test_geo_boundaries_multipolygon_response(): r0 = [point(1, 2), point(3, 4), point(5, 6), point(1, 2)] r1 = [point(7, 8), point(9, 10), point(11, 12), point(7, 8)] r2 = [point(13, 14), point(15, 16), point(17, 18), point(13, 14)] r3 = [point(19, 20), point(21, 22), point(23, 24), point(19, 20)] response: SuccessResponse = make_success_response() \ .set_geocoded_features( [ NAMED_FEATURE_BUILDER \ .set_boundary( make_multipolygon_boundary( multipolygon( polygon( ring(*r0) ), polygon( ring(*r1), ring(*r2) ) ), ) ).build_geocoded(), NAMED_FEATURE_BUILDER \ .set_boundary( make_multipolygon_boundary( multipolygon( polygon(ring(*r3)) ) ) ).build_geocoded() ] ).build() assert_success_response(response) boundary: DataFrame = BoundariesGeoDataFrame().to_data_frame( queries=features_to_queries(response.features), answers=features_to_answers(response.features), level_kind=LevelKind.city) assert_geo_multiboundary(boundary, index=0, multipolygon=[[r0], [r1, r2]]) assert_geo_multiboundary(boundary, index=1, multipolygon=[[r3]])
def test_geo_limit_response(): response: SuccessResponse = make_success_response() \ .set_geocoded_features( [ NAMED_FEATURE_BUILDER \ .set_limit(make_limit_rect()) \ .build_geocoded() ] ).build() assert_success_response(response) data_frame: DataFrame = LimitsGeoDataFrame().to_data_frame( answers=features_to_answers(response.features), queries=features_to_queries(response.features), level_kind=LevelKind.city) assert_row(df=data_frame, names=FOUND_NAME, found_name=FOUND_NAME, lon_min=GEO_RECT_MIN_LON, lon_max=GEO_RECT_MAX_LON, lat_min=GEO_RECT_MIN_LAT, lat_max=GEO_RECT_MAX_LAT)