isard-map 2.4.2__tar.gz → 2.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {isard_map-2.4.2 → isard_map-2.6.0}/PKG-INFO +1 -1
- {isard_map-2.4.2 → isard_map-2.6.0}/pyproject.toml +1 -1
- {isard_map-2.4.2 → isard_map-2.6.0}/src/isard_map/__init__.py +3 -2
- isard_map-2.6.0/src/isard_map/_ogcapi.py +51 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/src/isard_map/static/widget.js +3 -3
- {isard_map-2.4.2 → isard_map-2.6.0}/tests/test_examples.py +9 -1
- {isard_map-2.4.2 → isard_map-2.6.0}/tests/test_map.py +34 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/uv.lock +1 -1
- {isard_map-2.4.2 → isard_map-2.6.0}/.gitignore +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/LICENSE +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/README.md +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/js/widget.ts +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/scripts/build-widget.ts +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/scripts/reference.py +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/scripts/snapshot.py +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/src/isard_map/_data.py +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/src/isard_map/_geoplateforme.py +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/src/isard_map/_js.py +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/src/isard_map/_map.py +0 -0
- {isard_map-2.4.2 → isard_map-2.6.0}/tsconfig.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: isard-map
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.0
|
|
4
4
|
Summary: isard maps in Jupyter: the IGN's WebGL2 map engine (globe, relief, 3D Tiles, vector tiles) as a notebook widget
|
|
5
5
|
Project-URL: Homepage, https://github.com/IGNF/isard
|
|
6
6
|
Project-URL: Documentation, https://github.com/IGNF/isard/tree/main/packages/python
|
|
@@ -4,6 +4,7 @@ from ._data import prop, to_geojson
|
|
|
4
4
|
from ._geoplateforme import geoplateforme_wfs
|
|
5
5
|
from ._js import JsObject, js, ref
|
|
6
6
|
from ._map import Map
|
|
7
|
+
from ._ogcapi import ogc_features
|
|
7
8
|
|
|
8
|
-
__version__ = "2.
|
|
9
|
-
__all__ = ["JsObject", "Map", "geoplateforme_wfs", "js", "prop", "ref", "to_geojson", "__version__"]
|
|
9
|
+
__version__ = "2.6.0"
|
|
10
|
+
__all__ = ["JsObject", "Map", "geoplateforme_wfs", "js", "ogc_features", "prop", "ref", "to_geojson", "__version__"]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""The OGC APIs from Python: a collection of OGC API - Features as a GeoDataFrame (geopandas), asked for as isard asks
|
|
2
|
+
for it (`ogcFeatures`: the same requests, page by page along their `next` links)."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from collections.abc import Sequence
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.parse import quote, urlencode, urljoin
|
|
9
|
+
|
|
10
|
+
from ._geoplateforme import fetch_json
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def ogc_features(
|
|
14
|
+
url: str,
|
|
15
|
+
collection: str,
|
|
16
|
+
bbox: Sequence[float] | None = None,
|
|
17
|
+
filter: str | None = None,
|
|
18
|
+
filter_lang: str = "cql2-text",
|
|
19
|
+
crs: str | None = None,
|
|
20
|
+
properties: Sequence[str] | None = None,
|
|
21
|
+
count: int = 10_000,
|
|
22
|
+
page_size: int = 1000,
|
|
23
|
+
) -> Any:
|
|
24
|
+
"""The features of a collection of an OGC API - Features service (`url` its landing page) as a GeoDataFrame:
|
|
25
|
+
`ogc_features("https://demo.ldproxy.net/vineyards", "vineyards", filter="region = 'Mosel'")`. `bbox` (west,
|
|
26
|
+
south, east, north, degrees) and `filter` (CQL2, Part 3) select them; `crs` (a URI, Part 2) the CRS of their
|
|
27
|
+
coordinates, the frame's `crs`. At most `count` features, the pages followed by their `next` links. Needs
|
|
28
|
+
geopandas."""
|
|
29
|
+
import geopandas as gpd
|
|
30
|
+
|
|
31
|
+
query = {
|
|
32
|
+
"f": "json",
|
|
33
|
+
"limit": str(max(1, min(page_size, count))),
|
|
34
|
+
**({"bbox": ",".join(str(v) for v in bbox)} if bbox else {}),
|
|
35
|
+
**({"filter": filter, "filter-lang": filter_lang} if filter else {}),
|
|
36
|
+
**({"crs": crs} if crs else {}),
|
|
37
|
+
**({"properties": ",".join(properties)} if properties else {}),
|
|
38
|
+
}
|
|
39
|
+
# Spaces as %20, not +: a server re-encodes a + in its next link (%2B), which breaks the filter past one page
|
|
40
|
+
page_url: str | None = (
|
|
41
|
+
f"{url.rstrip('/')}/collections/{quote(collection)}/items?{urlencode(query, quote_via=quote)}"
|
|
42
|
+
)
|
|
43
|
+
features: list[Any] = []
|
|
44
|
+
while page_url and len(features) < count:
|
|
45
|
+
page = fetch_json(page_url)
|
|
46
|
+
found = page.get("features", [])
|
|
47
|
+
features += found
|
|
48
|
+
link = next((link for link in page.get("links", []) if link.get("rel") == "next"), None)
|
|
49
|
+
# An empty page ends it whatever its links say
|
|
50
|
+
page_url = urljoin(page_url, link["href"]) if link and found else None
|
|
51
|
+
return gpd.GeoDataFrame.from_features(features[:count], crs=crs or "EPSG:4326")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Made by `bun scripts/build-widget.ts` from js/widget.ts: not to edit (isard 2.
|
|
2
|
-
var A="2.
|
|
1
|
+
// Made by `bun scripts/build-widget.ts` from js/widget.ts: not to edit (isard 2.6.0)
|
|
2
|
+
var A="2.6.0";var re=`https://cdn.jsdelivr.net/npm/isard@${A}/dist/index.js`,j=`(() => {
|
|
3
3
|
const Native = window.Worker;
|
|
4
4
|
window.Worker = class extends Native {
|
|
5
5
|
constructor(url, options) {
|
|
@@ -14,4 +14,4 @@ var A="2.4.2";var re=`https://cdn.jsdelivr.net/npm/isard@${A}/dist/index.js`,j=`
|
|
|
14
14
|
super(URL.createObjectURL(new Blob([source], { type: 'text/javascript' })), options);
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
})();`;import{GeoMap as B}from"https://cdn.jsdelivr.net/npm/isard@2.
|
|
17
|
+
})();`;import{GeoMap as B}from"https://cdn.jsdelivr.net/npm/isard@2.6.0/dist/index.js";import*as O from"https://cdn.jsdelivr.net/npm/isard@2.6.0/dist/index.js";var M=(e,n)=>Function("isard","map",`return (${e});`)(O,n),R={isard:async()=>O,"isard/geoplateforme":()=>import("https://cdn.jsdelivr.net/npm/isard@2.6.0/dist/geoplateforme.js"),"isard/formats":()=>import("https://cdn.jsdelivr.net/npm/isard@2.6.0/dist/formats.js"),"isard/projections":()=>import("https://cdn.jsdelivr.net/npm/isard@2.6.0/dist/projections.js")},w=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),y=(e,n=0)=>{if(e===null||["string","number","boolean"].includes(typeof e))return e;if(n>8)return null;if(ArrayBuffer.isView(e)&&!(e instanceof DataView))return Array.from(e);if(Array.isArray(e))return e.map((t)=>y(t,n+1));if(!w(e))return null;let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)return null;return Object.fromEntries(Object.entries(e).map(([t,a])=>[t,y(a,n+1)]))},D=async(e)=>{let[n,r]=e.includes(":")?e.split(":",2):["isard",e],t=R[n??"isard"];if(!t)throw Error(`isard: no entry point ${n}`);return(r??"").split(".").reduce((a,i)=>w(a)||typeof a==="object"?Reflect.get(Object(a),i):void 0,await t())};class b{event;handles=new Map;queue=Promise.resolve();constructor(e,n){this.event=n;this.handles.set("map",e)}async resolve(e,n){if((n==="data"||n==="values")&&!(w(e)&&Object.keys(e).some((t)=>t.startsWith("$"))))return e;if(Array.isArray(e))return Promise.all(e.map((t)=>this.resolve(t)));if(!w(e))return e;if(typeof e.$handle==="string"){if(!this.handles.has(e.$handle))throw Error(`isard: nothing kept as ${e.$handle}`);return this.handles.get(e.$handle)}if(typeof e.$date==="string")return new Date(e.$date);if(typeof e.$bytes==="string")return Uint8Array.from(atob(e.$bytes),(t)=>t.charCodeAt(0));if(typeof e.$isard==="string")return D(e.$isard);if(typeof e.$js==="string")return M(e.$js,this.handles.get("map"));if(typeof e.$callback==="number"){let t=e.$callback;return(...a)=>this.event(t,a.map((i)=>y(i)))}if(typeof e.property==="string"&&Object.keys(e).every((t)=>t==="property"||t==="default")){let{property:t,default:a}=e;return(i)=>i?.[t]??a}let r=await Promise.all(Object.entries(e).map(async([t,a])=>[t,await this.resolve(a,t)]));return Object.fromEntries(r)}run(e){let n=this.queue.then(async()=>{let r=e.target.startsWith("module:")?await R[e.target.slice(7)]?.():this.handles.get(e.target);if(e.access==="value"&&this.handles.has(e.target))return y(r);if(r===void 0)throw Error(`isard: nothing kept as ${e.target}`);if(e.access){let s=e.access==="get"?Reflect.get(Object(r),e.method):Reflect.set(Object(r),e.method,await this.resolve(e.args[0]));if(e.handle)this.handles.set(e.handle,s);return y(s)}let t=Reflect.get(Object(r),e.method);if(typeof t!=="function")throw Error(`isard: ${e.target} has no ${e.method}`);let a=await Promise.all(e.args.map((s)=>this.resolve(s))),i=await(e.construct?Reflect.construct(t,a):Reflect.apply(t,r,a));if(e.handle)this.handles.set(e.handle,i);return y(i)});return this.queue=n.catch(()=>{return}),n}}var g=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),I=["setCamera","easeTo","flyTo","getCamera","pickSurface"],_=(e)=>g(e)&&typeof e.id==="string"&&typeof e.type==="string",E=(e)=>Array.isArray(e)&&e.every(_),F=(e)=>typeof e==="string"&&I.includes(e);var V=(e)=>{if(!g(e))return!1;switch(e.kind){case"init":return g(e.options)&&E(e.layers);case"layers":return E(e.layers);case"call":return typeof e.id==="number"&&F(e.method)&&Array.isArray(e.args);case"invoke":return typeof e.id==="number"&&typeof e.target==="string"&&typeof e.method==="string"&&Array.isArray(e.args)&&(e.handle===void 0||typeof e.handle==="string")&&(e.access===void 0||e.access==="get"||e.access==="set"||e.access==="value");default:return!1}};var v=(e)=>{let n=L(e);return V(n)?n:void 0},L=(e)=>{if(typeof e!=="string")return e;try{return JSON.parse(e)}catch{return}},h=({id:e,...n})=>n,W=(e)=>g(e)&&typeof e.property==="string"&&Object.keys(e).every((n)=>n==="property"||n==="default"),S=(e,n)=>({...Object.fromEntries(Object.entries(e).map(([r,t])=>{if(n&&g(t)&&typeof t.$js==="string")return[r,n(t.$js)];if(r==="data"||r==="values"||!W(t))return[r,t];let{property:a,default:i}=t;return[r,(s)=>s?.[a]??i]})),type:e.type}),T=(e,n)=>{let r=new Map(n.map((a)=>[a.id,a])),t={add:[],data:[],rebuild:[],remove:[]};return r.forEach((a,i)=>{let s=e.get(i);if(s===void 0){t.add.push(a);return}if(s===JSON.stringify(h(a)))return;let d=L(s),{data:u,values:f,...o}=g(d)?d:{},{data:c,values:p,...l}=h(a);(JSON.stringify(o)===JSON.stringify(l)?t.data:t.rebuild).push(a)}),e.forEach((a,i)=>{if(!r.has(i))t.remove.push(i)}),t};var G=()=>{let e=Reflect.get(window,"ReactNativeWebView"),n=typeof e==="object"&&e!==null?Reflect.get(e,"postMessage"):void 0;return typeof n==="function"?{postMessage:(r)=>Reflect.apply(n,e,[r])}:void 0},U=()=>{let e=G();return{send:(r)=>{let t=JSON.stringify(r);if(e)e.postMessage(t);else window.parent.postMessage(t,"*")},listen:(r)=>{let t=(a)=>{let i=a instanceof MessageEvent?v(a.data):void 0;if(i)r(i)};window.addEventListener("message",t),document.addEventListener("message",t)}}},q=(e)=>{let n=Reflect.get(e,"setData");return typeof n==="function"?(r)=>Reflect.apply(n,e,[r]):void 0},C=(e,n)=>{let r=Reflect.get(e,"setValues");if(typeof r!=="function"||!Array.isArray(n))return;Reflect.apply(r,e,[Float32Array.from(n,(t)=>typeof t==="number"?t:Number.NaN)])};class P{map;held=new Map;constructor(e){this.map=e}set(e){let n=T(new Map([...this.held].map(([t,{json:a}])=>[t,a])),e);n.remove.forEach((t)=>{this.held.get(t)?.layer.remove(),this.held.delete(t)}),n.data.forEach((t)=>{let a=this.held.get(t.id),i=a&&q(a.layer);if(a&&i&&K(t.data))i(t.data),C(a.layer,t.values),a.json=JSON.stringify(h(t));else n.rebuild.push(t)}),n.rebuild.forEach((t)=>{this.held.get(t.id)?.layer.remove(),this.held.delete(t.id)}),[...n.add,...n.rebuild].forEach((t)=>{let{values:a,...i}=h(t),s=this.map.add(S({...i,type:t.type},(d)=>M(d,this.map)));C(s,a),this.held.set(t.id,{layer:s,json:JSON.stringify(h(t))})});let r=e.flatMap(({id:t})=>this.held.get(t)?.layer??[]);r.slice(0,-1).forEach((t,a)=>{t.moveBefore(r[a+1])})}idOf(e){return[...this.held].find(([,n])=>n.layer===e)?.[0]}get all(){return[...this.held.values()].map(({layer:e})=>e)}}var z=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),K=(e)=>typeof e==="object"&&e!==null&&("type"in e),N=(e)=>{let{center:n,zoom:r,pitch:t,bearing:a}=e.getCamera();return{center:n,zoom:r,pitch:t,bearing:a}},H=(e)=>({setCamera:(n)=>e.setCamera(n),easeTo:(n,r)=>e.easeTo(n,r),flyTo:(n,r)=>e.flyTo(n,r===void 0?{}:{duration:r}),getCamera:()=>N(e),pickSurface:(n)=>e.pickSurface(n)}),Q=(e,n,r)=>Reflect.apply(e[n],void 0,r),x=(e=U(),n)=>{let r={waiting:[]},t=(s)=>e.send({kind:"error",message:String(s)}),a=(s)=>{let{map:d,layers:u,invoker:f}=r;if(s.kind==="init"){if(r.map)return;i(s.options,s.layers).catch(t);return}if(!d||!u||!f){r.waiting.push(s);return}if(s.kind==="layers"){try{u.set(s.layers)}catch(o){t(o)}return}if(s.kind==="invoke"){let{id:o}=s;f.run(s).then((c)=>e.send({kind:"result",id:o,value:s.answer?c??null:null}),(c)=>e.send({kind:"failed",id:o,message:String(c)}));return}try{e.send({kind:"result",id:s.id,value:Q(H(d),s.method,s.args)??null})}catch(o){e.send({kind:"failed",id:s.id,message:String(o)})}},i=async(s,d)=>{let u=n??document.getElementById("map");if(!u)throw Error("the page has no #map");let f=await new b({},()=>{return}).resolve(s),o=await B.create(u,z(f)?f:s);if(r.gone){o.destroy();return}let c=new P(o);r.map=o,r.layers=c,r.invoker=new b(o,(p,l)=>e.send({kind:"event",callback:p,args:l})),c.set(d),o.on("click",async({point:p,lonLat:l})=>{let m=await o.pickFeature(p,{layers:c.all}),k=m&&c.idOf(m.layer),J={point:p,lonLat:l,feature:k?{layer:k,properties:m.feature?.properties??{}}:void 0};e.send({kind:"click",click:J})}),o.on("moveend",()=>e.send({kind:"moveend",camera:N(o)})),o.on("gpulost",({reason:p,message:l,losses:m,recovery:k})=>e.send({kind:"error",message:`the GPU device was lost (${p}: ${l}; ${m} so far), the map made again (${k})`})),e.send({kind:"ready"}),r.waiting.splice(0).forEach(a)};return e.listen(a),e.send({kind:"loaded"}),()=>{r.gone=!0,r.map?.destroy()}};var X=()=>{if(document.querySelector("script[data-isard-workers]"))return;let e=document.createElement("script");e.dataset.isardWorkers="",e.textContent=j,document.head.append(e)},Y=(e,n)=>({send:(r)=>{if(r.kind==="moveend"){e.set("camera",r.camera),e.save_changes();return}if(r.kind==="error"||r.kind==="failed")console.error(`isard: ${r.message}`);e.send(r)},listen:(r)=>{let t=()=>r({kind:"layers",layers:e.get("layers")}),a=(i)=>{let s=v(typeof i==="string"?i:JSON.stringify(i));if(s?.kind==="call"||s?.kind==="invoke")r(s)};e.on("change:layers",t),e.on("msg:custom",a),n.push(()=>e.off("change:layers",t),()=>e.off("msg:custom",a)),r({kind:"init",options:e.get("options"),layers:e.get("layers")})}}),fe={render({model:e,el:n}){X();let r=document.createElement("div");r.style.position="relative",r.style.width="100%",r.style.height=e.get("height"),n.append(r);let t=[],a=x(Y(e,t),r);return()=>{t.forEach((i)=>{i()}),a()}}};export{fe as default};
|
|
@@ -18,7 +18,14 @@ def wfs(type_name, bbox, count=50_000, srs_name="EPSG:4326"):
|
|
|
18
18
|
"""A WFS layer's frame: two features within `bbox`, the columns the examples read"""
|
|
19
19
|
west, south, east, north = bbox
|
|
20
20
|
return gpd.GeoDataFrame(
|
|
21
|
-
{
|
|
21
|
+
{
|
|
22
|
+
"nom_officiel": ["A", "B"],
|
|
23
|
+
"population": [12_000, 80_000],
|
|
24
|
+
"hauteur": [9.5, float("nan")],
|
|
25
|
+
"cleabs": ["BATIMENT0000000000000001", "BATIMENT0000000000000002"],
|
|
26
|
+
"altitude_minimale_sol": [33.0, 35.5],
|
|
27
|
+
"altitude_maximale_toit": [float("nan"), float("nan")],
|
|
28
|
+
},
|
|
22
29
|
geometry=[box(west, south, (west + east) / 2, north), Point(east, north).buffer(0.001)],
|
|
23
30
|
crs=4326,
|
|
24
31
|
)
|
|
@@ -27,6 +34,7 @@ def wfs(type_name, bbox, count=50_000, srs_name="EPSG:4326"):
|
|
|
27
34
|
@pytest.mark.parametrize("path", EXAMPLES, ids=lambda p: p.stem)
|
|
28
35
|
def test_an_example_makes_its_map(path, monkeypatch):
|
|
29
36
|
monkeypatch.setattr(isard_map, "geoplateforme_wfs", wfs)
|
|
37
|
+
monkeypatch.setattr(isard_map, "ogc_features", lambda url, collection, **query: wfs(collection, (0, 0, 1, 1)))
|
|
30
38
|
names = runpy.run_path(str(path))
|
|
31
39
|
m = names["m"]
|
|
32
40
|
|
|
@@ -4,6 +4,7 @@ import geopandas as gpd
|
|
|
4
4
|
import pytest
|
|
5
5
|
from shapely.geometry import Point
|
|
6
6
|
|
|
7
|
+
import isard_map
|
|
7
8
|
from isard_map import Map, prop, to_geojson
|
|
8
9
|
|
|
9
10
|
|
|
@@ -173,3 +174,36 @@ def test_an_object_as_plain_data_given_to_then():
|
|
|
173
174
|
*_, get, value = sent
|
|
174
175
|
assert value["target"] == get["handle"] and value["access"] == "value" and value["answer"]
|
|
175
176
|
assert places == [{"lonLat": [2.35, 48.85], "elevation": 35}]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def test_ogc_features_follows_the_next_links(monkeypatch):
|
|
180
|
+
"""The query as isard asks it (spaces as %20), the pages followed by their relative next links, the CRS kept"""
|
|
181
|
+
import isard_map._ogcapi as ogcapi
|
|
182
|
+
|
|
183
|
+
asked = []
|
|
184
|
+
|
|
185
|
+
def fetch_json(url):
|
|
186
|
+
asked.append(url)
|
|
187
|
+
page = len(asked) - 1
|
|
188
|
+
point = {"type": "Point", "coordinates": [5 + page, 51]}
|
|
189
|
+
return {
|
|
190
|
+
"type": "FeatureCollection",
|
|
191
|
+
"features": [{"type": "Feature", "properties": {"n": page}, "geometry": point}],
|
|
192
|
+
"links": [{"rel": "next", "href": f"items?page={page + 1}"}] if page < 2 else [],
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
monkeypatch.setattr(ogcapi, "fetch_json", fetch_json)
|
|
196
|
+
frame = isard_map.ogc_features(
|
|
197
|
+
"https://example.org/ogc/", "castles", bbox=(5, 51, 6, 52), filter="region = 'Mosel'", page_size=1
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
assert asked[0] == (
|
|
201
|
+
"https://example.org/ogc/collections/castles/items?f=json&limit=1&bbox=5%2C51%2C6%2C52"
|
|
202
|
+
"&filter=region%20%3D%20%27Mosel%27&filter-lang=cql2-text"
|
|
203
|
+
)
|
|
204
|
+
assert asked[1:] == [
|
|
205
|
+
"https://example.org/ogc/collections/castles/items?page=1",
|
|
206
|
+
"https://example.org/ogc/collections/castles/items?page=2",
|
|
207
|
+
]
|
|
208
|
+
assert list(frame["n"]) == [0, 1, 2]
|
|
209
|
+
assert frame.crs == "EPSG:4326"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|