top of page

Primary School Proximity Calculator with Map and Onemap API
Project Details:
The project utilizes the OneMap API to fetch geographic data, calculates distances between schools and a specified point, then visualizes the data with color-coded markers, enhancing spatial understanding on a website.
Software / programming language used:
Python
SQL
Hex Tech
Highlights
One map API
A One map API function was created. This function, getcoordinates, takes an address as input and queries the OneMap API to retrieve latitude, longitude, and address details. It uses the requests library to send an HTTP GET request to the OneMap API endpoint with the provided address. Then it evaluates the response text into a dictionary. If results are found, it returns the latitude, longitude, and address from the first result; otherwise, it returns an error message. Note: It's better to handle exceptions instead of returning an error message directly.
SQL Query
This SQL query calculates the distance between schools' geographic coordinates and a specific point's coordinates, both represented as geographic points. It selects the name of the school, rounds the distance to two decimal places, and retrieves the latitude and longitude of the schools. The query first converts the latitude and longitude of both the schools and the specified point into geographic points. Then it filters the schools within a 2000-meter radius from the specified point. Finally, it calculates the distance between each school and the point using the ST_DWithin function, which checks if a geometry is within a specified distance of another geometry.
Python Code
This Python code adds color and size attributes to a DataFrame representing data from the OneMap API. It assigns color '2' to rows where the distance is less than or equal to 1000, otherwise '3'. All rows initially get a size of 1. It then adds a new row representing 'Your Address' with distance 0 and coordinates from df1. This row gets color '1' and a larger size of 1.15. Finally, it appends this new row to the DataFrame and returns the updated DataFrame. This process helps visualize data points on a map, distinguishing points based on their distance and indicating a specific address with a unique marker.

bottom of page