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

[feature] Improve Guidance/Code snippet in "Web services" link #910

Open
mapninja opened this issue Nov 9, 2022 · 4 comments
Open

[feature] Improve Guidance/Code snippet in "Web services" link #910

mapninja opened this issue Nov 9, 2022 · 4 comments

Comments

@mapninja
Copy link

mapninja commented Nov 9, 2022

As a researcher who primarily works with Python/R/Leaflet, I would like a code snippet that I can use in my Python Notebook/RScript/Leaflet Map to make immediate use of the data I have discovered in Earthworks

We currently provide a link directly to the geoserver, and the WMS/WFS layer name, but no reference on how to make use of those? Preference would be to develop a set of boilerplate snippets to insert this info into for a more useful presentation of this info. Code snippets might provide cut-&-paste code for:

Python:

import geopandas as gpd
import requests
import geojson

# Specify the url for the backend. Here we are using data from Statistics Finland: https://www.stat.fi/org/avoindata/paikkatietoaineistot_en.html
url = 'http://geo.stat.fi/geoserver/vaestoruutu/wfs'

# Specify parameters (read data in json format).
# Available feature types in this particular data source: http://geo.stat.fi/geoserver/vaestoruutu/wfs?service=wfs&version=2.0.0&request=describeFeatureType
params = dict(service='WFS', version='2.0.0', request='GetFeature',
         typeName='vaestoruutu:vaki2017_5km', outputFormat='json')

# Fetch data from WFS using requests
r = requests.get(url, params=params)

# Create GeoDataFrame from geojson
data = gpd.GeoDataFrame.from_features(geojson.loads(r.content))  

R:

https://inbo.github.io/tutorials/tutorials/spatial_wfs_services/

Leaflet JS (may need to enable the Jsonp in GeoServer):

<html>
  <head>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css">
    <style>
      #map {
        width: 100%;
        height: 500px;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script>
  </body>
</html>

<script>
var map = L.map("map").setView([38.45, 70.6], 6);
var osm = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
  attribution:
    '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
//Geoserver Web Feature Service
$.ajax('http://localhost:8080/geoserver/wfs',{
  type: 'GET',
  data: {
    service: 'WFS',
    version: '1.1.0',
    request: 'GetFeature',
    typename: 'workspace:layer_name',
    CQL_FILTER: "column='demo'",
    srsname: 'EPSG:4326',
    outputFormat: 'text/javascript',
    },
  dataType: 'jsonp',
  jsonpCallback:'callback:handleJson',
  jsonp:'format_options'
 });
  //Geojson style file
  var myStyle = {
    'color': 'red'
  }
// the ajax callback function
function handleJson(data) {
    selectedArea = L.geoJson(data, {
      style: myStyle,
      onEachFeature: function(feature, layer) {
        layer.bindPopup(`Name: ${feature.properties.name_of_your_property}`)
      }
    }).addTo(map);
  map.fitBounds(selectedArea.getBounds());
}
</script>

Really nice example from Google Earth Engine Catalog:

https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC08_C02_T1_L2

@thatbudakguy
Copy link
Member

per @mapninja, Planet.com does this really well with its API links that allow you to copy/paste code snippets directly. we want stuff you can copy-paste and use immediately.

@thatbudakguy
Copy link
Member

it seems like the simplest option would be to do this in a modal, similar to the web services links now.

@mapninja
Copy link
Author

mapninja commented Nov 9, 2022

Planet does this pretty elegantly, in their Explorer interface with the API button and it's resulting widget:

Image

WHere the user's API Key, curl code and item IDs can be easily grabbed for programmatic access:

Image

@mapninja
Copy link
Author

mapninja commented Nov 9, 2022

Google Earth Engine's Data Catalog is a "best in class" for this feature:

Image

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

No branches or pull requests

2 participants