Skip to main content

A Python package for Egyptian governorate centroids, boundaries, reverse geocoding, and map visualization.

Project description

EGYGEO

EGYGEO is a Python package for Egypt’s 27 governorates. It lets you look up each governorate’s centroid coordinates by English or Arabic name, resolve any latitude/longitude to the governorate that contains it using real administrative borders, and retrieve GeoJSON polygons for mapping or analysis.

Use it when you need to:

  • Look up a point — get the latitude/longitude centroid of a governorate by English or Arabic name (get_coordinates)
  • Reverse-geocode a location — given any lat/lon inside Egypt, find which governorate it falls in using real borders, not just the nearest city center (get_name)
  • Get border outlines — retrieve GeoJSON polygons for mapping, analysis, or export (get_boundary)
  • Get shape + metadata together — return a full GeoJSON Feature with English/Arabic names, id, and centroid (as_feature=True or geometry_type="feature")
  • List all governorates — iterate English and Arabic names programmatically (list_governorates)
  • Draw interactive maps — plot a governorate border (and optional centroid marker) as HTML with Folium (draw_governorate)

Installation

pip install egygeo

For map drawing support:

pip install egygeo[map]

For the interactive Plotly showcase:

pip install egygeo[plotly]

Interactive showcase (Plotly)

EGYGEO Plotly map of Egypt's 27 governorates

Generate a browser map of all 27 governorate borders:

pip install -e ".[plotly]"
python examples/plotly_showcase.py

Open examples/output/egygeo_plotly_showcase.html. Hover a governorate for its English and Arabic name.

Usage

Get a governorate centroid

Returns a (latitude, longitude) tuple, or () if the name is not found.

from egygeo import get_coordinates

latitude, longitude = get_coordinates("Cairo")
print(f"Cairo centroid: {latitude}, {longitude}")

# Arabic names work too
latitude, longitude = get_coordinates("القاهرة")

Get a governorate border

By default returns the GeoJSON geometry only (the outline).
Pass as_feature=True to also include names, id, and centroid (see Return types and parameters).

from egygeo import get_boundary

cairo_border = get_boundary("Cairo")
# {"type": "Polygon", "coordinates": [...]}

cairo_feature = get_boundary("Cairo", as_feature=True)
# {"type": "Feature", "properties": {...}, "geometry": {...}}

Reverse lookup — any point inside Egypt

get_name uses point-in-polygon against real governorate borders, so any coordinate inside a governorate works (not just centroids).

Returns a dict with english, arabic, and id keys, or None if the point is outside Egypt.

from egygeo import get_name

# Pyramids of Giza area
result = get_name(29.9792, 31.1342)
print(result["english"])  # Giza
print(result["arabic"])   # الجيزة

# Downtown Cairo
result = get_name(30.0444, 31.2357)
print(result["english"])  # Cairo

# Returns None if the point is outside Egypt
result = get_name(40.7128, -74.0060)
print(result)  # None

Draw a governorate on a map

Returns a Folium Map object. Saves an HTML file when output_path is provided. Requires egygeo[map].

from egygeo import draw_governorate

draw_governorate("Alexandria", output_path="alexandria.html")
draw_governorate("Cairo", output_path="cairo.html", fill_color="#e74c3c")

List all governorates

Returns a list of dicts with english, arabic, and id keys.

from egygeo import list_governorates

for governorate in list_governorates():
    print(governorate["english"], governorate["arabic"])

Unified geometry access

get_geometry is one function that can return a point, polygon, or full feature depending on geometry_type (see below).

from egygeo import get_geometry

point = get_geometry("Alexandria", geometry_type="point")
polygon = get_geometry("Alexandria", geometry_type="polygon")
feature = get_geometry("Alexandria", geometry_type="feature")

Return types and parameters

Quick reference

Function Returns
get_coordinates(name) (latitude, longitude) tuple, or () if not found
get_name(lat, lon) {"english": str, "arabic": str, "id": int} if inside Egypt, otherwise None
get_boundary(name) GeoJSON geometry dict (Polygon or MultiPolygon), or None if not found
get_boundary(name, as_feature=True) GeoJSON Feature dict (geometry + properties), or None if not found
get_geometry(name, geometry_type=...) Point, polygon, or feature — depends on geometry_type
list_governorates() List of {"english": str, "arabic": str, "id": int}
draw_governorate(...) Folium Map object (also saves HTML when output_path is set)

