giswqs commited on
Commit
9d76428
·
1 Parent(s): cbe193f

Update change dataset function

Browse files
Files changed (2) hide show
  1. pages/01_morocco.py +9 -1
  2. pages/02_libya.py +9 -1
pages/01_morocco.py CHANGED
@@ -68,10 +68,18 @@ def add_widgets(m):
68
  )
69
 
70
  def change_dataset(change):
71
- default_geojson = f'{url}/datasets/{change.new}.geojson'
72
  m.layers = m.layers[:2]
73
  m.controls = m.controls[:-1]
 
 
 
 
 
 
 
74
  m.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
 
75
  image.options = get_catalogs(change.new)
76
 
77
  dataset.observe(change_dataset, names='value')
 
68
  )
69
 
70
  def change_dataset(change):
71
+ default_geojson = f'{url}/datasets/{change.new}_union.geojson'
72
  m.layers = m.layers[:2]
73
  m.controls = m.controls[:-1]
74
+ basename = os.path.basename(default_geojson)
75
+ tempdir = tempfile.gettempdir()
76
+ tmp_geojson = os.path.join(tempdir, basename)
77
+ if os.path.exists(tmp_geojson):
78
+ default_geojson = tmp_geojson
79
+ else:
80
+ leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
81
  m.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
82
+
83
  image.options = get_catalogs(change.new)
84
 
85
  dataset.observe(change_dataset, names='value')
pages/02_libya.py CHANGED
@@ -68,10 +68,18 @@ def add_widgets(m):
68
  )
69
 
70
  def change_dataset(change):
71
- default_geojson = f'{url}/datasets/{change.new}.geojson'
72
  m.layers = m.layers[:2]
73
  m.controls = m.controls[:-1]
 
 
 
 
 
 
 
74
  m.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
 
75
  image.options = get_catalogs(change.new)
76
 
77
  dataset.observe(change_dataset, names='value')
 
68
  )
69
 
70
  def change_dataset(change):
71
+ default_geojson = f'{url}/datasets/{change.new}_union.geojson'
72
  m.layers = m.layers[:2]
73
  m.controls = m.controls[:-1]
74
+ basename = os.path.basename(default_geojson)
75
+ tempdir = tempfile.gettempdir()
76
+ tmp_geojson = os.path.join(tempdir, basename)
77
+ if os.path.exists(tmp_geojson):
78
+ default_geojson = tmp_geojson
79
+ else:
80
+ leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
81
  m.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
82
+
83
  image.options = get_catalogs(change.new)
84
 
85
  dataset.observe(change_dataset, names='value')