MalaGIS

Sharing GIS Technologies, Resources and News.

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:

Read 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.

Creating Marathon Distribution Heatmaps in QGIS

Following our previous article on Processing China Marathon Data for Spatial Analysis, this guide demonstrates heatmap visualization of marathon venues using QGIS.

Read More >>

Processing China Marathon Data for Spatial Analysis

In follow-up to our tutorial on Creating Dynamic Marathon Route Visualizations with MapPlus: A No-Code GIS Solution, we compiled a comprehensive dataset of Chinese marathons through automated data processing. This article documents the methodology and technical implementation.


Marathon distribution heatmap in QGIS

Read More >>

Open-Source Dashboard Templates for GIS Developers: BigDataView Project

During discussions in our GIS community chat, a colleague humorously noted: "After three years in 3D GIS, my most frequent projects are dashboards." This resonated widely among GIS developers, highlighting a common industry reality—dashboard projects dominate the WebGIS landscape. While not technically complex, these projects demand meticulous attention to aesthetic details like color schemes that consume disproportionate time.

Introducing BigDataView: An open-source repository of dashboard templates designed to alleviate this pain point.

Read More >>

Authoritative World Map Vector Data with Official Approval Number (AMap Source)

Building on previous world map solutions—either officially approved but misaligned or precisely georeferenced but non-compliant—we present Amap's dataset that combines regulatory compliance, spatial accuracy, and practical usability.

Source:
Amap DistrictLayer API

Read More >>

Georeferencing Marathon Route Maps in QGIS: Manual vs. AI-Assisted Approaches

When crafting dynamic marathon routes from official maps, directly tracing simplified route images is inefficient without proper spatial referencing. Georeferencing solves this by aligning raster images with real-world coordinates.

Read More >>

Batch Exporting CAD Layers to Shapefile in QGIS

When processing DWG data in QGIS, exporting multiple layers individually becomes tedious. Here are three efficient batch export methods。

Read More >>

Creating Dynamic Marathon Route Visualizations with MapPlus: A No-Code GIS Solution

When asked about generating dynamic marathon route maps like those in Beijing Marathon 2024, I discovered MapPlus—a zero-code solution for creating animated race visualizations. This tool eliminates the need for custom development while producing professional-grade outputs.

Read More >>

Extracting Administrative Division Codes from Authoritative National GIS Datasets

In our previous article 《「GIS Data」Download Updated National Administrative Division Codes》, we discussed methods to acquire administrative codes. A common application is powering location selection components in frontend systems, as shown below:

Read More >>

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

Back to top