as_feature (get_boundary)

Controls whether you get only the border outline, or the outline plus metadata.

Value What you get
False (default) Geometry only: {"type": "Polygon"|"MultiPolygon", "coordinates": [...]}
True Full GeoJSON Feature: geometry and properties (Subdivision_en, Subdivision_ar, id, centroid)

Use as_feature=False when you only need the shape (drawing, spatial checks, export).
Use as_feature=True when you also need the governorate name, Arabic name, id, or centroid along with the border.

geometry = get_boundary("Cairo")
# Shape only

feature = get_boundary("Cairo", as_feature=True)

Example of what feature looks like (coordinates shortened for readability; the real border has many more points):

{
  "type": "Feature",
  "properties": {
    "id": 6,
    "Subdivision_en": "Cairo",
    "Subdivision_ar": "القاهرة",
    "centroid": [31.2357257, 30.0443879]  # [longitude, latitude]
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [31.8367932, 30.3209168],
        [31.630124, 30.1979663],
        [31.5924734, 30.1721293],
        # ... more [longitude, latitude] pairs ...
      ]
    ]
  }
}

Access the fields like this:

print(feature["properties"]["Subdivision_en"])  # Cairo
print(feature["properties"]["Subdivision_ar"])  # القاهرة
print(feature["geometry"]["type"])              # Polygon or MultiPolygon

geometry_type (get_geometry)

Chooses which form of data to return. It does not create a new data source — it wraps the same helpers as above.

geometry_type Equivalent to Returns
"point" (default) get_coordinates(name) Centroid as (latitude, longitude)
"polygon" get_boundary(name) Border GeoJSON geometry only
"feature" get_boundary(name, as_feature=True) Full GeoJSON Feature (geometry + properties)
from egygeo import get_geometry

# Centroid
lat, lon = get_geometry("Alexandria", geometry_type="point")

# Border outline only
polygon = get_geometry("Alexandria", geometry_type="polygon")
# {"type": "Polygon", "coordinates": [...]}

# Border + metadata
feature = get_geometry("Alexandria", geometry_type="feature")
# {"type": "Feature", "properties": {...}, "geometry": {...}}

Any other geometry_type value raises ValueError.

Name matching

Governorate names can be provided in English or Arabic. Common alternate spellings from other datasets are also supported:

  • Cairo, Al Qahirah, القاهرة
  • Alexandria, Al Iskandariyah, الإسكندرية
  • Sharqia, Al Sharqia, الشرقية
  • Kafr El Sheikh, Kafr el-Sheikh, كفر الشيخ

Data

Boundary polygons are sourced from geoBoundaries (CC BY 4.0 / ODbL) and normalized to use consistent Subdivision_en and Subdivision_ar property names across the package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

egygeo-1.3.1.tar.gz (74.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

egygeo-1.3.1-py3-none-any.whl (71.4 kB view details)

Uploaded Python 3

File details

Details for the file egygeo-1.3.1.tar.gz.

File metadata

  • Download URL: egygeo-1.3.1.tar.gz
  • Upload date:
  • Size: 74.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.16

File hashes

Hashes for egygeo-1.3.1.tar.gz
Algorithm Hash digest
SHA256 1c9604ee0177d8dde9431b9e967164df15f22aeff1297275622331297169495b
MD5 cf9afbbbd7929a65f18c44c6af81c465
BLAKE2b-256 b2c21a2311ec690f9e3fbc30a2f6b81e50c2a9b5894d43338dda5c7ccdbbdcec

See more details on using hashes here.

File details

Details for the file egygeo-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: egygeo-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 71.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.16

File hashes

Hashes for egygeo-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b32ed2ed15e2a2172c3cbc1879534529c7c3312c3914c1a7d2608e18d1c6851
MD5 73153c92b3b76a2da85a4957ea03b59a
BLAKE2b-256 ae58500b37f80b1093207e9e3facd4135df4d49774443b0929b497ac07899cab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page