geeViz.esriLib

ArcGIS / Esri REST services client for geeViz. DEPRECATED.

Deprecated since version Use: georest instead. This module now delegates to it and will be removed in a future release.

georest is the maintained implementation of everything here that talks to an Esri REST endpoint, it is stdlib-only (no runtime dependencies), and it does considerably more than this module ever did — exportImage, identifyPixelValue, getSamples, computeStatisticsHistograms, queryBoundary, and a full client for the USFS Enterprise Data Warehouse.

The move, function by function:

geeViz.esriLib.searchPortal        -> georest.esri.portal.searchPortal
geeViz.esriLib.getServiceMetadata  -> georest.esri.portal.getServiceMetadata

The signatures match, so the change is the import line.

The addEsri*Service functions are NOT going to georest: they add layers to a geeViz Map, which is geeViz’s concern, not a REST client’s. They stay available here (and as Map.addEsri*).

This module is a patch over georest, not a fork of it. What is left here is only what georest should not have:

  • the geeViz Map calls – addLayer, addTileLayer, addDynamicMapService – and the naming and viz-key handling around them;

  • geeViz._ssrf.check_url(), which is this package’s policy and has to be applied on THIS side of every delegated call, because georest has none;

  • the exception contract callers already depend on: georest reports an unreachable host or a bad status as RuntimeError, and this module has always raised ConnectionError, so it translates at the boundary rather than rewriting what callers catch.

Everything else delegates. _resolve_portal, _detect_service_type and _resolve_url were byte-identical copies of georest’s and now call them; PORTALS is georest’s own dict rather than a copy, so a name added at runtime through either module resolves in both; the feature-service count pre-flight, overflow guard and GeoJSON fetch are one call to georest.esri.services.queryFeatureService; the {z}/{y}/{x} tile template comes from getImageServiceTileUrl.

Bridges three Esri service types into the geeViz viewer:

Service type

Mechanism

Image Service (cached)

Map.addTileLayer("<url>/tile/{z}/{y}/{x}")

Image Service (uncached, e.g. NAIP)

Map.addDynamicMapService — <url>/exportImage per viewport

Map Service (cached)

Map.addTileLayer(...) — same tile path

Map Service (dynamic, e.g. FEMA NFHL)

Map.addDynamicMapService — <url>/export per viewport

Feature Service (≤ max_features)

<url>/query?f=geojson, generalized for display → Map.addLayer(geojson_dict)

Feature Service (> max_features)

ValueError with remediation message

Usage – georest to find and inspect, esriLib (or Map.addEsri*) to draw:

import geeViz.esriLib as el
from georest.esri import portal

# Discover data on any ArcGIS Portal
results = portal.searchPortal("naip")                     # IIPP (default)
results = portal.searchPortal("naip", portal="agol")      # ArcGIS Online
results = portal.searchPortal("naip",
                              portal="https://myagency.gov/portal")

# Available portals
portal.PORTALS.keys()   # iipp, agol, usgs, noaa, usfs, nasa

# Inspect any service
meta = portal.getServiceMetadata("https://.../ImageServer")

# Add to the geeViz map (auto-dispatches by service type)
el.addEsriService(result_or_url)

# Or call the typed helpers directly
el.addEsriImageService("https://.../ImageServer", name="NAIP 2023")
el.addEsriFeatureService("https://.../FeatureServer/0",
                         max_features=2000, where="STATE='UT'")
el.addEsriMapService("https://.../MapServer")

Token-gated portals:

# Obtain a token first:
#   POST <portal>/sharing/rest/generateToken
#     username=...&password=...&client=requestip&expiration=60&f=json
token = "..."
portal.searchPortal("classified data", token=token)
el.addEsriFeatureService(url, token=token)

Copyright 2026 Ian Housman

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Functions

addEsriFeatureService(url_or_result[, ...])

Fetch and add an ArcGIS Feature Service layer as a GeoJSON vector layer.

addEsriImageService(url_or_result[, ...])

