egygeo 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
egygeo-1.0.0/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2024 EGYGEO
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
egygeo-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.1
2
+ Name: egygeo
3
+ Version: 1.0.0
4
+ Summary: A Python package designed to provide easy access to the geographic coordinates (latitude and longitude) of various Egyptian subdivisions.
5
+ Author: Sara Habib
6
+ Author-email: sara.habib48@gmail.com
7
+ License-File: LICENSE
egygeo-1.0.0/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # EGYGEO
2
+
3
+ EGYGEO is a Python package designed to provide easy access to the geographic coordinates (latitude and longitude) of various Egyptian subdivisions. It includes a module named `egysubdiv` that offers a convenient function, `get_coordinates`, allowing users to retrieve the geographic coordinates of a specified Egyptian subdivision by providing its name in either Arabic or English. The package supports the normalization of input subdivision names for robust matching.
4
+
5
+ ## Installation
6
+
7
+ You can install egygeo using pip:
8
+
9
+ ```bash
10
+ pip install egygeo
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ from egygeo import get_coordinates
17
+
18
+ # Get coordinates for Cairo
19
+ latitude, longitude = get_coordinates('Cairo')
20
+ print(f"The coordinates of Cairo are: {latitude}, {longitude}")
21
+ ```
@@ -0,0 +1,2 @@
1
+ from .egygeo import get_coordinates
2
+ from .egygeo import get_name
@@ -0,0 +1,61 @@
1
+ import json
2
+ import requests
3
+
4
+
5
+ def load_geojson_from_url(url):
6
+ response = requests.get(url)
7
+ response.raise_for_status() # Raise an exception for bad responses
8
+ return json.loads(response.text)
9
+
10
+
11
+ def load_geojson(file_path_or_url):
12
+ if file_path_or_url.startswith('http'):
13
+ # If the path starts with 'http', assume it's a URL
14
+ return load_geojson_from_url(file_path_or_url)
15
+ else:
16
+ with open(file_path_or_url, 'r', encoding='utf-8') as geojson_file:
17
+ return json.load(geojson_file)
18
+
19
+
20
+ def get_coordinates(subdivision_name, geojson_path_or_url='https://raw.githubusercontent.com/srahabib/Egypt-governorates-geojson/main/Subdivisions%20of%20Egypt.json'):
21
+ geojson_data = load_geojson(geojson_path_or_url)
22
+
23
+ normalized_name = subdivision_name.lower().strip()
24
+
25
+ for feature in geojson_data['features']:
26
+ properties = feature['properties']
27
+ geometry = feature['geometry']
28
+
29
+ # Check both English and Arabic names
30
+ english_name = properties.get('Subdivision_en', '').lower()
31
+ arabic_name = properties.get('Subdivision_ar', '').lower()
32
+
33
+ if normalized_name in [english_name, arabic_name]:
34
+ if geometry['type'] == 'Point' and len(geometry['coordinates']) == 2:
35
+ return tuple(geometry['coordinates'])
36
+
37
+ # Return an empty tuple if subdivision not found
38
+ return ()
39
+
40
+
41
+ def get_name(latitude, longitude, geojson_path_or_url='https://raw.githubusercontent.com/srahabib/Egypt-governorates-geojson/main/Subdivisions%20of%20Egypt.json'):
42
+ geojson_data = load_geojson(geojson_path_or_url)
43
+
44
+ for feature in geojson_data['features']:
45
+ geometry = feature['geometry']
46
+
47
+ if geometry['type'] == 'Point' and len(geometry['coordinates']) == 2:
48
+ feature_latitude, feature_longitude = geometry['coordinates']
49
+
50
+ # Set a tolerance level for coordinates matching
51
+ tolerance = 0.0001
52
+ if (
53
+ abs(feature_latitude - latitude) < tolerance and
54
+ abs(feature_longitude - longitude) < tolerance
55
+ ):
56
+ properties = feature['properties']
57
+ english_name = properties.get('Subdivision_en', '')
58
+ arabic_name = properties.get('Subdivision_ar', '')
59
+ return f"{english_name},{arabic_name}"
60
+
61
+ return "Location not found in the GeoJSON data."
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.1
2
+ Name: egygeo
3
+ Version: 1.0.0
4
+ Summary: A Python package designed to provide easy access to the geographic coordinates (latitude and longitude) of various Egyptian subdivisions.
5
+ Author: Sara Habib
6
+ Author-email: sara.habib48@gmail.com
7
+ License-File: LICENSE
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ egygeo/__init__.py
5
+ egygeo/egygeo.py
6
+ egygeo.egg-info/PKG-INFO
7
+ egygeo.egg-info/SOURCES.txt
8
+ egygeo.egg-info/dependency_links.txt
9
+ egygeo.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ egygeo
egygeo-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
egygeo-1.0.0/setup.py ADDED
@@ -0,0 +1,13 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="egygeo",
5
+ version="1.0.0",
6
+ author="Sara Habib",
7
+ author_email="sara.habib48@gmail.com",
8
+ description="A Python package designed to provide easy access to the geographic coordinates (latitude and longitude) of various Egyptian subdivisions.",
9
+ packages=find_packages(),
10
+ install_requires=[
11
+ # List any dependencies your package requires
12
+ ],
13
+ )