Skip to content

Module src.query_builder.builder

Page Contains Query logic required for application

Variables

HDX_FILTER_CRITERIA
HDX_MARKDOWN
USE_DUCK_DB_FOR_CUSTOM_EXPORTS

Functions

check_exisiting_country

def check_exisiting_country(
    geom
)

check_last_updated_rawdata

def check_last_updated_rawdata(

)

convert_tags_pattern_to_postgres

def convert_tags_pattern_to_postgres(
    query_string
)

create_column_filter

def create_column_filter(
    columns,
    create_schema=False,
    output_type='geojson',
    use_centroid=False,
    include_osm_type=True,
    include_user_metadata=False
)
generates column filter , which will be used to filter column in output will be used on select query - Rawdata extraction

create_geom_filter

def create_geom_filter(
    geom,
    geom_lookup_by='ST_intersects'
)
generates geometry intersection filter - Rawdata extraction

create_tag_sql_logic

def create_tag_sql_logic(
    key,
    value,
    filter_list
)

extract_attributes_tags

def extract_attributes_tags(
    filters
)

extract_custom_features_from_postgres

def extract_custom_features_from_postgres(
    select_q,
    from_q,
    where_q,
    geom=None,
    cid=None
)
Generates Postgresql query for custom feature extraction

extract_features_custom_exports

def extract_features_custom_exports(
    base_table_name,
    select,
    feature_type,
    where,
    geometry=None,
    cid=None
)
Generate a Extraction query to extract features based on given parameters.

Args: - base_table_name (str): Base table name. - select (List[str]): List of selected fields. - feature_type (str): Type of feature (points, lines, polygons). - where (str): SQL-like condition to filter features.

Returns: str: Extraction query to extract features.

extract_geometry_type_query

def extract_geometry_type_query(
    params,
    ogr_export=False,
    g_id=None,
    c_id=None,
    country_export=False
)
used for specifically focused on export tool , this will generate separate queries for line point and polygon can be used on other datatype support - Rawdata extraction

format_file_name_str

def format_file_name_str(
    input_str
)

generate_polygon_stats_graphql_query

def generate_polygon_stats_graphql_query(
    geojson_feature
)
Gernerates the graphql query for the statistics

generate_tag_filter_query

def generate_tag_filter_query(
    filter,
    join_by=' OR ',
    plain_query_filter=False
)

generate_where_clause_indexes_case

def generate_where_clause_indexes_case(
    geom_filter,
    g_id,
    c_id,
    country_export,
    table_name='ways_poly'
)

get_countries_query

def get_countries_query(
    q
)

get_country_cid

def get_country_cid(
    cid
)

get_country_from_iso

def get_country_from_iso(
    iso3
)
Generate a SQL query to retrieve country information based on ISO3 code.

Args: - iso3 (str): ISO3 Country Code.

Returns: str: SQL query to fetch country information.

get_country_geojson

def get_country_geojson(
    c_id
)

get_country_geom_from_iso

def get_country_geom_from_iso(
    iso3
)
Generate a SQL query to retrieve country geometry based on ISO3 code.

Args: - iso3 (str): ISO3 Country Code.

Returns: str: SQL query to fetch country geometry.

get_country_id_query

def get_country_id_query(
    geom_dump
)

get_grid_id_query

def get_grid_id_query(
    geometry_dump
)

get_osm_feature_query

def get_osm_feature_query(
    osm_id
)

get_query_as_geojson

def get_query_as_geojson(
    query_list,
    ogr_export=None
)

postgres2duckdb_query

def postgres2duckdb_query(
    base_table_name,
    table,
    cid=None,
    geometry=None,
    single_category_where=None,
    enable_users_detail=False
)
Generate a DuckDB query to create a table from a PostgreSQL query.

Args: - base_table_name (str): Base table name. - table (str): PostgreSQL table name. - cid (int, optional): Country ID for filtering. Defaults to None. - geometry (Polygon, optional): Custom polygon geometry. Defaults to None. - single_category_where (str, optional): Where clause for single category to fetch it from postgres - enable_users_detail (bool, optional): Enable user details. Defaults to False.

Returns: str: DuckDB query for creating a table.

raw_currentdata_extraction_query

def raw_currentdata_extraction_query(
    params,
    g_id=None,
    c_id=None,
    ogr_export=False,
    country_export=False
)
Default function to support current snapshot extraction with all of the feature that export_tool_api has

raw_extract_plain_geojson

def raw_extract_plain_geojson(
    params,
    inspect_only=False
)

remove_spaces

def remove_spaces(
    input_str
)