Add an ArcGIS Image Service to the geeViz map.

addEsriMapService(url_or_result[, name, ...])

Add an ArcGIS Map Service to the geeViz map.

addEsriService(url_or_result[, viz_params, ...])

Auto-detect the Esri service type and call the appropriate add helper.

getServiceMetadata(url[, token])

Fetch and return the JSON metadata for any ArcGIS REST service.

searchPortal(query[, portal, limit, ...])

Search any ArcGIS Portal for hosted services.

geeViz.esriLib.searchPortal(query: str, portal: str = 'iipp', limit: int = 20, data_only: bool = True, raw_q: str | None = None, token: str | None = None, **filters: Any) → list[dict[str, Any]][source]

Search any ArcGIS Portal for hosted services.

Uses the standard /sharing/rest/search endpoint present on ArcGIS Online, IIPP, and any ArcGIS Enterprise install.

Parameters:
  • query (str) – Free-text search query (e.g. "naip 2023", "fire perimeter").

  • portal (str, optional) – Either a short name from PORTALS ("iipp", "agol", "usgs", "noaa", "usfs", "nasa") or a full portal base URL. Defaults to "iipp".

  • limit (int, optional) – Maximum results to return (1–100). Defaults to 20.

  • data_only (bool, optional) – When True (default), appends a bundled exclusion list that filters out non-data items (styles, web apps, dashboards, etc.) so results are datasets only. Set to False to search without restrictions.

  • raw_q (str, optional) – If supplied, overrides the assembled query string entirely — ignores query, data_only, and filters. Use for portal query DSL power users.

  • token (str, optional) – ArcGIS token for secured portals. Omit for public services. Obtain via POST <portal>/sharing/rest/generateToken.

  • **filters – Extra ArcGIS search filters forwarded verbatim as query params (e.g. sortField="title", sortOrder="asc", bbox="-120,35,-110,42").

Returns:

Parsed portal items. Each dict includes:

  • id (str): Item ID.

  • title (str): Item title.

  • type (str): Esri item type (e.g. "Image Service", "Feature Service").

  • snippet (str): Short description.

  • tags (list of str): Associated tags.

  • url (str): Service endpoint URL (may be "" if not set).

  • owner (str): Portal username of the owner.

  • created (int): Unix timestamp (ms) of item creation.

  • modified (int): Unix timestamp (ms) of last modification.

  • thumbnail (str or None): Thumbnail URL, or None if absent.

  • _raw (dict): Full raw portal item dict for advanced access.

Return type:

list of dict

Example:

import geeViz.esriLib as el

# Search IIPP for NAIP imagery (default portal)
results = el.searchPortal("naip 2023", limit=10)
for r in results:
    print(r["title"], r["type"], r["url"])

# ArcGIS Online
results = el.searchPortal("wildfire perimeter", portal="agol")

# Custom Enterprise portal
results = el.searchPortal("hydrology",
                          portal="https://gis.mystate.gov/portal")

# Raw portal query DSL (bypasses data_only and filters)
results = el.searchPortal("", raw_q='type:"Feature Service" owner:USGS')
geeViz.esriLib.getServiceMetadata(url: str, token: str | None = None) → dict[str, Any][source]

Fetch and return the JSON metadata for any ArcGIS REST service.

Appends ?f=json to the URL and returns the parsed response. Works for ImageServer, FeatureServer, MapServer, and any sub-layer URL (e.g. /FeatureServer/0).

Parameters:
  • url (str) –

    ArcGIS service endpoint, e.g.:

    "https://naip.services.arcgis.com/.../ImageServer"
    "https://services.arcgis.com/.../FeatureServer/0"
    "https://server.arcgisonline.com/.../MapServer"
    

  • token (str, optional) – ArcGIS token for secured services.

Returns:

