MCPcopy Create free account
hub / github.com/opengeos/leafmap / add_vector

Method add_vector

leafmap/deck.py:244–285  ·  view source on GitHub ↗

Adds a vector file to the map. Args: data (str): The input file path to the vector dataset. layer_type (str, optional): The layer type to be used. Defaults to "GeoJsonLayer". layer_name (str, optional): The layer name to be used. Defaults to None.

(
        self,
        data: str,
        layer_type: str = "GeoJsonLayer",
        layer_name: Optional[str] = None,
        random_color_column: Optional[str] = None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

242 raise Exception(e)
243
244 def add_vector(
245 self,
246 data: str,
247 layer_type: str = "GeoJsonLayer",
248 layer_name: Optional[str] = None,
249 random_color_column: Optional[str] = None,
250 **kwargs,
251 ):
252 """Adds a vector file to the map.
253
254 Args:
255 data (str): The input file path to the vector dataset.
256 layer_type (str, optional): The layer type to be used. Defaults to "GeoJsonLayer".
257 layer_name (str, optional): The layer name to be used. Defaults to None.
258 random_color_column (str, optional): The column name to use for random color. Defaults to None.
259
260 Raises:
261 FileNotFoundError: The provided vector file could not be found.
262 """
263
264 try:
265 import fiona
266 import geopandas as gpd
267
268 if isinstance(data, str):
269 if not data.startswith("http"):
270 data = os.path.abspath(data)
271 if data.endswith(".zip"):
272 data = "zip://" + data
273
274 if data.endswith(".kml"):
275 fiona.drvsupport.supported_drivers["KML"] = "rw"
276 gdf = gpd.read_file(data, driver="KML")
277 else:
278 gdf = gpd.read_file(data)
279 else:
280 gdf = data
281
282 self.add_gdf(gdf, layer_type, layer_name, random_color_column, **kwargs)
283
284 except Exception as e:
285 raise Exception(e)
286
287 def add_geojson(
288 self,

Callers 7

view_vectorFunction · 0.95
view_vectorFunction · 0.95
add_geojsonMethod · 0.95
add_shpMethod · 0.95
add_kmlMethod · 0.95
test_add_vectorMethod · 0.95
test_add_vectorMethod · 0.95

Calls 1

add_gdfMethod · 0.95

Tested by 2

test_add_vectorMethod · 0.76
test_add_vectorMethod · 0.76