Skip to main content
Glama

gearys_c

Calculate spatial autocorrelation using Global Geary's C statistic to identify patterns in geographic data distributions.

Instructions

Compute Global Geary's C Autocorrelation Statistic.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
shapefile_pathYes
dependent_varNoLAND_USE
target_crsNoEPSG:4326
distance_thresholdNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary handler function for the 'gearys_c' MCP tool. Loads shapefile data using helper, computes Geary's C statistic with esda.Geary on row-standardized distance weights, handles errors and returns results with preview.
    @gis_mcp.tool()
    def gearys_c(shapefile_path: str, dependent_var: str = "LAND_USE", target_crs: str = "EPSG:4326", distance_threshold: float = 100000) -> Dict[str, Any]:
        """Compute Global Geary's C Autocorrelation Statistic."""
        gdf, y, w, (threshold, unit), err = pysal_load_data(shapefile_path, dependent_var, target_crs, distance_threshold)
        if err:
            return {"status": "error", "message": err}
    
        import esda
        stat = esda.Geary(y, w)
        preview = gdf[['geometry', dependent_var]].head(5).assign(
            geometry=lambda df: df.geometry.apply(lambda g: g.wkt)
        ).to_dict(orient="records")
    
        return {
            "status": "success",
            "message": f"Geary's C completed successfully (threshold: {threshold} {unit})",
            "result": {
                "C": float(stat.C),
                "gearys_c": float(stat.C),  # Also include as gearys_c for test compatibility
                "p_value": float(stat.p_sim),
                "z_score": float(stat.z_sim),
                "data_preview": preview
            }
        }
  • Helper function shared by 'gearys_c' and other PySAL tools for loading GeoDataFrame, validating inputs, reprojecting, creating row-standardized distance-band spatial weights (libpysal), and handling isolated observations (islands).
    def pysal_load_data(shapefile_path: str, dependent_var: str, target_crs: str, distance_threshold: float):
        """Common loader and weight creation for esda statistics."""
        if not os.path.exists(shapefile_path):
            return None, None, None, None, f"Shapefile not found: {shapefile_path}"
    
        gdf = gpd.read_file(shapefile_path)
        if dependent_var not in gdf.columns:
            return None, None, None, None, f"Dependent variable '{dependent_var}' not found in shapefile columns"
    
        gdf = gdf.to_crs(target_crs)
    
        effective_threshold = distance_threshold
        unit = "meters"
        if target_crs.upper() == "EPSG:4326":
            effective_threshold = distance_threshold / 111000
            unit = "degrees"
    
        y = gdf[dependent_var].values.astype(np.float64)
        import libpysal
        w = libpysal.weights.DistanceBand.from_dataframe(gdf, threshold=effective_threshold, binary=False)
        w.transform = 'r'
    
        for island in w.islands:
            w.weights[island] = [0] * len(w.weights[island])
            w.cardinalities[island] = 0
    
        return gdf, y, w, (effective_threshold, unit), None
  • MCP resource endpoint listing available ESDA (PySAL) operations, including 'gearys_c', discoverable by clients.
    @gis_mcp.resource("gis://operations/esda")
    def get_spatial_operations() -> Dict[str, List[str]]:
        """List available spatial analysis operations. This is for esda library. They are using pysal library."""
        return {
            "operations": [
                "getis_ord_g",
                "morans_i",
                "gearys_c",
                "gamma_statistic",
                "moran_local",
                "getis_ord_g_local",
                "join_counts",
                "join_counts_local",
                "adbscan"
            ]
        }
  • src/gis_mcp/mcp.py:5-5 (registration)
    Creation of the FastMCP server instance 'gis_mcp' used by @gis_mcp.tool() decorators to register tools like 'gearys_c'.
    gis_mcp = FastMCP("GIS MCP")
  • Import of pysal_functions module in main.py, which triggers execution of @gis_mcp.tool() decorators and registers the 'gearys_c' tool.
        pysal_functions,
    )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure but provides minimal information. It doesn't explain what the statistic measures, what the output represents, computational characteristics, or any limitations. The description only states what is computed, not how it behaves or what users should expect from the operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just one sentence that directly states the tool's purpose. There is zero wasted language or unnecessary elaboration. The single sentence is front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the statistical nature of the tool, 4 parameters with no schema descriptions, and the presence of an output schema, the description is incomplete. While the output schema may document return values, the description doesn't provide enough context about what the tool actually does, how parameters affect the computation, or when to use it versus alternatives. For a statistical tool with multiple parameters, more explanatory context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage and 4 parameters, the description provides no information about any parameters. It doesn't explain what shapefile_path should contain, what dependent_var represents, what target_crs does, or how distance_threshold affects the calculation. The description fails to compensate for the complete lack of parameter documentation in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool computes Global Geary's C autocorrelation statistic, which is a specific statistical operation. It distinguishes itself from siblings by focusing on this particular spatial autocorrelation measure rather than general spatial operations. However, it doesn't explicitly differentiate from similar statistical tools like morans_i or getis_ord_g.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance about when to use this tool versus alternatives. There are multiple spatial autocorrelation tools in the sibling list (morans_i, getis_ord_g, join_counts, etc.), but the description doesn't explain when Geary's C is preferred over these other measures or what analytical context it's suited for.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mahdin75/gis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server