Skip to content

Commit

Permalink
Limit output decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Apr 20, 2024
1 parent b0bba1c commit 98bc916
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions lib/overpass_parser/nodes/out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def to_sql(sql_dialect)
#{sql_dialect.json_strip_nulls}(#{sql_dialect.json_build_object}(
'type', CASE osm_type WHEN 'n' THEN 'node' WHEN 'w' THEN 'way' WHEN 'r' THEN 'relation' WHEN 'a' THEN 'area' END,
'id', id,
'lon', CASE osm_type WHEN 'n' THEN ST_X(geom) END,
'lat', CASE osm_type WHEN 'n' THEN ST_Y(geom) END\
'lon', CASE osm_type WHEN 'n' THEN round(ST_X(geom), 7) END,
'lat', CASE osm_type WHEN 'n' THEN round(ST_Y(geom), 7) END\
#{meta ? ",\n 'timestamp', created" : ''}\
#{meta ? ",\n 'version', version" : ''}\
#{if @geom == 'center'
",
'center', CASE osm_type = 'w' OR osm_type = 'r'
WHEN true THEN #{sql_dialect.json_build_object}(
'lon', ST_X(ST_PointOnSurface(geom)),
'lat', ST_Y(ST_PointOnSurface(geom))
'lon', round(ST_X(ST_PointOnSurface(geom)), 7),
'lat', round(ST_Y(ST_PointOnSurface(geom)), 7)
)
END"
else
Expand All @@ -50,10 +50,10 @@ def to_sql(sql_dialect)
",
'bounds', CASE osm_type = 'w' OR osm_type = 'r'
WHEN true THEN #{sql_dialect.json_build_object}(
'minlon', ST_XMin(ST_Envelope(geom)),
'minlat', ST_YMin(ST_Envelope(geom)),
'maxlon', ST_XMax(ST_Envelope(geom)),
'maxlat', ST_YMax(ST_Envelope(geom))
'minlon', round(ST_XMin(ST_Envelope(geom)), 7),
'minlat', round(ST_YMin(ST_Envelope(geom)), 7),
'maxlon', round(ST_XMax(ST_Envelope(geom)), 7),
'maxlat', round(ST_YMax(ST_Envelope(geom)), 7)
)
END"
end}\
Expand All @@ -63,13 +63,13 @@ def to_sql(sql_dialect)
WHEN 'w' THEN " + (
if sql_dialect.st_dump_points
"(SELECT \
#{sql_dialect.jsonb_agg}(#{sql_dialect.json_build_object}('lon', ST_X(geom), 'lat', ST_Y(geom))) \
#{sql_dialect.jsonb_agg}(#{sql_dialect.json_build_object}('lon', round(ST_X(geom), 7), 'lat', round(ST_Y(geom), 7))) \
FROM #{sql_dialect.st_dump_points}(geom))"
else
"replace(replace(replace(replace(replace((
CASE ST_GeometryType(geom)
WHEN 'LINESTRING' THEN ST_AsGeoJson(geom)->'coordinates'
ELSE ST_AsGeoJson(geom)->'coordinates'->0
WHEN 'LINESTRING' THEN ST_AsGeoJson(geom, 7)->'coordinates'
ELSE ST_AsGeoJson(geom, 7)->'coordinates'->0
END
)::text, '[', '{\"lon\":'), \
',', ',\"lat\":'), \
Expand Down
8 changes: 4 additions & 4 deletions test/overpass_parser/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def test_matches_to_sql
jsonb_strip_nulls(jsonb_build_object(
'type', CASE osm_type WHEN 'n' THEN 'node' WHEN 'w' THEN 'way' WHEN 'r' THEN 'relation' WHEN 'a' THEN 'area' END,
'id', id,
'lon', CASE osm_type WHEN 'n' THEN ST_X(geom) END,
'lat', CASE osm_type WHEN 'n' THEN ST_Y(geom) END,
'lon', CASE osm_type WHEN 'n' THEN round(ST_X(geom), 7) END,
'lat', CASE osm_type WHEN 'n' THEN round(ST_Y(geom), 7) END,
'timestamp', created,
'version', version,
'center', CASE osm_type = 'w' OR osm_type = 'r'
WHEN true THEN jsonb_build_object(
'lon', ST_X(ST_PointOnSurface(geom)),
'lat', ST_Y(ST_PointOnSurface(geom))
'lon', round(ST_X(ST_PointOnSurface(geom)), 7),
'lat', round(ST_Y(ST_PointOnSurface(geom)), 7)
)
END,
'nodes', nodes,
Expand Down
8 changes: 4 additions & 4 deletions test/overpass_parser/visitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ def test_to_sql
jsonb_strip_nulls(jsonb_build_object(
'type', CASE osm_type WHEN 'n' THEN 'node' WHEN 'w' THEN 'way' WHEN 'r' THEN 'relation' WHEN 'a' THEN 'area' END,
'id', id,
'lon', CASE osm_type WHEN 'n' THEN ST_X(geom) END,
'lat', CASE osm_type WHEN 'n' THEN ST_Y(geom) END,
'lon', CASE osm_type WHEN 'n' THEN round(ST_X(geom), 7) END,
'lat', CASE osm_type WHEN 'n' THEN round(ST_Y(geom), 7) END,
'timestamp', created,
'version', version,
'center', CASE osm_type = 'w' OR osm_type = 'r'
WHEN true THEN jsonb_build_object(
'lon', ST_X(ST_PointOnSurface(geom)),
'lat', ST_Y(ST_PointOnSurface(geom))
'lon', round(ST_X(ST_PointOnSurface(geom)), 7),
'lat', round(ST_Y(ST_PointOnSurface(geom)), 7)
)
END,
'nodes', nodes,
Expand Down

0 comments on commit 98bc916

Please sign in to comment.