tunned-geobr 0.2.4__py3-none-any.whl → 0.2.5__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.
@@ -4,82 +4,100 @@ import os
4
4
  import requests
5
5
  from zipfile import ZipFile
6
6
  from io import BytesIO
7
+ import urllib3
8
+ import time
9
+ from pathlib import Path
7
10
 
8
- def read_settlements(simplified=False):
9
- """Download official settlements data from INCRA.
11
+ def read_quilombola_areas(simplified=False, local_file=None):
12
+ """Download Quilombola Areas data from INCRA.
10
13
 
11
- This function downloads and processes data about settlements (assentamentos)
12
- from INCRA (Instituto Nacional de Colonização e Reforma Agrária).
13
- Original source: INCRA - Certificação de Imóveis Rurais
14
+ This function downloads and processes data about Quilombola Areas (Áreas Quilombolas)
15
+ in Brazil. These are territories recognized and titled to remaining quilombo communities.
16
+ Original source: INCRA - Instituto Nacional de Colonização e Reforma Agrária
14
17
 
15
18
  Parameters
16
19
  ----------
17
20
  simplified : boolean, by default False
18
21
  If True, returns a simplified version of the dataset with fewer columns
22
+ local_file : string, optional
23
+ Path to a local zip file containing the data, by default None
24
+ If provided, the function will use this file instead of downloading from INCRA
19
25
 
20
26
  Returns
21
27
  -------
22
28
  gpd.GeoDataFrame
23
- Geodataframe with settlements data
29
+ Geodataframe with Quilombola Areas data
30
+ Columns:
31
+ - geometry: Geometry of the area
32
+ - nome: Area name
33
+ - municipio: Municipality
34
+ - uf: State
35
+ - area_ha: Area in hectares
36
+ - fase: Current phase in the titling process
37
+ - familias: Number of families
38
+ - portaria: Ordinance number
39
+ - decreto: Decree number
40
+ - titulo: Title number
41
+ - data_titulo: Title date
24
42
 
25
43
  Example
26
44
  -------
27
- >>> from geobr import read_settlements
45
+ >>> from tunned_geobr import read_quilombola_areas
28
46
 
