Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : Fetch Countries by cid #247

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions API/raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,13 @@ def get_countries(q: str = ""):
return result


@router.get("/countries/{cid}/")
@version(1)
def get_specific_country(cid: int):
result = RawData().get_country(cid)
return result


@router.get("/osm_id/")
@version(1)
def get_osm_feature(osm_id: int):
Expand Down
18 changes: 18 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
extract_geometry_type_query,
generate_polygon_stats_graphql_query,
get_countries_query,
get_country_cid,
get_country_from_iso,
get_country_geom_from_iso,
get_osm_feature_query,
Expand Down Expand Up @@ -847,6 +848,23 @@ def get_countries_list(self, q):
self.cur.close()
return FeatureCollection(features=features)

def get_country(self, q):
"""Gets specific country from the database

Args:
cid (_type_): country cid

Returns:
featurecollection: geojson of country
"""
query = get_country_cid(q)
self.cur.execute(query)
get_fetched = self.cur.fetchall()
self.cur.close()
if len(get_fetched) < 1:
return "Not found"
return orjson.loads(get_fetched[0][0])

def get_osm_feature(self, osm_id):
"""Returns geometry of osm_id in geojson

Expand Down
8 changes: 8 additions & 0 deletions src/query_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
# 1100 13th Street NW Suite 800 Washington, D.C. 20005
# <[email protected]>
"""Page Contains Query logic required for application"""
# Standard library imports
import re
from json import dumps, loads

# Third party imports
from geomet import wkt

# Reader imports
from src.config import USE_DUCK_DB_FOR_CUSTOM_EXPORTS
from src.config import logger as logging
from src.validation.models import SupportedFilters, SupportedGeometryFilters
Expand Down Expand Up @@ -777,6 +780,11 @@ def get_countries_query(q):
return query


def get_country_cid(cid):
query = f"Select ST_AsGeoJSON(cf.*) FROM countries cf where cid = {cid}"
return query


def get_osm_feature_query(osm_id):
select_condition = (
"osm_id, tableoid::regclass AS osm_type, tags,changeset,timestamp,geom"
Expand Down
Loading