# Welcome to geomaroc
![geomaroc_logo](https://user-images.githubusercontent.com/49843367/164335838-537f0514-ce89-43ed-956f-c6c6de6ed264.png)
**A Python library to make working with geospatial data of Morocco easier.**
- GitHub repo: <https://github.com/AmineAndam04/geomaroc>
- PyPI: <https://pypi.org/project/geomaroc/>
- Raw data: <https://github.com/AmineAndam04/geomaroc-Raw-data>
- R version: https://github.com/AmineAndam04/R-geomaroc
- CRAN: https://CRAN.R-project.org/package=geomaroc
## Introduction
People who work in data science are seeing increased need to work with geospatial data, especially for visualization purposes (e.g. during the covid-19 pandemic).Geopandas is a very popular geospatial library in python that extends Pandas to allow spatial operations on geometrics types.
Working with geopands requires having access to coordinates of the items of our map (polygon coordinates), but having accesss to those coordinates is not an easy task.In fact, we often need the shapefiles in order to plot a map. Trying to find those shapefiles can be a long journey, especailly for someone with zero experience with geospatial data. Moreover, for someone interested in the geospatial data of Morocco, the majority of shapefiles available online are either of very poor quality, or they don't provide province-level,prefectue-level or district-level coordinates.Even if we manage to find the appropriate shapefiles, they usually come without the southern regions of Morocco.
**Geomaroc** helps the user get those coordinates easly.This library aims to fix these problem by:
1. providing methods to automatically get the boundary coordinates to plot maps of Morocco **without having acces to shapefiles.**
2. providing access to the coordinates of low-level administrative subdivisions (e.g. province, prefecture, districs).
3. providing access to the complete map of Morocco (including the southern regions of Morocco)
**illustration:**
To generate those plots go to [Gallery](https://github.com/AmineAndam04/geomaroc/tree/main/geomaroc)
![pic2](https://user-images.githubusercontent.com/49843367/164767535-ed77f71a-6610-4abc-a9f9-bb5c54ed4890.png)
## Requirements
geomaroc library needs the following packages :**pandas**, **geopandas**, **shapely**, **json** and **importlib**.
## Install
```python
pip install geomaroc
import geomaroc
```
## Usage
- getRegion() :Helps to plot the shape of each region.
```python
import geomaroc
## working with n_region
gp=geomaroc.getRegion("Casablanca-Settat")
gp.plot()
## working with id_region
gp=geomaroc.getRegion(id_region=6) # Attention!! don't write geomaroc.getRegion(6)
gp.plot()
```
- getMultiRegion() :Helps to plot the shape of multiple regions.
```python
import geomaroc
## working with n_region
gp=geomaroc.getMultiRegion(["Casablanca-Settat",Draa-Tafilalet])
gp.plot()
## working with id_region
gp=geomaroc.getMultiRegion(id_region=[6,8])
gp.plot()
```
- getProvince() :Helps to plot the shape of provinces within a region.
```python
import geomaroc
## working with n_region
gp=geomaroc.getProvince("Casablanca-Settat")
gp.plot()
## working with id_region
gp=geomaroc.getProvince(id_region=6)
gp.plot()
```
- getMultiProvince(): Helps to plot the shape of provinces in multiple regions.
```python
import geomaroc
## working with n_region
gp=geomaroc.getMultiProvince(["Casablanca-Settat",Draa-Tafilalet])
gp.plot()
## working with id_region
gp=geomaroc.getMultiProvince(id_region=[6,8])
gp.plot()
```
- getDistrict(): Helps to plot the shape of districts within a province.
```python
import geomaroc
## working with n_province
geomaroc.getDistrict("Tetouan")
gp.plot()
## working with id_province
gp=geomaroc.getProvince(id_region=571)
gp.plot()
```
- getMultiDistrict(): Helps to plot the shape of districts in multiple provinces.
```python
import geomaroc
## working with n_province
gp=geomaroc.gp=geomaroc.getMultiDistrict(["Tetouan","Tanger-Assilah","Al-Hoceima"])
gp.plot()
## working with id_province
gp=geomaroc.geomaroc.getProvince(id_region=[571,51,511])
gp.plot()
```
- Regions() & Provinces() : Hepls to respect the notation and to get the id of each region and province
## Notation
We adpoted this methode to work with names and id of regions,provinces and districts :
- replace "é" with "e"
- replace "è" with "e"
- replace " " with "-"
- replace "â" with "a"
-
So "Tanger-Tétouan-Al Hoceima" becomes "Tanger-Tetouan-Al-Hoceima" and "Drâa-Tafilalet" becomes "Drâa-Tafilalet"
Use geomaroc.Regions() and geomaroc.Provinces() to check the notations:
```python
region=geomaroc.Regions()
region
```
```{r, engine='python', count_lines}
{'Beni-Mellal-Khenifra': 5,
'Casablanca-Settat': 6,
'Draa-Tafilalet': 8,
'Eddakhla-Oued-Eddahab': 12,
'Fes-Meknes': 3,
'Guelmim-Oued-Noun': 10,
'Laayoune-Sakia-El-Hamra': 11,
'Marrakech-Safi': 7,
'Oriental': 2,
'Rabat-Sale-Kenitra': 4,
'Souss-Massa': 9,
'Tanger-Tetouan-Al-Hoceima': 1}
```
```python
import pandas as pd
provinces=geomaroc.Provinces()
province=pd.DataFrame(columns=["Region","Id_region","Province","Id_province"])
for i in range(len(provinces.keys())):
for j in range(len(provinces[list(provinces.keys())[i]])):
reg=list(provinces.keys())[i]
prov=list(provinces[reg].keys())[j]
province=province.append({"Region":reg,"Id_region":region[reg],"Province":prov,"Id_province":provinces[reg][prov]},ignore_index=True)
province
```
```{r, engine='python', count_lines}
Region Id_region Province Id_province
0 Beni-Mellal-Khenifra 5 Khouribga 311
1 Beni-Mellal-Khenifra 5 Khenifra 301
2 Beni-Mellal-Khenifra 5 Azilal 81
3 Beni-Mellal-Khenifra 5 Beni-Mellal 91
4 Beni-Mellal-Khenifra 5 Fquih-Ben-Salah 255
... ... ... ... ...
70 Tanger-Tetouan-Al-Hoceima 1 Mdiq-Fnidq 573
71 Tanger-Tetouan-Al-Hoceima 1 Ouezzane 405
72 Tanger-Tetouan-Al-Hoceima 1 Tanger-Assilah 511
73 Tanger-Tetouan-Al-Hoceima 1 Tetouan 571
74 Tanger-Tetouan-Al-Hoceima 1 Al-Hoceima 51
```
## Raw data
Visit [geomaroc raw data](https://github.com/AmineAndam04/geomaroc-Raw-data)
## gallery
![pic2](https://user-images.githubusercontent.com/49843367/164767535-ed77f71a-6610-4abc-a9f9-bb5c54ed4890.png)
![pic3](https://user-images.githubusercontent.com/49843367/164767545-31ebbdd9-49ff-472e-a396-7e94c2964547.png)
![pic4](https://user-images.githubusercontent.com/49843367/164767547-4e9f179e-1e8b-4478-b099-ff9d93d92b2c.png)
![pic5](https://user-images.githubusercontent.com/49843367/164767553-00114d1f-17d5-4b1e-994b-0d7f9642235e.png)
![pic1](https://user-images.githubusercontent.com/49843367/164767555-e9acaa22-9891-40c2-a7b3-37726c985746.png)
Raw data
{
"_id": null,
"home_page": "https://github.com/AmineAndam04/geomaroc",
"name": "geomaroc",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "geospatial,data visualization,Morocco,data-science,maps",
"author": "ANDAM Amine",
"author_email": "andamamine83@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ed/24/f56c27b47b1c264cbe73f452556a3d779c0fcfa42c94592d8d8cd731642c/geomaroc-1.0.3.tar.gz",
"platform": null,
"description": "# Welcome to geomaroc\r\n\r\n![geomaroc_logo](https://user-images.githubusercontent.com/49843367/164335838-537f0514-ce89-43ed-956f-c6c6de6ed264.png)\r\n\r\n\r\n**A Python library to make working with geospatial data of Morocco easier.**\r\n\r\n- GitHub repo: <https://github.com/AmineAndam04/geomaroc>\r\n- PyPI: <https://pypi.org/project/geomaroc/>\r\n- Raw data: <https://github.com/AmineAndam04/geomaroc-Raw-data>\r\n- R version: https://github.com/AmineAndam04/R-geomaroc\r\n- CRAN: https://CRAN.R-project.org/package=geomaroc\r\n## Introduction\r\n\r\nPeople who work in data science are seeing increased need to work with geospatial data, especially for visualization purposes (e.g. during the covid-19 pandemic).Geopandas is a very popular geospatial library in python that extends Pandas to allow spatial operations on geometrics types.\r\n\r\nWorking with geopands requires having access to coordinates of the items of our map (polygon coordinates), but having accesss to those coordinates is not an easy task.In fact, we often need the shapefiles in order to plot a map. Trying to find those shapefiles can be a long journey, especailly for someone with zero experience with geospatial data. Moreover, for someone interested in the geospatial data of Morocco, the majority of shapefiles available online are either of very poor quality, or they don't provide province-level,prefectue-level or district-level coordinates.Even if we manage to find the appropriate shapefiles, they usually come without the southern regions of Morocco.\r\n\r\n**Geomaroc** helps the user get those coordinates easly.This library aims to fix these problem by:\r\n\r\n 1. providing methods to automatically get the boundary coordinates to plot maps of Morocco **without having acces to shapefiles.**\r\n \r\n 2. providing access to the coordinates of low-level administrative subdivisions (e.g. province, prefecture, districs).\r\n \r\n 3. providing access to the complete map of Morocco (including the southern regions of Morocco)\r\n\r\n**illustration:**\r\n\r\nTo generate those plots go to [Gallery](https://github.com/AmineAndam04/geomaroc/tree/main/geomaroc)\r\n\r\n![pic2](https://user-images.githubusercontent.com/49843367/164767535-ed77f71a-6610-4abc-a9f9-bb5c54ed4890.png)\r\n\r\n\r\n## Requirements\r\ngeomaroc library needs the following packages :**pandas**, **geopandas**, **shapely**, **json** and **importlib**.\r\n## Install\r\n```python\r\npip install geomaroc\r\nimport geomaroc \r\n```\r\n## Usage\r\n- getRegion() :Helps to plot the shape of each region.\r\n```python\r\nimport geomaroc\r\n## working with n_region\r\ngp=geomaroc.getRegion(\"Casablanca-Settat\")\r\ngp.plot()\r\n## working with id_region\r\ngp=geomaroc.getRegion(id_region=6) # Attention!! don't write geomaroc.getRegion(6)\r\ngp.plot()\r\n```\r\n\r\n- getMultiRegion() :Helps to plot the shape of multiple regions.\r\n```python\r\nimport geomaroc\r\n## working with n_region\r\ngp=geomaroc.getMultiRegion([\"Casablanca-Settat\",Draa-Tafilalet])\r\ngp.plot()\r\n## working with id_region\r\ngp=geomaroc.getMultiRegion(id_region=[6,8]) \r\ngp.plot()\r\n```\r\n- getProvince() :Helps to plot the shape of provinces within a region.\r\n```python\r\nimport geomaroc\r\n## working with n_region\r\ngp=geomaroc.getProvince(\"Casablanca-Settat\")\r\ngp.plot()\r\n## working with id_region\r\ngp=geomaroc.getProvince(id_region=6)\r\ngp.plot()\r\n```\r\n- getMultiProvince(): Helps to plot the shape of provinces in multiple regions.\r\n```python\r\nimport geomaroc\r\n## working with n_region\r\ngp=geomaroc.getMultiProvince([\"Casablanca-Settat\",Draa-Tafilalet])\r\ngp.plot()\r\n## working with id_region\r\ngp=geomaroc.getMultiProvince(id_region=[6,8])\r\ngp.plot()\r\n```\r\n- getDistrict(): Helps to plot the shape of districts within a province.\r\n```python\r\nimport geomaroc\r\n## working with n_province\r\ngeomaroc.getDistrict(\"Tetouan\")\r\ngp.plot()\r\n## working with id_province\r\ngp=geomaroc.getProvince(id_region=571)\r\ngp.plot()\r\n```\r\n- getMultiDistrict(): Helps to plot the shape of districts in multiple provinces.\r\n```python\r\nimport geomaroc\r\n## working with n_province\r\ngp=geomaroc.gp=geomaroc.getMultiDistrict([\"Tetouan\",\"Tanger-Assilah\",\"Al-Hoceima\"])\r\ngp.plot()\r\n## working with id_province\r\ngp=geomaroc.geomaroc.getProvince(id_region=[571,51,511])\r\ngp.plot()\r\n```\r\n- Regions() & Provinces() : Hepls to respect the notation and to get the id of each region and province\r\n\r\n## Notation \r\nWe adpoted this methode to work with names and id of regions,provinces and districts :\r\n- replace \"\u00e9\" with \"e\"\r\n- replace \"\u00e8\" with \"e\"\r\n- replace \" \" with \"-\"\r\n- replace \"\u00e2\" with \"a\"\r\n- \r\nSo \"Tanger-T\u00e9touan-Al Hoceima\" becomes \"Tanger-Tetouan-Al-Hoceima\" and \"Dr\u00e2a-Tafilalet\" becomes \"Dr\u00e2a-Tafilalet\"\r\n\r\nUse geomaroc.Regions() and geomaroc.Provinces() to check the notations:\r\n```python\r\nregion=geomaroc.Regions()\r\nregion\r\n```\r\n\r\n```{r, engine='python', count_lines}\r\n{'Beni-Mellal-Khenifra': 5,\r\n 'Casablanca-Settat': 6,\r\n 'Draa-Tafilalet': 8,\r\n 'Eddakhla-Oued-Eddahab': 12,\r\n 'Fes-Meknes': 3,\r\n 'Guelmim-Oued-Noun': 10,\r\n 'Laayoune-Sakia-El-Hamra': 11,\r\n 'Marrakech-Safi': 7,\r\n 'Oriental': 2,\r\n 'Rabat-Sale-Kenitra': 4,\r\n 'Souss-Massa': 9,\r\n 'Tanger-Tetouan-Al-Hoceima': 1}\r\n \r\n ```\r\n ```python\r\n import pandas as pd\r\nprovinces=geomaroc.Provinces()\r\nprovince=pd.DataFrame(columns=[\"Region\",\"Id_region\",\"Province\",\"Id_province\"])\r\nfor i in range(len(provinces.keys())):\r\n for j in range(len(provinces[list(provinces.keys())[i]])):\r\n reg=list(provinces.keys())[i]\r\n prov=list(provinces[reg].keys())[j]\r\n province=province.append({\"Region\":reg,\"Id_region\":region[reg],\"Province\":prov,\"Id_province\":provinces[reg][prov]},ignore_index=True)\r\nprovince\r\n```\r\n\r\n```{r, engine='python', count_lines}\r\n\tRegion\t Id_region\tProvince\tId_province\r\n0\tBeni-Mellal-Khenifra\t 5\t Khouribga\t 311\r\n1\tBeni-Mellal-Khenifra\t 5\t Khenifra\t 301\r\n2\tBeni-Mellal-Khenifra\t 5\t Azilal\t 81\r\n3\tBeni-Mellal-Khenifra\t 5\t Beni-Mellal\t 91\r\n4\tBeni-Mellal-Khenifra\t 5\t Fquih-Ben-Salah 255\r\n...\t...\t...\t...\t...\r\n70\tTanger-Tetouan-Al-Hoceima\t1\t Mdiq-Fnidq\t 573\r\n71\tTanger-Tetouan-Al-Hoceima\t1\t Ouezzane\t 405\r\n72\tTanger-Tetouan-Al-Hoceima\t1\t Tanger-Assilah\t 511\r\n73\tTanger-Tetouan-Al-Hoceima\t1\t Tetouan\t 571\r\n74\tTanger-Tetouan-Al-Hoceima\t1\t Al-Hoceima\t 51\r\n ``` \r\n\r\n## Raw data\r\nVisit [geomaroc raw data](https://github.com/AmineAndam04/geomaroc-Raw-data)\r\n## gallery\r\n\r\n![pic2](https://user-images.githubusercontent.com/49843367/164767535-ed77f71a-6610-4abc-a9f9-bb5c54ed4890.png)\r\n![pic3](https://user-images.githubusercontent.com/49843367/164767545-31ebbdd9-49ff-472e-a396-7e94c2964547.png)\r\n![pic4](https://user-images.githubusercontent.com/49843367/164767547-4e9f179e-1e8b-4478-b099-ff9d93d92b2c.png)\r\n![pic5](https://user-images.githubusercontent.com/49843367/164767553-00114d1f-17d5-4b1e-994b-0d7f9642235e.png)\r\n![pic1](https://user-images.githubusercontent.com/49843367/164767555-e9acaa22-9891-40c2-a7b3-37726c985746.png)\r\n",
"bugtrack_url": null,
"license": "",
"summary": "A Python library to easily visualize geospatial data of Morocco.",
"version": "1.0.3",
"split_keywords": [
"geospatial",
"data visualization",
"morocco",
"data-science",
"maps"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "78082c7de5de5e2f93ac6c3ca43768ea1e68863398edb01da9f25887d659b0c9",
"md5": "c1d8a487690e09a67720e0793e3df217",
"sha256": "30ecbfd9e1d46c5f50a91e5509c16f37cf0bf10cdf34b80309bf2f49f25f9921"
},
"downloads": -1,
"filename": "geomaroc-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1d8a487690e09a67720e0793e3df217",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 12329133,
"upload_time": "2023-04-26T20:38:20",
"upload_time_iso_8601": "2023-04-26T20:38:20.457528Z",
"url": "https://files.pythonhosted.org/packages/78/08/2c7de5de5e2f93ac6c3ca43768ea1e68863398edb01da9f25887d659b0c9/geomaroc-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ed24f56c27b47b1c264cbe73f452556a3d779c0fcfa42c94592d8d8cd731642c",
"md5": "ceb98365e4ec5367c3690a47ea21859d",
"sha256": "f3ae67c2645db9e1487145118afc0d702669fc0f6c95c568358f394f3dc02606"
},
"downloads": -1,
"filename": "geomaroc-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "ceb98365e4ec5367c3690a47ea21859d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 12304595,
"upload_time": "2023-04-26T20:38:24",
"upload_time_iso_8601": "2023-04-26T20:38:24.450122Z",
"url": "https://files.pythonhosted.org/packages/ed/24/f56c27b47b1c264cbe73f452556a3d779c0fcfa42c94592d8d8cd731642c/geomaroc-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-26 20:38:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "AmineAndam04",
"github_project": "geomaroc",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "geomaroc"
}