Orchardcore spatial

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore spatial is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for working with geographic and spatial data in Orchard Core. Covers GeoPointField for location storage, standard and Leaflet map editors, culture-invariant latitude and longitude values, GraphQL, Lucene and Elasticsearch geo indexing with the shared Location field, geo-bounding-box queries, g

How to use this skill

Skill file

Orchard Core Spatial - Prompt Templates

Work with Geographic and Spatial Data

You are an Orchard Core expert. Generate code and queries for spatial data including GeoPointField usage, geo-bounding-box queries, geo-distance queries, and combined spatial filtering with Lucene.

Guidelines

Enabling the Spatial Feature

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Spatial"
      ],
      "disable": []
    }
  ]
}

Adding a GeoPointField to a Content Type

Add a GeoPointField named Location to a content type via recipe:

{
  "steps": [
    {
      "name": "ContentDefinition",
      "ContentTypes": [
        {
          "Name": "Store",
          "DisplayName": "Store",
          "Settings": {
            "ContentTypeSettings": {
              "Creatable": true,
              "Listable": true,
              "Draftable": true
            }
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "StorePart",
              "Name": "StorePart",
              "Settings": {}
            }
          ]
        }
      ],
      "ContentParts": [
        {
          "Name": "StorePart",
          "Settings": {},
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "TextField",
              "Name": "Name",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Name"
                }
              }
            },
            {
              "FieldName": "GeoPointField",
              "Name": "Location",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Location"
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

Field Data, Display, and GraphQL

{
  "StorePart": {
    "Location": {
      "Latitude": -33.8688,
      "Longitude": 151.2093
    }
  }
}

The default display template GeoPointField.cshtml renders Latitude, Longitude with six decimals; override it (e.g. GeoPointField-StorePart-Location.cshtml or a Liquid template) to render a map. In Liquid, read {{ Model.ContentItem.Content.StorePart.Location.Latitude }}. With GraphQL enabled, query storePart { location { latitude longitude } }.

Geo Bounding Box Query

A geo_bounding_box query finds documents within a rectangular area defined by top-left and bottom-right coordinates. This is fast and does not calculate distance from a center point.

Example: Find all Store content items with a Location field within a bounding box:

{
    "query": {
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_bounding_box": {
                    "StorePart.Location": {
                        "top_left": {
                            "lat": -33,
                            "lon": 137
                        },
                        "bottom_right": {
                            "lat": -35,
                            "lon": 139
                        }
                    }
                }
            }
        }
    }
}

This returns content items whose Location falls within the rectangle bounded by:

Geo Distance Query

A geo_distance query finds documents within a specified radius of a central point. It uses the Haversine formula to calculate the distance between each document and the center point.

Example: Find all Store content items within 200km of a point:

{
    "query": {
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_distance": {
                    "distance": "200km",
                    "StorePart.Location": {
                        "lat": -34,
                        "lon": 138
                    }
                }
            }
        }
    }
}

A 200km radius is approximately 1.7986 degrees of arc from the center point.

Distance Units

| Unit | Example | Description |

|------|---------|-------------|

| km | "200km" | Kilometers |

| mi | "100mi" | Miles |

| m | "5000m" | Meters |

Combined Bounding Box and Distance Query

For large datasets, combine geo_bounding_box with geo_distance for optimal performance. The bounding box pre-filters the dataset to a smaller region, then the distance calculation runs only on the filtered results:

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "Content.ContentItem.ContentType.keyword": "Store"
                    }
                },
                {
                    "bool": {
                        "filter": {
                            "geo_distance": {
                                "distance": "200km",
                                "StorePart.Location": {
                                    "lat": -33,
                                    "lon": 137
                                }
                            }
                        }
                    }
                }
            ],
            "filter": {
                "geo_bounding_box": {
                    "StorePart.Location": {
                        "top_left": {
                            "lat": -31,
                            "lon": 135
                        },
                        "bottom_right": {
                            "lat": -35,
                            "lon": 139
                        }
                    }
                }
            }
        }
    }
}

Query Strategy Comparison

| Query Type | Speed | Precision | Use Case |

|------------|-------|-----------|----------|

| geo_bounding_box | Fast | Rectangular area only | Quick area filtering, map viewport queries |

| geo_distance | Slower (Haversine) | Exact radius | Precise "within X km" searches |

| Combined | Optimal | Exact radius with pre-filter | Large datasets requiring radius search |

Haversine Formula

The geo_distance query uses the Haversine formula to calculate the great-circle distance between two points on a sphere. Key characteristics:

Content Type with Multiple Spatial Fields

A content type can have multiple GeoPointField instances for different geographic attributes:

{
  "steps": [
    {
      "name": "ContentDefinition",
      "ContentParts": [
        {
          "Name": "DeliveryRoute",
          "Settings": {},
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "GeoPointField",
              "Name": "Origin",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Origin Location"
                }
              }
            },
            {
              "FieldName": "GeoPointField",
              "Name": "Destination",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Destination Location"
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

Query by origin location:

{
    "query": {
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_distance": {
                    "distance": "50km",
                    "DeliveryRoute.Origin": {
                        "lat": 40.7128,
                        "lon": -74.0060
                    }
                }
            }
        }
    }
}
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.