Skip to content

Commit

Permalink
update type to osm_type field
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Dec 27, 2023
1 parent 0d9f81c commit 459c287
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions src/query_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def create_column_filter(
if len(columns) > 0:
filter_col = []
filter_col.append("osm_id")
filter_col.append("tableoid::regclass AS type")
filter_col.append("tableoid::regclass AS osm_type")

if create_schema:
schema = {}
Expand Down Expand Up @@ -154,7 +154,7 @@ def create_column_filter(
return select_condition, schema
return select_condition
else:
return f"osm_id, tableoid::regclass AS type, tags,changeset,timestamp,{'ST_Centroid(geom) as geom' if use_centroid else 'geom'}" # this is default attribute that we will deliver to user if user defines his own attribute column then those will be appended with osm_id only
return f"osm_id, tableoid::regclass AS osm_type, tags,changeset,timestamp,{'ST_Centroid(geom) as geom' if use_centroid else 'geom'}" # this is default attribute that we will deliver to user if user defines his own attribute column then those will be appended with osm_id only


def create_tag_sql_logic(key, value, filter_list):
Expand Down Expand Up @@ -229,7 +229,7 @@ def extract_geometry_type_query(
params.geometry,
"ST_within" if params.use_st_within is True else "ST_intersects",
)
select_condition = f"""osm_id, tableoid::regclass AS type, tags,changeset,timestamp , {'ST_Centroid(geom) as geom' if params.centroid else 'geom'}""" # this is default attribute that we will deliver to user if user defines his own attribute column then those will be appended with osm_id only
select_condition = f"""osm_id, tableoid::regclass AS osm_type, tags,changeset,timestamp , {'ST_Centroid(geom) as geom' if params.centroid else 'geom'}""" # this is default attribute that we will deliver to user if user defines his own attribute column then those will be appended with osm_id only
schema = {
"osm_id": "int64",
"type": "str",
Expand Down Expand Up @@ -524,9 +524,9 @@ def raw_currentdata_extraction_query(

# query_table = []
if select_all:
select_condition = f"""osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,{'ST_Centroid(geom) as geom' if params.centroid else 'geom'}""" # FIXme have condition for displaying userinfo after user authentication
select_condition = f"""osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,{'ST_Centroid(geom) as geom' if params.centroid else 'geom'}""" # FIXme have condition for displaying userinfo after user authentication
else:
select_condition = f"""osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,{'ST_Centroid(geom) as geom' if params.centroid else 'geom'}""" # this is default attribute that we will deliver to user if user defines his own attribute column then those will be appended with osm_id only
select_condition = f"""osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,{'ST_Centroid(geom) as geom' if params.centroid else 'geom'}""" # this is default attribute that we will deliver to user if user defines his own attribute column then those will be appended with osm_id only

point_select_condition = select_condition # initializing default
line_select_condition = select_condition
Expand Down Expand Up @@ -772,7 +772,7 @@ def get_countries_query(q):

def get_osm_feature_query(osm_id):
select_condition = (
"osm_id, tableoid::regclass AS type, tags,changeset,timestamp,geom"
"osm_id, tableoid::regclass AS osm_type, tags,changeset,timestamp,geom"
)
query = f"""SELECT ST_AsGeoJSON(n.*)
FROM (select {select_condition} from nodes) n
Expand Down Expand Up @@ -877,11 +877,11 @@ def postgres2duckdb_query(
Returns:
str: DuckDB query for creating a table.
"""
select_query = """osm_id, tableoid::regclass AS type, version, changeset, timestamp, tags, ST_AsBinary(geom) as geometry"""
select_query = """osm_id, tableoid::regclass AS osm_type, version, changeset, timestamp, tags, ST_AsBinary(geom) as geometry"""
create_select_duck_db = """osm_id, type , version, changeset, timestamp, type, cast(tags::json AS map(varchar, varchar)) AS tags, cast(ST_GeomFromWKB(geometry) as GEOMETRY) AS geometry"""

if enable_users_detail:
select_query = """osm_id, tableoid::regclass AS type, uid, user, version, changeset, timestamp, tags, ST_AsBinary(geom) as geometry"""
select_query = """osm_id, tableoid::regclass AS osm_type, uid, user, version, changeset, timestamp, tags, ST_AsBinary(geom) as geometry"""
create_select_duck_db = """osm_id, type, uid, user, version, changeset, timestamp,type, cast(tags::json AS map(varchar, varchar)) AS tags, cast(ST_GeomFromWKB(geometry) as GEOMETRY) AS geometry"""

def convert_tags_pattern(query_string):
Expand Down
36 changes: 18 additions & 18 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ def test_rawdata_current_snapshot_geometry_query():
}
validated_params = RawDataCurrentParams(**test_param)
expected_query = """select ST_AsGeoJSON(t0.*) from (select
osm_id , tableoid::regclass AS type , tags ->> 'name' as name , geom
osm_id , tableoid::regclass AS osm_type , tags ->> 'name' as name , geom
from
nodes
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}')) and (tags ->> 'amenity' IN ( 'shop' , 'toilet' ))) t0 UNION ALL select ST_AsGeoJSON(t1.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
ways_line
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t1 UNION ALL select ST_AsGeoJSON(t2.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
ways_poly
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t2 UNION ALL select ST_AsGeoJSON(t3.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
relations
where
Expand Down Expand Up @@ -92,22 +92,22 @@ def test_rawdata_current_snapshot_normal_query():
}
validated_params = RawDataCurrentParams(**test_param)
expected_query = """select ST_AsGeoJSON(t0.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
nodes
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t0 UNION ALL select ST_AsGeoJSON(t1.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
ways_line
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t1 UNION ALL select ST_AsGeoJSON(t2.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
ways_poly
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t2 UNION ALL select ST_AsGeoJSON(t3.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
relations
where
Expand Down Expand Up @@ -136,22 +136,22 @@ def test_rawdata_current_snapshot_normal_query_ST_within():
}
validated_params = RawDataCurrentParams(**test_param)
expected_query = """select ST_AsGeoJSON(t0.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
nodes
where
ST_within(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t0 UNION ALL select ST_AsGeoJSON(t1.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
ways_line
where
ST_within(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t1 UNION ALL select ST_AsGeoJSON(t2.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
ways_poly
where
ST_within(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[84.92431640625, 27.766190642387496], [85.31982421875, 27.766190642387496], [85.31982421875, 28.02592458049937], [84.92431640625, 28.02592458049937], [84.92431640625, 27.766190642387496]]]}'))) t2 UNION ALL select ST_AsGeoJSON(t3.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
relations
where
Expand Down Expand Up @@ -186,22 +186,22 @@ def test_attribute_filter_rawdata():
}
validated_params = RawDataCurrentParams(**test_param)
expected_query = """select ST_AsGeoJSON(t0.*) from (select
osm_id , tableoid::regclass AS type , tags ->> 'name' as name , geom
osm_id , tableoid::regclass AS osm_type , tags ->> 'name' as name , geom
from
ways_line
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[83.502574, 27.569073], [83.502574, 28.332758], [85.556417, 28.332758], [85.556417, 27.569073], [83.502574, 27.569073]]]}')) and (tags ->> 'building' = 'yes')) t0 UNION ALL select ST_AsGeoJSON(t1.*) from (select
osm_id , tableoid::regclass AS type , tags ->> 'name' as name , geom
osm_id , tableoid::regclass AS osm_type , tags ->> 'name' as name , geom
from
relations
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[83.502574, 27.569073], [83.502574, 28.332758], [85.556417, 28.332758], [85.556417, 27.569073], [83.502574, 27.569073]]]}')) and (tags ->> 'building' = 'yes') and (geometrytype(geom)='MULTILINESTRING')) t1 UNION ALL select ST_AsGeoJSON(t2.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
ways_poly
where
(grid = 1187 OR grid = 1188) and (ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[83.502574, 27.569073], [83.502574, 28.332758], [85.556417, 28.332758], [85.556417, 27.569073], [83.502574, 27.569073]]]}'))) and (tags ->> 'building' = 'yes')) t2 UNION ALL select ST_AsGeoJSON(t3.*) from (select
osm_id, tableoid::regclass AS type, version,tags,changeset,timestamp,geom
osm_id, tableoid::regclass AS osm_type, version,tags,changeset,timestamp,geom
from
relations
where
Expand Down Expand Up @@ -258,12 +258,12 @@ def test_and_filters():
}
validated_params = RawDataCurrentParams(**test_param)
expected_query = """select ST_AsGeoJSON(t0.*) from (select
osm_id , tableoid::regclass AS type , tags ->> 'building' as building , tags ->> 'destroyed:building' as destroyed_building , tags ->> 'damage:date' as damage_date , tags ->> 'name' as name , tags ->> 'source' as source , geom
osm_id , tableoid::regclass AS osm_type , tags ->> 'building' as building , tags ->> 'destroyed:building' as destroyed_building , tags ->> 'damage:date' as damage_date , tags ->> 'name' as name , tags ->> 'source' as source , geom
from
ways_poly
where
ST_intersects(geom,ST_GEOMFROMGEOJSON('{"type": "Polygon", "coordinates": [[[36.70588085657477, 37.1979648807274], [36.70588085657477, 37.1651408422983], [36.759267544807194, 37.1651408422983], [36.759267544807194, 37.1979648807274], [36.70588085657477, 37.1979648807274]]]}')) and (tags ->> 'destroyed:building' = 'yes' AND tags ->> 'damage:date' = '2023-02-06')) t0 UNION ALL select ST_AsGeoJSON(t1.*) from (select
osm_id , tableoid::regclass AS type , tags ->> 'building' as building , tags ->> 'destroyed:building' as destroyed_building , tags ->> 'damage:date' as damage_date , tags ->> 'name' as name , tags ->> 'source' as source , geom
osm_id , tableoid::regclass AS osm_type , tags ->> 'building' as building , tags ->> 'destroyed:building' as destroyed_building , tags ->> 'damage:date' as damage_date , tags ->> 'name' as name , tags ->> 'source' as source , geom
from
relations
where
Expand Down

0 comments on commit 459c287

Please sign in to comment.