tunned-geobr 0.1.2__py3-none-any.whl → 0.2.1__py3-none-any.whl

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.
Files changed (44) hide show
  1. tunned_geobr/__init__.py +34 -2
  2. tunned_geobr/list_geobr.py +112 -34
  3. tunned_geobr/read_apcb_amazon.py +78 -0
  4. tunned_geobr/read_apcb_caatinga.py +78 -0
  5. tunned_geobr/read_apcb_cerrado_pantanal.py +78 -0
  6. tunned_geobr/read_apcb_mata_atlantica.py +78 -0
  7. tunned_geobr/read_apcb_pampa.py +78 -0
  8. tunned_geobr/read_apcb_zcm.py +78 -0
  9. tunned_geobr/read_archaeological_sites.py +94 -0
  10. tunned_geobr/read_atlantic_forest_law_limits.py +74 -0
  11. tunned_geobr/read_baze_sites.py +155 -0
  12. tunned_geobr/read_biosphere_reserves.py +85 -0
  13. tunned_geobr/read_cave_potential.py +79 -0
  14. tunned_geobr/read_census_tract_2022.py +101 -0
  15. tunned_geobr/read_ebas.py +80 -0
  16. tunned_geobr/read_federal_highways.py +79 -0
  17. tunned_geobr/read_fossil_occurrences.py +94 -0
  18. tunned_geobr/read_geographic_regions.py +88 -0
  19. tunned_geobr/read_heliports.py +81 -0
  20. tunned_geobr/read_municipality_direct.py +127 -0
  21. tunned_geobr/read_natural_caves.py +83 -0
  22. tunned_geobr/read_neighborhoods_2022.py +99 -0
  23. tunned_geobr/read_pan_strategic_areas.py +89 -0
  24. tunned_geobr/read_ports.py +80 -0
  25. tunned_geobr/read_private_aerodromes.py +81 -0
  26. tunned_geobr/read_public_aerodromes.py +81 -0
  27. tunned_geobr/read_quilombola_areas.py +85 -0
  28. tunned_geobr/read_quilombola_areas_temp.py +103 -0
  29. tunned_geobr/read_railways.py +80 -0
  30. tunned_geobr/read_rppn.py +107 -0
  31. tunned_geobr/read_sigef_properties.py +83 -0
  32. tunned_geobr/read_snci_properties.py +83 -0
  33. tunned_geobr/read_state_direct.py +103 -0
  34. tunned_geobr/read_state_highways.py +79 -0
  35. tunned_geobr/read_transmission_lines_ons.py +87 -0
  36. tunned_geobr/read_vegetation.py +84 -0
  37. tunned_geobr/read_water_bodies_ana.py +87 -0
  38. tunned_geobr/read_waterways.py +80 -0
  39. {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.1.dist-info}/METADATA +35 -3
  40. tunned_geobr-0.2.1.dist-info/RECORD +82 -0
  41. tunned_geobr-0.1.2.dist-info/RECORD +0 -46
  42. {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.1.dist-info}/WHEEL +0 -0
  43. {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.1.dist-info}/entry_points.txt +0 -0
  44. {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.1.dist-info}/licenses/LICENSE.txt +0 -0
tunned_geobr/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from .read_state import read_state
1
+ from .read_state_direct import read_state
2
2
  from .read_amazon import read_amazon
3
3
  from .read_biomes import read_biomes
4
4
  from .read_country import read_country
@@ -16,7 +16,7 @@ from .list_geobr import list_geobr
16
16
  from .read_census_tract import read_census_tract
17
17
  from .read_meso_region import read_meso_region
18
18
  from .read_micro_region import read_micro_region
19
- from .read_municipality import read_municipality
19
+ from .read_municipality_direct import read_municipality
20
20
  from .read_weighting_area import read_weighting_area
21
21
  from .read_neighborhood import read_neighborhood
22
22
  from .read_health_region import read_health_region
@@ -36,3 +36,35 @@ from .read_climate_aggressiveness import read_climate_aggressiveness
36
36
  from .read_amazon_ibas import read_amazon_ibas
