Homestock Example
In [1]:
Copied!
import sys, os
# Assuming notebook lives in docs/examples/
repo_root = os.path.abspath(os.path.join(os.getcwd(), "..", ".."))
sys.path.insert(0, repo_root)
import homestock
import sys, os
# Assuming notebook lives in docs/examples/
repo_root = os.path.abspath(os.path.join(os.getcwd(), "..", ".."))
sys.path.insert(0, repo_root)
import homestock
In [2]:
Copied!
# Import the necessary modules from the homestock package
import homestock
from homestock.homestock import Map
import ipyleaflet
import folium
import localtileserver
# Create a Map instance from the homestock package
m = Map(center=[40.7128, -74.0060], zoom=10) # Center map on New York City
# Add a basemap to the map
m.add_basemap("Esri.WorldImagery")
# Display the map in the notebook
m
# Add a GeoJSON layer to the map (optional demonstration of GeoJSON)
geojson_data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.0060, 40.7128],
},
"properties": {
"name": "New York City",
},
}
],
}
m.add_geojson(geojson_data)
# Set the center of the map to a new location (e.g., a different city)
m.set_center(lat=34.0522, lon=-118.2437, zoom=10) # Center map on Los Angeles
m
# Add a vector layer (GeoJSON or other supported format)
vector_data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-118.3, 34.0],
[-118.2, 34.0],
[-118.2, 34.1],
[-118.3, 34.1],
[-118.3, 34.0],
]
],
},
"properties": {"name": "Los Angeles Area"},
}
],
}
m.add_vector(vector_data)
# Add a raster layer (demonstrating cloud-optimized GeoTIFF usage)
# m.add_raster(filepath="path_to_your_raster_file.tif")
# Add a video overlay (use a video file URL)
# m.add_video(url="https://example.com/your_video.mp4", bounds=[[34.0, -118.4], [34.1, -118.2]])
# Add a WMS layer
# m.add_wms_layer(
# url="https://example.com/wms_service",
# layers="your_layer_name",
# name="Example WMS Layer",
# format="image/png",
# transparent=True,
# )
# Add basemap dropdown control to switch between basemaps
m.add_basemap_dropdown()
# Display the map
m
# Import the necessary modules from the homestock package
import homestock
from homestock.homestock import Map
import ipyleaflet
import folium
import localtileserver
# Create a Map instance from the homestock package
m = Map(center=[40.7128, -74.0060], zoom=10) # Center map on New York City
# Add a basemap to the map
m.add_basemap("Esri.WorldImagery")
# Display the map in the notebook
m
# Add a GeoJSON layer to the map (optional demonstration of GeoJSON)
geojson_data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.0060, 40.7128],
},
"properties": {
"name": "New York City",
},
}
],
}
m.add_geojson(geojson_data)
# Set the center of the map to a new location (e.g., a different city)
m.set_center(lat=34.0522, lon=-118.2437, zoom=10) # Center map on Los Angeles
m
# Add a vector layer (GeoJSON or other supported format)
vector_data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-118.3, 34.0],
[-118.2, 34.0],
[-118.2, 34.1],
[-118.3, 34.1],
[-118.3, 34.0],
]
],
},
"properties": {"name": "Los Angeles Area"},
}
],
}
m.add_vector(vector_data)
# Add a raster layer (demonstrating cloud-optimized GeoTIFF usage)
# m.add_raster(filepath="path_to_your_raster_file.tif")
# Add a video overlay (use a video file URL)
# m.add_video(url="https://example.com/your_video.mp4", bounds=[[34.0, -118.4], [34.1, -118.2]])
# Add a WMS layer
# m.add_wms_layer(
# url="https://example.com/wms_service",
# layers="your_layer_name",
# name="Example WMS Layer",
# format="image/png",
# transparent=True,
# )
# Add basemap dropdown control to switch between basemaps
m.add_basemap_dropdown()
# Display the map
m
Out[2]: