tunned-geobr 1.0.2__py3-none-any.whl → 1.0.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.
@@ -4,48 +4,72 @@ import os
4
4
  import requests
5
5
  from zipfile import ZipFile
6
6
  from io import BytesIO
7
+ from requests.adapters import HTTPAdapter
8
+ from urllib3.util.retry import Retry
9
+ import time # Import time for potential delays between retries
7
10
 
8
11
  def read_sigef_properties(simplified=False):
9
- """Download Certified Properties data from INCRA's SNCI.
10
-
11
- This function downloads and processes certified properties data from INCRA's
12
- National Property Certification System (Sistema Nacional de Certificação de Imóveis - SNCI).
13
- The data includes information about certified rural properties across Brazil.
12
+ """Download SIGEF Properties data from INCRA.
13
+
14
+ This function downloads and processes rural property data from INCRA's
15
+ SIGEF (Sistema de Gestão Fundiária). The dataset contains information
16
+ about rural properties registered in the SIGEF system across Brazil.
17
+
14
18
  Original source: INCRA (Instituto Nacional de Colonização e Reforma Agrária)
15
-
19
+
16
20
  Parameters
17
21
  ----------
18
- simplified : boolean, by default False
19
- If True, returns a simplified version of the dataset with fewer columns
22
+ simplified : bool, default False
23
+ If True, returns a simplified version of the dataset with selected columns.
20
24
 
21
25
  Returns
22
26
  -------
23
27
  gpd.GeoDataFrame
24
- Geodataframe with certified properties data
25
-
28
+ GeoDataFrame with SIGEF properties data.
29
+
26
30
  Example
27
31
  -------
28
- >>> from tunned_geobr import read_snci_properties
29
-
30
- # Read certified properties data
31
- >>> properties = read_snci_properties()
32
+ >>> from tunned_geobr import read_sigef_properties
33
+
34
+ # Read SIGEF properties data
35
+ >>> properties = read_sigef_properties()
32
36
  """
33
37
 
34
38
  url = "https://certificacao.incra.gov.br/csv_shp/zip/Sigef%20Brasil.zip"
39
+
40
+ # Configure retries
41
+ retries = Retry(
42
+ total=5, # Total number of retries to allow
43
+ backoff_factor=1, # A backoff factor to apply between attempts (e.g., 1, 2, 4, 8 seconds)
44
+ status_forcelist=[500, 502, 503, 504], # HTTP status codes to retry on
45
+ allowed_methods={"GET"}, # Only retry GET requests
46
+ raise_on_status=False # Don't raise an exception on failed status codes immediately
47
+ )
48
+
49
+ # Create a session and mount the adapter with retries
50
+ session = requests.Session()
51
+ session.mount('https://', HTTPAdapter(max_retries=retries))
52
+
35
53
  try:
36
- # Download the zip file
54
+ # Download the zip file in chunks
37
55
  # Disable SSL verification due to INCRA's certificate issues
38
56
  import urllib3
39
57
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
40
58
 
41
- response = requests.get(url, verify=False)
42
- if response.status_code != 200:
43
- raise Exception("Failed to download data from INCRA")
59
+ # Use stream=True to download content in chunks with the session
60
+ response = session.get(url, stream=True, verify=False, timeout=300) # Added a timeout for the request
61
+ response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
44
62
 
45
63
  # Create a temporary directory
46
64
  with tempfile.TemporaryDirectory() as temp_dir:
65
+ zip_file_path = os.path.join(temp_dir, "Sigef Brasil.zip")
66
+ # Write the content to the file
67
+ with open(zip_file_path, 'wb') as fd:
68
+ for chunk in response.iter_content(chunk_size=8192):
69
+ fd.write(chunk)
70
+
47
71
  # Extract the zip file
48
- with ZipFile(BytesIO(response.content)) as zip_ref:
72
+ with ZipFile(zip_file_path) as zip_ref:
49
73
  zip_ref.extractall(temp_dir)
50
74
 
51
75
  # Find the shapefile
@@ -75,7 +99,17 @@ def read_sigef_properties(simplified=False):
75
99
  existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
76
100
  gdf = gdf[existing_columns]
77
101
 
102
+ except requests.exceptions.Timeout:
103
+ raise Exception(f"Download timed out after {300} seconds. The file might be too large or the connection too slow.")
104
+ except requests.exceptions.ConnectionError as e:
105
+ raise Exception(f"A connection error occurred during download: {str(e)}. This might be due to network issues or server availability.")
106
+ except requests.exceptions.RequestException as e:
107
+ raise Exception(f"An unexpected request error occurred: {str(e)}")
78
108
  except Exception as e:
79
- raise Exception(f"Error downloading certified properties data: {str(e)}")
109
+ raise Exception(f"Error processing certified properties data: {str(e)}")
110
+
111
+ finally:
112
+ session.close() # Ensure the session is closed
80
113
 
81
114
  return gdf
115
+
@@ -32,8 +32,6 @@ def read_snci_properties(simplified=False):
32
32
  """
33
33
 
34
34
  url = "https://certificacao.incra.gov.br/csv_shp/zip/Imóvel%20certificado%20SNCI%20Brasil.zip"
35
- if 1==1:
36
- return "Essa camada está muito pesada, baixe manualmente no link: " + url
37
35
  try:
38
36
  # Download the zip file
39
37
  # Disable SSL verification due to INCRA's certificate issues