Parsed service metadata. Common keys vary by service type:

  • name (str): Service name.

  • type (str): Layer geometry type (Feature Services).

  • fields (list): Schema fields (Feature Services).

  • extent (dict): Spatial extent.

  • spatialReference (dict): Spatial reference info.

  • minScale, maxScale (int): Scale range.

  • capabilities (str): Comma-separated capabilities string.

Return type:

dict

Raises:
  • ConnectionError – If the URL is unreachable.

  • ValueError – If the response is not valid JSON.

Example:

import geeViz.esriLib as el

meta = el.getServiceMetadata("https://.../ImageServer")
print(meta["name"])
print(meta["extent"])

# FeatureServer layer 0
meta = el.getServiceMetadata("https://.../FeatureServer/0")
print([f["name"] for f in meta.get("fields", [])])
geeViz.esriLib.addEsriImageService(url_or_result: str | dict, viz_params: dict | None = None, name: str | None = None, token: str | None = None, target_map=None, _meta: dict | None = None) → None[source]

Add an ArcGIS Image Service to the geeViz map.

A CACHED service (its metadata reports tileInfo) is added as an XYZ tile layer on <service_url>/tile/{z}/{y}/{x}. An UNCACHED one – most of them, including every NAIP service on IIPP – has no tiles to serve; every /tile request answers 404 and the layer is blank. It is drawn instead through <service_url>/exportImage, re-rendered for the viewport on each pan and zoom.

Note

ArcGIS tile URLs use {z}/{y}/{x} order (y before x), not the XYZ standard {z}/{x}/{y}. This function emits the correct ArcGIS order automatically.

Parameters:
  • url_or_result (str or dict) –

    Either:

    • A bare service URL, e.g. "https://naip.services.arcgis.com/.../ImageServer"

    • A searchPortal() result dict (the "url" key is used).

  • viz_params (dict, optional) – Forwarded to addTileLayer as keyword arguments. Supported keys: opacity (float), visible (bool), max_zoom (int).

  • name (str, optional) – Layer name shown in the geeViz layer list. Defaults to the last segment of the service URL.

  • token (str, optional) – ArcGIS token appended to tile requests as ?token=<>.

Example:

import geeViz.esriLib as el
import geeViz.geeView as gv

el.addEsriImageService(
    "https://naip.services.arcgis.com/.../ImageServer",
    name="NAIP 2022",
    viz_params={"opacity": 0.85},
)
gv.Map.centerObject(gv.ee.Geometry.Point([-111.89, 40.77]), 12)
gv.Map.view()
geeViz.esriLib.addEsriMapService(url_or_result: str | dict, name: str | None = None, token: str | None = None, viz_params: dict | None = None, target_map=None, visible: bool | None = None) → None[source]

Add an ArcGIS Map Service to the geeViz map.

A cached service (singleFusedMapCache: true) is added as an XYZ tile layer on /tile/{z}/{y}/{x}. A dynamic one – FEMA NFHL, most authoritative government services – is drawn through /export, re-rendered for the viewport on each pan and zoom, keeping the server’s own symbology. For the features themselves, use addEsriFeatureService() on a sub-layer (.../MapServer/<n>).

Parameters:
  • url_or_result (str or dict) – Service URL or searchPortal() result dict.

  • name (str, optional) – Layer name. Defaults to last URL segment.

  • token (str, optional) – ArcGIS token for secured services.

  • viz_params (dict, optional) – opacity, visible, max_zoom.

Example:

import geeViz.esriLib as el

el.addEsriMapService(
    "https://server.arcgisonline.com/ArcGIS/rest/services/"
    "World_Imagery/MapServer",
    name="ESRI World Imagery",
)
geeViz.esriLib.addEsriFeatureService(url_or_result: str | dict, viz_params: dict | None = None, name: str | None = None, max_features: int = 1000, where: str = '1=1', bbox: str | list | tuple | None = None, token: str | None = None, target_map=None, simplify='auto', max_layer_mb: float | None = None) → None[source]

Fetch and add an ArcGIS Feature Service layer as a GeoJSON vector layer.

