This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def switch_view_to_new_source(view_item: Union[str, Item], new_source_item: Union[str, Item], gis: Optional[GIS] = None) -> bool: | |
""" | |
Switch an ArcGIS Online or ArcGIS Enterprise Feature Layer View from one source to another with _significant_ error catching. | |
Before switching to the Feature Layer View to the new source, the following checks are performed. | |
- Layer ID: Ensure layer ids match. | |
- Geometry Type: Ensure the correct geometry type such as point, line or polygon. | |
- Spatial Reference: Ensure geometry spatial references match. | |
- Needed Fields: Ensure fields needed by the view are in the new source. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pyspark.sql import DataFrame | |
def get_pyspark_dataframe_schema(df: DataFrame) -> str: | |
"""Output the DataFrame schema to easily be included when constructing a new PySpark DataFrame.""" | |
# characters to include for tab, since python, using four spaces | |
tab = ' ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def copy_to_clipboard(string: str) -> None: | |
""" | |
Copy a string to the system clipboard. | |
.. note:: | |
This leans on Pandas, so it will not work unless Pandas is installed. | |
""" | |
# ensure Pandas is installed and available | |
if not importlib.util.find_spec('pandas'): | |
raise EnvironmentError('copy_to_clipboard requires Pandas. Please ensure Pandas is installed in the environment to use.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import lru_cache | |
from typing import Union, List, Optional | |
from arcgis.geoenrichment import Country | |
from arcgis.geometry import Polygon | |
import numpy as np | |
import pandas as pd | |
from sklearn.base import BaseEstimator, TransformerMixin | |
__all__ = ['EnrichBase', 'EnrichPolygon', 'EnrichStandardGeography', 'KeepOnlyEnrichColumns', 'ArrayToDataFrame'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import md5 | |
import pandas as pd | |
from typing import Optional, Iterable | |
def get_md5_from_series(input_iterable: Iterable) -> str: | |
""" | |
Create a MD5 hash from an Iterable, typically a row from a Pandas ``DataFrame``, but can be any | |
Iterable object instance such as a list, tuple or Pandas ``Series``. | |
Args: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from pathlib import Path | |
from typing import Union | |
def get_logger(log_path: Union[str, Path] = 'logfile.log', log_name: str = 'logger', log_level: int = logging.ERROR): | |
""" | |
Standardized way to create a console and file logger in one. | |
Args: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psutil | |
import platform | |
from datetime import datetime | |
def get_size(bytes, suffix="B"): | |
""" | |
Scale bytes to its proper format | |
e.g: | |
1253656 => '1.20MB' | |
1253656678 => '1.17GB' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from arcgis.geometry import Polygon | |
def get_simplified_polygon(geometry: Polygon, simplification_factor: float = 0.1) -> Polygon: | |
# ensure working with a polygon | |
assert isinstance(geometry, Polygon) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: arcgis | |
channels: | |
- esri | |
- conda-forge | |
dependencies: | |
- arcgis | |
- arcpy | |
- jupyterlab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pro_at_least_version(version: str) -> bool: | |
""" | |
Test the current ArcGIS Pro version to be equal or greater than. | |
Args: | |
version: Version number eg ('2', '2.1', '2.8.1') | |
Returns: | |
Boolean indicating if version is at least or greater than specified version. | |
""" | |
# late import since may or may not already be loaded |
NewerOlder