tunned-geobr 0.2.2__py3-none-any.whl → 0.2.4__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 (67) hide show
  1. tunned_geobr/__init__.py +59 -1
  2. tunned_geobr/list_geobr.py +74 -3
  3. tunned_geobr/read_ama_anemometric_towers.py +119 -0
  4. tunned_geobr/read_areas_under_contract.py +129 -0
  5. tunned_geobr/read_biodiesel_plants.py +128 -0
  6. tunned_geobr/read_biomethane_plants.py +128 -0
  7. tunned_geobr/read_compression_stations.py +128 -0
  8. tunned_geobr/read_drainage_ducts.py +128 -0
  9. tunned_geobr/read_etanol_plants.py +128 -0
  10. tunned_geobr/read_existent_biomass_ute.py +128 -0
  11. tunned_geobr/read_existent_cgh.py +168 -0
  12. tunned_geobr/read_existent_eolic.py +165 -0
  13. tunned_geobr/read_existent_fossile_ute.py +128 -0
  14. tunned_geobr/read_existent_nuclear_ute.py +128 -0
  15. tunned_geobr/read_existent_pch.py +168 -0
  16. tunned_geobr/read_existent_solar.py +165 -0
  17. tunned_geobr/read_existent_substations.py +128 -0
  18. tunned_geobr/read_existent_transmission_lines.py +128 -0
  19. tunned_geobr/read_existent_uhe.py +168 -0
  20. tunned_geobr/read_exploration_production_environment.py +119 -0
  21. tunned_geobr/read_federal_union_areas.py +129 -0
  22. tunned_geobr/read_fuel_bases.py +128 -0
  23. tunned_geobr/read_gas_distribution_pipelines.py +128 -0
  24. tunned_geobr/read_gas_transport_pipelines.py +128 -0
  25. tunned_geobr/read_glp_bases.py +128 -0
  26. tunned_geobr/read_gnl_terminals.py +128 -0
  27. tunned_geobr/read_hydroelectric_feasibility_studies.py +119 -0
  28. tunned_geobr/read_hydroelectric_inventory_aai_studies.py +119 -0
  29. tunned_geobr/read_isolated_systems.py +128 -0
  30. tunned_geobr/read_natural_gas_delivery_points.py +128 -0
  31. tunned_geobr/read_natural_gas_processing_hub.py +128 -0
  32. tunned_geobr/read_og_basement.py +119 -0
  33. tunned_geobr/read_og_effective_geographic_basin.py +129 -0
  34. tunned_geobr/read_og_ipa_direct_evidence.py +119 -0
  35. tunned_geobr/read_og_ipa_exploratory_activity.py +119 -0
  36. tunned_geobr/read_og_ipa_exploratory_intensity.py +129 -0
  37. tunned_geobr/read_og_ipa_need_for_knowledge.py +119 -0
  38. tunned_geobr/read_og_ipa_prospectiveness.py +119 -0
  39. tunned_geobr/read_og_ipa_supply_infrastructure.py +119 -0
  40. tunned_geobr/read_og_legal_pre_salt_polygon.py +119 -0
  41. tunned_geobr/read_og_predominant_fluid_type.py +129 -0
  42. tunned_geobr/read_og_probabilistic_effective_basin.py +129 -0
  43. tunned_geobr/read_og_total_ipa.py +129 -0
  44. tunned_geobr/read_og_unconventional_resources.py +129 -0
  45. tunned_geobr/read_oil_and_derivatives_terminal.py +128 -0
  46. tunned_geobr/read_pan_strategic_areas 2.py +71 -0
  47. tunned_geobr/read_pio_ducts.py +128 -0
  48. tunned_geobr/read_pio_terminals.py +128 -0
  49. tunned_geobr/read_planned_biomass_ute.py +166 -0
  50. tunned_geobr/read_planned_cgh.py +166 -0
  51. tunned_geobr/read_planned_eolic.py +165 -0
  52. tunned_geobr/read_planned_fossile_ute.py +166 -0
  53. tunned_geobr/read_planned_nuclear_ute.py +165 -0
  54. tunned_geobr/read_planned_pch.py +166 -0
  55. tunned_geobr/read_planned_solar.py +165 -0
  56. tunned_geobr/read_planned_substations.py +164 -0
  57. tunned_geobr/read_planned_transmission_lines.py +165 -0
  58. tunned_geobr/read_planned_uhe.py +166 -0
  59. tunned_geobr/read_processing_facilities.py +128 -0
  60. tunned_geobr/read_sedimentary_basins.py +119 -0
  61. tunned_geobr/read_subsystem_interconnected.py +163 -0
  62. {tunned_geobr-0.2.2.dist-info → tunned_geobr-0.2.4.dist-info}/METADATA +1 -1
  63. {tunned_geobr-0.2.2.dist-info → tunned_geobr-0.2.4.dist-info}/RECORD +66 -8
  64. tunned_geobr/constants.py +0 -13
  65. {tunned_geobr-0.2.2.dist-info → tunned_geobr-0.2.4.dist-info}/WHEEL +0 -0
  66. {tunned_geobr-0.2.2.dist-info → tunned_geobr-0.2.4.dist-info}/entry_points.txt +0 -0
  67. {tunned_geobr-0.2.2.dist-info → tunned_geobr-0.2.4.dist-info}/licenses/LICENSE.txt +0 -0
