Skip to content

Commit

Permalink
AG-7: Added Boundary Type for markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aanish97 committed May 5, 2023
1 parent a94b677 commit f5be3bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,14 @@ def fetch_fields_for_a_point():
lat = data.get('latitude')
long = data.get('longitude')
domain = data.get('domain')
boundary_type = data.get('boundary_type')
s2_index = data.get('s2_index')
if not lat or not long:
return make_response(jsonify({
"message": "Latitude and Longitude are required."
}), 400)
s2_cell_token_13, s2_cell_token_20 = S2Service.get_cell_token_for_lat_long(lat, long)
fetched_fields = Utils.fetch_fields_for_a_point_two_way(s2_cell_token_13, s2_cell_token_20, domain, s2_index)
fetched_fields = Utils.fetch_fields_for_a_point_two_way(s2_cell_token_13, s2_cell_token_20, domain, s2_index, boundary_type)
return make_response(jsonify({
"Fetched fields": fetched_fields
}), 200)
Expand Down
8 changes: 6 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def fetch_fields_for_cell_tokens(s2_cell_tokens_13, s2_cell_tokens_20, s2_index=
return fields_to_return

@staticmethod
def fetch_fields_for_a_point_two_way(s2_cell_token_13, s2_cell_token_20, domain, s2_index=None):
def fetch_fields_for_a_point_two_way(s2_cell_token_13, s2_cell_token_20, domain, s2_index=None, boundary_type=None):
"""
Checks if token exists in L13, then further checks for L20
Returns the fields if token exists at both the levels
Expand All @@ -340,11 +340,15 @@ def fetch_fields_for_a_point_two_way(s2_cell_token_13, s2_cell_token_20, domain,
else:
geo_ids = db.session.query(GeoIds.geo_id).distinct().join(CellsGeosMiddle).join(S2CellTokens).filter(
S2CellTokens.cell_token == s2_cell_token_13)
if boundary_type:
geo_ids = geo_ids.filter(GeoIds.boundary_type == boundary_type)
geo_ids = [r.geo_id for r in geo_ids]
fields_to_return = []
for geo_id in geo_ids:
geo_data_to_return = {}
geo_data = json.loads(GeoIds.query.filter(GeoIds.geo_id == geo_id).first().geo_data)
geo_data_obj = GeoIds.query.filter(GeoIds.geo_id == geo_id).first()
geo_data = json.loads(geo_data_obj.geo_data)
geo_data['boundary_type'] = geo_data_obj.boundary_type
if s2_index and s2_indexes_to_remove != -1:
geo_data_to_return = Utils.get_specific_s2_index_geo_data(json.dumps(geo_data), s2_indexes_to_remove)
if s2_cell_token_13 in geo_data['13'] and s2_cell_token_20 in geo_data['20']:
Expand Down

0 comments on commit f5be3bf

Please sign in to comment.