From 6b49d300c260379b1ddfdcacc89369a4721adbf4 Mon Sep 17 00:00:00 2001 From: John Yaist Date: Mon, 12 Aug 2024 14:50:40 -0700 Subject: [PATCH 1/3] initial updates to adv map usage --- .../advanced-map-widget-usage.ipynb | 667 +++++++++++++++++- 1 file changed, 666 insertions(+), 1 deletion(-) diff --git a/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb b/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb index 761c75d6c9..245b2ee32a 100644 --- a/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb +++ b/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb @@ -1 +1,666 @@ -{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# Advanced Map Widget Useage\n", "\n", "This guide covers more advanced uses for the map widget: see [using the map widget](../using-the-map-widget) for more information!"]}, {"cell_type": "markdown", "metadata": {"toc": true}, "source": ["

Table of Contents

\n", "
"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## Property Updating"]}, {"cell_type": "markdown", "metadata": {}, "source": ["The map widget handles `zoom`, `tilt`, `heading`/`rotation`, `basemap`, `center`, `extent`, etc. features in an interesting and powerful way. Try running the below cells to gain insight into how these properties are updated:"]}, {"cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [{"data": {"text/html": [""], "text/plain": [""]}, "execution_count": 18, "metadata": {}, "output_type": "execute_result"}], "source": ["from arcgis.gis import GIS\n", "\n", "def print_map_info(map):\n", " print(\"Mode =\\t\\t{}\".format(map.mode))\n", " if map.mode == \"2D\":\n", " print(\"Zoom =\\t\\t{}\\n\".format(map.zoom) + \\\n", " \"Rotation =\\t{}\".format(map.rotation))\n", " elif map.mode == \"3D\":\n", " print(\"Zoom =\\t\\t{}\\n\".format(map.zoom) + \\\n", " \"Tilt =\\t\\t{}\\n\".format(map.tilt) + \\\n", " \"Heading =\\t{}\".format(map.heading))\n", " else:\n", " raise Exception(\"Not supported argument\")\n", "\n", "usa_map = GIS().map(\"USA\")\n", "usa_map.mode = \"3D\"\n", "usa_map"]}, {"cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Mode =\t\t3D\n", "Zoom =\t\t1.3856049324356938\n", "Tilt =\t\t0.13085251425698102\n", "Heading =\t8.537736462515939e-07\n"]}], "source": ["print_map_info(usa_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now, using your mouse, move the map to a new location, zoom in, modify the tilt and heading, etc. After you've move the camera, run the below cell to print out the current state of those properties:"]}, {"cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Mode =\t\t3D\n", "Zoom =\t\t4.057564184135124\n", "Tilt =\t\t8.446352685544214\n", "Heading =\t15.599097870716443\n"]}], "source": ["print_map_info(usa_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["The values of those python variables have changed when you moved around in the widget! Experiment with printing out the values of `center`, `extent`, and any of the above properties. See the API reference for more information.\n", "\n", "Then, try clicking on this icon on the upper left corner of the widget:\n", "\n", " \n", "\n", "You'll notice that you've switched from 3D mode to 2D mode! All properties, including `map.mode` have been updated! Try running the below cell to see what your current values are:"]}, {"cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Mode =\t\t2D\n", "Zoom =\t\t4.0\n", "Rotation =\t344.40090214146767\n"]}], "source": ["print_map_info(usa_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You can always click the icon on the upper left corner to switch between 2D and 3D mode. The widget will do it's best to preserve your current view."]}, {"cell_type": "markdown", "metadata": {}, "source": ["# Callbacks\n", "\n", "You can setup an asyncronous callback using the `on_click()` or `on_draw_end()` to create dynamic, interactive 'apps'. You need to create a callback function like `function_name(map_inst, geometry)`, with `map_inst` being the `MapView` instance, and `geometry` being the geometry instance that the user clicked.\n", "\n", "The below example takes a point a user clicks on the map, reverse geocodes from the geometry, and prints out the resultant location. Also to note here, you can either create the GIS connection using existing profile, or by simply entering the username and password, e.g. `gis = GIS(\"https://www.arcgis.com\", \"arcgis_python\", \"P@ssword123\")`."]}, {"cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [{"data": {"text/html": [""], "text/plain": [""]}, "execution_count": 14, "metadata": {}, "output_type": "execute_result"}], "source": ["from arcgis.gis import GIS\n", "import arcgis.geocoding as geocoding\n", "gis = GIS('home')\n", "callback_map = gis.map('San Diego convention center, San Diego, CA', 16)\n", "def find_addr(callback_map, g):\n", " try:\n", " callback_map.draw(g)\n", " geocoded = geocoding.reverse_geocode(g)\n", " print(geocoded['address']['Match_addr'])\n", " except:\n", " print(\"Couldn't match address. Try another place...\")\n", "callback_map.on_click(find_addr)\n", "callback_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["# 3D Feature Layers"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let's create a new map of Zion National Park in Utah. 3D mode will show the elevation of the many canyons, rides, and elevation changes. It will even cast shadows. Run the below cell and explore!"]}, {"cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [{"data": {"text/html": [""], "text/plain": [""]}, "execution_count": 15, "metadata": {}, "output_type": "execute_result"}], "source": ["from arcgis.gis import GIS\n", "zion_map = gis.map(\"Angel's Landing UT\", 15)\n", "zion_map.mode = \"3D\"\n", "zion_map.tilt= 40\n", "zion_map.heading = 180\n", "\n", "zion_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You can also add Portal items and layers to the 3D map just like before. Run the below cell to add a layer of trails: notice how the trails follow the elevation changes of the land!"]}, {"cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": ["trails_layer = gis.content.get('dd0889d7ccd340dd876dac12184e99f9').layers[0]\n", "zion_map.add_layer(trails_layer)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["The Python API also supports specifying Javascript renderers via [autocasting](https://developers.arcgis.com/javascript/latest/guide/autocasting/index.html). This Python API displays maps in a Jupyter notebook by leveraging the ArcGIS API for JavaScript. By specifying `renderer: \"autocast\"` for any renderer, you are directing Python to allow the Javascript API to attempt to infer the renderer by following Javascript API rules. Since Python `dict`'s map directly to JavaScript `JSON`, you can specify any [Javascript Renderer](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-Renderer.html) for a large range of visualization options! Try running the below code snippet to use a `SimpleRenderer` with a `LineSymbol3D` symbol. More on autocast renderers below."]}, {"cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": ["symbol = {\n", " \"type\": \"line-3d\", # JS type of new LineSymbol3D()\n", " \"symbolLayers\": [{\n", " \"type\": \"path\", # JS type of new PathSymbol3DLayer()\n", " \"size\": 20, # 20 meters in diameter\n", " \"material\": { \"color\": \"#0083ff\" } #The hex color code\n", " }]\n", "}\n", "zion_map.add_layer(trails_layer,\n", " {\"renderer\" : \"autocast\", #Tell Python to autocast JS types\n", " \"type\" : \"simple\", #JS type of SimpleRenderer()\n", " \"symbol\": symbol} #The symbol we previously defined\n", ")"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You will notice a much more 3D friendly representation of trails! You can then specify some properties to propery visualize the \"Angel's Landing\" hike in Zion, one of the most dangerous and exciting hikes in the US! Run the below cell:"]}, {"cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": ["zion_map.center = {'spatialReference': {'latestWkid': 3857, 'wkid': 102100},\n", " 'x': -12573456.64044217,\n", " 'y': 4476861.2153126905,\n", " 'z': 1638.3878966225311}\n", "zion_map.zoom= 15.528381436708822\n", "zion_map.heading = 190\n", "zion_map.tilt = 45"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You can save your current work as a WebScene by calling map.save(). Run the following code to save your WebScene!\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["my_zion_webscene_item = \\\n", " zion_map.save({'title' : 'My Zion Park Web Scene',\n", " 'snippet' : 'What I made in the new beta ArcGIS API for Python!',\n", " 'tags' : 'zion, NPS, python'})\n", "my_zion_webscene_item"]}, {"cell_type": "markdown", "metadata": {}, "source": ["# Taking advantage of Autocasting"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You are only limitted in your visualization options by the Javascript API: you can specify any renderer and modify any properties of said renderer. To show how poewrful this really is, let's use the SimpleRenderer's [visual variables](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-SimpleRenderer.html#visualVariables) functionality. Run the below cell to see a standard Feature Layer about Hurricane tracks in 2D mode."]}, {"cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [{"data": {"text/html": [""], "text/plain": [""]}, "execution_count": 20, "metadata": {}, "output_type": "execute_result"}], "source": ["from arcgis.gis import GIS\n", "from arcgis.features import FeatureLayer\n", "anon_gis = GIS()\n", "hurricane_layer = FeatureLayer(\n", " url=\"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/0\")\n", "hurricane_map = anon_gis.map('Atlantic Ocean', 3)\n", "hurricane_map.add_layer(hurricane_layer)\n", "hurricane_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You can represent this same information on a 3D map by specifying a SimpleRenderer using white spheres. Run the below cell, click on some points, and examine some fields:"]}, {"cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [{"data": {"text/html": [""], "text/plain": [""]}, "execution_count": 22, "metadata": {}, "output_type": "execute_result"}], "source": ["hurricane_map_3D = anon_gis.map('Atlantic Ocean', 3)\n", "hurricane_map_3D.mode = \"3D\"\n", "renderer = {\"renderer\": \"autocast\", #This tells python to use JS autocasting\n", " \"type\": \"simple\", # JS type of new SimpleRenderer()\n", " \"symbol\": {\n", " \"type\": \"point-3d\", #JS type of new PointSymbol3D()\n", " \"symbolLayers\": [{ \n", " \"type\": \"object\", #JS type of new ObjectSymbol3DLayer()\n", " \"resource\": { \"primitive\": \"sphere\" },\n", " \"width\": 50000\n", " }]\n", " },\n", "}\n", "\n", "hurricane_map_3D.add_layer(hurricane_layer, renderer)\n", "hurricane_map_3D"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now that we have the base set up, lets specify the `visualVariables` field to vary the color of each point for the changing `PRESSURE` field, and vary the size of each point for the changing `WINDSPEED` field. Run the below cell, then try modifying the options to see different results! Maybe try tuning the `\"value\"` fields to see different color and size variations."]}, {"cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [{"data": {"text/html": [""], "text/plain": [""]}, "execution_count": 17, "metadata": {}, "output_type": "execute_result"}], "source": ["visual_var_map = anon_gis.map('Atlantic Ocean', 3)\n", "visual_var_map.mode = \"3D\"\n", "#Update the renderer to include visual variable information\n", "renderer[\"visualVariables\"] = [{ #JS configuration of visualVariables\n", " \"type\": \"color\",\n", " \"field\": \"PRESSURE\", \n", " \"stops\": [\n", " { \"value\": 950, \"color\": \"red\" },\n", " { \"value\": 1020, \"color\": \"blue\" }\n", " ]\n", " }, {\n", " \"type\": \"size\",\n", " \"field\": \"WINDSPEED\",\n", " \"stops\": [\n", " { \"value\": 20, \"size\": 60000 },\n", " { \"value\": 150, \"size\": 500000 }\n", " ],\n", " \"axis\": \"height\"\n", " }, {\n", " \"type\": \"size\",\n", " \"axis\": \"width-and-depth\",\n", " \"useSymbolValue\": True\n", " }]\n", "visual_var_map.add_layer(hurricane_layer, renderer)\n", "visual_var_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## Export to HTML"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Another new feature in 1.5.0 is the ability to export the current widget as a standalone HTML file. This added functionality provides a new workflow for creating standalone HTML maps that can be shared with anyone: all they need is a web browser!\n", "\n", "The below cell will write the current widget to the file specified by a string path. Run the cell, find the file on your disk, and open it in your favorite web browser.\n", "\n", "> Note: By default, only publically accesible layers will show on the exported HTML maps. You must specify credentials_prompt=True to allow users to authenticate to portal to view private layers. See [the API reference](https://developers.arcgis.com/python/api-reference/arcgis.widgets.html#arcgis.widgets.MapView.export_to_html) for more information."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import os\n", "\n", "file_dir = os.path.join(os.getcwd(), 'home')\n", "if not os.path.isdir(file_dir):\n", " os.mkdir(file_dir)\n", " \n", "file_path = os.path.join(file_dir, 'myHurricaneMap.html')\n", "\n", "visual_var_map.export_to_html(file_path)\n", "print(\"html saved as \" + file_path) # On Windows, path can be 'C:\\Users\\Username\\Documents\\home\\myHurricaneMap.html'"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.8.2"}, "toc": {"base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": {}, "toc_section_display": true, "toc_window_display": true}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Advanced Map Widget Usage\n", + "\n", + "This guide covers more advanced uses for the map widget: see [using the map widget](../using-the-map-widget) for more information!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Property Updating" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The map widget handles `zoom`, `tilt`, `heading`/`rotation`, `basemap`, `center`, `extent`, etc. features in an interesting and powerful way. Try running the below cells to gain insight into how these properties are updated:" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "def print_map_info(map):\n", + " print(\"Widget Type =\\t\\t{}\".format(type(map)))\n", + " if not hasattr(map, \"camera\"):\n", + " print(\"Zoom =\\t\\t{}\\n\".format(map.zoom))\n", + " elif map.camera:\n", + " print(\"Zoom =\\t\\t{}\\n\".format(map.zoom) + \\\n", + " \"Tilt =\\t\\t{}\\n\".format(map.tilt) + \\\n", + " \"Heading =\\t{}\".format(map.heading))\n", + " else:\n", + " raise Exception(\"Not supported argument\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The *mode* property from the previous MapView class has been removed as a property from the Map class, but it can be used when initializing a widget to differentiate a _Scene_ or _Map_ widget:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from arcgis.gis import GIS" + ] + }, + { + "cell_type": "code", + "execution_count": 237, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "arcgis.map.map_widget.Map" + ] + }, + "execution_count": 237, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(GIS().map(\"USA\", mode=\"2D\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 238, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "arcgis.map.scene_widget.Scene" + ] + }, + "execution_count": 238, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(GIS().map(\"USA\", mode=\"3D\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 257, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 257, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from arcgis.gis import GIS\n", + "\n", + "usa_map = GIS().map(\"USA\", mode=\"3D\")\n", + "usa_map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, using your mouse, move the map to a new location, zoom in, modify the tilt and heading, etc. After you've moved the camera, run the below cells to change the zoom and print the current state of those properties:" + ] + }, + { + "cell_type": "code", + "execution_count": 240, + "metadata": {}, + "outputs": [], + "source": [ + "usa_map.zoom = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 241, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Widget Type =\t\t\n", + "Zoom =\t\t2.0\n", + "Tilt =\t\t0.09999878139707691\n", + "Heading =\t0\n" + ] + } + ], + "source": [ + "print_map_info(usa_map)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The values of the widget properties will change with use of the various buttons in the map widget view! Experiment with printing out the values of `center`, `extent`, and any of the above properties. See the API reference for more information." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3D Feature Layers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's create a new map of Zion National Park in Utah. 3D mode will show the elevation of the many canyons, rides, and elevation changes. It will even cast shadows. Run the below cell and explore!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gis = GIS(profile=\"your_online_profile\")" + ] + }, + { + "cell_type": "code", + "execution_count": 256, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 256, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from arcgis.gis import GIS\n", + "zion_map = gis.map(\"Angel's Landing UT\", mode=\"3D\")\n", + "zion_map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Run each of these cells below individually to watch how the view changes." + ] + }, + { + "cell_type": "code", + "execution_count": 249, + "metadata": {}, + "outputs": [], + "source": [ + "zion_map.zoom = 14" + ] + }, + { + "cell_type": "code", + "execution_count": 250, + "metadata": {}, + "outputs": [], + "source": [ + "zion_map.center = [37.2502, -112.9564]" + ] + }, + { + "cell_type": "code", + "execution_count": 251, + "metadata": {}, + "outputs": [], + "source": [ + "zion_map.camera = {\n", + " \"position\": {\n", + " \"x\": -12573578.761488685,\n", + " \"y\": 4461966.125736885,\n", + " \"z\": 6300,\n", + " },\n", + " \"tilt\": 65,\n", + " \"heading\": 360, \n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can also add Portal items and layers to the 3D map just like before. Run the below cell to add a layer of trails: notice how the trails follow the elevation changes of the land!" + ] + }, + { + "cell_type": "code", + "execution_count": 252, + "metadata": {}, + "outputs": [], + "source": [ + "trails_layer = gis.content.get(\"881694a7049b419ebb8d271c0e6d7ddd\").layers[0]\n", + "zion_map.content.add(trails_layer)" + ] + }, + { + "cell_type": "code", + "execution_count": 253, + "metadata": {}, + "outputs": [], + "source": [ + "zion_map.camera = {\n", + " \"position\": {\n", + " \"x\": -12573578.761488685,\n", + " \"y\": 4461966.125736885,\n", + " \"z\": 6300,\n", + " },\n", + " \"tilt\": 65,\n", + " \"heading\": 360, \n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can save your current work as a WebScene by calling map.save(). Run the following code to save your WebScene!\n" + ] + }, + { + "cell_type": "code", + "execution_count": 255, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "\n", + "
\n", + " My Zion Park Web Scene\n", + " \n", + "
What I made with the ArcGIS API for Python Scene widget!
Web Scene by arcgis_python\n", + "
Last Modified: August 07, 2024\n", + "
0 comments, 0 views\n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 255, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_zion_webscene_item = zion_map.save(\n", + " {\"title\" : \"My Zion Park Web Scene\",\n", + " \"snippet\" : \"What I made with the ArcGIS API for Python Scene widget!\",\n", + " \"tags\" : \"zion, NPS, python\"}\n", + ")\n", + "\n", + "my_zion_webscene_item" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Rendering" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The Python API also supports rendering symbols on the map wideget through defining properties. Once defined, the widget makes use of the Javascript API renderers. Try running the below code snippet to use a `SimpleRenderer` with a `LineSymbol3D` symbol. More on autocast renderers below." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You are only limitted in your visualization options by the Javascript API: you can specify any renderer and modify any properties of said renderer. To show how powerful this really is, let's use the SimpleRenderer's [visual variables](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-SimpleRenderer.html#visualVariables) functionality. Run the below cell to see a standard Feature Layer about Hurricane tracks in 2D mode." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n", + "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/john3092/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/dask/dataframe/_pyarrow_compat.py:23: UserWarning: You are using pyarrow version 11.0.0 which is known to be insecure. See https://www.cve.org/CVERecord?id=CVE-2023-47248 for further details. Please upgrade to pyarrow>=14.0.1 or install pyarrow-hotfix to patch your current version.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "from arcgis.gis import GIS\n", + "from arcgis.features import FeatureLayer" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "anon_gis = GIS()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "hurricane_layer = FeatureLayer(\n", + " url=\"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/0\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "hurricane_map = anon_gis.map('Atlantic Ocean')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "df34faa68f024e72895a693f94d04f51", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(center=[3716583.6647425774, -4155920.0458218013], extent={'xmin': -8511072.484127043, 'ymin': -835007.2772…" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "hurricane_map.content.add(hurricane_layer)\n", + "hurricane_map" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "hurricane_map.legend.enabled=True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can represent this same information on a 3D map by specifying a SimpleRenderer using white spheres. Run the below cell, click on some points, and examine some fields:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "from arcgis.map import Scene" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "hurricane_map_3D = Scene(location='Atlantic Ocean')" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "from arcgis.map import renderers, symbols" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "renderer = renderers.SimpleRenderer(\n", + " symbol=symbols.SimpleMarkerSymbolEsriSMS(\n", + " style=\"esriSMSCircle\", color=[255, 0, 0, 1], size=20\n", + " )\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "ename": "ValidationError", + "evalue": "1 validation error for FeatureLayerArcGISFeatureLayer\nlayerDefinition.timeInfo.timeIntervalUnits\n Input should be 'esriTimeUnitsCenturies', 'esriTimeUnitsDays', 'esriTimeUnitsDecades', 'esriTimeUnitsHours', 'esriTimeUnitsMilliseconds', 'esriTimeUnitsMinutes', 'esriTimeUnitsMonths', 'esriTimeUnitsSeconds', 'esriTimeUnitsUnknown', 'esriTimeUnitsWeeks' or 'esriTimeUnitsYears' [type=enum, input_value=, input_type=TimeIntervalUnits]", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[13], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m hurricane_map_3D\u001b[38;5;241m.\u001b[39mcontent\u001b[38;5;241m.\u001b[39madd(\n\u001b[1;32m 2\u001b[0m item\u001b[38;5;241m=\u001b[39mhurricane_layer,\n\u001b[1;32m 3\u001b[0m drawing_info \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrenderer\u001b[39m\u001b[38;5;124m\"\u001b[39m: renderer\n\u001b[1;32m 5\u001b[0m }\n\u001b[1;32m 6\u001b[0m )\n", + "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/scene_widget.py:1327\u001b[0m, in \u001b[0;36mSceneContent.add\u001b[0;34m(self, item, drawing_info, popup_info, index)\u001b[0m\n\u001b[1;32m 1324\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[1;32m 1325\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1326\u001b[0m \u001b[38;5;66;03m# Only one layer, create the layer and add\u001b[39;00m\n\u001b[0;32m-> 1327\u001b[0m layer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_helper\u001b[38;5;241m.\u001b[39m_create_layer_from_item(item, drawing_info, popup_info)\n\u001b[1;32m 1328\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlayers\u001b[38;5;241m.\u001b[39minsert(index, item)\n\u001b[1;32m 1330\u001b[0m \u001b[38;5;66;03m# Check that layer is not None at this point\u001b[39;00m\n", + "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/_utils.py:1048\u001b[0m, in \u001b[0;36m_HelperMethods._create_layer_from_item\u001b[0;34m(self, layer, drawing_info, popup_info)\u001b[0m\n\u001b[1;32m 1046\u001b[0m ld \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1047\u001b[0m popup \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_create_popup_dataclass(layer, popup_info)\n\u001b[0;32m-> 1048\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mspec\u001b[38;5;241m.\u001b[39mFeatureLayerArcGISFeatureLayer(\n\u001b[1;32m 1049\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mproperties,\n\u001b[1;32m 1050\u001b[0m url\u001b[38;5;241m=\u001b[39mlayer\u001b[38;5;241m.\u001b[39m_url,\n\u001b[1;32m 1051\u001b[0m layerDefinition\u001b[38;5;241m=\u001b[39mld,\n\u001b[1;32m 1052\u001b[0m popupInfo\u001b[38;5;241m=\u001b[39mpopup,\n\u001b[1;32m 1053\u001b[0m itemId\u001b[38;5;241m=\u001b[39mitem_id,\n\u001b[1;32m 1054\u001b[0m title\u001b[38;5;241m=\u001b[39mproperties[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 1055\u001b[0m )\n\u001b[1;32m 1056\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(layer, arcgis_layers\u001b[38;5;241m.\u001b[39mVectorTileLayer):\n\u001b[1;32m 1057\u001b[0m style_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlayer\u001b[38;5;241m.\u001b[39m_url\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/resources/styles/root.json\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", + "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/pydantic/main.py:164\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[0;34m(__pydantic_self__, **data)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001b[39;00m\n\u001b[1;32m 163\u001b[0m __tracebackhide__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 164\u001b[0m __pydantic_self__\u001b[38;5;241m.\u001b[39m__pydantic_validator__\u001b[38;5;241m.\u001b[39mvalidate_python(data, self_instance\u001b[38;5;241m=\u001b[39m__pydantic_self__)\n", + "\u001b[0;31mValidationError\u001b[0m: 1 validation error for FeatureLayerArcGISFeatureLayer\nlayerDefinition.timeInfo.timeIntervalUnits\n Input should be 'esriTimeUnitsCenturies', 'esriTimeUnitsDays', 'esriTimeUnitsDecades', 'esriTimeUnitsHours', 'esriTimeUnitsMilliseconds', 'esriTimeUnitsMinutes', 'esriTimeUnitsMonths', 'esriTimeUnitsSeconds', 'esriTimeUnitsUnknown', 'esriTimeUnitsWeeks' or 'esriTimeUnitsYears' [type=enum, input_value=, input_type=TimeIntervalUnits]" + ] + } + ], + "source": [ + "hurricane_map_3D.content.add(\n", + " item=hurricane_layer,\n", + " drawing_info = {\n", + " \"renderer\": renderer\n", + " }\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now that we have the base set up, lets specify the `visualVariables` field to vary the color of each point for the changing `PRESSURE` field, and vary the size of each point for the changing `WINDSPEED` field. Run the below cell, then try modifying the options to see different results! Maybe try tuning the `\"value\"` fields to see different color and size variations." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "visual_var_map = anon_gis.map('Atlantic Ocean', mode=\"3D\")\n", + "\n", + "#Update the renderer to include visual variable information\n", + "renderer[\"visualVariables\"] = [{ #JS configuration of visualVariables\n", + " \"type\": \"color\",\n", + " \"field\": \"PRESSURE\", \n", + " \"stops\": [\n", + " { \"value\": 950, \"color\": \"red\" },\n", + " { \"value\": 1020, \"color\": \"blue\" }\n", + " ]\n", + " }, {\n", + " \"type\": \"size\",\n", + " \"field\": \"WINDSPEED\",\n", + " \"stops\": [\n", + " { \"value\": 20, \"size\": 60000 },\n", + " { \"value\": 150, \"size\": 500000 }\n", + " ],\n", + " \"axis\": \"height\"\n", + " }, {\n", + " \"type\": \"size\",\n", + " \"axis\": \"width-and-depth\",\n", + " \"useSymbolValue\": True\n", + " }]\n", + "visual_var_map.content.add(hurricane_layer, renderer)\n", + "visual_var_map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Export to HTML" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Another new feature in 1.5.0 is the ability to export the current widget as a standalone HTML file. This added functionality provides a new workflow for creating standalone HTML maps that can be shared with anyone: all they need is a web browser!\n", + "\n", + "The below cell will write the current widget to the file specified by a string path. Run the cell, find the file on your disk, and open it in your favorite web browser.\n", + "\n", + "> Note: By default, only publically accesible layers will show on the exported HTML maps. You must specify credentials_prompt=True to allow users to authenticate to portal to view private layers. See [the API reference](https://developers.arcgis.com/python/api-reference/arcgis.widgets.html#arcgis.widgets.MapView.export_to_html) for more information." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "file_dir = os.path.join(os.getcwd(), 'home')\n", + "if not os.path.isdir(file_dir):\n", + " os.mkdir(file_dir)\n", + " \n", + "file_path = os.path.join(file_dir, 'myHurricaneMap.html')\n", + "\n", + "visual_var_map.export_to_html(file_path)\n", + "print(\"html saved as \" + file_path) # On Windows, path can be 'C:\\Users\\Username\\Documents\\home\\myHurricaneMap.html'" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.0" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": true, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": true + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 3a4e877c5fc3d396570b8dbdebc83567b1f7f6d3 Mon Sep 17 00:00:00 2001 From: John Yaist Date: Wed, 14 Aug 2024 13:22:23 -0700 Subject: [PATCH 2/3] updates for rendering 3d symbols --- .../advanced-map-widget-usage.ipynb | 186 +++++++++++++----- 1 file changed, 136 insertions(+), 50 deletions(-) diff --git a/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb b/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb index 245b2ee32a..05e08a9c21 100644 --- a/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb +++ b/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb @@ -60,9 +60,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n", + "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/john3092/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/dask/dataframe/_pyarrow_compat.py:23: UserWarning: You are using pyarrow version 11.0.0 which is known to be insecure. See https://www.cve.org/CVERecord?id=CVE-2023-47248 for further details. Please upgrade to pyarrow>=14.0.1 or install pyarrow-hotfix to patch your current version.\n", + " warnings.warn(\n" + ] + } + ], "source": [ "from arcgis.gis import GIS" ] @@ -374,34 +391,17 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n", - "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/john3092/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/dask/dataframe/_pyarrow_compat.py:23: UserWarning: You are using pyarrow version 11.0.0 which is known to be insecure. See https://www.cve.org/CVERecord?id=CVE-2023-47248 for further details. Please upgrade to pyarrow>=14.0.1 or install pyarrow-hotfix to patch your current version.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ "from arcgis.gis import GIS\n", - "from arcgis.features import FeatureLayer" + "from arcgis.layers import Service" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -410,17 +410,18 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ - "hurricane_layer = FeatureLayer(\n", - " url=\"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/0\")" + "hurricane_layer = Service(\n", + " url_or_item=\"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/0\"\n", + ")" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -429,13 +430,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "df34faa68f024e72895a693f94d04f51", + "model_id": "814ae58630a447f2bc1d7a99ede4674c", "version_major": 2, "version_minor": 1 }, @@ -443,7 +444,7 @@ "Map(center=[3716583.6647425774, -4155920.0458218013], extent={'xmin': -8511072.484127043, 'ymin': -835007.2772…" ] }, - "execution_count": 5, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -455,7 +456,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ @@ -471,7 +472,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -480,7 +481,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -489,7 +490,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -498,22 +499,72 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 59, "metadata": {}, "outputs": [], "source": [ - "renderer = renderers.SimpleRenderer(\n", - " symbol=symbols.SimpleMarkerSymbolEsriSMS(\n", - " style=\"esriSMSCircle\", color=[255, 0, 0, 1], size=20\n", - " )\n", + "os3d_layer = symbols.ObjectSymbol3DLayer(\n", + " resource=symbols.ObjectSymbol3DLayerResource(primitive=symbols.Primitive.sphere),\n", + " material=symbols.Material(color=[255,0,0]),\n", + " type=\"Object\",\n", + " width=100\n", ")" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "pt3d_symbol = symbols.PointSymbol3D(\n", + " symbol_layers = [os3d_layer]\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "ename": "ValidationError", + "evalue": "1 validation error for PointSymbol3D\nsymbolLayers\n Field required [type=missing, input_value={'symbol': PointSymbol3D(...'type': 'PointSymbol3D'}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.5/v/missing", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[64], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m pt3d_renderer \u001b[38;5;241m=\u001b[39m renderers\u001b[38;5;241m.\u001b[39mPointSymbol3D(\n\u001b[1;32m 2\u001b[0m symbol\u001b[38;5;241m=\u001b[39mpt3d_symbol,\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mtype\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPointSymbol3D\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 4\u001b[0m )\n", + "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/pydantic/main.py:164\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[0;34m(__pydantic_self__, **data)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001b[39;00m\n\u001b[1;32m 163\u001b[0m __tracebackhide__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 164\u001b[0m __pydantic_self__\u001b[38;5;241m.\u001b[39m__pydantic_validator__\u001b[38;5;241m.\u001b[39mvalidate_python(data, self_instance\u001b[38;5;241m=\u001b[39m__pydantic_self__)\n", + "\u001b[0;31mValidationError\u001b[0m: 1 validation error for PointSymbol3D\nsymbolLayers\n Field required [type=missing, input_value={'symbol': PointSymbol3D(...'type': 'PointSymbol3D'}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.5/v/missing" + ] + } + ], + "source": [ + "pt3d_renderer = renderers.PointSymbol3D(\n", + " symbol=pt3d_symbol,\n", + " type=\"PointSymbol3D\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR:root:Renderer of type PointSymbol3D could not be created. Error: 2 validation errors for SimpleRenderer\n", + "symbol\n", + " Field required [type=missing, input_value={'symbolLayers': [{'ancho...'type': 'PointSymbol3D'}, input_type=dict]\n", + " For further information visit https://errors.pydantic.dev/2.5/v/missing\n", + "type\n", + " Input should be 'simple' [type=literal_error, input_value='PointSymbol3D', input_type=str]\n", + " For further information visit https://errors.pydantic.dev/2.5/v/literal_error\n" + ] + }, { "ename": "ValidationError", "evalue": "1 validation error for FeatureLayerArcGISFeatureLayer\nlayerDefinition.timeInfo.timeIntervalUnits\n Input should be 'esriTimeUnitsCenturies', 'esriTimeUnitsDays', 'esriTimeUnitsDecades', 'esriTimeUnitsHours', 'esriTimeUnitsMilliseconds', 'esriTimeUnitsMinutes', 'esriTimeUnitsMonths', 'esriTimeUnitsSeconds', 'esriTimeUnitsUnknown', 'esriTimeUnitsWeeks' or 'esriTimeUnitsYears' [type=enum, input_value=, input_type=TimeIntervalUnits]", @@ -521,9 +572,9 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[13], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m hurricane_map_3D\u001b[38;5;241m.\u001b[39mcontent\u001b[38;5;241m.\u001b[39madd(\n\u001b[1;32m 2\u001b[0m item\u001b[38;5;241m=\u001b[39mhurricane_layer,\n\u001b[1;32m 3\u001b[0m drawing_info \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrenderer\u001b[39m\u001b[38;5;124m\"\u001b[39m: renderer\n\u001b[1;32m 5\u001b[0m }\n\u001b[1;32m 6\u001b[0m )\n", - "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/scene_widget.py:1327\u001b[0m, in \u001b[0;36mSceneContent.add\u001b[0;34m(self, item, drawing_info, popup_info, index)\u001b[0m\n\u001b[1;32m 1324\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[1;32m 1325\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1326\u001b[0m \u001b[38;5;66;03m# Only one layer, create the layer and add\u001b[39;00m\n\u001b[0;32m-> 1327\u001b[0m layer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_helper\u001b[38;5;241m.\u001b[39m_create_layer_from_item(item, drawing_info, popup_info)\n\u001b[1;32m 1328\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlayers\u001b[38;5;241m.\u001b[39minsert(index, item)\n\u001b[1;32m 1330\u001b[0m \u001b[38;5;66;03m# Check that layer is not None at this point\u001b[39;00m\n", - "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/_utils.py:1048\u001b[0m, in \u001b[0;36m_HelperMethods._create_layer_from_item\u001b[0;34m(self, layer, drawing_info, popup_info)\u001b[0m\n\u001b[1;32m 1046\u001b[0m ld \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1047\u001b[0m popup \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_create_popup_dataclass(layer, popup_info)\n\u001b[0;32m-> 1048\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mspec\u001b[38;5;241m.\u001b[39mFeatureLayerArcGISFeatureLayer(\n\u001b[1;32m 1049\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mproperties,\n\u001b[1;32m 1050\u001b[0m url\u001b[38;5;241m=\u001b[39mlayer\u001b[38;5;241m.\u001b[39m_url,\n\u001b[1;32m 1051\u001b[0m layerDefinition\u001b[38;5;241m=\u001b[39mld,\n\u001b[1;32m 1052\u001b[0m popupInfo\u001b[38;5;241m=\u001b[39mpopup,\n\u001b[1;32m 1053\u001b[0m itemId\u001b[38;5;241m=\u001b[39mitem_id,\n\u001b[1;32m 1054\u001b[0m title\u001b[38;5;241m=\u001b[39mproperties[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 1055\u001b[0m )\n\u001b[1;32m 1056\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(layer, arcgis_layers\u001b[38;5;241m.\u001b[39mVectorTileLayer):\n\u001b[1;32m 1057\u001b[0m style_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlayer\u001b[38;5;241m.\u001b[39m_url\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/resources/styles/root.json\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", + "Cell \u001b[0;32mIn[51], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m hurricane_map_3D\u001b[38;5;241m.\u001b[39mcontent\u001b[38;5;241m.\u001b[39madd(\n\u001b[1;32m 2\u001b[0m item\u001b[38;5;241m=\u001b[39mhurricane_layer,\n\u001b[1;32m 3\u001b[0m drawing_info\u001b[38;5;241m=\u001b[39m{\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrenderer\u001b[39m\u001b[38;5;124m\"\u001b[39m: pt3d_renderer\n\u001b[1;32m 5\u001b[0m }\n\u001b[1;32m 6\u001b[0m )\n", + "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/scene_widget.py:920\u001b[0m, in \u001b[0;36mSceneContent.add\u001b[0;34m(self, item, drawing_info, popup_info, index)\u001b[0m\n\u001b[1;32m 917\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[1;32m 918\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 919\u001b[0m \u001b[38;5;66;03m# Only one layer, create the layer and add\u001b[39;00m\n\u001b[0;32m--> 920\u001b[0m layer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_helper\u001b[38;5;241m.\u001b[39m_create_layer_from_item(item, drawing_info, popup_info)\n\u001b[1;32m 921\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlayers\u001b[38;5;241m.\u001b[39minsert(index, item)\n\u001b[1;32m 923\u001b[0m \u001b[38;5;66;03m# Check that layer is not None at this point\u001b[39;00m\n", + "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/_utils.py:1053\u001b[0m, in \u001b[0;36m_HelperMethods._create_layer_from_item\u001b[0;34m(self, layer, drawing_info, popup_info)\u001b[0m\n\u001b[1;32m 1051\u001b[0m ld \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1052\u001b[0m popup \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_create_popup_dataclass(layer, popup_info)\n\u001b[0;32m-> 1053\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mspec\u001b[38;5;241m.\u001b[39mFeatureLayerArcGISFeatureLayer(\n\u001b[1;32m 1054\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mproperties,\n\u001b[1;32m 1055\u001b[0m url\u001b[38;5;241m=\u001b[39mlayer\u001b[38;5;241m.\u001b[39m_url,\n\u001b[1;32m 1056\u001b[0m layerDefinition\u001b[38;5;241m=\u001b[39mld,\n\u001b[1;32m 1057\u001b[0m popupInfo\u001b[38;5;241m=\u001b[39mpopup,\n\u001b[1;32m 1058\u001b[0m itemId\u001b[38;5;241m=\u001b[39mitem_id,\n\u001b[1;32m 1059\u001b[0m title\u001b[38;5;241m=\u001b[39mproperties[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 1060\u001b[0m )\n\u001b[1;32m 1061\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(layer, arcgis_layers\u001b[38;5;241m.\u001b[39mVectorTileLayer):\n\u001b[1;32m 1062\u001b[0m style_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlayer\u001b[38;5;241m.\u001b[39m_url\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/resources/styles/root.json\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/pydantic/main.py:164\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[0;34m(__pydantic_self__, **data)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001b[39;00m\n\u001b[1;32m 163\u001b[0m __tracebackhide__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 164\u001b[0m __pydantic_self__\u001b[38;5;241m.\u001b[39m__pydantic_validator__\u001b[38;5;241m.\u001b[39mvalidate_python(data, self_instance\u001b[38;5;241m=\u001b[39m__pydantic_self__)\n", "\u001b[0;31mValidationError\u001b[0m: 1 validation error for FeatureLayerArcGISFeatureLayer\nlayerDefinition.timeInfo.timeIntervalUnits\n Input should be 'esriTimeUnitsCenturies', 'esriTimeUnitsDays', 'esriTimeUnitsDecades', 'esriTimeUnitsHours', 'esriTimeUnitsMilliseconds', 'esriTimeUnitsMinutes', 'esriTimeUnitsMonths', 'esriTimeUnitsSeconds', 'esriTimeUnitsUnknown', 'esriTimeUnitsWeeks' or 'esriTimeUnitsYears' [type=enum, input_value=, input_type=TimeIntervalUnits]" ] @@ -532,12 +583,37 @@ "source": [ "hurricane_map_3D.content.add(\n", " item=hurricane_layer,\n", - " drawing_info = {\n", - " \"renderer\": renderer\n", + " drawing_info={\n", + " \"renderer\": pt3d_renderer\n", " }\n", ")" ] }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "81ec8d571d1443c19a7a73503d3d98e4", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Scene(camera={'heading': 0.0, 'position': {'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'x': -415…" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "hurricane_map_3D" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -603,7 +679,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Another new feature in 1.5.0 is the ability to export the current widget as a standalone HTML file. This added functionality provides a new workflow for creating standalone HTML maps that can be shared with anyone: all they need is a web browser!\n", + "You als have the ability to export the current widget as a standalone HTML file. This added functionality provides a workflow for creating standalone HTML maps that can be shared with anyone: all they need is a web browser!\n", "\n", "The below cell will write the current widget to the file specified by a string path. Run the cell, find the file on your disk, and open it in your favorite web browser.\n", "\n", @@ -612,19 +688,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "html saved as /Users/john3092/Job/data_formats/html_pages/myHurricaneMap.html\n" + ] + } + ], "source": [ "import os\n", "\n", - "file_dir = os.path.join(os.getcwd(), 'home')\n", + "file_dir = r\"/Users/john3092/Job/data_formats/html_pages\"\n", "if not os.path.isdir(file_dir):\n", " os.mkdir(file_dir)\n", " \n", "file_path = os.path.join(file_dir, 'myHurricaneMap.html')\n", "\n", - "visual_var_map.export_to_html(file_path)\n", + "hurricane_map.export_to_html(\n", + " path_to_file=file_path\n", + ")\n", "print(\"html saved as \" + file_path) # On Windows, path can be 'C:\\Users\\Username\\Documents\\home\\myHurricaneMap.html'" ] } From 65e48ac969dbabc6e63eae276f270ce4602fc6a7 Mon Sep 17 00:00:00 2001 From: John Yaist Date: Tue, 24 Sep 2024 09:14:02 -0700 Subject: [PATCH 3/3] update adv guide for 24 --- .../advanced-map-widget-usage.ipynb | 347 +----------------- 1 file changed, 15 insertions(+), 332 deletions(-) diff --git a/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb b/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb index 05e08a9c21..89328f06d3 100644 --- a/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb +++ b/guide/10-mapping-and-visualization/advanced-map-widget-usage.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -60,33 +60,16 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n", - "Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/john3092/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/dask/dataframe/_pyarrow_compat.py:23: UserWarning: You are using pyarrow version 11.0.0 which is known to be insecure. See https://www.cve.org/CVERecord?id=CVE-2023-47248 for further details. Please upgrade to pyarrow>=14.0.1 or install pyarrow-hotfix to patch your current version.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ "from arcgis.gis import GIS" ] }, { "cell_type": "code", - "execution_count": 237, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -95,7 +78,7 @@ "arcgis.map.map_widget.Map" ] }, - "execution_count": 237, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -106,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 238, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -115,7 +98,7 @@ "arcgis.map.scene_widget.Scene" ] }, - "execution_count": 238, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -209,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -250,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 249, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -259,7 +242,7 @@ }, { "cell_type": "code", - "execution_count": 250, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -268,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": 251, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -292,7 +275,7 @@ }, { "cell_type": "code", - "execution_count": 252, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -302,7 +285,7 @@ }, { "cell_type": "code", - "execution_count": 253, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -368,306 +351,6 @@ "my_zion_webscene_item" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Rendering" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The Python API also supports rendering symbols on the map wideget through defining properties. Once defined, the widget makes use of the Javascript API renderers. Try running the below code snippet to use a `SimpleRenderer` with a `LineSymbol3D` symbol. More on autocast renderers below." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You are only limitted in your visualization options by the Javascript API: you can specify any renderer and modify any properties of said renderer. To show how powerful this really is, let's use the SimpleRenderer's [visual variables](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-SimpleRenderer.html#visualVariables) functionality. Run the below cell to see a standard Feature Layer about Hurricane tracks in 2D mode." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from arcgis.gis import GIS\n", - "from arcgis.layers import Service" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "anon_gis = GIS()" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [], - "source": [ - "hurricane_layer = Service(\n", - " url_or_item=\"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/0\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [], - "source": [ - "hurricane_map = anon_gis.map('Atlantic Ocean')" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "814ae58630a447f2bc1d7a99ede4674c", - "version_major": 2, - "version_minor": 1 - }, - "text/plain": [ - "Map(center=[3716583.6647425774, -4155920.0458218013], extent={'xmin': -8511072.484127043, 'ymin': -835007.2772…" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "hurricane_map.content.add(hurricane_layer)\n", - "hurricane_map" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [], - "source": [ - "hurricane_map.legend.enabled=True" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can represent this same information on a 3D map by specifying a SimpleRenderer using white spheres. Run the below cell, click on some points, and examine some fields:" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "from arcgis.map import Scene" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "hurricane_map_3D = Scene(location='Atlantic Ocean')" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "from arcgis.map import renderers, symbols" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [], - "source": [ - "os3d_layer = symbols.ObjectSymbol3DLayer(\n", - " resource=symbols.ObjectSymbol3DLayerResource(primitive=symbols.Primitive.sphere),\n", - " material=symbols.Material(color=[255,0,0]),\n", - " type=\"Object\",\n", - " width=100\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": {}, - "outputs": [], - "source": [ - "pt3d_symbol = symbols.PointSymbol3D(\n", - " symbol_layers = [os3d_layer]\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": {}, - "outputs": [ - { - "ename": "ValidationError", - "evalue": "1 validation error for PointSymbol3D\nsymbolLayers\n Field required [type=missing, input_value={'symbol': PointSymbol3D(...'type': 'PointSymbol3D'}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.5/v/missing", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[64], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m pt3d_renderer \u001b[38;5;241m=\u001b[39m renderers\u001b[38;5;241m.\u001b[39mPointSymbol3D(\n\u001b[1;32m 2\u001b[0m symbol\u001b[38;5;241m=\u001b[39mpt3d_symbol,\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mtype\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPointSymbol3D\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 4\u001b[0m )\n", - "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/pydantic/main.py:164\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[0;34m(__pydantic_self__, **data)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001b[39;00m\n\u001b[1;32m 163\u001b[0m __tracebackhide__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 164\u001b[0m __pydantic_self__\u001b[38;5;241m.\u001b[39m__pydantic_validator__\u001b[38;5;241m.\u001b[39mvalidate_python(data, self_instance\u001b[38;5;241m=\u001b[39m__pydantic_self__)\n", - "\u001b[0;31mValidationError\u001b[0m: 1 validation error for PointSymbol3D\nsymbolLayers\n Field required [type=missing, input_value={'symbol': PointSymbol3D(...'type': 'PointSymbol3D'}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.5/v/missing" - ] - } - ], - "source": [ - "pt3d_renderer = renderers.PointSymbol3D(\n", - " symbol=pt3d_symbol,\n", - " type=\"PointSymbol3D\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 51, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "ERROR:root:Renderer of type PointSymbol3D could not be created. Error: 2 validation errors for SimpleRenderer\n", - "symbol\n", - " Field required [type=missing, input_value={'symbolLayers': [{'ancho...'type': 'PointSymbol3D'}, input_type=dict]\n", - " For further information visit https://errors.pydantic.dev/2.5/v/missing\n", - "type\n", - " Input should be 'simple' [type=literal_error, input_value='PointSymbol3D', input_type=str]\n", - " For further information visit https://errors.pydantic.dev/2.5/v/literal_error\n" - ] - }, - { - "ename": "ValidationError", - "evalue": "1 validation error for FeatureLayerArcGISFeatureLayer\nlayerDefinition.timeInfo.timeIntervalUnits\n Input should be 'esriTimeUnitsCenturies', 'esriTimeUnitsDays', 'esriTimeUnitsDecades', 'esriTimeUnitsHours', 'esriTimeUnitsMilliseconds', 'esriTimeUnitsMinutes', 'esriTimeUnitsMonths', 'esriTimeUnitsSeconds', 'esriTimeUnitsUnknown', 'esriTimeUnitsWeeks' or 'esriTimeUnitsYears' [type=enum, input_value=, input_type=TimeIntervalUnits]", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[51], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m hurricane_map_3D\u001b[38;5;241m.\u001b[39mcontent\u001b[38;5;241m.\u001b[39madd(\n\u001b[1;32m 2\u001b[0m item\u001b[38;5;241m=\u001b[39mhurricane_layer,\n\u001b[1;32m 3\u001b[0m drawing_info\u001b[38;5;241m=\u001b[39m{\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrenderer\u001b[39m\u001b[38;5;124m\"\u001b[39m: pt3d_renderer\n\u001b[1;32m 5\u001b[0m }\n\u001b[1;32m 6\u001b[0m )\n", - "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/scene_widget.py:920\u001b[0m, in \u001b[0;36mSceneContent.add\u001b[0;34m(self, item, drawing_info, popup_info, index)\u001b[0m\n\u001b[1;32m 917\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[1;32m 918\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 919\u001b[0m \u001b[38;5;66;03m# Only one layer, create the layer and add\u001b[39;00m\n\u001b[0;32m--> 920\u001b[0m layer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_helper\u001b[38;5;241m.\u001b[39m_create_layer_from_item(item, drawing_info, popup_info)\n\u001b[1;32m 921\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlayers\u001b[38;5;241m.\u001b[39minsert(index, item)\n\u001b[1;32m 923\u001b[0m \u001b[38;5;66;03m# Check that layer is not None at this point\u001b[39;00m\n", - "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/arcgis/map/_utils.py:1053\u001b[0m, in \u001b[0;36m_HelperMethods._create_layer_from_item\u001b[0;34m(self, layer, drawing_info, popup_info)\u001b[0m\n\u001b[1;32m 1051\u001b[0m ld \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1052\u001b[0m popup \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_create_popup_dataclass(layer, popup_info)\n\u001b[0;32m-> 1053\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mspec\u001b[38;5;241m.\u001b[39mFeatureLayerArcGISFeatureLayer(\n\u001b[1;32m 1054\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mproperties,\n\u001b[1;32m 1055\u001b[0m url\u001b[38;5;241m=\u001b[39mlayer\u001b[38;5;241m.\u001b[39m_url,\n\u001b[1;32m 1056\u001b[0m layerDefinition\u001b[38;5;241m=\u001b[39mld,\n\u001b[1;32m 1057\u001b[0m popupInfo\u001b[38;5;241m=\u001b[39mpopup,\n\u001b[1;32m 1058\u001b[0m itemId\u001b[38;5;241m=\u001b[39mitem_id,\n\u001b[1;32m 1059\u001b[0m title\u001b[38;5;241m=\u001b[39mproperties[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 1060\u001b[0m )\n\u001b[1;32m 1061\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(layer, arcgis_layers\u001b[38;5;241m.\u001b[39mVectorTileLayer):\n\u001b[1;32m 1062\u001b[0m style_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlayer\u001b[38;5;241m.\u001b[39m_url\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/resources/styles/root.json\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", - "File \u001b[0;32m~/opt/anaconda3/envs/geosaurus_dev_env/lib/python3.11/site-packages/pydantic/main.py:164\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[0;34m(__pydantic_self__, **data)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001b[39;00m\n\u001b[1;32m 163\u001b[0m __tracebackhide__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 164\u001b[0m __pydantic_self__\u001b[38;5;241m.\u001b[39m__pydantic_validator__\u001b[38;5;241m.\u001b[39mvalidate_python(data, self_instance\u001b[38;5;241m=\u001b[39m__pydantic_self__)\n", - "\u001b[0;31mValidationError\u001b[0m: 1 validation error for FeatureLayerArcGISFeatureLayer\nlayerDefinition.timeInfo.timeIntervalUnits\n Input should be 'esriTimeUnitsCenturies', 'esriTimeUnitsDays', 'esriTimeUnitsDecades', 'esriTimeUnitsHours', 'esriTimeUnitsMilliseconds', 'esriTimeUnitsMinutes', 'esriTimeUnitsMonths', 'esriTimeUnitsSeconds', 'esriTimeUnitsUnknown', 'esriTimeUnitsWeeks' or 'esriTimeUnitsYears' [type=enum, input_value=, input_type=TimeIntervalUnits]" - ] - } - ], - "source": [ - "hurricane_map_3D.content.add(\n", - " item=hurricane_layer,\n", - " drawing_info={\n", - " \"renderer\": pt3d_renderer\n", - " }\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "81ec8d571d1443c19a7a73503d3d98e4", - "version_major": 2, - "version_minor": 1 - }, - "text/plain": [ - "Scene(camera={'heading': 0.0, 'position': {'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'x': -415…" - ] - }, - "execution_count": 52, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "hurricane_map_3D" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now that we have the base set up, lets specify the `visualVariables` field to vary the color of each point for the changing `PRESSURE` field, and vary the size of each point for the changing `WINDSPEED` field. Run the below cell, then try modifying the options to see different results! Maybe try tuning the `\"value\"` fields to see different color and size variations." - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "visual_var_map = anon_gis.map('Atlantic Ocean', mode=\"3D\")\n", - "\n", - "#Update the renderer to include visual variable information\n", - "renderer[\"visualVariables\"] = [{ #JS configuration of visualVariables\n", - " \"type\": \"color\",\n", - " \"field\": \"PRESSURE\", \n", - " \"stops\": [\n", - " { \"value\": 950, \"color\": \"red\" },\n", - " { \"value\": 1020, \"color\": \"blue\" }\n", - " ]\n", - " }, {\n", - " \"type\": \"size\",\n", - " \"field\": \"WINDSPEED\",\n", - " \"stops\": [\n", - " { \"value\": 20, \"size\": 60000 },\n", - " { \"value\": 150, \"size\": 500000 }\n", - " ],\n", - " \"axis\": \"height\"\n", - " }, {\n", - " \"type\": \"size\",\n", - " \"axis\": \"width-and-depth\",\n", - " \"useSymbolValue\": True\n", - " }]\n", - "visual_var_map.content.add(hurricane_layer, renderer)\n", - "visual_var_map" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -695,14 +378,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "html saved as /Users/john3092/Job/data_formats/html_pages/myHurricaneMap.html\n" + "html saved as /Users//path/data_formats/html_pages/myHurricaneMap.html\n" ] } ], "source": [ "import os\n", "\n", - "file_dir = r\"/Users/john3092/Job/data_formats/html_pages\"\n", + "file_dir = r\"/Users//path/data_formats/html_pages\"\n", "if not os.path.isdir(file_dir):\n", " os.mkdir(file_dir)\n", " \n",