Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read_geojson function #939

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14853,3 +14853,18 @@ def find_max_value_coords(
x, y = transformer.transform(x, y)

return x, y, max_value


def read_geojson(data: str, **kwargs: Any) -> Dict[str, Any]:
"""
Fetches and parses a GeoJSON file from a given URL.

Args:
data (str): The URL of the GeoJSON file.
**kwargs (Any): Additional keyword arguments to pass to the requests.get() method.

Returns:
Dict[str, Any]: The parsed GeoJSON data.
"""

return requests.get(data, **kwargs).json()
8 changes: 4 additions & 4 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3316,7 +3316,7 @@ def construct_maptiler_style(style: str, api_key: Optional[str] = None) -> str:

This function generates a URL for accessing a specific MapTiler map style. If an API key is not provided,
it attempts to retrieve one using a predefined method. If the request to MapTiler fails, it defaults to
a "dark-matter" style.
a "liberty" style.

Args:
style (str): The name of the MapTiler style to be accessed. It can be one of the following:
Expand All @@ -3326,7 +3326,7 @@ def construct_maptiler_style(style: str, api_key: Optional[str] = None) -> str:
attempts to retrieve the API key using a predefined method. Defaults to None.

Returns:
str: The URL for the requested MapTiler style. If the request fails, returns a URL for the "dark-matter" style.
str: The URL for the requested MapTiler style. If the request fails, returns a URL for the "liberty" style.

Raises:
requests.exceptions.RequestException: If the request to the MapTiler API fails.
Expand All @@ -3340,9 +3340,9 @@ def construct_maptiler_style(style: str, api_key: Optional[str] = None) -> str:
response = requests.get(url)
if response.status_code != 200:
print(
"Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style."
"Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style."
)
url = "dark-matter"
url = "https://tiles.openfreemap.org/styles/liberty"

return url

Expand Down