37
37
  from .read_atlantic_forest_ibas import read_atlantic_forest_ibas
38
38
  from .read_settlements import read_settlements
39
+ from .read_apcb_amazon import read_apcb_amazon
40
+ from .read_apcb_caatinga import read_apcb_caatinga
41
+ from .read_apcb_cerrado_pantanal import read_apcb_cerrado_pantanal
42
+ from .read_apcb_mata_atlantica import read_apcb_mata_atlantica
43
+ from .read_apcb_pampa import read_apcb_pampa
44
+ from .read_apcb_zcm import read_apcb_zcm
45
+ from .read_natural_caves import read_natural_caves
46
+ from .read_ports import read_ports
47
+ from .read_public_aerodromes import read_public_aerodromes
48
+ from .read_private_aerodromes import read_private_aerodromes
49
+ from .read_state_highways import read_state_highways
50
+ from .read_federal_highways import read_federal_highways
51
+ from .read_railways import read_railways
52
+ from .read_waterways import read_waterways
53
+ from .read_heliports import read_heliports
54
+ from .read_snci_properties import read_snci_properties
55
+ from .read_sigef_properties import read_sigef_properties
56
+ from .read_atlantic_forest_law_limits import read_atlantic_forest_law_limits
57
+ from .read_fossil_occurrences import read_fossil_occurrences
58
+ from .read_cave_potential import read_cave_potential
59
+ from .read_rppn import read_rppn
60
+ from .read_archaeological_sites import read_archaeological_sites
61
+ from .read_ebas import read_ebas
62
+ from .read_vegetation import read_vegetation
63
+ from .read_transmission_lines_ons import read_transmission_lines_ons
64
+ from .read_water_bodies_ana import read_water_bodies_ana
65
+ from .read_pan_strategic_areas import read_pan_strategic_areas
66
+ from .read_geographic_regions import read_geographic_regions
67
+ from .read_biosphere_reserves import read_biosphere_reserves
68
+ from .read_census_tract_2022 import read_census_tract_2022
69
+ from .read_neighborhoods_2022 import read_neighborhoods_2022
70
+ from .read_baze_sites import read_baze_sites
@@ -1,39 +1,117 @@
1
- from requests import get
2
1
  import pandas as pd
3
- from io import StringIO
4
- from urllib.error import HTTPError
5
- import re
2
+ from tabulate import tabulate
6
3
 
7
4
  def list_geobr():
