tunned-geobr 1.0.17__py3-none-any.whl → 1.0.18__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.
@@ -5,13 +5,11 @@ import requests
5
5
  from zipfile import ZipFile
6
6
  from io import BytesIO
7
7
  import urllib3
8
- import time
9
- from pathlib import Path
10
8
 
11
- def read_quilombola_areas(simplified=False, local_file=None):
9
+ def read_quilombola_areas(simplified=False):
12
10
  """Download Quilombola Areas data from INCRA.
13
11
 
14
- This function downloads and processes data about Quilombola Areas (Áreas Quilombolas)
12
+ This function downloads and processes data about Quilombola Areas (Áreas Quilombolas)
15
13
  in Brazil. These are territories recognized and titled to remaining quilombo communities.
16
14
  Original source: INCRA - Instituto Nacional de Colonização e Reforma Agrária
17
15
 
@@ -19,9 +17,6 @@ def read_quilombola_areas(simplified=False, local_file=None):
19
17
  ----------
20
18
  simplified : boolean, by default False
21
19
  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
20
 
26
21
  Returns
27
22
  -------
@@ -46,57 +41,54 @@ def read_quilombola_areas(simplified=False, local_file=None):
46
41
 
47
42
  # Read Quilombola Areas data
48
43
  >>> 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
44
  """
53
45
 
54
46
  url = "https://certificacao.incra.gov.br/csv_shp/zip/Áreas%20de%20Quilombolas.zip"
55
47
 
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]}")
48
+ try:
49
+ # Download the zip file
50
+ # Disable SSL verification due to INCRA's certificate issues
51
+ response = requests.get(url, verify=False)
52
+ if response.status_code != 200:
53
+ raise Exception("Failed to download data from INCRA")
54
+
55
+ # Suppress the InsecureRequestWarning
56
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
57
+
58
+ # Create a temporary directory
59
+ with tempfile.TemporaryDirectory() as temp_dir:
60
+ # Extract the zip file
61
+ with ZipFile(BytesIO(response.content)) as zip_ref:
62
+ zip_ref.extractall(temp_dir)
63
+
64
+ # Find the shapefile
65
+ shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
66
+ if not shp_files:
67
+ raise Exception("No shapefile found in the downloaded data")
71
68
 
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
69
+ # Read the shapefile
70
+ gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
71
+ gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
72
+
73
+ if simplified:
74
+ # Keep only the most relevant columns
75
+ columns_to_keep = [
76
+ 'geometry',
77
+ 'nome', # Area name
78
+ 'municipio', # Municipality
79
+ 'uf', # State
80
+ 'area_ha', # Area in hectares
81
+ 'fase' # Current phase
82
+ ]
75
83
 
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)}")
84
+ # Filter columns that actually exist in the dataset
85
+ existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
86
+ gdf = gdf[existing_columns]
96
87
 
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')"
88
+ except Exception as e:
89
+ raise Exception(f"Error downloading Quilombola Areas data: {str(e)}")
90
+
91
+ return gdf
100
92
 
101
93
  if __name__ == '__main__':
102
94
  quilombos = read_quilombola_areas()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tunned-geobr
3
- Version: 1.0.17
3
+ Version: 1.0.18
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-1.0.17.dist-info/METADATA,sha256=L_vwL2Yy63eLa0GHgHmVcRwJ9oeSAeb_euYaNWaPrEI,5019
2
- tunned_geobr-1.0.17.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- tunned_geobr-1.0.17.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- tunned_geobr-1.0.17.dist-info/licenses/LICENSE.txt,sha256=mECZRcbde3HssOKe1Co4zgqBLGVN0OWpTsEy3LIbcRA,75
1
+ tunned_geobr-1.0.18.dist-info/METADATA,sha256=0REjnixXDIlXgmgKPHUUd97T6sEfy3TfM7tV1qH1VIs,5019
2
+ tunned_geobr-1.0.18.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ tunned_geobr-1.0.18.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ tunned_geobr-1.0.18.dist-info/licenses/LICENSE.txt,sha256=mECZRcbde3HssOKe1Co4zgqBLGVN0OWpTsEy3LIbcRA,75
5
5
  tunned_geobr/__init__.py,sha256=8STl_F6A8JWqePcb22E5eW-_EZ5Ln_tOnkCsjlrVOFc,8045
6
6
  tunned_geobr/data/grid_state_correspondence_table.csv,sha256=FpkBuX_-lRXQ1yBrQODxQgG9oha9Fd8A8zGKfdsDAmk,2660
7
7
  tunned_geobr/list_geobr.py,sha256=JXQeF8bKmXlNVOHUyNKaYgOtLZQ9e2mb2b2PSLfzIhU,18426
@@ -118,7 +118,7 @@ tunned_geobr/read_private_aerodromes.py,sha256=Il9sfvBxDM-Xv6fkvOXYfaFLfjOaHlIw-
118
118
  tunned_geobr/read_processing_facilities.py,sha256=8iCveDTk7MXm1bmb1pcknzen62HTGYQ3KEzvUGSdWfk,5349
119
119
  tunned_geobr/read_production_fields.py,sha256=yw1g6u4kLGgiFwEbIcoj2IxvGGcT6u8sASqM2RRNk1Q,3182
120
120
  tunned_geobr/read_public_aerodromes.py,sha256=nq3b9HF5_e-yeNcSfQ5ktdAGHKbSfDD_imj-tOhjKJA,2909
121
- tunned_geobr/read_quilombola_areas.py,sha256=iY-r4YDRjaGyO-iPRBm1kWDkN_-axjYxMAQyAjIfG68,4288
121
+ tunned_geobr/read_quilombola_areas.py,sha256=hJFcj23Msh7pCaxQgAkgOefbgi228bnezrW7jZgykyY,3385
122
122
  tunned_geobr/read_railways.py,sha256=J6eM0yr049CaOL95PMd4sGc7JJHiEinJhqf0ThCOClg,2763
123
123
  tunned_geobr/read_region.py,sha256=X7IwsAVxwUl0apsExSuBr9kIK_7IUehPenLXAF-JFDA,2331
124
124
  tunned_geobr/read_rppn.py,sha256=nXDzclIiqhutkYWvxlIH_mYSNGdfRVSUzSzi-15X-3w,3963
@@ -146,4 +146,4 @@ tunned_geobr/read_water_bodies_ana.py,sha256=Z-dpTPVgRHVndTeSFxx8uXn7ufMg2jm0Dlz
146
146
  tunned_geobr/read_waterways.py,sha256=mEdoVogYWr5EYZ8bE3xMCVWyLrHYU7xTL2lUE0XbDAM,2951
147
147
  tunned_geobr/read_weighting_area.py,sha256=m2X5Ua3jRqLlkqCQbIzR2jmo58pzqkyR3UYcGtgy20E,2325
148
148
  tunned_geobr/utils.py,sha256=WT9PSGWvcERjj3yhfTvyWSE5ZiEjO4tYK5xIj5jJCg8,8170
149
- tunned_geobr-1.0.17.dist-info/RECORD,,
149
+ tunned_geobr-1.0.18.dist-info/RECORD,,