Hits <url>/query?f=geojson&where=<where>&outSR=4326 and passes the returned GeoJSON directly to geeViz.geeView.Map.addLayer.

Warning

Always performs a returnCountOnly=true pre-flight before fetching geometry. If the result count exceeds max_features, a ValueError is raised with a concrete remediation message.

Parameters:
  • url_or_result (str or dict) – Feature Service or sub-layer URL (e.g. ".../FeatureServer/0"), or a searchPortal() result dict. If the URL points to the FeatureServer root rather than a specific layer, /0 is appended automatically.

  • viz_params (dict, optional) – Passed to Map.addLayer as the viz dict. Supports all geeViz vector viz keys ("color", "strokeColor", "fillColor", "opacity", "strokeWidth", "layerType", etc.).

  • name (str, optional) – Layer name. Defaults to last URL segment.

  • max_features (int, optional) – Hard cap on feature count. If the service has more than this many features matching where, a ValueError is raised. Defaults to 1000. Increase with care — very large GeoJSON payloads can slow the viewer.

  • where (str, optional) – SQL WHERE clause sent to the service for server-side filtering. Defaults to "1=1" (all features). Example: where="STATE_FIPS='06'" (California only).

  • bbox (str, list or tuple, optional) – Spatial filter, "xmin,ymin,xmax,ymax" in WGS84 degrees, or the same four numbers as a list or tuple.

  • token (str, optional) – ArcGIS token for secured services.

  • simplify (str, bool or float, optional) – "auto" (default) asks the service for geometry generalized to ~5 m – far smaller and faster than full resolution – then, if the layer is still over max_layer_mb, simplifies it further at increasing tolerances until it fits: the whole layer is embedded in the map page, and a page that is too large never reaches the browser. A number is a fixed tolerance in meters, applied by the service. False fetches and keeps the exact geometry.

  • max_layer_mb (float, optional) – Size budget for this layer in the page, used by simplify="auto". Defaults to 8 MB.

Raises:
  • ValueError – If the feature count exceeds max_features.

  • ConnectionError – If the service URL is unreachable.

Example:

import geeViz.esriLib as el
import geeViz.geeView as gv

# Simple fetch — all features up to default cap
el.addEsriFeatureService(
    "https://services.arcgis.com/.../FeatureServer/0",
    name="Wildfire Perimeters",
)

# Filter server-side to stay under the cap
el.addEsriFeatureService(
    "https://services.arcgis.com/.../FeatureServer/0",
    where="YEAR_=2023 AND GIS_ACRES > 10000",
    name="Large 2023 Fires",
    max_features=500,
)

gv.Map.view()
geeViz.esriLib.addEsriService(url_or_result: str | dict, viz_params: dict | None = None, name: str | None = None, token: str | None = None, max_features: int = 1000, where: str = '1=1', target_map=None, bbox: str | None = None, simplify='auto') → None[source]

Auto-detect the Esri service type and call the appropriate add helper.

Inspects the URL path (and falls back to the service metadata) to determine whether url_or_result is an Image Service, Feature Service, or Map Service, then delegates to addEsriImageService(), addEsriFeatureService(), or addEsriMapService().

Parameters:
  • url_or_result (str or dict) – Service URL or searchPortal() result dict.

  • viz_params (dict, optional) – Visualization parameters forwarded to the typed helper.

  • name (str, optional) – Layer name.

  • token (str, optional) – ArcGIS token.

  • max_features (int, optional) – Forwarded to addEsriFeatureService().

  • where (str, optional) – SQL WHERE clause forwarded to addEsriFeatureService().

  • bbox (str, optional) – Spatial filter forwarded to addEsriFeatureService().

  • simplify (optional) – Forwarded to addEsriFeatureService().

Raises:

ValueError – If the service type cannot be determined.

Example:

import geeViz.esriLib as el
from georest.esri import portal

results = portal.searchPortal("naip", limit=5)
for r in results:
    el.addEsriService(r)  # dispatches by type automatically