tunned-geobr 0.2.10__py3-none-any.whl → 1.0.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.
tunned_geobr/__init__.py CHANGED
@@ -18,7 +18,6 @@ from .read_meso_region import read_meso_region
18
18
  from .read_micro_region import read_micro_region
19
19
  from .read_municipality import read_municipality
20
20
  from .read_weighting_area import read_weighting_area
21
- from .read_neighborhood import read_neighborhood
22
21
  from .read_health_region import read_health_region
23
22
  from .read_pop_arrangements import read_pop_arrangements
24
23
  from .lookup_muni import lookup_muni
@@ -65,7 +64,7 @@ from .read_water_bodies_ana import read_water_bodies_ana
65
64
  from .read_pan_strategic_areas import read_pan_strategic_areas
66
65
  from .read_geographic_regions import read_geographic_regions
67
66
  from .read_biosphere_reserves import read_biosphere_reserves
68
- from .read_neighborhoods_2022 import read_neighborhoods_2022
67
+ from .read_neighborhood import read_neighborhood
69
68
  from .read_baze_sites import read_baze_sites
70
69
  from .read_existent_eolic import read_existent_eolic
71
70
  from .read_planned_eolic import read_planned_eolic
@@ -125,3 +124,6 @@ from .read_natural_gas_processing_hub import read_natural_gas_processing_hub
125
124
  from .read_compression_stations import read_compression_stations
126
125
  from .read_natural_gas_delivery_points import read_natural_gas_delivery_points
127
126
  from .read_quilombola_areas import read_quilombola_areas
127
+ from .read_icmbio_embargoes import read_icmbio_embargoes
128
+ from .read_icmbio_infractions import read_icmbio_infractions
129
+ from .read_ibama_embargoes import read_ibama_embargoes
@@ -168,7 +168,12 @@ def list_geobr():
168
168
  {"Function": "read_og_basement", "Geography": "Oil and Gas Basement", "Years": "All", "Source": "EPE"},
169
169
  {"Function": "read_hydroelectric_feasibility_studies", "Geography": "Hydroelectric Feasibility Studies", "Years": "All", "Source": "EPE"},
170
170
  {"Function": "read_hydroelectric_inventory_aai_studies", "Geography": "Hydroelectric Inventory and AAI Studies", "Years": "All", "Source": "EPE"},
171
- {"Function": "read_ama_anemometric_towers", "Geography": "AMA Anemometric Towers", "Years": "All", "Source": "EPE"}
171
+ {"Function": "read_ama_anemometric_towers", "Geography": "AMA Anemometric Towers", "Years": "All", "Source": "EPE"},
172
+
173
+ # Environmental Enforcement Data
174
+ {"Function": "read_icmbio_embargoes", "Geography": "ICMBio Embargoed Areas", "Years": "All", "Source": "ICMBio"},
175
+ {"Function": "read_icmbio_infractions", "Geography": "ICMBio Infraction Notices", "Years": "All", "Source": "ICMBio"},
176
+ {"Function": "read_ibama_embargoes", "Geography": "IBAMA Embargoed Areas", "Years": "All", "Source": "IBAMA"}
172
177
  ]
173
178
 
174
179
  # Create DataFrame
@@ -1,7 +1,7 @@
1
1
  from geobr.utils import select_metadata, download_gpkg
2
2
 
3
3
 
