Skip to content

Commit

Permalink
simple_point_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaczero committed Feb 21, 2024
1 parent 5767c7e commit a581e99
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion api/v1/countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from models.country import Country
from states.aed_state import AEDState
from states.country_state import CountryState
from utils import simple_point_mapping

router = APIRouter(prefix='/countries')

Expand Down Expand Up @@ -74,7 +75,7 @@ async def get_geojson(country_code: Annotated[str, Path(min_length=2, max_length
'features': [
{
'type': 'Feature',
'geometry': mapping(aed.position),
'geometry': simple_point_mapping(aed.position),
'properties': {
'@osm_type': 'node',
'@osm_id': aed.id,
Expand Down
10 changes: 4 additions & 6 deletions states/country_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from osm_countries import get_osm_countries
from state_utils import get_state_doc, set_state_doc
from transaction import Transaction
from utils import retry_exponential
from utils import retry_exponential, simple_point_mapping
from validators.geometry import geometry_validator


Expand Down Expand Up @@ -164,11 +164,9 @@ async def get_countries_within(cls, bbox_or_pos: BBox | Point) -> Sequence[Count
{
'geometry': {
'$geoIntersects': {
'$geometry': mapping(
bbox_or_pos.to_polygon(nodes_per_edge=8)
if isinstance(bbox_or_pos, BBox) #
else bbox_or_pos
)
'$geometry': mapping(bbox_or_pos.to_polygon(nodes_per_edge=8))
if isinstance(bbox_or_pos, BBox)
else simple_point_mapping(bbox_or_pos)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import anyio
import httpx
from shapely import Point, get_coordinates

from config import USER_AGENT

Expand Down Expand Up @@ -56,3 +57,8 @@ def abbreviate(num: int) -> str:

def get_wikimedia_commons_url(path: str) -> str:
return f'https://commons.wikimedia.org/wiki/{path}'


def simple_point_mapping(point: Point) -> dict:
x, y = get_coordinates(point)[0]
return {'type': 'Point', 'coordinates': (x, y)}

0 comments on commit a581e99

Please sign in to comment.