{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "[](https://demo.leafmap.org/lab/index.html?path=notebooks/95_edit_vector.ipynb)\n", "[](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/notebooks/95_edit_vector.ipynb)\n", "[](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n", "\n", "# Edit Vector Data Interactively\n", "\n", "Uncomment the following line to install [leafmap](https://leafmap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "# %pip install -U leafmap" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "from leafmap import leafmap" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "## Edit points" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "m = leafmap.Map(center=[40, -100], zoom=4)\n", "# Load any vector dataset that can be loaded by GeoPandas\n", "geojson_url = \"https://github.com/opengeos/datasets/releases/download/us/cities.geojson\"\n", "m.edit_points(geojson_url)\n", "m" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "Save the edits to a new file. Choose any of the supported formats by GeoPandas, such as GeoJSON, Shapefile, or GeoPackage." ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "m.save_edits(\"cities.geojson\")" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "## Edit lines" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "m = leafmap.Map()\n", "# Load any vector dataset that can be loaded by GeoPandas\n", "geojson_url = (\n", " \"https://github.com/opengeos/datasets/releases/download/places/nyc_roads.geojson\"\n", ")\n", "m.edit_lines(geojson_url)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "m.save_edits(\"nyc_roads.geojson\")" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "## Edit polygons" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "m = leafmap.Map()\n", "# Load any vector dataset that can be loaded by GeoPandas\n", "geojson_url = \"https://github.com/opengeos/datasets/releases/download/places/nyc_buildings.geojson\"\n", "m.edit_polygons(geojson_url)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "m.save_edits(\"nyc_buildings.geojson\")" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "" ] } ], "metadata": { "kernelspec": { "display_name": "geo", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.8" } }, "nbformat": 4, "nbformat_minor": 5 }