4
- def read_amazon(year=2012, simplified=True, verbose=False):
4
+ def read_amazon(year=2012, simplified=False, verbose=False):
5
5
  """ Download official data of Brazil's Legal Amazon as an sf object.
6
6
 
7
7
  This data set covers the whole of Brazil's Legal Amazon as defined in the federal law n. 12.651/2012). The original
@@ -0,0 +1,85 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ from io import BytesIO
4
+
5
+ def read_ibama_embargoes(simplified=False, verbose=False):
6
+ """Download IBAMA Embargoes data.
7
+
8
+ This function downloads and processes embargoes data from the Brazilian Institute
9
+ of Environment and Renewable Natural Resources (IBAMA) through their WFS service.
10
+ Original source: IBAMA SISCOM
11
+
12
+ Parameters
13
+ ----------
14
+ simplified : boolean, by default False
15
+ If True, returns a simplified version of the dataset with fewer columns
16
+ verbose : boolean, by default False
17
+ If True, prints detailed information about the download process
18
+
19
+ Returns
20
+ -------
21
+ gpd.GeoDataFrame
22
+ Geodataframe with IBAMA Embargoes data
23
+
24
+ Example
25
+ -------
26
+ >>> from tunned_geobr import read_ibama_embargoes
27
+
28
+ # Read IBAMA Embargoes data
29
+ >>> embargoes = read_ibama_embargoes()
30
+ """
31
+
32
+ url = "https://siscom.ibama.gov.br/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=publica:vw_brasil_adm_embargo_a&outputFormat=application/json"
33
+
34
+ if verbose:
35
+ print("Downloading IBAMA Embargoes data...")
36
+
37
+ try:
38
+ # Download the JSON data
39
+ response = requests.get(url)
40
+ if response.status_code != 200:
41
+ raise Exception(f"Failed to download data from IBAMA WFS service. Status code: {response.status_code}")
42
+
43
+ if verbose:
44
+ print("Data downloaded successfully. Processing...")
45
+
46
+ # Read the GeoJSON directly from the response content
47
+ gdf = gpd.read_file(BytesIO(response.content))
48
+
49
+ # Convert to SIRGAS 2000 (EPSG:4674) if needed
50
+ if gdf.crs is None or gdf.crs.to_epsg() != 4674:
51
+ if verbose:
52
+ print(f"Converting CRS from {gdf.crs} to SIRGAS 2000 (EPSG:4674)")
53
+ gdf = gdf.to_crs(4674)
54
+
55
+ if simplified:
56
+ # Keep only the most relevant columns
57
+ # Adjust these based on the actual columns in the dataset
58
+ columns_to_keep = [
59
+ 'geometry',
60
+ 'nm_municipio', # Municipality name
61
+ 'sg_uf', # State abbreviation
62
+ 'nm_pessoa', # Person/entity name
63
+ 'nr_cpfcnpj', # CPF/CNPJ number
64
+ 'dt_embargo', # Embargo date
65
+ 'nr_processo', # Process number
66
+ 'nr_termo', # Term number
67
+ 'ar_embargada', # Embargoed area
68
+ 'tp_infracao', # Infraction type
69
+ 'ds_infracao' # Infraction description
70
+ ]
71
+
72
+ # Filter columns that actually exist in the dataset
73
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
74
+ gdf = gdf[existing_columns]
75
+
76
+ if verbose:
77
+ print(f"Simplified dataset with {len(existing_columns)} columns")
78
+
79
+ except Exception as e:
80
+ raise Exception(f"Error downloading IBAMA Embargoes data: {str(e)}")
81
+
82
+ if verbose:
83
+ print(f"Download completed. Returning GeoDataFrame with {len(gdf)} records")
84
+
85
+ return gdf
@@ -0,0 +1,83 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ from io import BytesIO
4
+
5
+ def read_icmbio_embargoes(simplified=False, verbose=False):
6
+ """Download ICMBio Embargoes data.
7
+
8
+ This function downloads and processes embargoes data from the Brazilian Institute
9
+ of Environment and Renewable Natural Resources (ICMBio) through the National Spatial
10
+ Data Infrastructure (INDE) WFS service.
11
+ Original source: ICMBio via INDE
12
+
13
+ Parameters
14
+ ----------
15
+ simplified : boolean, by default False
16
+ If True, returns a simplified version of the dataset with fewer columns
17
+ verbose : boolean, by default False
18
+ If True, prints detailed information about the download process
19
+
20
+ Returns
21
+ -------
22
+ gpd.GeoDataFrame
23
+ Geodataframe with ICMBio Embargoes data
24
+
25
+ Example
26
+ -------
27
+ >>> from tunned_geobr import read_icmbio_embargoes
28
+
29
+ # Read ICMBio Embargoes data
30
+ >>> embargoes = read_icmbio_embargoes()
31
+ """
32
+
33
+ url = "https://geoservicos.inde.gov.br/geoserver/ICMBio/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=embargos_icmbio&outputFormat=application/json"
34
+
35
+ if verbose:
36
+ print("Downloading ICMBio Embargoes data...")
37
+
38
+ try:
39
+ # Download the JSON data
40
+ response = requests.get(url)
41
+ if response.status_code != 200:
42
+ raise Exception(f"Failed to download data from ICMBio WFS service. Status code: {response.status_code}")
43
+
44
+ if verbose:
45
+ print("Data downloaded successfully. Processing...")
46
+
47
+ # Read the GeoJSON directly from the response content
48
+ gdf = gpd.read_file(BytesIO(response.content))
49
+
50
+ # Convert to SIRGAS 2000 (EPSG:4674) if needed
51
+ if gdf.crs is None or gdf.crs.to_epsg() != 4674:
52
+ if verbose:
53
+ print(f"Converting CRS from {gdf.crs} to SIRGAS 2000 (EPSG:4674)")
54
+ gdf = gdf.to_crs(4674)
55
+
56
+ if simplified:
57
+ # Keep only the most relevant columns
58
+ # Adjust these based on the actual columns in the dataset
59
+ columns_to_keep = [
60
+ 'geometry',
61
+ 'NOME_AREA', # Area name
62
+ 'MUNICIPIO', # Municipality
63
+ 'UF', # State
64
+ 'AREA_HA', # Area in hectares
65
+ 'TIPO_INFRA', # Infraction type
66
+ 'DATA_EMBARG', # Embargo date
67
+ 'TERMO_EMBG' # Embargo term
68
+ ]
69
+
70
+ # Filter columns that actually exist in the dataset
71
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
72
+ gdf = gdf[existing_columns]
73
+
74
+ if verbose:
75
+ print(f"Simplified dataset with {len(existing_columns)} columns")
76
+
77
+ except Exception as e:
78
+ raise Exception(f"Error downloading ICMBio Embargoes data: {str(e)}")
79
+
80
+ if verbose:
81
+ print(f"Download completed. Returning GeoDataFrame with {len(gdf)} records")
82
+
83
+ return gdf
@@ -0,0 +1,83 @@
1
+ import geopandas as gpd
2
+ import requests
3
+ from io import BytesIO
4
+
5
+ def read_icmbio_infractions(simplified=False, verbose=False):
6
+ """Download ICMBio Infraction Notices data.
7
+
8
+ This function downloads and processes infraction notices data from the Brazilian Institute
9
+ of Environment and Renewable Natural Resources (ICMBio) through the National Spatial
10
+ Data Infrastructure (INDE) WFS service.
11
+ Original source: ICMBio via INDE
12
+
13
+ Parameters
14
+ ----------
15
+ simplified : boolean, by default False
16
+ If True, returns a simplified version of the dataset with fewer columns
17
+ verbose : boolean, by default False
18
+ If True, prints detailed information about the download process
19
+
20
+ Returns
21
+ -------
22
+ gpd.GeoDataFrame
23
+ Geodataframe with ICMBio Infraction Notices data
24
+
25
+ Example
26
+ -------
27
+ >>> from tunned_geobr import read_icmbio_infractions
28
+
29
+ # Read ICMBio Infraction Notices data
30
+ >>> infractions = read_icmbio_infractions()
31
+ """
32
+
33
+ url = "https://geoservicos.inde.gov.br/geoserver/ICMBio/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=autos_infracao_icmbio&outputFormat=application/json"
34
+
35
+ if verbose:
36
+ print("Downloading ICMBio Infraction Notices data...")
37
+
38
+ try:
39
+ # Download the JSON data
40
+ response = requests.get(url)
41
+ if response.status_code != 200:
42
+ raise Exception(f"Failed to download data from ICMBio WFS service. Status code: {response.status_code}")
43
+
44
+ if verbose:
45
+ print("Data downloaded successfully. Processing...")
46
+
47
+ # Read the GeoJSON directly from the response content
48
+ gdf = gpd.read_file(BytesIO(response.content))
49
+
50
+ # Convert to SIRGAS 2000 (EPSG:4674) if needed
51
+ if gdf.crs is None or gdf.crs.to_epsg() != 4674:
52
+ if verbose:
53
+ print(f"Converting CRS from {gdf.crs} to SIRGAS 2000 (EPSG:4674)")
54
+ gdf = gdf.to_crs(4674)
55
+
56
+ if simplified:
57
+ # Keep only the most relevant columns
58
+ # Adjust these based on the actual columns in the dataset
59
+ columns_to_keep = [
60
+ 'geometry',
61
+ 'MUNICIPIO', # Municipality
62
+ 'UF', # State
63
+ 'DATA_AUTO', # Infraction date
64
+ 'TIPO_INFRA', # Infraction type
65
+ 'AREA_PROTE', # Protected area
66
+ 'VALOR_AUTO', # Fine value
67
+ 'NUM_AUTO' # Infraction number
68
+ ]
69
+
70
+ # Filter columns that actually exist in the dataset
71
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
72
+ gdf = gdf[existing_columns]
73
+
74
+ if verbose:
75
+ print(f"Simplified dataset with {len(existing_columns)} columns")
76
+
77
+ except Exception as e:
78
+ raise Exception(f"Error downloading ICMBio Infraction Notices data: {str(e)}")
79
+
80
+ if verbose:
81
+ print(f"Download completed. Returning GeoDataFrame with {len(gdf)} records")
82
+
83
+ return gdf
@@ -1,81 +1,69 @@
1
- from geobr.utils import select_metadata, download_gpkg, change_type_list, test_options
2
-
3
-
4
- def read_immediate_region(
5
- code_immediate="all", year=2017, simplified=False, verbose=False
6
- ):
7
- """ Download shape files of Brazil's Immediate Geographic Areas as sf objects
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_immediate_region(simplified=False):
9
+ """Download official immediate region data from IBGE.
10
+
11
+ This function downloads and processes immediate region data from IBGE (Brazilian Institute of Geography and Statistics).
12
+ The data includes immediate regions of Brazil for the year 2023.
13
+ Original source: IBGE
8
14
 
9
- The Immediate Geographic Areas are part of the geographic division of
10
- Brazil created in 2017 by IBGE to replace the "Micro Regions" division.
11
- Data at scale 1:250,000, using Geodetic reference system "SIRGAS2000"
12
- and CRS(4674)
13
-
14
15
  Parameters
15
16
  ----------
16
- code_immediate:
17
- 6-digit code of an immediate region. If the two-digit code or a
18
- two-letter uppercase abbreviation of a state is passed, (e.g. 33 or
19
- "RJ") the function will load all immediate regions of that state. If
20
- code_immediate="all", all immediate regions of the country are loaded
21
- (defaults to "all").
22
- year : int, optional
23
- Year of the data, by default 2017
24
- simplify: boolean, by default True
25
- Data 'type', indicating whether the function returns the 'original' dataset
26
- with high resolution or a dataset with 'simplify' borders (Default)
27
- verbose : bool, optional
28
- by default False
29
-
17
+ simplified : boolean, by default False
18
+ If True, returns a simplified version of the dataset with fewer columns
19
+
30
20
  Returns
31
21
  -------
32
22
  gpd.GeoDataFrame
33
- Metadata and geopackage of selected states
34
-
35
- Raises
36
- ------
37
- Exception
38
- If parameters are not found or not well defined
39
-
23
+ Geodataframe with immediate region data
24
+
40
25
  Example
41
26
  -------
42
27
  >>> from geobr import read_immediate_region
43
-
44
- # Read specific state at a given year
45
- >>> df = read_immediate_region(year=2017)
28
+
29
+ # Read immediate region data
30
+ >>> immediate_region = read_immediate_region()
46
31
  """