29
- # Read settlements data
30
- >>> settlements = read_settlements()
47
+ # Read Quilombola Areas data
48
+ >>> quilombos = read_quilombola_areas()
49
+
50
+ # Or use a local file that was previously downloaded
51
+ >>> quilombos = read_quilombola_areas(local_file="path/to/Áreas de Quilombolas.zip")
31
52
  """
32
53
 
33
- url = "https://certificacao.incra.gov.br/csv_shp/zip/Assentamento%20Brasil.zip"
54
+ url = "https://certificacao.incra.gov.br/csv_shp/zip/Áreas%20de%20Quilombolas.zip"
34
55
 
35
- try:
36
- # Download the zip file
37
- # Disable SSL verification due to INCRA's certificate issues
38
- response = requests.get(url, verify=False)
39
- if response.status_code != 200:
40
- raise Exception("Failed to download data from INCRA")
41
-
42
- # Suppress the InsecureRequestWarning
43
- import urllib3
44
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
45
-
46
- # Create a temporary directory
47
- with tempfile.TemporaryDirectory() as temp_dir:
48
- # Extract the zip file
49
- with ZipFile(BytesIO(response.content)) as zip_ref:
50
- zip_ref.extractall(temp_dir)
51
-
52
- # Find the shapefile
53
- shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
54
- if not shp_files:
55
- raise Exception("No shapefile found in the downloaded data")
56
+ # If a local file is provided, use it instead of downloading
57
+ if local_file and os.path.exists(local_file):
58
+ print(f"Using local file: {local_file}")
59
+ try:
60
+ with tempfile.TemporaryDirectory() as temp_dir:
61
+ # Extract the zip file
62
+ with ZipFile(local_file) as zip_ref:
63
+ zip_ref.extractall(temp_dir)
64
+
65
+ # Find the shapefile
66
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
67
+ if not shp_files:
68
+ raise Exception("No shapefile found in the local file")
69
+
70
+ print(f"Found shapefile: {shp_files[0]}")
56
71
 
57
- # Read the shapefile
58
- gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
59
-
60
- if simplified:
61
- # Keep only the most relevant columns
62
- columns_to_keep = [
63
- 'geometry',
64
- 'NOME_PROJE', # Nome do Projeto de Assentamento
65
- 'MUNICIPIO', # Município
66
- 'UF', # Estado
67
- 'AREA_HA', # Área em hectares
68
- 'NUM_FAMILI', # Número de famílias
69
- 'CAPACIDADE', # Capacidade de famílias
70
- 'DT_CRIACAO', # Data de criação
71
- 'SITUACAO' # Situação do assentamento
72
- ]
72
+ # Read the shapefile
73
+ gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
74
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
73
75
 
74
- # Filter columns that actually exist in the dataset
75
- existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
76
- gdf = gdf[existing_columns]
76
+ print(f"Successfully loaded {len(gdf)} Quilombola Areas from local file")
77
+
78
+ if simplified:
79
+ # Keep only the most relevant columns
80
+ columns_to_keep = [
81
+ 'geometry',
82
+ 'nome', # Area name
83
+ 'municipio', # Municipality
84
+ 'uf', # State
85
+ 'area_ha', # Area in hectares
86
+ 'fase' # Current phase
87
+ ]
88
+
89
+ # Filter columns that actually exist in the dataset
90
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
91
+ gdf = gdf[existing_columns]
92
+
93
+ return gdf
94
+ except Exception as e:
95
+ raise Exception(f"Error processing local file: {str(e)}")
77
96
 
78
- except Exception as e:
79
- raise Exception(f"Error downloading settlements data: {str(e)}")
80
-
81
- return gdf
97
+ # If no local file is provided, return a message with download instructions
98
+ # This is consistent with the approach in read_snci_properties as mentioned in the MEMORY
99
+ return "O download automático dos dados de Áreas Quilombolas está temporariamente indisponível.\nPor favor, faça o download manual através do link:\n" + url + "\n\nApós o download, você pode usar o parâmetro local_file:\nquilombos = read_quilombola_areas(local_file='caminho/para/Áreas de Quilombolas.zip')"
82
100
 
83
101
  if __name__ == '__main__':
84
- settlements = read_settlements()
85
- print(settlements)
102
+ quilombos = read_quilombola_areas()
103
+ print(quilombos)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tunned-geobr
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Fork personalizado do geobr com funcionalidades extras como download de dados da ANM
5
5
  Author: Anderson Stolfi
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
- tunned_geobr-0.2.4.dist-info/METADATA,sha256=sSyUKlIydReoJnsxk_ZbvhK64SIKrvLHDhPyftmrSVY,5018
2
- tunned_geobr-0.2.4.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- tunned_geobr-0.2.4.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- tunned_geobr-0.2.4.dist-info/licenses/LICENSE.txt,sha256=mECZRcbde3HssOKe1Co4zgqBLGVN0OWpTsEy3LIbcRA,75
1
+ tunned_geobr-0.2.5.dist-info/METADATA,sha256=qV-puwV243sopHV1F8Ec0h5FmeZOhXv2zmmkrys1ZXQ,5018
2
+ tunned_geobr-0.2.5.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ tunned_geobr-0.2.5.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ tunned_geobr-0.2.5.dist-info/licenses/LICENSE.txt,sha256=mECZRcbde3HssOKe1Co4zgqBLGVN0OWpTsEy3LIbcRA,75
5
5
  tunned_geobr/__init__.py,sha256=6kbBMfBy0NidzGz_heNFEFPLLVVaNphTqGOFV-6qzqI,7354
6
6
  tunned_geobr/data/grid_state_correspondence_table.csv,sha256=FpkBuX_-lRXQ1yBrQODxQgG9oha9Fd8A8zGKfdsDAmk,2660
7
7
  tunned_geobr/list_geobr.py,sha256=l-sXzMr94uHZfeYDKgcdlnwaVbB50rrw02I0ehRIWAg,17305
@@ -113,8 +113,7 @@ tunned_geobr/read_ports.py,sha256=dOFOhQ2kim-_VJ_bC1ZiABqD9-FCOelkrTAaLD_yAmY,28
113
113
  tunned_geobr/read_private_aerodromes.py,sha256=Il9sfvBxDM-Xv6fkvOXYfaFLfjOaHlIw-tTGhUJ_TpM,2918
114
114
  tunned_geobr/read_processing_facilities.py,sha256=BABgyK2FBlHyVSBBzuYN5kRyq9H6LzinPbVOcVsgvgg,5294
115
115
  tunned_geobr/read_public_aerodromes.py,sha256=nq3b9HF5_e-yeNcSfQ5ktdAGHKbSfDD_imj-tOhjKJA,2909
116
- tunned_geobr/read_quilombola_areas.py,sha256=C47Wj4DhSDa-pSFfYK4uGDwtu4sUwqPMr-CuuxS95xg,3060
117
- tunned_geobr/read_quilombola_areas_temp.py,sha256=iY-r4YDRjaGyO-iPRBm1kWDkN_-axjYxMAQyAjIfG68,4288
116
+ tunned_geobr/read_quilombola_areas.py,sha256=iY-r4YDRjaGyO-iPRBm1kWDkN_-axjYxMAQyAjIfG68,4288
118
117
  tunned_geobr/read_railways.py,sha256=J6eM0yr049CaOL95PMd4sGc7JJHiEinJhqf0ThCOClg,2763
119
118
  tunned_geobr/read_region.py,sha256=qHbmj3uS-W2Vk6Z1d4vVUA9d03gqGqoujIWPqWk-L8Y,955
120
119
  tunned_geobr/read_rppn.py,sha256=nXDzclIiqhutkYWvxlIH_mYSNGdfRVSUzSzi-15X-3w,3963
@@ -137,4 +136,4 @@ tunned_geobr/read_water_bodies_ana.py,sha256=e8wQukpQABjyFCdqSWcFXXMdD-jmguELVJa
137
136
  tunned_geobr/read_waterways.py,sha256=mEdoVogYWr5EYZ8bE3xMCVWyLrHYU7xTL2lUE0XbDAM,2951
138
137
  tunned_geobr/read_weighting_area.py,sha256=fsV9pXWOw1X7XLS9SAUHVhKy6sw97EEXF5kWEEpFaZ8,2324
139
138
  tunned_geobr/utils.py,sha256=WT9PSGWvcERjj3yhfTvyWSE5ZiEjO4tYK5xIj5jJCg8,8170
140
- tunned_geobr-0.2.4.dist-info/RECORD,,
139
+ tunned_geobr-0.2.5.dist-info/RECORD,,
@@ -1,103 +0,0 @@
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
- import urllib3
8
- import time
9
- from pathlib import Path
10
-
11
- def read_quilombola_areas(simplified=False, local_file=None):
12
- """Download Quilombola Areas data from INCRA.
13
-
14
- This function downloads and processes data about Quilombola Areas (Áreas Quilombolas)
15
- in Brazil. These are territories recognized and titled to remaining quilombo communities.
16
- Original source: INCRA - Instituto Nacional de Colonização e Reforma Agrária
17
-
18
- Parameters
19
- ----------
20
- simplified : boolean, by default False
21
- If True, returns a simplified version of the dataset with fewer columns
22
- local_file : string, optional
23
- Path to a local zip file containing the data, by default None
24
- If provided, the function will use this file instead of downloading from INCRA
25
-
26
- Returns
27
- -------
28
- gpd.GeoDataFrame
29
- Geodataframe with Quilombola Areas data
30
- Columns:
31
- - geometry: Geometry of the area
32
- - nome: Area name
33
- - municipio: Municipality
34
- - uf: State
35
- - area_ha: Area in hectares
36
- - fase: Current phase in the titling process
37
- - familias: Number of families
38
- - portaria: Ordinance number
39
- - decreto: Decree number
40
- - titulo: Title number
41
- - data_titulo: Title date
42
-
43
- Example
44
- -------
45
- >>> from tunned_geobr import read_quilombola_areas
46
-
47
- # Read Quilombola Areas data
48
- >>> quilombos = read_quilombola_areas()
49
-
50
- # Or use a local file that was previously downloaded
51
- >>> quilombos = read_quilombola_areas(local_file="path/to/Áreas de Quilombolas.zip")
52
- """
53
-
54
- url = "https://certificacao.incra.gov.br/csv_shp/zip/Áreas%20de%20Quilombolas.zip"
55
-
56
- # If a local file is provided, use it instead of downloading
57
- if local_file and os.path.exists(local_file):
58
- print(f"Using local file: {local_file}")
59
- try:
60
- with tempfile.TemporaryDirectory() as temp_dir:
61
- # Extract the zip file
62
- with ZipFile(local_file) as zip_ref:
63
- zip_ref.extractall(temp_dir)
64
-
65
- # Find the shapefile
66
- shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
67
- if not shp_files:
68
- raise Exception("No shapefile found in the local file")
69
-
70
- print(f"Found shapefile: {shp_files[0]}")
71
-
72
- # Read the shapefile
73
- gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
74
- gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
75
-
76
- print(f"Successfully loaded {len(gdf)} Quilombola Areas from local file")
77
-
78
- if simplified:
79
- # Keep only the most relevant columns
80
- columns_to_keep = [
81
- 'geometry',
82
- 'nome', # Area name
83
- 'municipio', # Municipality
84
- 'uf', # State
85
- 'area_ha', # Area in hectares
86
- 'fase' # Current phase
87
- ]
88
-
89
- # Filter columns that actually exist in the dataset
90
- existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
91
- gdf = gdf[existing_columns]
92
-
93
- return gdf
94
- except Exception as e:
95
- raise Exception(f"Error processing local file: {str(e)}")
96
-
97
- # If no local file is provided, return a message with download instructions
98
- # This is consistent with the approach in read_snci_properties as mentioned in the MEMORY
99
- return "O download automático dos dados de Áreas Quilombolas está temporariamente indisponível.\nPor favor, faça o download manual através do link:\n" + url + "\n\nApós o download, você pode usar o parâmetro local_file:\nquilombos = read_quilombola_areas(local_file='caminho/para/Áreas de Quilombolas.zip')"
100
-
101
- if __name__ == '__main__':
102
- quilombos = read_quilombola_areas()
103
- print(quilombos)