@@ -0,0 +1,128 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ import shutil
4
+ import zipfile
5
+ import tempfile
6
+ import warnings
7
+ import os
8
+ from shapely.geometry.point import Point
9
+
10
+
11
+ def read_biomethane_plants(simplified=False, verbose=False):
12
+ """Download data of biomethane production plants in Brazil.
13
+
14
+ This function downloads and returns data of biomethane production plants
15
+ in Brazil as a GeoPandas GeoDataFrame. The data comes from EPE (Energy Research Company).
16
+
17
+ Parameters
18
+ ----------
19
+ simplified : bool, optional
20
+ If True, returns a simplified version of the dataset with only the most
21
+ important columns. If False, returns the complete dataset. Default is False.
22
+ verbose : bool, optional
23
+ If True, displays detailed messages about the download and processing
24
+ steps. Default is False.
25
+
26
+ Returns
27
+ -------
28
+ gpd.GeoDataFrame
29
+ A GeoDataFrame containing data on biomethane production plants in Brazil.
30
+
31
+ Raises
32
+ ------
33
+ Exception
34
+ If the download or processing of the data fails.
35
+
36
+ Example
37
+ -------
38
+ >>> from tunned_geobr import read_biomethane_plants
39
+ >>>
40
+ >>> # Read the data
41
+ >>> biomethane_plants = read_biomethane_plants()
42
+ >>>
43
+ >>> # Plot the data
44
+ >>> biomethane_plants.plot()
45
+ """
46
+
47
+ if verbose:
48
+ print("Downloading data of biomethane production plants in Brazil")
49
+
50
+ # Define the URL for the API request
51
+ url = "https://gisepeprd2.epe.gov.br/arcgis/rest/services/Download_Dados_Webmap_EPE/GPServer/Extract%20Data%20Task/execute?f=json&env%3AoutSR=102100&Layers_to_Clip=%5B%22Plantas%20de%20biometano%22%5D&Area_of_Interest=%7B%22geometryType%22%3A%22esriGeometryPolygon%22%2C%22features%22%3A%5B%7B%22geometry%22%3A%7B%22rings%22%3A%5B%5B%5B-8655251.47456396%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C-4787514.465591563%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%7D%7D%7D%5D%2C%22sr%22%3A%7B%22wkid%22%3A102100%7D%7D&Feature_Format=Shapefile%20-%20SHP%20-%20.shp&Raster_Format=Tagged%20Image%20File%20Format%20-%20TIFF%20-%20.tif"
52
+
53
+ try:
54
+ # Make the API request
55
+ response = requests.get(url)
56
+ response.raise_for_status()
57
+
58
+ # Parse the JSON response
59
+ data = response.json()
60
+
61
+ # Extract the URL for the zip file
62
+ if 'results' in data and len(data['results']) > 0 and 'value' in data['results'][0]:
63
+ download_url = data['results'][0]['value']['url']
64
+ else:
65
+ raise Exception("Failed to extract download URL from API response")
66
+
67
+ # Create a temporary directory to store the downloaded files
68
+ with tempfile.TemporaryDirectory() as temp_dir:
69
+ # Download the zip file
70
+ zip_path = os.path.join(temp_dir, "biomethane_plants.zip")
71
+ if verbose:
72
+ print("Downloading zip file")
73
+
74
+ response = requests.get(download_url, stream=True)
75
+ response.raise_for_status()
76
+
77
+ with open(zip_path, 'wb') as f:
78
+ response.raw.decode_content = True
79
+ shutil.copyfileobj(response.raw, f)
80
+
81
+ # Extract the zip file
82
+ if verbose:
83
+ print("Extracting files")
84
+
85
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
86
+ zip_ref.extractall(temp_dir)
87
+
88
+ # Find the shapefile in the extracted files
89
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
90
+
91
+ if not shp_files:
92
+ raise Exception("No shapefile found in the downloaded zip file")
93
+
94
+ # Read the shapefile
95
+ if verbose:
96
+ print("Reading shapefile")
97
+
98
+ shp_path = os.path.join(temp_dir, shp_files[0])
99
+ gdf = gpd.read_file(shp_path)
100
+
101
+ # Convert to SIRGAS 2000 (EPSG:4674)
102
+ if verbose:
103
+ print("Converting to SIRGAS 2000 (EPSG:4674)")
104
+
105
+ gdf = gdf.to_crs(epsg=4674)
106
+
107
+ # Simplify the dataset if requested
108
+ if simplified:
109
+ if verbose:
110
+ print("Simplifying the dataset")
111
+
112
+ # Select only the most important columns
113
+ # Adjust these columns based on the actual data structure
114
+ cols_to_keep = ['NOME', 'CAPACIDADE', 'PROPRIETAR', 'UF', 'MUNICIPIO', 'geometry']
115
+ cols_available = [col for col in cols_to_keep if col in gdf.columns]
116
+
117
+ if not cols_available:
118
+ warnings.warn("None of the specified columns for simplification are available. Returning the full dataset.")
119
+ else:
120
+ gdf = gdf[cols_available]
121
+
122
+ if verbose:
123
+ print("Finished processing biomethane production plants data")
124
+
125
+ return gdf
126
+
127
+ except Exception as e:
128
+ raise Exception(f"Failed to download or process biomethane production plants data: {str(e)}")
@@ -0,0 +1,128 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ import shutil
4
+ import zipfile
5
+ import tempfile
6
+ import warnings
7
+ import os
8
+ from shapely.geometry.point import Point
9
+
10
+
11
+ def read_compression_stations(simplified=False, verbose=False):
12
+ """Download data of natural gas compression stations in Brazil.
13
+
14
+ This function downloads and returns data of natural gas compression stations
15
+ in Brazil as a GeoPandas GeoDataFrame. The data comes from EPE (Energy Research Company).
16
+
17
+ Parameters
18
+ ----------
19
+ simplified : bool, optional
20
+ If True, returns a simplified version of the dataset with only the most
21
+ important columns. If False, returns the complete dataset. Default is False.
22
+ verbose : bool, optional
23
+ If True, displays detailed messages about the download and processing
24
+ steps. Default is False.
25
+
26
+ Returns
27
+ -------
28
+ gpd.GeoDataFrame
29
+ A GeoDataFrame containing data on compression stations in Brazil.
30
+
31
+ Raises
32
+ ------
33
+ Exception
34
+ If the download or processing of the data fails.
35
+
36
+ Example
37
+ -------
38
+ >>> from tunned_geobr import read_compression_stations
39
+ >>>
40
+ >>> # Read the data
41
+ >>> compression_stations = read_compression_stations()
42
+ >>>
43
+ >>> # Plot the data
44
+ >>> compression_stations.plot()
45
+ """
46
+
47
+ if verbose:
48
+ print("Downloading data of compression stations in Brazil")
49
+
50
+ # Define the URL for the API request
51
+ url = "https://gisepeprd2.epe.gov.br/arcgis/rest/services/Download_Dados_Webmap_EPE/GPServer/Extract%20Data%20Task/execute?f=json&env%3AoutSR=102100&Layers_to_Clip=%5B%22Esta%C3%A7%C3%B5es%20de%20compress%C3%A3o%22%5D&Area_of_Interest=%7B%22geometryType%22%3A%22esriGeometryPolygon%22%2C%22features%22%3A%5B%7B%22geometry%22%3A%7B%22rings%22%3A%5B%5B%5B-8655251.47456396%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C-4787514.465591563%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%7D%7D%7D%5D%2C%22sr%22%3A%7B%22wkid%22%3A102100%7D%7D&Feature_Format=Shapefile%20-%20SHP%20-%20.shp&Raster_Format=Tagged%20Image%20File%20Format%20-%20TIFF%20-%20.tif"
52
+
53
+ try:
54
+ # Make the API request
55
+ response = requests.get(url)
56
+ response.raise_for_status()
57
+
58
+ # Parse the JSON response
59
+ data = response.json()
60
+
61
+ # Extract the URL for the zip file
62
+ if 'results' in data and len(data['results']) > 0 and 'value' in data['results'][0]:
63
+ download_url = data['results'][0]['value']['url']
64
+ else:
65
+ raise Exception("Failed to extract download URL from API response")
66
+
67
+ # Create a temporary directory to store the downloaded files
68
+ with tempfile.TemporaryDirectory() as temp_dir:
69
+ # Download the zip file
70
+ zip_path = os.path.join(temp_dir, "compression_stations.zip")
71
+ if verbose:
72
+ print("Downloading zip file")
73
+
74
+ response = requests.get(download_url, stream=True)
75
+ response.raise_for_status()
76
+
77
+ with open(zip_path, 'wb') as f:
78
+ response.raw.decode_content = True
79
+ shutil.copyfileobj(response.raw, f)
80
+
81
+ # Extract the zip file
82
+ if verbose:
83
+ print("Extracting files")
84
+
85
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
86
+ zip_ref.extractall(temp_dir)
87
+
88
+ # Find the shapefile in the extracted files
89
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
90
+
91
+ if not shp_files:
92
+ raise Exception("No shapefile found in the downloaded zip file")
93
+
94
+ # Read the shapefile
95
+ if verbose:
96
+ print("Reading shapefile")
97
+
98
+ shp_path = os.path.join(temp_dir, shp_files[0])
99
+ gdf = gpd.read_file(shp_path)
100
+
101
+ # Convert to SIRGAS 2000 (EPSG:4674)
102
+ if verbose:
103
+ print("Converting to SIRGAS 2000 (EPSG:4674)")
104
+
105
+ gdf = gdf.to_crs(epsg=4674)
106
+
107
+ # Simplify the dataset if requested
108
+ if simplified:
109
+ if verbose:
110
+ print("Simplifying the dataset")
111
+
112
+ # Select only the most important columns
113
+ # Adjust these columns based on the actual data structure
114
+ cols_to_keep = ['NOME', 'EMPRESA', 'POTENCIA', 'UF', 'MUNICIPIO', 'geometry']
115
+ cols_available = [col for col in cols_to_keep if col in gdf.columns]
116
+
117
+ if not cols_available:
118
+ warnings.warn("None of the specified columns for simplification are available. Returning the full dataset.")
119
+ else:
120
+ gdf = gdf[cols_available]
121
+
122
+ if verbose:
123
+ print("Finished processing compression stations data")
124
+
125
+ return gdf
126
+
127
+ except Exception as e:
128
+ raise Exception(f"Failed to download or process compression stations data: {str(e)}")
@@ -0,0 +1,128 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ import shutil
4
+ import zipfile
5
+ import tempfile
6
+ import warnings
7
+ import os
8
+ from shapely.geometry.point import Point
9
+
10
+
11
+ def read_drainage_ducts(simplified=False, verbose=False):
12
+ """Download data of drainage ducts in Brazil.
13
+
14
+ This function downloads and returns data of drainage ducts (dutos de escoamento)
15
+ in Brazil as a GeoPandas GeoDataFrame. The data comes from EPE (Energy Research Company).
16
+
17
+ Parameters
18
+ ----------
19
+ simplified : bool, optional
20
+ If True, returns a simplified version of the dataset with only the most
21
+ important columns. If False, returns the complete dataset. Default is False.
22
+ verbose : bool, optional
23
+ If True, displays detailed messages about the download and processing
24
+ steps. Default is False.
25
+
26
+ Returns
27
+ -------
28
+ gpd.GeoDataFrame
29
+ A GeoDataFrame containing data on drainage ducts in Brazil.
30
+
31
+ Raises
32
+ ------
33
+ Exception
34
+ If the download or processing of the data fails.
35
+
36
+ Example
37
+ -------
38
+ >>> from tunned_geobr import read_drainage_ducts
39
+ >>>
40
+ >>> # Read the data
41
+ >>> drainage_ducts = read_drainage_ducts()
42
+ >>>
43
+ >>> # Plot the data
44
+ >>> drainage_ducts.plot()
45
+ """
46
+
47
+ if verbose:
48
+ print("Downloading data of drainage ducts in Brazil")
49
+
50
+ # Define the URL for the API request
51
+ url = "https://gisepeprd2.epe.gov.br/arcgis/rest/services/Download_Dados_Webmap_EPE/GPServer/Extract%20Data%20Task/execute?f=json&env%3AoutSR=102100&Layers_to_Clip=%5B%22Dutos%20de%20escoamento%22%5D&Area_of_Interest=%7B%22geometryType%22%3A%22esriGeometryPolygon%22%2C%22features%22%3A%5B%7B%22geometry%22%3A%7B%22rings%22%3A%5B%5B%5B-8655251.47456396%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C-4787514.465591563%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%7D%7D%7D%5D%2C%22sr%22%3A%7B%22wkid%22%3A102100%7D%7D&Feature_Format=Shapefile%20-%20SHP%20-%20.shp&Raster_Format=Tagged%20Image%20File%20Format%20-%20TIFF%20-%20.tif"
52
+
53
+ try:
54
+ # Make the API request
55
+ response = requests.get(url)
56
+ response.raise_for_status()
57
+
58
+ # Parse the JSON response
59
+ data = response.json()
60
+
61
+ # Extract the URL for the zip file
62
+ if 'results' in data and len(data['results']) > 0 and 'value' in data['results'][0]:
63
+ download_url = data['results'][0]['value']['url']
64
+ else:
65
+ raise Exception("Failed to extract download URL from API response")
66
+
67
+ # Create a temporary directory to store the downloaded files
68
+ with tempfile.TemporaryDirectory() as temp_dir:
69
+ # Download the zip file
70
+ zip_path = os.path.join(temp_dir, "drainage_ducts.zip")
71
+ if verbose:
72
+ print("Downloading zip file")
73
+
74
+ response = requests.get(download_url, stream=True)
75
+ response.raise_for_status()
76
+
77
+ with open(zip_path, 'wb') as f:
78
+ response.raw.decode_content = True
79
+ shutil.copyfileobj(response.raw, f)
80
+
81
+ # Extract the zip file
82
+ if verbose:
83
+ print("Extracting files")
84
+
85
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
86
+ zip_ref.extractall(temp_dir)
87
+
88
+ # Find the shapefile in the extracted files
89
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
90
+
91
+ if not shp_files:
92
+ raise Exception("No shapefile found in the downloaded zip file")
93
+
94
+ # Read the shapefile
95
+ if verbose:
96
+ print("Reading shapefile")
97
+
98
+ shp_path = os.path.join(temp_dir, shp_files[0])
99
+ gdf = gpd.read_file(shp_path)
100
+
101
+ # Convert to SIRGAS 2000 (EPSG:4674)
102
+ if verbose:
103
+ print("Converting to SIRGAS 2000 (EPSG:4674)")
104
+
105
+ gdf = gdf.to_crs(epsg=4674)
106
+
107
+ # Simplify the dataset if requested
108
+ if simplified:
109
+ if verbose:
110
+ print("Simplifying the dataset")
111
+
112
+ # Select only the most important columns
113
+ # Adjust these columns based on the actual data structure
114
+ cols_to_keep = ['NOME', 'EMPRESA', 'EXTENSAO', 'DIAMETRO', 'FLUIDO', 'UF', 'geometry']
115
+ cols_available = [col for col in cols_to_keep if col in gdf.columns]
116
+
117
+ if not cols_available:
118
+ warnings.warn("None of the specified columns for simplification are available. Returning the full dataset.")
119
+ else:
120
+ gdf = gdf[cols_available]
121
+
122
+ if verbose:
123
+ print("Finished processing drainage ducts data")
124
+
125
+ return gdf
126
+
127
+ except Exception as e:
128
+ raise Exception(f"Failed to download or process drainage ducts data: {str(e)}")
@@ -0,0 +1,128 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ import shutil
4
+ import zipfile
5
+ import tempfile
6
+ import warnings
7
+ import os
8
+ from shapely.geometry.point import Point
9
+
10
+
11
+ def read_etanol_plants(simplified=False, verbose=False):
12
+ """Download data of ethanol production plants in Brazil.
13
+
14
+ This function downloads and returns data of ethanol production plants
15
+ in Brazil as a GeoPandas GeoDataFrame. The data comes from EPE (Energy Research Company).
16
+
17
+ Parameters
18
+ ----------
19
+ simplified : bool, optional
20
+ If True, returns a simplified version of the dataset with only the most
21
+ important columns. If False, returns the complete dataset. Default is False.
22
+ verbose : bool, optional
23
+ If True, displays detailed messages about the download and processing
24
+ steps. Default is False.
25
+
26
+ Returns
27
+ -------
28
+ gpd.GeoDataFrame
29
+ A GeoDataFrame containing data on ethanol production plants in Brazil.
30
+
31
+ Raises
32
+ ------
33
+ Exception
34
+ If the download or processing of the data fails.
35
+
36
+ Example
37
+ -------
38
+ >>> from tunned_geobr import read_etanol_plants
39
+ >>>
40
+ >>> # Read the data
41
+ >>> etanol_plants = read_etanol_plants()
42
+ >>>
43
+ >>> # Plot the data
44
+ >>> etanol_plants.plot()
45
+ """
46
+
47
+ if verbose:
48
+ print("Downloading data of ethanol production plants in Brazil")
49
+
50
+ # Define the URL for the API request
51
+ url = "https://gisepeprd2.epe.gov.br/arcgis/rest/services/Download_Dados_Webmap_EPE/GPServer/Extract%20Data%20Task/execute?f=json&env%3AoutSR=102100&Layers_to_Clip=%5B%22Plantas%20de%20etanol%22%5D&Area_of_Interest=%7B%22geometryType%22%3A%22esriGeometryPolygon%22%2C%22features%22%3A%5B%7B%22geometry%22%3A%7B%22rings%22%3A%5B%5B%5B-8655251.47456396%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C-4787514.465591563%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%7D%7D%7D%5D%2C%22sr%22%3A%7B%22wkid%22%3A102100%7D%7D&Feature_Format=Shapefile%20-%20SHP%20-%20.shp&Raster_Format=Tagged%20Image%20File%20Format%20-%20TIFF%20-%20.tif"
52
+
53
+ try:
54
+ # Make the API request
55
+ response = requests.get(url)
56
+ response.raise_for_status()
57
+
58
+ # Parse the JSON response
59
+ data = response.json()
60
+
61
+ # Extract the URL for the zip file
62
+ if 'results' in data and len(data['results']) > 0 and 'value' in data['results'][0]:
63
+ download_url = data['results'][0]['value']['url']
64
+ else:
65
+ raise Exception("Failed to extract download URL from API response")
66
+
67
+ # Create a temporary directory to store the downloaded files
68
+ with tempfile.TemporaryDirectory() as temp_dir:
69
+ # Download the zip file
70
+ zip_path = os.path.join(temp_dir, "etanol_plants.zip")
71
+ if verbose:
72
+ print("Downloading zip file")
73
+
74
+ response = requests.get(download_url, stream=True)
75
+ response.raise_for_status()
76
+
77
+ with open(zip_path, 'wb') as f:
78
+ response.raw.decode_content = True
79
+ shutil.copyfileobj(response.raw, f)
80
+
81
+ # Extract the zip file
82
+ if verbose:
83
+ print("Extracting files")
84
+
85
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
86
+ zip_ref.extractall(temp_dir)
87
+
88
+ # Find the shapefile in the extracted files
89
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
90
+
91
+ if not shp_files:
92
+ raise Exception("No shapefile found in the downloaded zip file")
93
+
94
+ # Read the shapefile
95
+ if verbose:
96
+ print("Reading shapefile")
97
+
98
+ shp_path = os.path.join(temp_dir, shp_files[0])
99
+ gdf = gpd.read_file(shp_path)
100
+
101
+ # Convert to SIRGAS 2000 (EPSG:4674)
102
+ if verbose:
103
+ print("Converting to SIRGAS 2000 (EPSG:4674)")
104
+
105
+ gdf = gdf.to_crs(epsg=4674)
106
+
107
+ # Simplify the dataset if requested
108
+ if simplified:
109
+ if verbose:
110
+ print("Simplifying the dataset")
111
+
112
+ # Select only the most important columns
113
+ # Adjust these columns based on the actual data structure
114
+ cols_to_keep = ['NOME', 'CAPACIDADE', 'PROPRIETAR', 'UF', 'MUNICIPIO', 'geometry']
115
+ cols_available = [col for col in cols_to_keep if col in gdf.columns]
116
+
117
+ if not cols_available:
118
+ warnings.warn("None of the specified columns for simplification are available. Returning the full dataset.")
119
+ else:
120
+ gdf = gdf[cols_available]
121
+
122
+ if verbose:
123
+ print("Finished processing ethanol production plants data")
124
+
125
+ return gdf
126
+
127
+ except Exception as e:
128
+ raise Exception(f"Failed to download or process ethanol production plants data: {str(e)}")
@@ -0,0 +1,128 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ import shutil
4
+ import zipfile
5
+ import tempfile
6
+ import warnings
7
+ import os
8
+ from shapely.geometry.point import Point
9
+
10
+
11
+ def read_existent_biomass_ute(simplified=False, verbose=False):
12
+ """Download data of existing biomass thermoelectric power plants in Brazil.
13
+
14
+ This function downloads and returns data of existing biomass thermoelectric power plants
15
+ in Brazil as a GeoPandas GeoDataFrame. The data comes from EPE (Energy Research Company).
16
+
17
+ Parameters
18
+ ----------
19
+ simplified : bool, optional
20
+ If True, returns a simplified version of the dataset with only the most
21
+ important columns. If False, returns the complete dataset. Default is False.
22
+ verbose : bool, optional
23
+ If True, displays detailed messages about the download and processing
24
+ steps. Default is False.
25
+
26
+ Returns
27
+ -------
28
+ gpd.GeoDataFrame
29
+ A GeoDataFrame containing data on existing biomass thermoelectric power plants in Brazil.
30
+
31
+ Raises
32
+ ------
33
+ Exception
34
+ If the download or processing of the data fails.
35
+
36
+ Example
37
+ -------
38
+ >>> from tunned_geobr import read_existent_biomass_ute
39
+ >>>
40
+ >>> # Read the data
41
+ >>> biomass_ute = read_existent_biomass_ute()
42
+ >>>
43
+ >>> # Plot the data
44
+ >>> biomass_ute.plot()
45
+ """
46
+
47
+ if verbose:
48
+ print("Downloading data of existing biomass thermoelectric power plants in Brazil")
49
+
50
+ # Define the URL for the API request
51
+ url = "https://gisepeprd2.epe.gov.br/arcgis/rest/services/Download_Dados_Webmap_EPE/GPServer/Extract%20Data%20Task/execute?f=json&env%3AoutSR=102100&Layers_to_Clip=%5B%22UTE%20Biomassa%20-%20Base%20Existente%22%5D&Area_of_Interest=%7B%22geometryType%22%3A%22esriGeometryPolygon%22%2C%22features%22%3A%5B%7B%22geometry%22%3A%7B%22rings%22%3A%5B%5B%5B-8655251.47456396%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C1229608.401015912%5D%2C%5B-3508899.2341809804%2C-4787514.465591563%5D%2C%5B-8655251.47456396%2C-4787514.465591563%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%7D%7D%7D%5D%2C%22sr%22%3A%7B%22wkid%22%3A102100%7D%7D&Feature_Format=Shapefile%20-%20SHP%20-%20.shp&Raster_Format=Tagged%20Image%20File%20Format%20-%20TIFF%20-%20.tif"
52
+
53
+ try:
54
+ # Make the API request
55
+ response = requests.get(url)
56
+ response.raise_for_status()
57
+
58
+ # Parse the JSON response
59
+ data = response.json()
60
+
61
+ # Extract the URL for the zip file
62
+ if 'results' in data and len(data['results']) > 0 and 'value' in data['results'][0]:
63
+ download_url = data['results'][0]['value']['url']
64
+ else:
65
+ raise Exception("Failed to extract download URL from API response")
66
+
67
+ # Create a temporary directory to store the downloaded files
68
+ with tempfile.TemporaryDirectory() as temp_dir:
69
+ # Download the zip file
70
+ zip_path = os.path.join(temp_dir, "biomass_ute.zip")
71
+ if verbose:
72
+ print("Downloading zip file")
73
+
74
+ response = requests.get(download_url, stream=True)
75
+ response.raise_for_status()
76
+
77
+ with open(zip_path, 'wb') as f:
78
+ response.raw.decode_content = True
79
+ shutil.copyfileobj(response.raw, f)
80
+
81
+ # Extract the zip file
82
+ if verbose:
83
+ print("Extracting files")
84
+
85
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
86
+ zip_ref.extractall(temp_dir)
87
+
88
+ # Find the shapefile in the extracted files
89
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
90
+
91
+ if not shp_files:
92
+ raise Exception("No shapefile found in the downloaded zip file")
93
+
94
+ # Read the shapefile
95
+ if verbose:
96
+ print("Reading shapefile")
97
+
98
+ shp_path = os.path.join(temp_dir, shp_files[0])
99
+ gdf = gpd.read_file(shp_path)
100
+
101
+ # Convert to SIRGAS 2000 (EPSG:4674)
102
+ if verbose:
103
+ print("Converting to SIRGAS 2000 (EPSG:4674)")
104
+
105
+ gdf = gdf.to_crs(epsg=4674)
106
+
107
+ # Simplify the dataset if requested
108
+ if simplified:
109
+ if verbose:
110
+ print("Simplifying the dataset")
111
+
112
+ # Select only the most important columns
113
+ # Adjust these columns based on the actual data structure
114
+ cols_to_keep = ['NOME', 'POTENCIA', 'COMBUSTIVE', 'PROPRIETAR', 'UF', 'MUNICIPIO', 'geometry']
115
+ cols_available = [col for col in cols_to_keep if col in gdf.columns]
116
+
117
+ if not cols_available:
118
+ warnings.warn("None of the specified columns for simplification are available. Returning the full dataset.")
119
+ else:
120
+ gdf = gdf[cols_available]
121
+
122
+ if verbose:
123
+ print("Finished processing existing biomass thermoelectric power plants data")
124
+
125
+ return gdf
126
+
127
+ except Exception as e:
128
+ raise Exception(f"Failed to download or process existing biomass thermoelectric power plants data: {str(e)}")