47
-
48
- test_options(code_immediate, "code_immediate", not_allowed=[None])
49
-
50
- metadata = select_metadata("immediate_regions", year=year, simplified=simplified)
51
-
52
- gdf = download_gpkg(metadata)
53
-
54
- # ensure type
55
- code_immediate = str(code_immediate)
56
-
57
- if code_immediate == "all":
58
-
59
- if verbose:
60
- print(
61
- "Loading data for the whole country. "
62
- "This might take a few minutes.\n"
63
- )
64
-
65
- return gdf
66
-
67
- elif code_immediate in gdf["abbrev_state"].tolist():
68
-
69
- return gdf.query(f'abbrev_state == "{code_immediate}"')
70
-
71
- elif code_immediate in change_type_list(gdf["code_state"].tolist()):
72
-
73
- return gdf.query(f'code_state == "{code_immediate}"')
74
-
75
- elif code_immediate in change_type_list(gdf["code_immediate"].tolist()):
76
-
77
- return gdf.query(f'code_immediate == "{code_immediate}"')
78
-
79
- else:
80
-
81
- raise Exception("Invalid Value to argument 'code_immediate'")
32
+
33
+ url = "https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2023/Brasil/BR_RG_Imediatas_2023.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 IBGE")
40
+
41
+ # Create a temporary directory
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ # Extract zip content
44
+ with ZipFile(BytesIO(response.content)) as zip_ref:
45
+ zip_ref.extractall(temp_dir)
46
+
47
+ # Find the shapefile
48
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
49
+ if not shp_files:
50
+ raise Exception("No shapefile found in the downloaded data")
51
+
52
+ # Read the shapefile
53
+ gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
54
+
55
+ if simplified:
56
+ # Keep only the most relevant columns
57
+ # Note: These columns are based on typical immediate region data structure
58
+ # You may want to adjust these based on the actual data
59
+ columns_to_keep = [
60
+ 'geometry',
61
+ 'CD_RGI', # Immediate region code
62
+ 'NM_RGI', # Immediate region name
63
+ ]
64
+ gdf = gdf[columns_to_keep]
65
+
66
+ except Exception as e:
67
+ raise Exception(f"Error downloading immediate region data: {str(e)}")
68
+
69
+ return gdf
@@ -1,44 +1,77 @@
1
- from geobr.utils import select_metadata, download_gpkg
1
+ import geopandas as gpd
2
+ import tempfile
3
+ import os
4
+ import requests
5
+ from zipfile import ZipFile
6
+ from io import BytesIO
2
7
 
