momepy: Urban Morphology Measuring Toolkit

repository·main·Indexed 20 days ago

https://github.com/pysal/momepy

A Python library for the quantitative analysis of urban form (urban morphometrics), built on GeoPandas, networkX, and PySAL. It provides tools to measure dimensions, shapes, spatial distributions, connectivity, and diversity of urban elements such as building footprints and street networks. Key capabilities include generating morphological tessellations, calculating centrality and meshedness for street networks, and performing advanced streetscape analysis via the Streetscape class.

Tokens
47.6K
Snippets
179
Records
213
Agent score
70%

What's inside momepy

  1. Overview of momepy core modules

    main

    momepy is a Python toolkit for Urban Morphometrics (UMM), designed to measure the physical form of cities across scales (from individual buildings to metropolitan regions). The toolkit is organized into several functional modules:

    • dimension: Measures dimensional morphometric characters.
    • shape: Measures shape-based morphometric characters.
    • distribution: Analyzes the spatial distribution of urban elements.
    • intensity: Measures the intensity of urban features.
    • graph: Analyzes connectivity, typically using street networks (built on networkx).
    • diversity: Measures the diversity of urban morphological characters.
    • elements: Generates morphological elements (like Voronoi tessellation for plots) and links elements using unique IDs based on spatial proximity.
    • utils: Provides data pre-processing tools, such as cleaning the topology of street networks or building footprints.

    momepy is built on top of GeoPandas (using GeoSeries and GeoDataFrame objects) and utilizes PySAL for spatial weights matrices to capture the adjacency of urban elements.

  2. Overview of momepy capabilities

    main

    momepy (Morphological Measuring in Python) is a library for the quantitative analysis of urban form (urban morphometrics). It is built on top of GeoPandas, networkX, and other PySAL modules.

    Key functionalities include:

    • Measuring dimensions: Of morphological elements, parts, and aggregated structures.
    • Quantifying shapes: Of geometries representing various morphological features.
    • Capturing spatial distribution: Of elements and relationships between different kinds.
    • Computing intensity: Density and other intensity characters.
    • Calculating diversity: Of various aspects of urban form.
    • Capturing connectivity: Of urban street networks.
    • Generating relational elements: Such as morphological tessellation.
  3. Generate morphological elements and tessellations in momepy

    main

    The elements module in momepy is used to generate morphological elements and link them together using a unique_id. The core functionality includes algorithms for generating morphological tessellation and creating blocks based on the geometry of that tessellation.

    Key features available in this module include:

    • tessellation: Generating morphological tessellations.
    • enclosed: Identifying enclosed areas.
    • proximity_bands: Creating proximity bands.
    • blocks: Generating blocks based on tessellation geometry.
    • links: Linking different morphological elements.
  4. How morphological tessellation works in momepy

    main
    The elements module can generate a morphological tessellation of a built-up area. This is achieved by applying Voronoi tessellation (via SciPy) to building footprints, which serves as a proxy for urban plots. This tessellation can also be aggregated to generate urban blocks at a higher scale. By combining this tessellation with PySAL spatial weights, users can perform relational, location-based aggregation to define the vicinity of urban elements.
  5. Manage morphological elements in momepy

    main

    momepy provides tools to create and manage bespoke morphological geometric features. This includes generating tessellations, enclosures, and blocks, as well as calculating proximity bands.

    Feature Generation:

    • morphological_tessellation: Create tessellations based on morphology.
    • enclosed_tessellation: Create tessellations for enclosed areas.
    • enclosures: Identify enclosed areas.
    • generate_blocks: Generate urban blocks.
    • proximity_bands: Create bands based on proximity.

    Supporting Tools:

    • buffered_limit: Create buffered limits.
    • verify_tessellation: Validate tessellation structures.

    Linking Elements:

    • get_nearest_street: Find the nearest street to an element.
    • get_nearest_node: Find the nearest network node.
    • get_network_ratio: Calculate ratios related to the network.
  6. Understand the core data structures in momepy

    main

    momepy relies on two primary data structures for its operations:

    1. geopandas.GeoDataFrame: Used for all morphometric analyses. Most functions accept a GeoDataFrame as input and return a pandas Series, which can be easily appended back to the original GeoDataFrame as a new column.
    2. networkx.Graph: Used specifically for network analysis. Network analysis functions typically return a networkx.Graph object enriched with additional node or edge attributes.

    You can perform analysis on various morphological elements such as buildings, plots, morphological cells, streets, street profiles, street networks, or blocks, provided they are represented as GeoDataFrames.

  7. Calculate simple morphological characters in momepy

    main

    In momepy, 'simple characters' are morphological metrics that can be calculated using only a single GeoDataFrame. Most other morphological characters require additional context, such as relations between multiple GeoDataFrames or spatial weights matrices.

    Simple characters available in momepy include:

    • Dimension metrics
    • Shape metrics

    You can implement these by passing a GeoDataFrame directly to the respective character functions.

  8. Perform network analysis using the momepy graph module

    main
    For morphometric analysis of street networks, use the momepy.graph module. Unlike most other momepy functions that operate on geopandas.GeoDataFrame objects, the functions in the graph module are designed to work with networkx.Graph objects. This allows for the calculation of network-based characters and structural properties of street networks.
  9. Understand the role of Spatial Graphs in momepy

    main
    To analyze morphometric characters within an urban context, momepy uses spatial graphs to account for neighboring elements. A spatial graph represents the relationships between elements (such as buildings) as a binary matrix where 1 indicates neighbors and 0 indicates non-neighbors. These graphs are fundamental to how momepy calculates location-based characters, such as the mean height of buildings within a specific radius.
  10. Categorize morphometric functions by data requirements

    main

    Morphometric functions in momepy are organized into four functional groups based on their input and output patterns:

    • Simple characters: Use a single GeoDataFrame as the data source.
    • Relational characters: Based on relationships between two or more GeoDataFrames (e.g., street_alignment, which compares street orientation with building orientation).
    • Network analysis: Based on networkx.Graph objects and return a networkx.Graph with added node or edge attributes.
    • Morphological elements: Functions in the elements and utils modules that generate new elements (like morphological tessellation) or create links between existing ones.
  11. Install momepy via conda or pip

    main

    The recommended way to install momepy is using conda via the conda-forge channel to ensure all geospatial dependencies are compatible. You can also use pip if you have already met all dependency requirements manually.

    # Recommended installation
    conda install -c conda-forge momepy
    
    # Alternative installation
    pip install momepy