Convert Figma logo to code with AI

Esri logoarcgis-python-api

Documentation and samples for ArcGIS API for Python

1,863
1,096
1,863
89

Top Related Projects

Python tools for geographic data

1,052

Python interface to PROJ (cartographic projections and coordinate transformations library)

3,832

Manipulation and analysis of geometric objects

Rasterio reads and writes geospatial raster datasets

1,103

This library reads and writes ESRI Shapefiles in pure Python.

Quick Overview

The ArcGIS API for Python is a powerful, modern, and easy-to-use library for working with maps and geospatial data. It provides tools for spatial analysis, data management, and visualization, allowing users to automate workflows and build applications using ArcGIS platform capabilities.

Pros

  • Comprehensive coverage of ArcGIS functionality in a Python environment
  • Seamless integration with other popular Python libraries like pandas and numpy
  • Supports both scripting and interactive notebook-style development
  • Extensive documentation and examples available

Cons

  • Requires an ArcGIS Online or ArcGIS Enterprise account for full functionality
  • Learning curve can be steep for users new to GIS concepts
  • Some advanced GIS operations may still require desktop ArcGIS software
  • Performance can be slower compared to native ArcGIS desktop tools for large datasets

Code Examples

  1. Creating a map and adding a layer:
from arcgis.gis import GIS
from arcgis.mapping import WebMap

gis = GIS("home")
webmap = WebMap()
webmap.add_layer(gis.content.search("USA Counties", item_type="Feature Layer")[0])
webmap
  1. Performing spatial analysis:
from arcgis.features import GeoAccessor
from arcgis.geometry import buffer

counties = gis.content.get("USA_Counties").layers[0]
ca_counties = counties.query(where="STATE_NAME = 'California'")
buffered = buffer(ca_counties.features, distances=[10, 20, 30], units="Miles")
  1. Working with raster data:
from arcgis.raster import ImageryLayer

imagery = ImageryLayer("https://landsat2.arcgis.com/arcgis/rest/services/Landsat8_Views/ImageServer")
ndvi = imagery.generate_raster({
    "rasterFunction": "NDVI",
    "renderingRule": {"functionName": "Stretch"}
})
ndvi.save("landsat_ndvi.tif")

Getting Started

  1. Install the ArcGIS API for Python:

    pip install arcgis
    
  2. Import the library and connect to your ArcGIS account:

    from arcgis.gis import GIS
    gis = GIS("https://www.arcgis.com", "username", "password")
    
  3. Start exploring and working with your GIS content:

    my_content = gis.content.search(query="owner:{}".format(gis.users.me.username))
    for item in my_content:
        print(item.title, item.type)
    

Competitor Comparisons

Python tools for geographic data

Pros of GeoPandas

  • Open-source and free to use
  • Integrates well with the broader Python data science ecosystem
  • Supports a wide range of geospatial file formats

Cons of GeoPandas

  • Limited support for web-based mapping and visualization
  • Lacks built-in geocoding and routing capabilities
  • May require additional libraries for advanced spatial analysis

Code Comparison

GeoPandas:

import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
world.plot()
cities.plot(ax=world.gca(), color='red', markersize=5)

ArcGIS Python API:

from arcgis.gis import GIS
from arcgis.features import FeatureLayer
gis = GIS()
world = FeatureLayer('https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Countries/FeatureServer/0')
map = gis.map()
map.add_layer(world)

Both libraries offer powerful geospatial capabilities, but GeoPandas is more focused on data analysis and manipulation, while the ArcGIS Python API provides a broader range of GIS functionalities, including web mapping and integration with ArcGIS services.

1,052

Python interface to PROJ (cartographic projections and coordinate transformations library)

Pros of pyproj

  • Open-source and community-driven, allowing for greater flexibility and customization
  • Lightweight and focused specifically on coordinate transformations and projections
  • Integrates well with other geospatial libraries in the Python ecosystem

Cons of pyproj

  • Limited to coordinate transformations and projections, lacking broader GIS functionality
  • May require additional libraries for more complex geospatial operations
  • Less comprehensive documentation compared to ArcGIS Python API

Code Comparison

pyproj:

from pyproj import Transformer
transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
x, y = transformer.transform(51.5074, -0.1278)

arcgis-python-api:

from arcgis.geometry import Point, project
point = Point({"x": -0.1278, "y": 51.5074, "spatialReference": {"wkid": 4326}})
projected_point = project([point], out_sr=3857)[0]

Both libraries provide functionality for coordinate transformations, but pyproj focuses solely on this task, while the ArcGIS Python API offers a broader range of GIS capabilities within its ecosystem.

3,832

Manipulation and analysis of geometric objects

Pros of shapely

  • Open-source and lightweight, with no dependencies on proprietary software
  • Focused solely on geometric operations, making it more versatile for various projects
  • Faster performance for basic geometric operations

Cons of shapely

  • Limited to 2D geometry operations
  • Lacks built-in visualization capabilities
  • No direct integration with GIS data formats or web services

Code Comparison

shapely example:

from shapely.geometry import Point, Polygon

point = Point(0, 0)
polygon = Polygon([(0, 0), (1, 1), (1, 0)])
print(polygon.contains(point))

arcgis-python-api example:

from arcgis.geometry import Point, Polygon

point = Point({"x": 0, "y": 0})
polygon = Polygon({"rings": [[[0, 0], [1, 1], [1, 0], [0, 0]]]})
print(polygon.contains(point))

Both libraries provide similar functionality for basic geometric operations, but arcgis-python-api offers more extensive GIS capabilities and integration with ArcGIS services. shapely is more focused on pure geometry operations and is often used in conjunction with other libraries for more complex GIS tasks.

Rasterio reads and writes geospatial raster datasets

Pros of rasterio

  • Open-source and community-driven development
  • Lightweight and focused on raster data processing
  • Integrates well with other geospatial Python libraries

Cons of rasterio

  • Limited functionality compared to ArcGIS Python API's comprehensive toolset
  • Lacks built-in visualization and mapping capabilities
  • Steeper learning curve for users without prior geospatial programming experience

Code Comparison

rasterio example:

import rasterio

with rasterio.open('example.tif') as src:
    data = src.read()
    profile = src.profile

ArcGIS Python API example:

from arcgis.raster import Raster

raster = Raster('example.tif')
data = raster.read()
metadata = raster.metadata

Both libraries provide methods to read raster data, but the ArcGIS Python API offers a more integrated approach within the ArcGIS ecosystem. rasterio focuses on efficient raster I/O operations, while the ArcGIS Python API provides a broader range of GIS functionality, including advanced spatial analysis and mapping capabilities. The choice between the two depends on the specific project requirements and the user's familiarity with GIS concepts and programming.

1,103

This library reads and writes ESRI Shapefiles in pure Python.

Pros of pyshp

  • Lightweight and focused solely on Shapefile manipulation
  • No external dependencies, making it easy to install and use
  • Open-source and community-driven development

Cons of pyshp

  • Limited to Shapefile format, lacking support for other geospatial data types
  • Fewer advanced GIS analysis capabilities compared to arcgis-python-api
  • Less comprehensive documentation and examples

Code Comparison

pyshp:

import shapefile

# Read a shapefile
sf = shapefile.Reader("myshapefile.shp")

# Get the first shape
shape = sf.shape(0)

# Print the shape's bounding box
print(shape.bbox)

arcgis-python-api:

from arcgis.gis import GIS
from arcgis.features import FeatureLayer

# Connect to ArcGIS Online
gis = GIS("https://www.arcgis.com", "username", "password")

# Access a feature layer
layer = FeatureLayer(gis.content.get("item_id").layers[0])

# Query features
features = layer.query(where="1=1", out_fields="*")

The code comparison demonstrates the simplicity of pyshp for basic Shapefile operations, while arcgis-python-api offers more comprehensive GIS functionality and integration with ArcGIS ecosystem.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ArcGIS API for Python

ArcGIS API for Python is a Python library for working with maps and geospatial data, powered by web GIS. It provides simple and efficient tools for deep learning, sophisticated vector and raster analysis, geocoding, map making, routing and directions, as well as for organizing and managing a GIS with users, groups and information items. In addition to working with your own data, the library enables access to ready to use maps and curated geographic data from Esri and other authoritative sources. It also integrates well with the scientific Python ecosystem and includes rich support for Pandas, Scikit-Learn, Fast.ai, etc. and Jupyter notebook.

To learn more about the API, visit the product page here. You can get in touch with the developers of the API and other users like you at the community page here.

What's included

This SDK repository contains the following items:

  • API Reference Documentation. A hosted version of this can be found here.
  • Samples as Jupyter Notebooks.
  • Guides chapters as Jupyter Notebooks.
  • API Reference Documentation can be found here. Downloads are available for current and previous versions here.

You have multiple ways of executing these notebooks as listed below:

  • Execute locally on your computer by installing anaconda and the API. See Install and set up help Package managers
  • Execute with ArcGIS Pro. See the Install and set up ArcGIS Pro topic. For additional details, see Notebooks in ArcGIS Pro.
  • Execute with ArcGIS Notebooks, hosted on ArcGIS Online. Checkout this group with sample notebooks.
  • Execute in a Dockerised environment. See Install and set up help Installation as Docker image
  • Execute with Binder. See help here

Issues

Find a bug or want to request a new feature? Please let us know by submitting an issue. Thank you!

Contributing

Anyone and everyone is welcome to contribute. Please see our contribution guideline here.

Licensing

Copyright 2018-2022 Esri

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

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's license.txt file.