3
-
4
- def read_indigenous_land(date=201907, simplified=False, verbose=False):
5
- """ Download official data of indigenous lands as an sf object.
8
+ def read_indigenous_land(simplified=False):
9
+ """Download Indigenous Land data from FUNAI.
10
+
11
+ This function downloads and processes data about indigenous lands in Brazil
12
+ from FUNAI (Fundação Nacional dos Povos Indígenas). The data includes location
13
+ and basic information about registered indigenous lands.
14
+ Original source: FUNAI - Fundação Nacional dos Povos Indígenas
6
15
 
7
- The data set covers the whole of Brazil and it includes indigenous lands from all ethnicities and
8
- in different stages of demarcation. The original data comes from the National Indian Foundation (FUNAI)
9
- and can be found at http://www.funai.gov.br/index.php/shape. Although original data is updated monthly,
10
- the geobr package will only keep the data for a few months per year.
11
-
12
16
  Parameters
13
17
  ----------
14
- date : int, optional
15
- A date numer in YYYYMM format, by default 201907
16
- simplified: boolean, by default True
17
- Data 'type', indicating whether the function returns the 'original' dataset
18
- with high resolution or a dataset with 'simplified' borders (Default)
19
- verbose : bool, optional
20
- by default False
21
-
18
+ simplified : boolean, by default False
19
+ If True, returns a simplified version of the dataset with fewer columns
20
+
22
21
  Returns