8
- """Prints available functions, according to latest README.md file
9
-
10
- Example output
11
- ------------------------------
12
- Function: read_immediate_region
13
- Geographies available: Immediate region
14
- Years available: 2017
15
- Source: IBGE
16
- ------------------------------
17
-
5
+ """Lists all available datasets in the tunned_geobr package.
6
+
7
+ This function displays a comprehensive table of all geographic datasets
8
+ available in the tunned_geobr package, including information about the
9
+ geographies, years, and sources.
10
+
11
+ Returns
12
+ -------
13
+ pandas.DataFrame
14
+ A DataFrame containing information about all available datasets
15
+
16
+ Example
17
+ -------
18
+ >>> from tunned_geobr import list_geobr
19
+ >>> datasets = list_geobr()
18
20
  """
21
+
22
+ # Create a comprehensive list of all datasets
23
+ datasets = [
24
+ # Original geobr datasets
25
+ {"Function": "read_country", "Geography": "Country", "Years": "All", "Source": "IBGE"},
26
+ {"Function": "read_region", "Geography": "Region", "Years": "All", "Source": "IBGE"},
27
+ {"Function": "read_state", "Geography": "State", "Years": "All", "Source": "IBGE"},
28
+ {"Function": "read_state_direct", "Geography": "State (direct)", "Years": "All", "Source": "IBGE"},
29
+ {"Function": "read_meso_region", "Geography": "Meso region", "Years": "1991, 2000, 2010, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020", "Source": "IBGE"},
30
+ {"Function": "read_micro_region", "Geography": "Micro region", "Years": "1991, 2000, 2010, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020", "Source": "IBGE"},
31
+ {"Function": "read_immediate_region", "Geography": "Immediate region", "Years": "2017, 2019, 2020", "Source": "IBGE"},
32
+ {"Function": "read_intermediate_region", "Geography": "Intermediate region", "Years": "2017, 2019, 2020", "Source": "IBGE"},
33
+ {"Function": "read_municipality", "Geography": "Municipality", "Years": "All", "Source": "IBGE"},
34
+ {"Function": "read_municipality_direct", "Geography": "Municipality (direct)", "Years": "All", "Source": "IBGE"},
35
+ {"Function": "read_weighting_area", "Geography": "Census weighting area", "Years": "2010", "Source": "IBGE"},
36
+ {"Function": "read_census_tract", "Geography": "Census tract", "Years": "2000, 2010", "Source": "IBGE"},
37
+ {"Function": "read_census_tract_2022", "Geography": "Census tract 2022", "Years": "2022", "Source": "IBGE"},
38
+ {"Function": "read_statistical_grid", "Geography": "Statistical grid", "Years": "2010", "Source": "IBGE"},
39
+ {"Function": "read_comparable_areas", "Geography": "Comparable areas", "Years": "1872, 1900, 1911, 1920, 1933, 1940, 1950, 1960, 1970, 1980, 1991, 2000, 2010", "Source": "IBGE"},
40
+ {"Function": "read_health_region", "Geography": "Health region", "Years": "1991, 1994, 1997, 2001, 2005, 2013", "Source": "DataSUS"},
41
+ {"Function": "read_metro_area", "Geography": "Metropolitan area", "Years": "All", "Source": "IBGE"},
42
+ {"Function": "read_urban_area", "Geography": "Urban area", "Years": "2005, 2015", "Source": "IBGE"},
43
+ {"Function": "read_urban_concentrations", "Geography": "Urban concentrations", "Years": "All", "Source": "IBGE"},
44
+ {"Function": "read_amazon", "Geography": "Amazon", "Years": "All", "Source": "IBGE, MMA, and others"},
45
+ {"Function": "read_biomes", "Geography": "Biomes", "Years": "2004, 2019", "Source": "IBGE"},
46
+ {"Function": "read_conservation_units", "Geography": "Conservation units", "Years": "All", "Source": "MMA"},
47
+ {"Function": "read_disaster_risk_area", "Geography": "Disaster risk areas", "Years": "2010", "Source": "CEMADEN and IBGE"},
48
+ {"Function": "read_indigenous_land", "Geography": "Indigenous lands", "Years": "All", "Source": "FUNAI"},
49
+ {"Function": "read_semiarid", "Geography": "Semi-arid region", "Years": "All", "Source": "IBGE and others"},
50
+ {"Function": "read_health_facilities", "Geography": "Health facilities", "Years": "All", "Source": "DataSUS"},
51
+ {"Function": "read_neighborhood", "Geography": "Neighborhood", "Years": "2010", "Source": "IBGE"},
52
+ {"Function": "read_neighborhoods_2022", "Geography": "Neighborhoods 2022", "Years": "2022", "Source": "IBGE"},
53
+ {"Function": "read_schools", "Geography": "Schools", "Years": "All", "Source": "INEP"},
54
+ {"Function": "read_ports", "Geography": "Ports", "Years": "All", "Source": "Ministério da Infraestrutura"},
55
+ {"Function": "read_municipal_seat", "Geography": "Municipal seats", "Years": "All", "Source": "IBGE"},
56
+ {"Function": "read_pop_arrangements", "Geography": "Population arrangements", "Years": "2015", "Source": "IBGE"},
57
+ {"Function": "read_rppn", "Geography": "Private Natural Heritage Reserves", "Years": "All", "Source": "ICMBio"},
58
+ {"Function": "read_settlements", "Geography": "Rural settlements", "Years": "All", "Source": "INCRA"},
59
+
60
+ # Additional datasets in tunned_geobr
61
+ {"Function": "read_mining_processes", "Geography": "Mining processes", "Years": "All", "Source": "ANM"},
62
+ {"Function": "read_ebas", "Geography": "Endemic Bird Areas", "Years": "All", "Source": "Global Forest Watch"},
63
+ {"Function": "read_vegetation", "Geography": "Brazilian Vegetation", "Years": "All", "Source": "IBGE"},
64
+ {"Function": "read_transmission_lines_ons", "Geography": "Transmission Lines", "Years": "All", "Source": "ONS"},
65
+ {"Function": "read_water_bodies_ana", "Geography": "Water Bodies", "Years": "All", "Source": "ANA"},
66
+ {"Function": "read_pan_strategic_areas", "Geography": "PAN Strategic Areas", "Years": "All", "Source": "ICMBio"},
67
+ {"Function": "read_geographic_regions", "Geography": "Geographic Regions", "Years": "All", "Source": "IBGE"},
68
+ {"Function": "read_biosphere_reserves", "Geography": "Biosphere Reserves", "Years": "All", "Source": "MMA"},
69
+ {"Function": "read_baze_sites", "Geography": "BAZE Sites", "Years": "2018", "Source": "MMA"},
70
+
71
+ # Environmental and conservation datasets
72
+ {"Function": "read_amazon_ibas", "Geography": "Amazon IBAs", "Years": "All", "Source": "SAVE Brasil"},
73
+ {"Function": "read_atlantic_forest_ibas", "Geography": "Atlantic Forest IBAs", "Years": "All", "Source": "SAVE Brasil"},
74
+ {"Function": "read_atlantic_forest_law_limits", "Geography": "Atlantic Forest Law Limits", "Years": "All", "Source": "MMA/IBGE"},
75
+ {"Function": "read_apcb_amazon", "Geography": "APCB Amazon", "Years": "All", "Source": "MMA"},
76
+ {"Function": "read_apcb_caatinga", "Geography": "APCB Caatinga", "Years": "All", "Source": "MMA"},
77
+ {"Function": "read_apcb_cerrado_pantanal", "Geography": "APCB Cerrado/Pantanal", "Years": "All", "Source": "MMA"},
78
+ {"Function": "read_apcb_mata_atlantica", "Geography": "APCB Atlantic Forest", "Years": "All", "Source": "MMA"},
79
+ {"Function": "read_apcb_pampa", "Geography": "APCB Pampa", "Years": "All", "Source": "MMA"},
80
+ {"Function": "read_apcb_zcm", "Geography": "APCB Coastal/Marine", "Years": "All", "Source": "MMA"},
81
+
82
+ # Geological and natural features datasets
83
+ {"Function": "read_natural_caves", "Geography": "Natural Caves", "Years": "All", "Source": "ICMBio"},
84
+ {"Function": "read_cave_potential", "Geography": "Cave Potential", "Years": "All", "Source": "ICMBio"},
85
+ {"Function": "read_fossil_occurrences", "Geography": "Fossil Occurrences", "Years": "All", "Source": "SGB"},
86
+ {"Function": "read_archaeological_sites", "Geography": "Archaeological Sites", "Years": "All", "Source": "IPHAN"},
87
+ {"Function": "read_geology", "Geography": "Geology", "Years": "All", "Source": "CPRM"},
88
+ {"Function": "read_geomorphology", "Geography": "Geomorphology", "Years": "All", "Source": "IBGE"},
89
+ {"Function": "read_pedology", "Geography": "Pedology", "Years": "All", "Source": "IBGE"},
90
+ {"Function": "read_climate_aggressiveness", "Geography": "Climate Aggressiveness", "Years": "All", "Source": "IBGE"},
91
+
92
+ # Transportation and infrastructure datasets
93
+ {"Function": "read_public_aerodromes", "Geography": "Public Aerodromes", "Years": "All", "Source": "MapBiomas"},
94
+ {"Function": "read_private_aerodromes", "Geography": "Private Aerodromes", "Years": "All", "Source": "MapBiomas"},
95
+ {"Function": "read_state_highways", "Geography": "State Highways", "Years": "All", "Source": "MapBiomas"},
96
+ {"Function": "read_federal_highways", "Geography": "Federal Highways", "Years": "All", "Source": "MapBiomas"},
97
+ {"Function": "read_railways", "Geography": "Railways", "Years": "All", "Source": "MapBiomas"},
98
+ {"Function": "read_waterways", "Geography": "Waterways", "Years": "All", "Source": "SNIRH"},
99
+ {"Function": "read_heliports", "Geography": "Heliports", "Years": "All", "Source": "MapBiomas"},
100
+
101
+ # Land tenure and property datasets
102
+ {"Function": "read_snci_properties", "Geography": "SNCI Properties", "Years": "All", "Source": "INCRA"},
103
+ {"Function": "read_sigef_properties", "Geography": "SIGEF Properties", "Years": "All", "Source": "INCRA"},
104
+ {"Function": "read_quilombola_areas", "Geography": "Quilombola Areas", "Years": "All", "Source": "INCRA"}
105
+ ]
106
+
107
+ # Create DataFrame
108
+ df = pd.DataFrame(datasets)
109
+
110
+ # Display the table
111
+ print(tabulate(df, headers='keys', tablefmt='psql', showindex=False))
112
+
113
+ # Return the DataFrame for further use
114
+ return df
19
115
 
20
- try:
21
- html_data = get("https://github.com/ipeaGIT/geobr/blob/master/README.md").text
22
- find_emoji = html_data.index("👉")
23
- html_data = html_data[find_emoji:]
24
- escaped_data = html_data.replace("\\u003c", "<").replace("\\u003e", ">")
25
- tables = re.findall("<table>(.+?)</table>", escaped_data)
26
- available_datasets = "<table>" + tables[0].replace("\\n", "") + "</table>"
27
- df = pd.DataFrame(pd.read_html(StringIO(available_datasets))[0])
28
-
29
- except HTTPError:
30
- print(
31
- "Geobr url functions list is broken"
32
- 'Please report an issue at "https://github.com/ipeaGIT/geobr/issues"'
33
- )
34
-
35
- for i in range(len(df)):
36
- for each in df.columns:
37
- print(f"{each}: {df.loc[i, each]}")
38
-
39
- print("------------------------------")
116
+ if __name__ == "__main__":
117
+ list_geobr()
@@ -0,0 +1,78 @@
1
+ import geopandas as gpd
2
+ import tempfile
3
+ import os
4
+ import requests
5
+ from zipfile import ZipFile
6
+ from io import BytesIO
7
+
8
+ def read_apcb_amazon(simplified=False):
9
+ """Download Priority Areas for Biodiversity Conservation (APCB) data for the Amazon region.
10
+
11
+ This function downloads and processes APCB data from the Ministry of Environment (MMA).
12
+ The data includes priority areas for biodiversity conservation in the Amazon region.
13
+ Original source: Ministério do Meio Ambiente (MMA)
14
+
15
+ Parameters
16
+ ----------
17
+ simplified : boolean, by default False
18
+ If True, returns a simplified version of the dataset with fewer columns
19
+
20
+ Returns
21
+ -------
22
+ gpd.GeoDataFrame
23
+ Geodataframe with Amazon APCB data
24
+
25
+ Example
26
+ -------
27
+ >>> from tunned_geobr import read_apcb_amazonia
28
+
29
+ # Read Amazon APCB data
30
+ >>> apcb = read_apcb_amazonia()
31
+ """
32
+
33
+ url = "https://www.gov.br/mma/pt-br/assuntos/biodiversidade-e-biomas/biomas-e-ecossistemas/conservacao-1/areas-prioritarias/arquivos/amazonia.zip"
34
+
35
+ try:
36
+ # Download the zip file
37
+ response = requests.get(url)
38
+ if response.status_code != 200:
39
+ raise Exception("Failed to download data from MMA")
40
+
41
+ # Create a temporary directory
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ # Extract the zip file
44
+ with ZipFile(BytesIO(response.content)) as zip_ref:
45
+ zip_ref.extractall(temp_dir)
46
+
47
+ # Find the shapefile
48
+ shp_files = []
49
+ for root, dirs, files in os.walk(temp_dir):
50
+ shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
51
+
52
+ if not shp_files:
53
+ raise Exception("No shapefile found in the downloaded data")
54
+
55
+ # Read the shapefile
56
+ gdf = gpd.read_file(shp_files[0])
57
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
58
+
59
+ if simplified:
60
+ # Keep only the most relevant columns
61
+ columns_to_keep = [
62
+ 'geometry',
63
+ 'Nome', # Area name
64
+ 'Importanci', # Importance
65
+ 'Prioridade', # Priority
66
+ 'Area_km2', # Area in km²
67
+ 'Oportunida', # Opportunity
68
+ 'Ameaca' # Threats
69
+ ]
70
+
71
+ # Filter columns that actually exist in the dataset
72
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
73
+ gdf = gdf[existing_columns]
74
+
75
+ except Exception as e:
76
+ raise Exception(f"Error downloading Amazon APCB data: {str(e)}")
77
+
78
+ return gdf
@@ -0,0 +1,78 @@
1
+ import geopandas as gpd
2
+ import tempfile
3
+ import os
4
+ import requests
5
+ from zipfile import ZipFile
6
+ from io import BytesIO
7
+
8
+ def read_apcb_caatinga(simplified=False):
9
+ """Download Priority Areas for Biodiversity Conservation (APCB) data for the Caatinga region.
10
+
11
+ This function downloads and processes APCB data from the Ministry of Environment (MMA).
12
+ The data includes priority areas for biodiversity conservation in the Caatinga region.
13
+ Original source: Ministério do Meio Ambiente (MMA)
14
+
15
+ Parameters
16
+ ----------
17
+ simplified : boolean, by default False
18
+ If True, returns a simplified version of the dataset with fewer columns
19
+
20
+ Returns
21
+ -------
22
+ gpd.GeoDataFrame
23
+ Geodataframe with Caatinga APCB data
24
+
25
+ Example
26
+ -------
27
+ >>> from tunned_geobr import read_apcb_caatinga
28
+
29
+ # Read Caatinga APCB data
30
+ >>> apcb = read_apcb_caatinga()
31
+ """
32
+
33
+ url = "https://www.gov.br/mma/pt-br/assuntos/biodiversidade-e-biomas/biomas-e-ecossistemas/conservacao-1/areas-prioritarias/arquivos/caatinga.zip"
34
+
35
+ try:
36
+ # Download the zip file
37
+ response = requests.get(url)
38
+ if response.status_code != 200:
39
+ raise Exception("Failed to download data from MMA")
40
+
41
+ # Create a temporary directory
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ # Extract the zip file
44
+ with ZipFile(BytesIO(response.content)) as zip_ref:
45
+ zip_ref.extractall(temp_dir)
46
+
47
+ # Find the shapefile
48
+ shp_files = []
49
+ for root, dirs, files in os.walk(temp_dir):
50
+ shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
51
+
52
+ if not shp_files:
53
+ raise Exception("No shapefile found in the downloaded data")
54
+
55
+ # Read the shapefile
56
+ gdf = gpd.read_file(shp_files[0])
57
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
58
+
59
+ if simplified:
60
+ # Keep only the most relevant columns
61
+ columns_to_keep = [
62
+ 'geometry',
63
+ 'Nome', # Area name
64
+ 'Importanci', # Importance
65
+ 'Prioridade', # Priority
66
+ 'Area_km2', # Area in km²
67
+ 'Oportunida', # Opportunity
68
+ 'Ameaca' # Threats
69
+ ]
70
+
71
+ # Filter columns that actually exist in the dataset
72
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
73
+ gdf = gdf[existing_columns]
74
+
75
+ except Exception as e:
76
+ raise Exception(f"Error downloading Caatinga APCB data: {str(e)}")
77
+
78
+ return gdf
@@ -0,0 +1,78 @@
1
+ import geopandas as gpd
2
+ import tempfile
3
+ import os
4
+ import requests
5
+ from zipfile import ZipFile
6
+ from io import BytesIO
7
+
8
+ def read_apcb_cerrado_pantanal(simplified=False):
9
+ """Download Priority Areas for Biodiversity Conservation (APCB) data for the Cerrado and Pantanal regions.
10
+
11
+ This function downloads and processes APCB data from the Ministry of Environment (MMA).
12
+ The data includes priority areas for biodiversity conservation in the Cerrado and Pantanal regions.
13
+ Original source: Ministério do Meio Ambiente (MMA)
14
+
15
+ Parameters
16
+ ----------
17
+ simplified : boolean, by default False
18
+ If True, returns a simplified version of the dataset with fewer columns
19
+
20
+ Returns
21
+ -------
22
+ gpd.GeoDataFrame
23
+ Geodataframe with Cerrado and Pantanal APCB data
24
+
25
+ Example
26
+ -------
27
+ >>> from tunned_geobr import read_apcb_cerrado_pantanal
28
+
29
+ # Read Cerrado and Pantanal APCB data
30
+ >>> apcb = read_apcb_cerrado_pantanal()
31
+ """
32
+
33
+ url = "https://www.gov.br/mma/pt-br/assuntos/biodiversidade-e-biomas/biomas-e-ecossistemas/conservacao-1/areas-prioritarias/arquivos/cerrado_pantanal.zip"
34
+
35
+ try:
36
+ # Download the zip file
37
+ response = requests.get(url)
38
+ if response.status_code != 200:
39
+ raise Exception("Failed to download data from MMA")
40
+
41
+ # Create a temporary directory
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ # Extract the zip file
44
+ with ZipFile(BytesIO(response.content)) as zip_ref:
45
+ zip_ref.extractall(temp_dir)
46
+
47
+ # Find the shapefile
48
+ shp_files = []
49
+ for root, dirs, files in os.walk(temp_dir):
50
+ shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
51
+
52
+ if not shp_files:
53
+ raise Exception("No shapefile found in the downloaded data")
54
+
55
+ # Read the shapefile
56
+ gdf = gpd.read_file(shp_files[0])
57
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
58
+
59
+ if simplified:
60
+ # Keep only the most relevant columns
61
+ columns_to_keep = [
62
+ 'geometry',
63
+ 'Nome', # Area name
64
+ 'Importanci', # Importance
65
+ 'Prioridade', # Priority
66
+ 'Area_km2', # Area in km²
67
+ 'Oportunida', # Opportunity
68
+ 'Ameaca' # Threats
69
+ ]
70
+
71
+ # Filter columns that actually exist in the dataset
72
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
73
+ gdf = gdf[existing_columns]
74
+
75
+ except Exception as e:
76
+ raise Exception(f"Error downloading Cerrado and Pantanal APCB data: {str(e)}")
77
+
78
+ return gdf
@@ -0,0 +1,78 @@
1
+ import geopandas as gpd
2
+ import tempfile
3
+ import os
4
+ import requests
5
+ from zipfile import ZipFile
6
+ from io import BytesIO
7
+
8
+ def read_apcb_mata_atlantica(simplified=False):
9
+ """Download Priority Areas for Biodiversity Conservation (APCB) data for the Atlantic Forest region.
10
+
11
+ This function downloads and processes APCB data from the Ministry of Environment (MMA).
12
+ The data includes priority areas for biodiversity conservation in the Atlantic Forest region.
13
+ Original source: Ministério do Meio Ambiente (MMA)
14
+
15
+ Parameters
16
+ ----------
17
+ simplified : boolean, by default False
18
+ If True, returns a simplified version of the dataset with fewer columns
19
+
20
+ Returns
21
+ -------
22
+ gpd.GeoDataFrame
23
+ Geodataframe with Atlantic Forest APCB data
24
+
25
+ Example
26
+ -------
27
+ >>> from tunned_geobr import read_apcb_mata_atlantica
28
+
29
+ # Read Atlantic Forest APCB data
30
+ >>> apcb = read_apcb_mata_atlantica()
31
+ """
32
+
33
+ url = "https://www.gov.br/mma/pt-br/assuntos/biodiversidade-e-biomas/biomas-e-ecossistemas/conservacao-1/areas-prioritarias/arquivos/mataatlantica.zip"
34
+
35
+ try:
36
+ # Download the zip file
37
+ response = requests.get(url)
38
+ if response.status_code != 200:
39
+ raise Exception("Failed to download data from MMA")
40
+
41
+ # Create a temporary directory
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ # Extract the zip file
44
+ with ZipFile(BytesIO(response.content)) as zip_ref:
45
+ zip_ref.extractall(temp_dir)
46
+
47
+ # Find the shapefile
48
+ shp_files = []
49
+ for root, dirs, files in os.walk(temp_dir):
50
+ shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
51
+
52
+ if not shp_files:
53
+ raise Exception("No shapefile found in the downloaded data")
54
+
55
+ # Read the shapefile
56
+ gdf = gpd.read_file(shp_files[0])
57
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
58
+
59
+ if simplified:
60
+ # Keep only the most relevant columns
61
+ columns_to_keep = [
62
+ 'geometry',
63
+ 'Nome', # Area name
64
+ 'Importanci', # Importance
65
+ 'Prioridade', # Priority
66
+ 'Area_km2', # Area in km²
67
+ 'Oportunida', # Opportunity
68
+ 'Ameaca' # Threats
69
+ ]
70
+
71
+ # Filter columns that actually exist in the dataset
72
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
73
+ gdf = gdf[existing_columns]
74
+
75
+ except Exception as e:
76
+ raise Exception(f"Error downloading Atlantic Forest APCB data: {str(e)}")
77
+
78
+ return gdf
@@ -0,0 +1,78 @@
1
+ import geopandas as gpd
2
+ import tempfile
3
+ import os
4
+ import requests
5
+ from zipfile import ZipFile
6
+ from io import BytesIO
7
+
8
+ def read_apcb_pampa(simplified=False):
9
+ """Download Priority Areas for Biodiversity Conservation (APCB) data for the Pampa region.
10
+
11
+ This function downloads and processes APCB data from the Ministry of Environment (MMA).
12
+ The data includes priority areas for biodiversity conservation in the Pampa region.
13
+ Original source: Ministério do Meio Ambiente (MMA)
14
+
15
+ Parameters
16
+ ----------
17
+ simplified : boolean, by default False
18
+ If True, returns a simplified version of the dataset with fewer columns
19
+
20
+ Returns
21
+ -------
22
+ gpd.GeoDataFrame
23
+ Geodataframe with Pampa APCB data
24
+
25
+ Example
26
+ -------
27
+ >>> from tunned_geobr import read_apcb_pampa
28
+
29
+ # Read Pampa APCB data
30
+ >>> apcb = read_apcb_pampa()
31
+ """
32
+
33
+ url = "https://www.gov.br/mma/pt-br/assuntos/biodiversidade-e-biomas/biomas-e-ecossistemas/conservacao-1/areas-prioritarias/arquivos/pampa.zip"
34
+
35
+ try:
36
+ # Download the zip file
37
+ response = requests.get(url)
38
+ if response.status_code != 200:
39
+ raise Exception("Failed to download data from MMA")
40
+
41
+ # Create a temporary directory
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ # Extract the zip file
44
+ with ZipFile(BytesIO(response.content)) as zip_ref:
45
+ zip_ref.extractall(temp_dir)
46
+
47
+ # Find the shapefile
48
+ shp_files = []
49
+ for root, dirs, files in os.walk(temp_dir):
50
+ shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
51
+
52
+ if not shp_files:
53
+ raise Exception("No shapefile found in the downloaded data")
54
+
55
+ # Read the shapefile
56
+ gdf = gpd.read_file(shp_files[0])
57
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
58
+
59
+ if simplified:
60
+ # Keep only the most relevant columns
61
+ columns_to_keep = [
62
+ 'geometry',
63
+ 'Nome', # Area name
64
+ 'Importanci', # Importance
65
+ 'Prioridade', # Priority
66
+ 'Area_km2', # Area in km²
67
+ 'Oportunida', # Opportunity
68
+ 'Ameaca' # Threats
69
+ ]
70
+
71
+ # Filter columns that actually exist in the dataset
72
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
73
+ gdf = gdf[existing_columns]
74
+
75
+ except Exception as e:
76
+ raise Exception(f"Error downloading Pampa APCB data: {str(e)}")
77
+
78
+ return gdf