Skip to main content

PyOneMap - Python Wrapper for SLA's OneMap API

PyOneMap is a Python package that provides a convenient and easy-to-use interface for interacting with the Singapore Land Authority's (SLA) OneMap API. With PyOneMap, you can retrieve various geospatial data and information from OneMap's services directly from your Python code.

This is built using the API doc release in 2023. The old API documentation and APIs will be available until 31 August 2023.

Features

  • Retrieve location details such as addresses, postal codes, and coordinates.
  • Search for places of interest, amenities, and landmarks in Singapore.
  • Perform geocoding and reverse geocoding operations effortlessly.
  • Access map layers and thematic data provided by the OneMap API.

Installation

You can install PyOneMap using pip:

pip install pyonemap

Usage

from pyonemap import OneMap

# Initialize the OneMapAPI client
onemap = OneMap('<--Insert your OneMap API token here-->')

# Get location details
location = onemap.search("5 Havelock Road")
print(location)

geocode = onemap.revGeoCodeXy(24291.97788882387, 31373.0117224489)
print(geocode)

geocode = onemap.revGeoCode(1.3254295, 103.9005321)
print(geocode)

Example

    access_token = os.environ.get("ONEMAP_TOKEN")

    onemap = OneMap(access_token)

    location = onemap.search("200640", 'Y', 'Y')
    print(location)

    geocode = onemap.reverseGeocode.revGeoCodeXy(24291.97788882387, 31373.0117224489)

    geocode = onemap.reverseGeocode.revGeoCode(1.3254295, 103.9005321)
    print(geocode)

    route = onemap.routing.route(1.320981, 103.844150, 1.326762, 103.8559)
    print(route['requestParameters']['preferredRoutes'])

    coordinate = onemap.converter.convert4326to3857(1.319728905, 103.8421581)
    print(coordinate)

    coordinate = onemap.converter.convert4326to3414(1.319728905, 103.8421581)
    print(coordinate)

    coordinate = onemap.converter.convert3414to3857(28983.788791079794, 33554.509813284)
    print(coordinate)

    coordinate = onemap.converter.convert3414to4326(28983.788791079794, 33554.5098132845)
    print(coordinate)

    coordinate = onemap.converter.convert3857to3414(146924.54200324757, 11559656.16256661)
    print(coordinate)

    coordinate = onemap.converter.convert3857to4326(146924.54200324757, 11559656.16256661)
    print(coordinate)
    # {'latitude': 1.3197289050000036, 'longitude': 103.8421581}

    themeStatus = onemap.themes.checkThemeStatus('kindergartens')
    print(themeStatus)
    # {'UpdatedFile': True}

    themeInfo = onemap.themes.getThemeInfo('kindergartens')
    print(themeInfo)

    allThemes = onemap.themes.getAllThemesInfo()
    print(f'Found {len(allThemes["Theme_Names"])} themes.')

    searchTheme = 'dengue_cluster'
    theme = onemap.themes.retrieveTheme(searchTheme)
    print(f'{len(theme["SrchResults"])} of {searchTheme} found.')

    boundary = '1.291789%2C103.7796402%2C1.3290461%2C103.8726032'
    exTheme = onemap.themes.retrieveTheme(searchTheme, boundary)
    print(f'{len(theme["SrchResults"])} of {searchTheme} found (with boundaries).')

    year = '2019'
    allPlanningArea = onemap.planningArea.getAllPlanningarea(year)
    print(f'{len(allPlanningArea["SearchResults"])} planning areas found for the year {year}.')

    planningAreaNames = onemap.planningArea.getPlanningareaNames(year)
    print(f'{len(planningAreaNames)} planning area names found for the year {year}.')

    lat = 1.3
    lon = 103.8
    planningArea = onemap.planningArea.getPlanningArea(lat, lon, year)
    print(f'({lat}, {lon}) is located in planning area {planningArea[0]["pln_area_n"]} in the year of {year}.')

    print(onemap.populationQuery.getEconomicStatus("Bedok", 2010))
    print(onemap.populationQuery.getEducationAttending("Bedok", 2020))
    print(onemap.populationQuery.getEthnicGroup("Bedok", 2020))
    print(onemap.populationQuery.getHouseholdMonthlyIncomeWork("Bedok", 2020))
    print(onemap.populationQuery.getHouseholdSize("Bedok", 2020))
    print(onemap.populationQuery.getHouseholdStructure("Bedok", 2020))
    print(onemap.populationQuery.getIncomeFromWork("Bedok", 2020))
    print(onemap.populationQuery.getIndustry("Bedok", 2020))
    print(onemap.populationQuery.getLanguageLiterate("Bedok", 2020))
    print(onemap.populationQuery.getMaritalStatus("Bedok", 2020))
    print(onemap.populationQuery.getModeOfTransportSchool("Bedok", 2020))
    print(onemap.populationQuery.getModeOfTransportWork("Bedok", 2020))
    print(onemap.populationQuery.getPopulationAgeGroup("Bedok", 2020))
    print(onemap.populationQuery.getReligion("Bedok", 2020))
    print(onemap.populationQuery.getSpokenAtHome("Bedok", 2020))
    print(onemap.populationQuery.getTenancy("Bedok", 2020))
    print(onemap.populationQuery.getTypeOfDwellingHousehold("Bedok", 2020))
    print(onemap.populationQuery.getTypeOfDwellingPop("Bedok", 2020))

Use case: Walk distance between 2 locations

from pyonemap import OneMap

# Obtain access token using email and password.
response = OneMap.getToken('your_email@email.com', 'your_password')
access_token = response['access_token']

# Instantiate OneMap object for API query.
onemap = OneMap(access_token)

# Search for a address using postal code.
start = onemap.search("380016", 'Y', 'Y')
end = onemap.search("658713", 'Y', 'Y')
route = onemap.routing.route(start["results"][0]["LATITUDE"],start["results"][0]["LONGITUDE"],end["results"][0]["LATITUDE"],end["results"][0]["LONGITUDE"], "walk")
route['route_summary']
# {'start_point': '', 'end_point': '', 'total_time': 11662, 'total_distance': 16198}

Unit Test

python3 -m unittest discover -s tests -p "test_*.py"

Building and Uploading

$ python3 setup.py sdist bdist_wheel
$ twine upload ./dist/*

Source

https://github.com/chengguan/pyonemap

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for pyonemap 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyonemap 0.10.0
File Size Uploaded Provenance Actions
pyonemap-0.10.0.tar.gz 11.1 kB Without provenance Details for pyonemap-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyonemap 0.10.0
File Interpreter ABI Platform Actions
pyonemap-0.10.0-py3-none-any.whl Python 3 none any Details for pyonemap-0.10.0-py3-none-any.whl

Total release size: 24.4 kB

Release files / pyonemap-0.10.0.tar.gz

Download URL pyonemap-0.10.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
842d9dfbf6db0c0b8831c6ea23f1208c067ccc30d158a70b2fd3fbffef328a80
BLAKE2b-256 checksum
How to use checksums
d450d5c6d88b06760e7a9b5092a6f14bc9ada9ea598a2fd24b122791a0126f4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / pyonemap-0.10.0-py3-none-any.whl

Download URL pyonemap-0.10.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70920cbd9b4a1e4ccb8f2c6203af94e42650657ba9dbeb90cf4708d47fc7dc67
BLAKE2b-256 checksum
How to use checksums
1a578b5e7548eb8d21a65a9cfb10418973d8cf0a867386b490ad28876714128c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for pyonemap 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page