@@ -81,3 +79,7 @@ def read_snci_properties(simplified=False):
81
79
  raise Exception(f"Error downloading certified properties data: {str(e)}")
82
80
 
83
81
  return gdf
82
+
83
+ if __name__ == "__main__":
84
+ # Example usage
85
+ properties = read_snci_properties(simplified=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tunned-geobr
3
- Version: 1.0.2
3
+ Version: 1.0.4
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
@@ -23,8 +23,6 @@ Requires-Dist: patool>=1.15.0
23
23
  Requires-Dist: fiona>=1.10.1
24
24
  Requires-Dist: gdown>=5.2.0
25
25
  Requires-Dist: tabulate>=0.9.0
26
- Requires-Dist: build>=1.2.2.post1
27
- Requires-Dist: twine>=6.1.0
28
26
  Description-Content-Type: text/markdown
29
27
 
30
28
  # geobr: Download Official Spatial Data Sets of Brazil
@@ -1,7 +1,7 @@
1
- tunned_geobr-1.0.2.dist-info/METADATA,sha256=mmz2jbljwyJeyc1qcdGLzi4bHmmeuUMwzOI_GLugK5Q,5080
2
- tunned_geobr-1.0.2.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- tunned_geobr-1.0.2.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- tunned_geobr-1.0.2.dist-info/licenses/LICENSE.txt,sha256=mECZRcbde3HssOKe1Co4zgqBLGVN0OWpTsEy3LIbcRA,75
1
+ tunned_geobr-1.0.4.dist-info/METADATA,sha256=nGQLZXxWle6_apjH-9-c-tQc16zLbdh7xUoqsFylA34,5018
2
+ tunned_geobr-1.0.4.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ tunned_geobr-1.0.4.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ tunned_geobr-1.0.4.dist-info/licenses/LICENSE.txt,sha256=mECZRcbde3HssOKe1Co4zgqBLGVN0OWpTsEy3LIbcRA,75
5
5
  tunned_geobr/__init__.py,sha256=rxOGWhc2o3F8qDORi34uF4sCGouQFK74bKpuuAXWlHY,7393
6
6
  tunned_geobr/data/grid_state_correspondence_table.csv,sha256=FpkBuX_-lRXQ1yBrQODxQgG9oha9Fd8A8zGKfdsDAmk,2660
7
7
  tunned_geobr/list_geobr.py,sha256=6rsdtSZUvFrS-n5KXLOSQ34P1AK_yMFAj_MVZRvvZmQ,17278
@@ -122,8 +122,8 @@ tunned_geobr/read_schools.py,sha256=kxaRwuKmZDPgSuhCUd_Ltxo-6_z3b3jXY9Qo0MY_b-A,
122
122
  tunned_geobr/read_sedimentary_basins.py,sha256=mpCde4-WRdAAuHF-AwrODd0GpxRhzJOuP60U6Zbl9pE,4583
123
123
  tunned_geobr/read_semiarid.py,sha256=pxxYTWq8_UPUyblA7_FXXXRz-XOCrrebCvYQ-kgDSrU,1358
124
124
  tunned_geobr/read_settlements.py,sha256=C47Wj4DhSDa-pSFfYK4uGDwtu4sUwqPMr-CuuxS95xg,3060
125
- tunned_geobr/read_sigef_properties.py,sha256=EBqTUbL9Kg9EUPh--nYHX2OVacymq80YrPCZXKAP6sQ,3108
126
- tunned_geobr/read_snci_properties.py,sha256=lKhRSBeayD3M_ffljSf5_Sn57VhYh0g3lwFnOgpYji0,3226
125
+ tunned_geobr/read_sigef_properties.py,sha256=rYdh8o_fhXom1A9wQsd5d9dKhT02wTpGRY2ACTpQZ4A,4735
126
+ tunned_geobr/read_snci_properties.py,sha256=80VUN5NesYiNTfioaw7aybLHDNpYJObQT-kV90big-c,3233
127
127
  tunned_geobr/read_state.py,sha256=JgV3cR0LFbmwIzuzPbR_Zfy1bR_2eBeEPxunozctuag,3819
128
128
  tunned_geobr/read_state_direct.py,sha256=8Tdz-gVH_t90BJngcfcpr0VLs5HfCUxRgRQj8hy4Bt0,3826
129
129
  tunned_geobr/read_state_highways.py,sha256=pvRkwuensDOFh3wrcui36iTLcOtkrXoZmT50oUL8WFI,2769
@@ -137,4 +137,4 @@ tunned_geobr/read_water_bodies_ana.py,sha256=Z-dpTPVgRHVndTeSFxx8uXn7ufMg2jm0Dlz
137
137
  tunned_geobr/read_waterways.py,sha256=mEdoVogYWr5EYZ8bE3xMCVWyLrHYU7xTL2lUE0XbDAM,2951
138
138
  tunned_geobr/read_weighting_area.py,sha256=m2X5Ua3jRqLlkqCQbIzR2jmo58pzqkyR3UYcGtgy20E,2325
139
139
  tunned_geobr/utils.py,sha256=WT9PSGWvcERjj3yhfTvyWSE5ZiEjO4tYK5xIj5jJCg8,8170
140
- tunned_geobr-1.0.2.dist-info/RECORD,,
140
+ tunned_geobr-1.0.4.dist-info/RECORD,,