vscee 0.6.6__py3-none-any.whl

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.
vscee/Map.py ADDED
@@ -0,0 +1,150 @@
1
+ """Earth Engine map bridge for VS Code.
2
+
3
+ There is only one map panel in the VS Code extension, so this module IS
4
+ the map — no instantiation, no class. The capitalised name mirrors the
5
+ `Map` global used in the Earth Engine Code Editor.
6
+
7
+ Usage:
8
+
9
+ import ee
10
+ from earthengine_vscode_map import Map
11
+
12
+ ee.Initialize(project="my-project")
13
+
14
+ image = ee.Image("COPERNICUS/S2_SR/20200101T100319_20200101T100321_T32TQM")
15
+ Map.addLayer(image, {"bands": ["B4", "B3", "B2"], "min": 0, "max": 3000}, "RGB")
16
+ Map.centerObject(image, zoom=10)
17
+ """
18
+
19
+ import json
20
+ import urllib.request
21
+
22
+ import ee
23
+
24
+ _PORT = 31415
25
+ _BASE_URL = f"http://127.0.0.1:{_PORT}"
26
+
27
+
28
+ def _post(endpoint: str, data: dict):
29
+ """Send a POST request to the VS Code extension map server."""
30
+ body = json.dumps(data).encode("utf-8")
31
+ req = urllib.request.Request(
32
+ f"{_BASE_URL}/{endpoint}",
33
+ data=body,
34
+ headers={"Content-Type": "application/json"},
35
+ method="POST",
36
+ )
37
+ try:
38
+ with urllib.request.urlopen(req, timeout=10) as resp:
39
+ return json.loads(resp.read().decode("utf-8"))
40
+ except Exception as e:
41
+ print(f"[Map] Could not connect to VS Code map server: {e}")
42
+ print("[Map] Make sure the Earth Engine extension is active in VS Code.")
43
+ return None
44
+
45
+
46
+ def addLayer(ee_object, vis_params=None, name=None, shown=True, opacity=1.0):
47
+ """Add an Earth Engine layer to the VS Code map.
48
+
49
+ The object is serialized and sent to the VS Code extension, which
50
+ resolves the tile URL via the EE JS client. No EE API calls are made
51
+ on the Python side.
52
+
53
+ Args:
54
+ ee_object: An ee.Image, ee.ImageCollection, ee.FeatureCollection,
55
+ ee.Feature, or ee.Geometry.
56
+ vis_params: Visualization parameters dict (bands, min, max, palette,
57
+ color, strokeWidth, etc.).
58
+ name: Layer name. Auto-generated if not provided.
59
+ shown: Whether the layer is visible.
60
+ opacity: Layer opacity (0 to 1).
61
+ """
62
+ vis_params = dict(vis_params or {})
63
+
64
+ # Normalise to a single ee.Image (expression only — no API calls) ------
65
+
66
+ if isinstance(ee_object, ee.ImageCollection):
67
+ ee_object = ee_object.mosaic()
68
+
69
+ if isinstance(ee_object, ee.Geometry):
70
+ ee_object = ee.FeatureCollection([ee.Feature(ee_object)])
71
+ elif isinstance(ee_object, ee.Feature):
72
+ ee_object = ee.FeatureCollection([ee_object])
73
+
74
+ if isinstance(ee_object, ee.FeatureCollection):
75
+ stroke_width = vis_params.pop("strokeWidth", 2)
76
+ color = vis_params.pop("color", "000000")
77
+ ee_object = ee.Image().paint(ee_object, 1, stroke_width)
78
+ vis_params = {"min": 0, "max": 1, "palette": [color]}
79
+
80
+ if not isinstance(ee_object, ee.Image):
81
+ print(f"[Map] Unsupported object type: {type(ee_object)}")
82
+ return
83
+
84
+ _post(
85
+ "addLayer",
86
+ {
87
+ "serialized": ee_object.serialize(),
88
+ "visParams": vis_params,
89
+ "name": name or "Layer",
90
+ "shown": shown,
91
+ "opacity": opacity,
92
+ },
93
+ )
94
+
95
+
96
+ def centerObject(ee_object, zoom=None):
97
+ """Center the map on an Earth Engine object.
98
+
99
+ Args:
100
+ ee_object: An ee.Image, ee.ImageCollection, ee.FeatureCollection,
101
+ ee.Feature, or ee.Geometry.
102
+ zoom: Optional zoom level (1-24). Auto-computed if not provided.
103
+ """
104
+ try:
105
+ if isinstance(ee_object, ee.Geometry):
106
+ geom = ee_object
107
+ elif isinstance(
108
+ ee_object,
109
+ (ee.Image, ee.ImageCollection, ee.FeatureCollection, ee.Feature),
110
+ ):
111
+ geom = ee_object.geometry()
112
+ else:
113
+ print(f"[Map] Unsupported object type: {type(ee_object)}")
114
+ return
115
+
116
+ bounds = geom.bounds().getInfo()
117
+ coords = bounds["coordinates"][0]
118
+ west = min(c[0] for c in coords)
119
+ south = min(c[1] for c in coords)
120
+ east = max(c[0] for c in coords)
121
+ north = max(c[1] for c in coords)
122
+
123
+ _post(
124
+ "centerObject",
125
+ {
126
+ "bounds": [south, west, north, east],
127
+ "zoom": zoom,
128
+ },
129
+ )
130
+ except Exception as e:
131
+ print(f"[Map] Error centering: {e}")
132
+
133
+
134
+ def setCenter(lon, lat, zoom=None):
135
+ """Set the map center to specific coordinates.
136
+
137
+ Args:
138
+ lon: Longitude.
139
+ lat: Latitude.
140
+ zoom: Optional zoom level.
141
+ """
142
+ _post("setCenter", {"lat": lat, "lon": lon, "zoom": zoom})
143
+
144
+
145
+ def clear():
146
+ """Remove all layers from the map."""
147
+ _post("clear", {})
148
+
149
+
150
+ __all__ = ["addLayer", "centerObject", "clear", "setCenter"]
vscee/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Earth Engine bridge for VS Code — public API."""
2
+
3
+ from . import Map
4
+
5
+ __all__ = ["Map"]
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.5
2
+ Name: vscee
3
+ Version: 0.6.6
4
+ Summary: Python bridge to the interactive map panel of the Earth Engine VS Code extension.
5
+ Project-URL: Homepage, https://github.com/12rambau/earthengine-extension
6
+ Author-email: Pierrick Rambaud <pierrick.rambaud49@gmail.com>
7
+ License-Expression: Apache-2.0
8
+ Keywords: bridge,earthengine,leaflet,map,vscode
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering :: GIS
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.9
20
+ Requires-Dist: earthengine-api
21
+ Provides-Extra: dev
22
+ Requires-Dist: mypy; extra == 'dev'
23
+ Requires-Dist: ruff; extra == 'dev'
24
+ Description-Content-Type: text/x-rst
25
+
26
+ earthengine-vscode-map
27
+ ======================
28
+
29
+ Python bridge to the interactive map panel of the `Earth Engine VS Code extension`_.
30
+
31
+ The extension embeds a Leaflet map with a Python bridge server. This package
32
+ exposes a ``Map`` module that mirrors the Earth Engine Code Editor API
33
+ (``Map.addLayer``, ``Map.centerObject``, ``Map.setCenter``, ``Map.clear``)
34
+ and forwards the calls to that bridge. All Earth Engine graphs are serialised
35
+ locally and evaluated by the extension host — the Python side never resolves
36
+ tile URLs.
37
+
38
+ Usage
39
+ -----
40
+
41
+ .. code-block:: python
42
+
43
+ import ee
44
+ from earthengine_vscode_map import Map
45
+
46
+ ee.Initialize(project="my-project")
47
+
48
+ image = ee.Image("COPERNICUS/S2_SR/20200101T100319_20200101T100321_T32TQM")
49
+ Map.addLayer(image, {"bands": ["B4", "B3", "B2"], "min": 0, "max": 3000}, "RGB")
50
+ Map.centerObject(image, zoom=10)
51
+
52
+ Requirements
53
+ ------------
54
+
55
+ - Python ``>=3.9``
56
+ - The Earth Engine VS Code extension installed and active
57
+ - A valid ``ee.Initialize(project=...)`` call before any ``Map.*`` invocation
58
+
59
+ Install
60
+ -------
61
+
62
+ From the repository root:
63
+
64
+ .. code-block:: bash
65
+
66
+ pip install -e python/
67
+
68
+ License
69
+ -------
70
+
71
+ Apache License 2.0 — see ``LICENSE``.
72
+
73
+ .. _Earth Engine VS Code extension: https://github.com/12rambau/earthengine-extension
@@ -0,0 +1,5 @@
1
+ vscee/Map.py,sha256=jod9Y-7_aVIga1b8INGdST5wJrQT4Sf_vI_2zuxJ4t8,4639
2
+ vscee/__init__.py,sha256=WCRhcJ_7ky5bkzK6aiBHXMuEfHFkAjdNSXcEalhPTZo,92
3
+ vscee-0.6.6.dist-info/METADATA,sha256=QyaytmCEvV5CJJwSgRWysjrBvwrzaV8RIcebFM3VsI4,2347
4
+ vscee-0.6.6.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
5
+ vscee-0.6.6.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any