Visualizing Vector Data with MyMapLib¶
This notebook demonstrates the capabilities of the MyMapLib package for visualizing vector data on interactive maps. MyMapLib supports various data formats, including GeoJSON, shapefiles, and GeoPandas GeoDataFrames. You can easily add different types of basemaps to enhance the visualization.
Setup¶
First, ensure you have installed the necessary packages (folium, geopandas, etc.). If you haven't, uncomment and run the following command:
!pip install folium geopandas¶
markdown
Importing the Package¶
Let's import the Map class from our package.
from mymaplib import Map markdown
Creating a Map Instance¶
Create a map instance with a default location and zoom level.
mymap = Map(location=[40.7128, -74.0060], zoom_start=10) # Example: New York City markdown
Adding a Basemap¶
You can add different types of basemaps to your map. Here, we add the OpenStreetMap basemap.
mymap.add_basemap('OpenStreetMap') markdown
Displaying the Map¶
Let's display the map with the added basemap.
mymap.show() markdown
Adding GeoJSON Data¶
Now, we will add GeoJSON data to our map. This could be from a local file, a dictionary, or a URL.
Example: Adding GeoJSON from a dictionary¶
geojson_example = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-74.0060, 40.7128] } } ] }
mymap.add_geojson(geojson_example) markdown
Adding a Shapefile¶
To add shapefile data, provide the path to the local file or a URL to a zipped shapefile.
Example: Adding a shapefile (Adjust the path or URL as needed)¶
mymap.add_shp('path/to/your/shapefile.shp')¶
markdown
Adding Vector Data¶
You can also add any supported vector data using the add_vector method. Here's how you can add a GeoDataFrame.
import geopandas as gpd
Example: Creating a GeoDataFrame to add to the map¶
gdf = gpd.GeoDataFrame({ 'geometry': gpd.points_from_xy([-74.0060], [40.7128]) })
mymap.add_vector(gdf) markdown
Conclusion¶
This notebook introduced the basic functionalities of MyMapLib for adding basemaps,