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

Code snippet updates #1297

Closed
hudajkhan opened this issue Aug 29, 2024 · 1 comment
Closed

Code snippet updates #1297

hudajkhan opened this issue Aug 29, 2024 · 1 comment
Assignees

Comments

@hudajkhan
Copy link
Contributor

Comments:

In the Leaflet code, it looks like an ampersand is missing at the end of line 20, which reads:
"version=1.1.0&request=GetFeature&typename=druid:cj149vc4113" +
but should be:
"version=1.1.0&request=GetFeature&typename=druid:cj149vc4113&" +
In the Python code, we should include the imports in the code, even when we note that the installs are necessary in the comment:
import requests
import geopandas as gpd
import folium


See correct python code below

Before running this code, install or check for these libraries

!pip install geopandas folium

import requests
import geopandas as gpd
import folium

Accept user input for the GeoServer URL and the typeName of the layer

geoserver_url = "https://geowebservices.stanford.edu/geoserver/wfs?"
type_name = "druid:mf519gg2738"

Define the parameters for the WFS service

params = {
'service': 'WFS',
'version': '2.0.0',
'request': 'GetFeature',
'typeName': type_name,
'outputFormat': 'application/json'
}

Send a GET request to the GeoServer WFS service

response = requests.get(geoserver_url, params=params)

Load the features from the WFS service into a GeoDataFrame

gdf = gpd.read_file(response.text)

Get the bounds of the GeoDataFrame

bounds = gdf.total_bounds

Calculate the center of the bounds

center = [(bounds[1] + bounds[3]) / 2, (bounds[0] + bounds[2]) / 2]

Create the map

m = folium.Map(location=center, zoom_start=2)

Add the GeoDataFrame to the map as a GeoJson layer

folium.GeoJson(gdf).add_to(m)

Display the map

m

@hudajkhan
Copy link
Contributor Author

Closed by #1331

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant