MalaGIS

Sharing GIS Technologies, Resources and News.

Installing Third-Party Libraries for ArcGIS Desktop Python Environment

When working on data processing projects with ArcGIS Desktop (non-Pro version), extending arcpy functionality often requires installing third-party libraries. Since Python 2 doesn't include pip by default, this guide outlines the installation process.

Prerequisites

  1. Install ArcGIS Desktop
  2. Add Python path to environment variables (e.g., C:\Python27\ArcGIS10.X)
  3. Remove other Python paths from system variables

more >>

Automated Geodatabase Schema Documentation with ArcPy

During a recent data processing project, I developed an ArcPy script to automate geodatabase schema documentation for technical reports, eliminating manual field inventory tasks. This solution leverages arcpy for data extraction and xlwt for Excel output generation.

Output Preview

The script produces structured Excel sheets detailing field names, aliases, data types, lengths, and spatial references:

more >>

Automated Raster Extent Vectorization Using ArcPy

When managing large volumes of high-resolution satellite imagery (e.g., 1:10,000 scale sheets), visualizing coverage gaps becomes challenging due to performance limitations in ArcMap. This script automates the creation of vector polygons representing raster extents for efficient gap analysis.

ArcPy Vectorized Raster Extents
Visualization: Red outlines = actual coverage, Green polygons = generated extents


Detail showing alignment accuracy

Implementation Code

# -*- coding: utf-8 -*-
import os
import time
import arcpy

def create_directory(path):
    """Ensure directory exists, create if missing"""
    if os.path.isdir(path):
        if not os.path.exists(path):
            os.makedirs(path)
    else:
        parent_dir = os.path.dirname(path)
        if not os.path.exists(parent_dir):
            os.makedirs(parent_dir)

if __name__ == '__main__':
    # Configure input/output
    raster_directory = r'F:\gisData\data0929\refY202410072'
    output_shapefile = os.path.join(raster_directory, 'shp', 'RasterExtent.shp')
    
    start_time = time.time()
    arcpy.env.workspace = raster_directory
    raster_list = arcpy.ListRasters()
    
    if not raster_list:
        raise IOError("Error: No raster files found!")
    
    # Prepare output feature class
    if arcpy.Exists(output_shapefile):
        arcpy.Delete_management(output_shapefile)
    
    create_directory(output_shapefile)
    output_fc = arcpy.CreateFeatureclass_management(
        os.path.dirname(output_shapefile), 
        "RasterExtent.shp", 
        "POLYGON"
    )
    arcpy.AddField_management(output_fc, "RasterName", "TEXT", 50)
    
    # Process rasters
    with arcpy.da.InsertCursor(output_fc, ["SHAPE@", "RasterName"]) as cursor:
        for raster_file in raster_list:
            raster = arcpy.Raster(raster_file)
            extent = raster.extent
            
            # Construct polygon from extent
            polygon_points = arcpy.Array([
                arcpy.Point(extent.XMin, extent.YMin),  # LL
                arcpy.Point(extent.XMin, extent.YMax),  # UL
                arcpy.Point(extent.XMax, extent.YMax),  # UR
                arcpy.Point(extent.XMax, extent.YMin),  # LR
                arcpy.Point(extent.XMin, extent.YMin)   # Close ring
            ])
            
            cursor.insertRow([arcpy.Polygon(polygon_points), raster_file])
    
    # Performance metrics
    elapsed = time.time() - start_time
    print(f"Process completed in: {elapsed:.2f} seconds")

Key Workflow

  1. Input Configuration: Specify directory containing raster files
  2. Output Handling: Automatically creates output shapefile
  3. Extent Extraction:

    • Retrieves XMin/YMin/XMax/YMax for each raster
    • Constructs rectangular polygons from corner coordinates
  4. Attribute Storage: Preserves original raster filenames

Advantages

  • Eliminates manual extent digitization
  • Enables efficient coverage gap analysis
  • Handles thousands of rasters in batch processing
  • Integrates with standard ArcGIS workflows
Note: Requires ArcGIS Desktop with Spatial Analyst extension. Execution time scales linearly with raster count.

Installing Python Packages in ArcGIS Environments: Manual and Automated Approaches

When extending ArcGIS Python functionality (e.g., using openpyxl for Excel integration), installing supplementary packages becomes necessary. This guide demonstrates manual and automated installation methods for both online and offline scenarios.

more >>

Practical Python Integration in ArcGIS: Key Implementation Methods

Using Python within ArcGIS requires foundational Python knowledge. The following modules support Python integration:

more >>

Copyright © 2020-2025 MalaGIS Drive by Typecho & Lingonberry Sitemap

Back to top