23
22
  -------
24
23
  gpd.GeoDataFrame
25
- Metadata and geopackage of selected states
26
-
27
- Raises
28
- ------
29
- Exception
30
- If parameters are not found or not well defined
31
-
24
+ Geodataframe with indigenous land data
25
+ Columns:
26
+ - geometry: Land boundaries
27
+ - nome: Land name
28
+ - municipio: Municipality
29
+ - uf: State
30
+ - etnia: Ethnicity
31
+ - fase: Legal status
32
+ - area_ha: Area in hectares
33
+
32
34
  Example
33
35
  -------
34
- >>> from geobr import read_indigenous_land
35
-
36
- # Read specific state at a given year
37
- >>> df = read_indigenous_land(date=201907)
36
+ >>> from tunned_geobr import read_indigenous_land
37
+ >>> lands = read_indigenous_land()
38
38
  """
39
-
40
- metadata = select_metadata("indigenous_land", year=date, simplified=simplified)
41
-
42
- gdf = download_gpkg(metadata)
43
-
39
+
40
+ url = "https://geoserver.funai.gov.br/geoserver/Funai/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Funai%3Atis_poligonais&maxFeatures=10000&outputFormat=SHAPE-ZIP"
41
+
42
+ try:
43
+ # Download the zip file with a 60-second timeout
44
+ response = requests.get(url, timeout=60)
45
+ if response.status_code != 200:
46
+ raise Exception(f"Failed to download data from FUNAI. Status code: {response.status_code}")
47
+
48
+ # Create a temporary directory
49
+ with tempfile.TemporaryDirectory() as temp_dir:
50
+ # Extract the zip file
51
+ with ZipFile(BytesIO(response.content)) as zip_ref:
52
+ zip_ref.extractall(temp_dir)
53
+
54
+ # Find the shapefile
55
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
56
+ if not shp_files:
57
+ raise Exception("No shapefile found in the downloaded data")
58
+
59
+ # Read the shapefile
60
+ gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
61
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
62
+
63
+ # Print columns for debugging
64
+ print("Available columns:", gdf.columns)
65
+
66
+ if simplified:
67
+ columns_to_keep = ['geometry', 'nome', 'municipio', 'uf', 'etnia', 'fase', 'area_ha']
68
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
69
+ gdf = gdf[existing_columns]
70
+
71
+ except Exception as e:
72
+ raise Exception(f"Error downloading indigenous land data: {str(e)}")
73
+
44
74
  return gdf
75
+
76
+ if __name__ == '__main__':
77
+ read_indigenous_land()