tunned-geobr 0.2.5__py3-none-any.whl → 0.2.7__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.
- tunned_geobr/__init__.py +2 -3
- tunned_geobr/list_geobr.py +1 -5
- tunned_geobr/read_ama_anemometric_towers.py +8 -6
- tunned_geobr/read_areas_under_contract.py +3 -2
- tunned_geobr/read_biodiesel_plants.py +3 -2
- tunned_geobr/read_biomes.py +1 -1
- tunned_geobr/read_biomethane_plants.py +3 -2
- tunned_geobr/read_census_tract.py +90 -88
- tunned_geobr/read_comparable_areas.py +1 -1
- tunned_geobr/read_compression_stations.py +3 -2
- tunned_geobr/read_conservation_units.py +1 -1
- tunned_geobr/read_country.py +1 -1
- tunned_geobr/read_disaster_risk_area.py +1 -1
- tunned_geobr/read_drainage_ducts.py +3 -2
- tunned_geobr/read_etanol_plants.py +3 -2
- tunned_geobr/read_existent_biomass_ute.py +6 -2
- tunned_geobr/read_existent_fossile_ute.py +7 -3
- tunned_geobr/read_existent_nuclear_ute.py +5 -4
- tunned_geobr/read_existent_substations.py +5 -4
- tunned_geobr/read_existent_transmission_lines.py +6 -5
- tunned_geobr/read_exploration_production_environment.py +6 -8
- tunned_geobr/read_federal_union_areas.py +3 -2
- tunned_geobr/read_fuel_bases.py +3 -2
- tunned_geobr/read_gas_distribution_pipelines.py +3 -2
- tunned_geobr/read_gas_transport_pipelines.py +3 -2
- tunned_geobr/read_glp_bases.py +3 -2
- tunned_geobr/read_health_region.py +1 -1
- tunned_geobr/read_hydroelectric_feasibility_studies.py +9 -8
- tunned_geobr/read_hydroelectric_inventory_aai_studies.py +9 -8
- tunned_geobr/read_immediate_region.py +1 -1
- tunned_geobr/read_indigenous_land.py +1 -1
- tunned_geobr/read_intermediate_region.py +1 -1
- tunned_geobr/read_isolated_systems.py +5 -4
- tunned_geobr/read_meso_region.py +1 -1
- tunned_geobr/read_metro_area.py +1 -1
- tunned_geobr/read_micro_region.py +1 -1
- tunned_geobr/read_municipality.py +111 -67
- tunned_geobr/read_municipality_direct.py +1 -1
- tunned_geobr/read_neighborhood.py +1 -1
- tunned_geobr/read_og_basement.py +9 -8
- tunned_geobr/read_og_effective_geographic_basin.py +3 -2
- tunned_geobr/read_og_ipa_direct_evidence.py +6 -8
- tunned_geobr/read_og_ipa_exploratory_activity.py +9 -8
- tunned_geobr/read_og_ipa_exploratory_intensity.py +3 -0
- tunned_geobr/read_og_ipa_need_for_knowledge.py +6 -8
- tunned_geobr/read_og_ipa_prospectiveness.py +6 -8
- tunned_geobr/read_og_ipa_supply_infrastructure.py +6 -8
- tunned_geobr/read_og_legal_pre_salt_polygon.py +6 -8
- tunned_geobr/read_og_predominant_fluid_type.py +3 -2
- tunned_geobr/read_og_probabilistic_effective_basin.py +3 -2
- tunned_geobr/read_og_total_ipa.py +3 -2
- tunned_geobr/read_og_unconventional_resources.py +3 -2
- tunned_geobr/read_oil_and_derivatives_terminal.py +3 -2
- tunned_geobr/read_pio_terminals.py +3 -2
- tunned_geobr/read_pop_arrangements.py +1 -1
- tunned_geobr/read_processing_facilities.py +3 -2
- tunned_geobr/read_region.py +1 -1
- tunned_geobr/read_sedimentary_basins.py +6 -8
- tunned_geobr/read_semiarid.py +1 -1
- tunned_geobr/read_state.py +83 -68
- tunned_geobr/read_state_direct.py +1 -1
- tunned_geobr/read_urban_area.py +1 -1
- tunned_geobr/read_urban_concentrations.py +1 -1
- tunned_geobr/read_water_bodies_ana.py +1 -1
- tunned_geobr/read_weighting_area.py +1 -1
- {tunned_geobr-0.2.5.dist-info → tunned_geobr-0.2.7.dist-info}/METADATA +1 -1
- tunned_geobr-0.2.7.dist-info/RECORD +138 -0
- tunned_geobr/read_census_tract_2022.py +0 -101
- tunned_geobr-0.2.5.dist-info/RECORD +0 -139
- {tunned_geobr-0.2.5.dist-info → tunned_geobr-0.2.7.dist-info}/WHEEL +0 -0
- {tunned_geobr-0.2.5.dist-info → tunned_geobr-0.2.7.dist-info}/entry_points.txt +0 -0
- {tunned_geobr-0.2.5.dist-info → tunned_geobr-0.2.7.dist-info}/licenses/LICENSE.txt +0 -0
tunned_geobr/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from .read_state_direct import
|
1
|
+
from .read_state_direct import read_state_direct
|
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_direct import
|
19
|
+
from .read_municipality_direct import read_municipality_direct
|
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
|
@@ -65,7 +65,6 @@ from .read_water_bodies_ana import read_water_bodies_ana
|
|
65
65
|
from .read_pan_strategic_areas import read_pan_strategic_areas
|
66
66
|
from .read_geographic_regions import read_geographic_regions
|
67
67
|
from .read_biosphere_reserves import read_biosphere_reserves
|
68
|
-
from .read_census_tract_2022 import read_census_tract_2022
|
69
68
|
from .read_neighborhoods_2022 import read_neighborhoods_2022
|
70
69
|
from .read_baze_sites import read_baze_sites
|
71
70
|
from .read_existent_eolic import read_existent_eolic
|
tunned_geobr/list_geobr.py
CHANGED
@@ -25,17 +25,13 @@ def list_geobr():
|
|
25
25
|
{"Function": "read_country", "Geography": "Country", "Years": "All", "Source": "IBGE"},
|
26
26
|
{"Function": "read_region", "Geography": "Region", "Years": "All", "Source": "IBGE"},
|
27
27
|
{"Function": "read_state", "Geography": "State", "Years": "All", "Source": "IBGE"},
|
28
|
-
{"Function": "read_state_direct", "Geography": "State", "Years": "All", "Source": "IBGE"},
|
29
28
|
{"Function": "read_meso_region", "Geography": "Meso region", "Years": "1991, 2000, 2010, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020", "Source": "IBGE"},
|
30
29
|
{"Function": "read_micro_region", "Geography": "Micro region", "Years": "1991, 2000, 2010, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020", "Source": "IBGE"},
|
31
30
|
{"Function": "read_immediate_region", "Geography": "Immediate region", "Years": "2017, 2019, 2020", "Source": "IBGE"},
|
32
31
|
{"Function": "read_intermediate_region", "Geography": "Intermediate region", "Years": "2017, 2019, 2020", "Source": "IBGE"},
|
33
32
|
{"Function": "read_municipality", "Geography": "Municipality", "Years": "All", "Source": "IBGE"},
|
34
|
-
{"Function": "read_municipality_direct", "Geography": "Municipality", "Years": "All", "Source": "IBGE"},
|
35
33
|
{"Function": "read_weighting_area", "Geography": "Census weighting area", "Years": "2010", "Source": "IBGE"},
|
36
|
-
{"Function": "read_census_tract", "Geography": "Census tract", "Years": "
|
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"},
|
34
|
+
{"Function": "read_census_tract", "Geography": "Census tract 2022", "Years": "2022", "Source": "IBGE"},
|
39
35
|
{"Function": "read_comparable_areas", "Geography": "Comparable areas", "Years": "1872, 1900, 1911, 1920, 1933, 1940, 1950, 1960, 1970, 1980, 1991, 2000, 2010", "Source": "IBGE"},
|
40
36
|
{"Function": "read_health_region", "Geography": "Health region", "Years": "1991, 1994, 1997, 2001, 2005, 2013", "Source": "DataSUS"},
|
41
37
|
{"Function": "read_metro_area", "Geography": "Metropolitan area", "Years": "All", "Source": "IBGE"},
|
@@ -7,7 +7,7 @@ import warnings
|
|
7
7
|
import shutil
|
8
8
|
|
9
9
|
|
10
|
-
def read_ama_anemometric_towers(simplified=
|
10
|
+
def read_ama_anemometric_towers(simplified=False, verbose=False):
|
11
11
|
"""Download data for AMA Anemometric Towers in Brazil.
|
12
12
|
|
13
13
|
This function downloads, processes, and returns data for AMA Anemometric Towers
|
@@ -45,10 +45,8 @@ def read_ama_anemometric_towers(simplified=True, verbose=False):
|
|
45
45
|
response.raise_for_status()
|
46
46
|
response_json = response.json()
|
47
47
|
|
48
|
-
if "value" not in response_json or not response_json["value"]:
|
49
|
-
raise ValueError("No data found in the response")
|
50
48
|
|
51
|
-
download_url = response_json[
|
49
|
+
download_url = response_json['results'][0]['value']['url']
|
52
50
|
|
53
51
|
if verbose:
|
54
52
|
print(f"Download URL: {download_url}")
|
@@ -74,12 +72,13 @@ def read_ama_anemometric_towers(simplified=True, verbose=False):
|
|
74
72
|
zip_ref.extractall(temp_dir)
|
75
73
|
|
76
74
|
# Find the shapefile
|
77
|
-
|
75
|
+
zip_dir = os.path.join(temp_dir, 'zipfolder')
|
76
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith(".shp")]
|
78
77
|
|
79
78
|
if not shp_files:
|
80
79
|
raise FileNotFoundError("No shapefile found in the downloaded zip file")
|
81
80
|
|
82
|
-
shp_path = os.path.join(
|
81
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
83
82
|
|
84
83
|
if verbose:
|
85
84
|
print(f"Reading shapefile from {shp_path}")
|
@@ -117,3 +116,6 @@ def read_ama_anemometric_towers(simplified=True, verbose=False):
|
|
117
116
|
except Exception as e:
|
118
117
|
warnings.warn(f"Unexpected error: {e}")
|
119
118
|
return None
|
119
|
+
|
120
|
+
if __name__ == '__main__':
|
121
|
+
read_ama_anemometric_towers()
|
@@ -86,8 +86,9 @@ def read_areas_under_contract(simplified=False, verbose=False):
|
|
86
86
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
87
87
|
zip_ref.extractall(temp_dir)
|
88
88
|
|
89
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
89
90
|
# Find the shapefile in the extracted files
|
90
|
-
shp_files = [f for f in os.listdir(
|
91
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
91
92
|
|
92
93
|
if not shp_files:
|
93
94
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -96,7 +97,7 @@ def read_areas_under_contract(simplified=False, verbose=False):
|
|
96
97
|
if verbose:
|
97
98
|
print("Reading shapefile")
|
98
99
|
|
99
|
-
shp_path = os.path.join(
|
100
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
100
101
|
gdf = gpd.read_file(shp_path)
|
101
102
|
|
102
103
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -85,8 +85,9 @@ def read_biodiesel_plants(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_biodiesel_plants(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
tunned_geobr/read_biomes.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from geobr.utils import select_metadata, download_gpkg
|
2
2
|
|
3
3
|
|
4
|
-
def read_biomes(year=2019, simplified=
|
4
|
+
def read_biomes(year=2019, simplified=False, verbose=False):
|
5
5
|
""" Download official data of Brazilian biomes as an sf object.
|
6
6
|
|
7
7
|
This data set includes polygons of all biomes present in Brazilian territory and coastal area.
|
@@ -85,8 +85,9 @@ def read_biomethane_plants(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_biomethane_plants(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -1,97 +1,99 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
import geopandas as gpd
|
2
|
+
import tempfile
|
3
|
+
import os
|
4
|
+
import requests
|
5
|
+
import subprocess
|
6
|
+
from io import BytesIO
|
7
|
+
|
8
|
+
def read_census_tract(simplified=False):
|
9
|
+
"""Download Brazilian Census Tracts data from IBGE (2022 Census).
|
10
|
+
|
11
|
+
This function downloads and processes the Brazilian Census Tracts data
|
12
|
+
from IBGE (Brazilian Institute of Geography and Statistics) for the 2022 Census.
|
13
|
+
Original source: IBGE - Instituto Brasileiro de Geografia e Estatística
|
14
|
+
|
9
15
|
Parameters
|
10
16
|
----------
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
all census tracts of the country are loaded.
|
15
|
-
year : int, optional
|
16
|
-
Year of the data, by default 2010
|
17
|
-
zone: string, optional
|
18
|
-
"urban" or "rural" census tracts come in separate files in the year 2000, by default urban
|
19
|
-
simplified: boolean, by default True
|
20
|
-
Data 'type', indicating whether the function returns the 'original' dataset
|
21
|
-
with high resolution or a dataset with 'simplified' borders (Default)
|
22
|
-
verbose : bool, optional
|
23
|
-
by default False
|
24
|
-
|
17
|
+
simplified : boolean, by default False
|
18
|
+
If True, returns a simplified version of the dataset with fewer columns
|
19
|
+
|
25
20
|
Returns
|
26
21
|
-------
|
27
22
|
gpd.GeoDataFrame
|
28
|
-
|
29
|
-
|
30
|
-
Raises
|
31
|
-
------
|
32
|
-
Exception
|
33
|
-
If parameters are not found or not well defined
|
34
|
-
|
23
|
+
Geodataframe with Brazilian census tracts data
|
24
|
+
|
35
25
|
Example
|
36
26
|
-------
|
37
|
-
>>> from
|
38
|
-
|
39
|
-
# Read
|
40
|
-
>>>
|
41
|
-
|
42
|
-
|
43
|
-
# Read all census tracts of a state at a given year
|
44
|
-
>>> df = read_census_tract(code_tract=53, year=2010) # or
|
45
|
-
>>> df = read_census_tract(code_tract="DF", year=2010)
|
46
|
-
|
47
|
-
# Read all census tracts of a municipality at a given year
|
48
|
-
>>> df = read_census_tract(code_tract=5201108, year=2010)
|
49
|
-
|
50
|
-
# Read all census tracts of the country at a given year
|
51
|
-
>>> df = read_census_tract(code_tract="all", year=2010)
|
52
|
-
|
27
|
+
>>> from tunned_geobr import read_census_tract_2022
|
28
|
+
|
29
|
+
# Read census tracts data
|
30
|
+
>>> census_tracts = read_census_tract_2022()
|
53
31
|
"""
|
32
|
+
|
33
|
+
url = "https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_de_setores_censitarios__divisoes_intramunicipais/censo_2022/setores/shp/BR/BR_setores_CD2022.zip"
|
34
|
+
|
35
|
+
try:
|
36
|
+
# Create a temporary directory
|
37
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
38
|
+
# Download the zip file to the temporary directory
|
39
|
+
zip_file_path = os.path.join(temp_dir, "census_tracts.zip")
|
40
|
+
|
41
|
+
# Download the file
|
42
|
+
response = requests.get(url)
|
43
|
+
if response.status_code != 200:
|
44
|
+
raise Exception("Failed to download census tracts data from IBGE")
|
45
|
+
|
46
|
+
# Save the content to a file
|
47
|
+
with open(zip_file_path, 'wb') as f:
|
48
|
+
f.write(response.content)
|
49
|
+
|
50
|
+
# Use unzip command line tool to extract the file (handles more compression methods)
|
51
|
+
try:
|
52
|
+
subprocess.run(['unzip', '-o', zip_file_path, '-d', temp_dir],
|
53
|
+
check=True,
|
54
|
+
stdout=subprocess.PIPE,
|
55
|
+
stderr=subprocess.PIPE)
|
56
|
+
except subprocess.CalledProcessError as e:
|
57
|
+
raise Exception(f"Failed to extract zip file: {e.stderr.decode()}")
|
58
|
+
|
59
|
+
# Find the shapefile
|
60
|
+
shp_files = []
|
61
|
+
for root, dirs, files in os.walk(temp_dir):
|
62
|
+
shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
|
63
|
+
|
64
|
+
if not shp_files:
|
65
|
+
raise Exception("No shapefile found in the downloaded data")
|
66
|
+
|
67
|
+
# Read the shapefile
|
68
|
+
gdf = gpd.read_file(shp_files[0])
|
69
|
+
|
70
|
+
# Convert to SIRGAS 2000 (EPSG:4674) if not already
|
71
|
+
if gdf.crs is None or gdf.crs.to_epsg() != 4674:
|
72
|
+
gdf = gdf.to_crs(4674)
|
73
|
+
|
74
|
+
if simplified:
|
75
|
+
# Keep only the most relevant columns
|
76
|
+
# Note: Column names may need adjustment based on actual data
|
77
|
+
columns_to_keep = [
|
78
|
+
'geometry',
|
79
|
+
'CD_SETOR', # Census Tract Code
|
80
|
+
'NM_SETOR', # Census Tract Name
|
81
|
+
'CD_SIT', # Situation Code
|
82
|
+
'NM_SIT', # Situation Name (Urban/Rural)
|
83
|
+
'CD_MUN', # Municipality Code
|
84
|
+
'NM_MUN', # Municipality Name
|
85
|
+
'CD_UF', # State Code
|
86
|
+
'NM_UF', # State Name
|
87
|
+
'SIGLA_UF', # State Abbreviation
|
88
|
+
'AREA_KM2' # Area in square kilometers
|
89
|
+
]
|
90
|
+
|
91
|
+
# Filter columns that actually exist in the dataset
|
92
|
+
existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
|
93
|
+
gdf = gdf[existing_columns]
|
94
|
+
|
95
|
+
except Exception as e:
|
96
|
+
raise Exception(f"Error downloading census tracts data: {str(e)}")
|
97
|
+
|
98
|
+
return gdf
|
54
99
|
|
55
|
-
test_options(zone, "zone", allowed=["urban", "rural"])
|
56
|
-
test_options(code_tract, "code_tract", not_allowed=[None])
|
57
|
-
|
58
|
-
metadata = select_metadata("census_tract", year=year, simplified=simplified)
|
59
|
-
|
60
|
-
# For year <= 2007, the code, eg. U11, comes with a trailing letter U for urban and
|
61
|
-
# R for rural. So, this code checks if the trailing code letter is the same as
|
62
|
-
# the argument zone.
|
63
|
-
if year <= 2007:
|
64
|
-
|
65
|
-
metadata = metadata[
|
66
|
-
metadata["code"].apply(lambda x: x[0].lower() == zone[0].lower())
|
67
|
-
]
|
68
|
-
# [R]12 == [r]ural
|
69
|
-
|
70
|
-
if code_tract == "all":
|
71
|
-
|
72
|
-
if verbose:
|
73
|
-
print("Loading data for the whole country. This might take a few minutes.")
|
74
|
-
|
75
|
-
return download_gpkg(metadata)
|
76
|
-
|
77
|
-
else:
|
78
|
-
|
79
|
-
metadata = metadata[
|
80
|
-
metadata[["code", "code_abbrev"]].apply(
|
81
|
-
lambda x: str(code_tract)[:2] in str(x["code"])
|
82
|
-
or str(code_tract)[:2] # if number e.g. 12
|
83
|
-
in str(x["code_abbrev"]), # if UF e.g. RO
|
84
|
-
1,
|
85
|
-
)
|
86
|
-
]
|
87
|
-
|
88
|
-
gdf = download_gpkg(metadata)
|
89
|
-
|
90
|
-
if len(str(code_tract)) == 2:
|
91
|
-
return gdf
|
92
|
-
|
93
|
-
elif code_tract in gdf["code_muni"].tolist():
|
94
|
-
return gdf.query(f"code_muni == {code_tract}")
|
95
|
-
|
96
|
-
else:
|
97
|
-
raise Exception("Invalid Value to argument code_tract.")
|
@@ -2,7 +2,7 @@ from geobr.utils import select_metadata, download_gpkg
|
|
2
2
|
|
3
3
|
|
4
4
|
def read_comparable_areas(
|
5
|
-
start_year=1970, end_year=2010, simplified=
|
5
|
+
start_year=1970, end_year=2010, simplified=False, verbose=False
|
6
6
|
):
|
7
7
|
r"""Download spatial data of historically comparable municipalities
|
8
8
|
|
@@ -85,8 +85,9 @@ def read_compression_stations(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_compression_stations(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from geobr.utils import select_metadata, download_gpkg
|
2
2
|
|
3
3
|
|
4
|
-
def read_conservation_units(date=201909, simplified=
|
4
|
+
def read_conservation_units(date=201909, simplified=False, verbose=False):
|
5
5
|
""" Download official data of Brazilian conservation untis as an sf object.
|
6
6
|
|
7
7
|
This data set covers the whole of Brazil and it includes the polygons of all conservation untis present in Brazilian
|
tunned_geobr/read_country.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from geobr.utils import select_metadata, download_gpkg
|
2
2
|
|
3
3
|
|
4
|
-
def read_country(year=2010, simplified=
|
4
|
+
def read_country(year=2010, simplified=False, verbose=False):
|
5
5
|
""" Download shape file of Brazil as sf objects. Data at scale 1:250,000, using Geodetic reference system "SIRGAS2000" and CRS(4674)
|
6
6
|
|
7
7
|
@param year Year of the data (defaults to 2010)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from geobr.utils import select_metadata, download_gpkg
|
2
2
|
|
3
3
|
|
4
|
-
def read_disaster_risk_area(year=2010, simplified=
|
4
|
+
def read_disaster_risk_area(year=2010, simplified=False, verbose=False):
|
5
5
|
""" Download official data of disaster risk areas as an sf object.
|
6
6
|
|
7
7
|
This function reads the the official data of disaster risk areas in Brazil. It specifically focuses
|
@@ -85,8 +85,9 @@ def read_drainage_ducts(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_drainage_ducts(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -85,8 +85,9 @@ def read_etanol_plants(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_etanol_plants(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -85,8 +85,9 @@ def read_existent_biomass_ute(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_existent_biomass_ute(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -126,3 +127,6 @@ def read_existent_biomass_ute(simplified=False, verbose=False):
|
|
126
127
|
|
127
128
|
except Exception as e:
|
128
129
|
raise Exception(f"Failed to download or process existing biomass thermoelectric power plants data: {str(e)}")
|
130
|
+
|
131
|
+
if __name__ == '__main__':
|
132
|
+
read_existent_biomass_ute()
|
@@ -85,8 +85,9 @@ def read_existent_fossile_ute(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_existent_fossile_ute(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -120,9 +121,12 @@ def read_existent_fossile_ute(simplified=False, verbose=False):
|
|
120
121
|
gdf = gdf[cols_available]
|
121
122
|
|
122
123
|
if verbose:
|
123
|
-
print("Finished processing existing
|
124
|
+
print("Finished processing existing biomass thermoelectric power plants data")
|
124
125
|
|
125
126
|
return gdf
|
126
127
|
|
127
128
|
except Exception as e:
|
128
129
|
raise Exception(f"Failed to download or process existing fossil thermoelectric power plants data: {str(e)}")
|
130
|
+
|
131
|
+
if __name__ == '__main__':
|
132
|
+
read_existent_fossile_ute()
|
@@ -85,8 +85,9 @@ def read_existent_nuclear_ute(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_existent_nuclear_ute(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -111,7 +112,7 @@ def read_existent_nuclear_ute(simplified=False, verbose=False):
|
|
111
112
|
|
112
113
|
# Select only the most important columns
|
113
114
|
# Adjust these columns based on the actual data structure
|
114
|
-
cols_to_keep = ['NOME', 'POTENCIA', 'PROPRIETAR', 'UF', 'MUNICIPIO', 'geometry']
|
115
|
+
cols_to_keep = ['NOME', 'POTENCIA', 'COMBUSTIVE', 'PROPRIETAR', 'UF', 'MUNICIPIO', 'geometry']
|
115
116
|
cols_available = [col for col in cols_to_keep if col in gdf.columns]
|
116
117
|
|
117
118
|
if not cols_available:
|
@@ -120,7 +121,7 @@ def read_existent_nuclear_ute(simplified=False, verbose=False):
|
|
120
121
|
gdf = gdf[cols_available]
|
121
122
|
|
122
123
|
if verbose:
|
123
|
-
print("Finished processing existing
|
124
|
+
print("Finished processing existing biomass thermoelectric power plants data")
|
124
125
|
|
125
126
|
return gdf
|
126
127
|
|
@@ -85,8 +85,9 @@ def read_existent_substations(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_existent_substations(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -111,7 +112,7 @@ def read_existent_substations(simplified=False, verbose=False):
|
|
111
112
|
|
112
113
|
# Select only the most important columns
|
113
114
|
# Adjust these columns based on the actual data structure
|
114
|
-
cols_to_keep = ['NOME', '
|
115
|
+
cols_to_keep = ['NOME', 'POTENCIA', 'COMBUSTIVE', 'PROPRIETAR', 'UF', 'MUNICIPIO', 'geometry']
|
115
116
|
cols_available = [col for col in cols_to_keep if col in gdf.columns]
|
116
117
|
|
117
118
|
if not cols_available:
|
@@ -120,7 +121,7 @@ def read_existent_substations(simplified=False, verbose=False):
|
|
120
121
|
gdf = gdf[cols_available]
|
121
122
|
|
122
123
|
if verbose:
|
123
|
-
print("Finished processing existing
|
124
|
+
print("Finished processing existing biomass thermoelectric power plants data")
|
124
125
|
|
125
126
|
return gdf
|
126
127
|
|
@@ -67,7 +67,7 @@ def read_existent_transmission_lines(simplified=False, verbose=False):
|
|
67
67
|
# Create a temporary directory to store the downloaded files
|
68
68
|
with tempfile.TemporaryDirectory() as temp_dir:
|
69
69
|
# Download the zip file
|
70
|
-
zip_path = os.path.join(temp_dir, "
|
70
|
+
zip_path = os.path.join(temp_dir, "existent_lt.zip")
|
71
71
|
if verbose:
|
72
72
|
print("Downloading zip file")
|
73
73
|
|
@@ -85,8 +85,9 @@ def read_existent_transmission_lines(simplified=False, verbose=False):
|
|
85
85
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
86
86
|
zip_ref.extractall(temp_dir)
|
87
87
|
|
88
|
+
zip_dir = os.path.join(temp_dir,'zipfolder')
|
88
89
|
# Find the shapefile in the extracted files
|
89
|
-
shp_files = [f for f in os.listdir(
|
90
|
+
shp_files = [f for f in os.listdir(zip_dir) if f.endswith('.shp')]
|
90
91
|
|
91
92
|
if not shp_files:
|
92
93
|
raise Exception("No shapefile found in the downloaded zip file")
|
@@ -95,7 +96,7 @@ def read_existent_transmission_lines(simplified=False, verbose=False):
|
|
95
96
|
if verbose:
|
96
97
|
print("Reading shapefile")
|
97
98
|
|
98
|
-
shp_path = os.path.join(
|
99
|
+
shp_path = os.path.join(zip_dir, shp_files[0])
|
99
100
|
gdf = gpd.read_file(shp_path)
|
100
101
|
|
101
102
|
# Convert to SIRGAS 2000 (EPSG:4674)
|
@@ -111,7 +112,7 @@ def read_existent_transmission_lines(simplified=False, verbose=False):
|
|
111
112
|
|
112
113
|
# Select only the most important columns
|
113
114
|
# Adjust these columns based on the actual data structure
|
114
|
-
cols_to_keep = ['NOME', '
|
115
|
+
cols_to_keep = ['NOME', 'POTENCIA', 'COMBUSTIVE', 'PROPRIETAR', 'UF', 'MUNICIPIO', 'geometry']
|
115
116
|
cols_available = [col for col in cols_to_keep if col in gdf.columns]
|
116
117
|
|
117
118
|
if not cols_available:
|
@@ -120,7 +121,7 @@ def read_existent_transmission_lines(simplified=False, verbose=False):
|
|
120
121
|
gdf = gdf[cols_available]
|
121
122
|
|
122
123
|
if verbose:
|
123
|
-
print("Finished processing existing
|
124
|
+
print("Finished processing existing biomass thermoelectric power plants data")
|
124
125
|
|
125
126
|
return gdf
|
126
127
|
|