tunned-geobr 0.1.2__py3-none-any.whl → 0.2.0__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 +34 -2
- tunned_geobr/read_apcb_amazon.py +78 -0
- tunned_geobr/read_apcb_caatinga.py +78 -0
- tunned_geobr/read_apcb_cerrado_pantanal.py +78 -0
- tunned_geobr/read_apcb_mata_atlantica.py +78 -0
- tunned_geobr/read_apcb_pampa.py +78 -0
- tunned_geobr/read_apcb_zcm.py +78 -0
- tunned_geobr/read_archaeological_sites.py +94 -0
- tunned_geobr/read_atlantic_forest_law_limits.py +74 -0
- tunned_geobr/read_baze_sites.py +155 -0
- tunned_geobr/read_biosphere_reserves.py +85 -0
- tunned_geobr/read_cave_potential.py +79 -0
- tunned_geobr/read_census_tract_2022.py +101 -0
- tunned_geobr/read_ebas.py +80 -0
- tunned_geobr/read_federal_highways.py +79 -0
- tunned_geobr/read_fossil_occurrences.py +94 -0
- tunned_geobr/read_geographic_regions.py +88 -0
- tunned_geobr/read_heliports.py +81 -0
- tunned_geobr/read_municipality_direct.py +127 -0
- tunned_geobr/read_natural_caves.py +83 -0
- tunned_geobr/read_neighborhoods_2022.py +99 -0
- tunned_geobr/read_pan_strategic_areas.py +89 -0
- tunned_geobr/read_ports.py +80 -0
- tunned_geobr/read_private_aerodromes.py +81 -0
- tunned_geobr/read_public_aerodromes.py +81 -0
- tunned_geobr/read_quilombola_areas.py +85 -0
- tunned_geobr/read_quilombola_areas_temp.py +103 -0
- tunned_geobr/read_railways.py +80 -0
- tunned_geobr/read_rppn.py +107 -0
- tunned_geobr/read_sigef_properties.py +83 -0
- tunned_geobr/read_snci_properties.py +83 -0
- tunned_geobr/read_state_direct.py +103 -0
- tunned_geobr/read_state_highways.py +79 -0
- tunned_geobr/read_transmission_lines_ons.py +87 -0
- tunned_geobr/read_vegetation.py +84 -0
- tunned_geobr/read_water_bodies_ana.py +87 -0
- tunned_geobr/read_waterways.py +80 -0
- {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.0.dist-info}/METADATA +35 -3
- tunned_geobr-0.2.0.dist-info/RECORD +82 -0
- tunned_geobr-0.1.2.dist-info/RECORD +0 -46
- {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.0.dist-info}/WHEEL +0 -0
- {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.0.dist-info}/entry_points.txt +0 -0
- {tunned_geobr-0.1.2.dist-info → tunned_geobr-0.2.0.dist-info}/licenses/LICENSE.txt +0 -0
@@ -0,0 +1,81 @@
|
|
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_private_aerodromes(simplified=False):
|
9
|
+
"""Download Private Aerodromes data from MapBiomas.
|
10
|
+
|
11
|
+
This function downloads and processes private aerodromes data from MapBiomas.
|
12
|
+
The data includes information about private airports and aerodromes across Brazil.
|
13
|
+
Original source: MapBiomas
|
14
|
+
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
simplified : boolean, by default False
|
18
|
+
If True, returns a simplified version of the dataset with fewer columns
|
19
|
+
|
20
|
+
Returns
|
21
|
+
-------
|
22
|
+
gpd.GeoDataFrame
|
23
|
+
Geodataframe with private aerodromes data
|
24
|
+
|
25
|
+
Example
|
26
|
+
-------
|
27
|
+
>>> from tunned_geobr import read_private_aerodromes
|
28
|
+
|
29
|
+
# Read private aerodromes data
|
30
|
+
>>> aerodromes = read_private_aerodromes()
|
31
|
+
"""
|
32
|
+
|
33
|
+
url = "https://brasil.mapbiomas.org/wp-content/uploads/sites/4/2023/08/Aerodromos_Privados.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 MapBiomas")
|
40
|
+
|
41
|
+
# Create a temporary directory
|
42
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
43
|
+
# Extract the zip file
|
44
|
+
with ZipFile(BytesIO(response.content)) as zip_ref:
|
45
|
+
zip_ref.extractall(temp_dir)
|
46
|
+
|
47
|
+
# Find the shapefile
|
48
|
+
shp_files = []
|
49
|
+
for root, dirs, files in os.walk(temp_dir):
|
50
|
+
shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
|
51
|
+
|
52
|
+
if not shp_files:
|
53
|
+
raise Exception("No shapefile found in the downloaded data")
|
54
|
+
|
55
|
+
# Read the shapefile
|
56
|
+
gdf = gpd.read_file(shp_files[0])
|
57
|
+
gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
|
58
|
+
|
59
|
+
if simplified:
|
60
|
+
# Keep only the most relevant columns
|
61
|
+
columns_to_keep = [
|
62
|
+
'geometry',
|
63
|
+
'nome', # Aerodrome name
|
64
|
+
'municipio', # Municipality
|
65
|
+
'uf', # State
|
66
|
+
'codigo_oaci', # ICAO code
|
67
|
+
'altitude', # Altitude
|
68
|
+
'tipo_uso', # Usage type
|
69
|
+
'compriment', # Runway length
|
70
|
+
'largura', # Runway width
|
71
|
+
'tipo_pista' # Runway type
|
72
|
+
]
|
73
|
+
|
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]
|
77
|
+
|
78
|
+
except Exception as e:
|
79
|
+
raise Exception(f"Error downloading private aerodromes data: {str(e)}")
|
80
|
+
|
81
|
+
return gdf
|
@@ -0,0 +1,81 @@
|
|
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_public_aerodromes(simplified=False):
|
9
|
+
"""Download Public Aerodromes data from MapBiomas.
|
10
|
+
|
11
|
+
This function downloads and processes public aerodromes data from MapBiomas.
|
12
|
+
The data includes information about public airports and aerodromes across Brazil.
|
13
|
+
Original source: MapBiomas
|
14
|
+
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
simplified : boolean, by default False
|
18
|
+
If True, returns a simplified version of the dataset with fewer columns
|
19
|
+
|
20
|
+
Returns
|
21
|
+
-------
|
22
|
+
gpd.GeoDataFrame
|
23
|
+
Geodataframe with public aerodromes data
|
24
|
+
|
25
|
+
Example
|
26
|
+
-------
|
27
|
+
>>> from tunned_geobr import read_public_aerodromes
|
28
|
+
|
29
|
+
# Read public aerodromes data
|
30
|
+
>>> aerodromes = read_public_aerodromes()
|
31
|
+
"""
|
32
|
+
|
33
|
+
url = "https://brasil.mapbiomas.org/wp-content/uploads/sites/4/2023/08/Aerodromos_publicos.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 MapBiomas")
|
40
|
+
|
41
|
+
# Create a temporary directory
|
42
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
43
|
+
# Extract the zip file
|
44
|
+
with ZipFile(BytesIO(response.content)) as zip_ref:
|
45
|
+
zip_ref.extractall(temp_dir)
|
46
|
+
|
47
|
+
# Find the shapefile
|
48
|
+
shp_files = []
|
49
|
+
for root, dirs, files in os.walk(temp_dir):
|
50
|
+
shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
|
51
|
+
|
52
|
+
if not shp_files:
|
53
|
+
raise Exception("No shapefile found in the downloaded data")
|
54
|
+
|
55
|
+
# Read the shapefile
|
56
|
+
gdf = gpd.read_file(shp_files[0])
|
57
|
+
gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
|
58
|
+
|
59
|
+
if simplified:
|
60
|
+
# Keep only the most relevant columns
|
61
|
+
columns_to_keep = [
|
62
|
+
'geometry',
|
63
|
+
'nome', # Aerodrome name
|
64
|
+
'municipio', # Municipality
|
65
|
+
'uf', # State
|
66
|
+
'codigo_oaci', # ICAO code
|
67
|
+
'altitude', # Altitude
|
68
|
+
'tipo_uso', # Usage type
|
69
|
+
'compriment', # Runway length
|
70
|
+
'largura', # Runway width
|
71
|
+
'tipo_pista' # Runway type
|
72
|
+
]
|
73
|
+
|
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]
|
77
|
+
|
78
|
+
except Exception as e:
|
79
|
+
raise Exception(f"Error downloading public aerodromes data: {str(e)}")
|
80
|
+
|
81
|
+
return gdf
|
@@ -0,0 +1,85 @@
|
|
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_settlements(simplified=False):
|
9
|
+
"""Download official settlements data from INCRA.
|
10
|
+
|
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
|
+
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
simplified : boolean, by default False
|
18
|
+
If True, returns a simplified version of the dataset with fewer columns
|
19
|
+
|
20
|
+
Returns
|
21
|
+
-------
|
22
|
+
gpd.GeoDataFrame
|
23
|
+
Geodataframe with settlements data
|
24
|
+
|
25
|
+
Example
|
26
|
+
-------
|
27
|
+
>>> from geobr import read_settlements
|
28
|
+
|
29
|
+
# Read settlements data
|
30
|
+
>>> settlements = read_settlements()
|
31
|
+
"""
|
32
|
+
|
33
|
+
url = "https://certificacao.incra.gov.br/csv_shp/zip/Assentamento%20Brasil.zip"
|
34
|
+
|
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
|
+
|
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
|
+
]
|
73
|
+
|
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]
|
77
|
+
|
78
|
+
except Exception as e:
|
79
|
+
raise Exception(f"Error downloading settlements data: {str(e)}")
|
80
|
+
|
81
|
+
return gdf
|
82
|
+
|
83
|
+
if __name__ == '__main__':
|
84
|
+
settlements = read_settlements()
|
85
|
+
print(settlements)
|
@@ -0,0 +1,103 @@
|
|
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)
|
@@ -0,0 +1,80 @@
|
|
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_railways(simplified=False):
|
9
|
+
"""Download Railways data from MapBiomas.
|
10
|
+
|
11
|
+
This function downloads and processes railways data from MapBiomas.
|
12
|
+
The data includes information about railway networks across Brazil.
|
13
|
+
Original source: MapBiomas
|
14
|
+
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
simplified : boolean, by default False
|
18
|
+
If True, returns a simplified version of the dataset with fewer columns
|
19
|
+
|
20
|
+
Returns
|
21
|
+
-------
|
22
|
+
gpd.GeoDataFrame
|
23
|
+
Geodataframe with railways data
|
24
|
+
|
25
|
+
Example
|
26
|
+
-------
|
27
|
+
>>> from tunned_geobr import read_railways
|
28
|
+
|
29
|
+
# Read railways data
|
30
|
+
>>> railways = read_railways()
|
31
|
+
"""
|
32
|
+
|
33
|
+
url = "https://brasil.mapbiomas.org/wp-content/uploads/sites/4/2023/08/ferrovia.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 MapBiomas")
|
40
|
+
|
41
|
+
# Create a temporary directory
|
42
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
43
|
+
# Extract the zip file
|
44
|
+
with ZipFile(BytesIO(response.content)) as zip_ref:
|
45
|
+
zip_ref.extractall(temp_dir)
|
46
|
+
|
47
|
+
# Find the shapefile
|
48
|
+
shp_files = []
|
49
|
+
for root, dirs, files in os.walk(temp_dir):
|
50
|
+
shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
|
51
|
+
|
52
|
+
if not shp_files:
|
53
|
+
raise Exception("No shapefile found in the downloaded data")
|
54
|
+
|
55
|
+
# Read the shapefile
|
56
|
+
gdf = gpd.read_file(shp_files[0])
|
57
|
+
gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
|
58
|
+
|
59
|
+
if simplified:
|
60
|
+
# Keep only the most relevant columns
|
61
|
+
columns_to_keep = [
|
62
|
+
'geometry',
|
63
|
+
'nome', # Railway name
|
64
|
+
'uf', # State
|
65
|
+
'operadora', # Operating company
|
66
|
+
'situacao', # Status
|
67
|
+
'extensao_km', # Length in km
|
68
|
+
'bitola', # Track gauge
|
69
|
+
'carga', # Cargo type
|
70
|
+
'eletrifica' # Electrification
|
71
|
+
]
|
72
|
+
|
73
|
+
# Filter columns that actually exist in the dataset
|
74
|
+
existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
|
75
|
+
gdf = gdf[existing_columns]
|
76
|
+
|
77
|
+
except Exception as e:
|
78
|
+
raise Exception(f"Error downloading railways data: {str(e)}")
|
79
|
+
|
80
|
+
return gdf
|
@@ -0,0 +1,107 @@
|
|
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_rppn(simplified=False):
|
9
|
+
"""Download Private Natural Heritage Reserves (RPPN) data from ICMBio.
|
10
|
+
|
11
|
+
This function downloads and processes data about Private Natural Heritage Reserves
|
12
|
+
(Reservas Particulares do Patrimônio Natural - RPPN) in Brazil. RPPNs are private
|
13
|
+
conservation units created by landowners to protect natural areas on their properties.
|
14
|
+
Original source: ICMBio - Instituto Chico Mendes de Conservação da Biodiversidade
|
15
|
+
|
16
|
+
Parameters
|
17
|
+
----------
|
18
|
+
simplified : boolean, by default False
|
19
|
+
If True, returns a simplified version of the dataset with fewer columns
|
20
|
+
|
21
|
+
Returns
|
22
|
+
-------
|
23
|
+
gpd.GeoDataFrame
|
24
|
+
Geodataframe with RPPN data
|
25
|
+
Columns:
|
26
|
+
- geometry: Geometry of the RPPN
|
27
|
+
- nome: RPPN name
|
28
|
+
- municipio: Municipality
|
29
|
+
- uf: State
|
30
|
+
- proprietar: Owner name
|
31
|
+
- area_ha: Area in hectares
|
32
|
+
- portaria: Ordinance number
|
33
|
+
- dt_criacao: Creation date
|
34
|
+
- bioma: Biome
|
35
|
+
- esfera: Administrative sphere (Federal/State)
|
36
|
+
|
37
|
+
Example
|
38
|
+
-------
|
39
|
+
>>> from tunned_geobr import read_rppn
|
40
|
+
|
41
|
+
# Read RPPN data
|
42
|
+
>>> rppn = read_rppn()
|
43
|
+
"""
|
44
|
+
|
45
|
+
url = "https://sistemas.icmbio.gov.br/simrppn/publico/rppn/shp/"
|
46
|
+
|
47
|
+
# Headers para simular um navegador
|
48
|
+
headers = {
|
49
|
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
50
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
51
|
+
'Accept-Language': 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
|
52
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
53
|
+
'Connection': 'keep-alive',
|
54
|
+
'Upgrade-Insecure-Requests': '1',
|
55
|
+
'Sec-Fetch-Dest': 'document',
|
56
|
+
'Sec-Fetch-Mode': 'navigate',
|
57
|
+
'Sec-Fetch-Site': 'none',
|
58
|
+
'Sec-Fetch-User': '?1',
|
59
|
+
'Cache-Control': 'max-age=0'
|
60
|
+
}
|
61
|
+
|
62
|
+
try:
|
63
|
+
# Download the zip file
|
64
|
+
response = requests.get(url, headers=headers, timeout=30, allow_redirects=True)
|
65
|
+
print(f"Status: {response.status_code}")
|
66
|
+
print(f"Headers: {dict(response.headers)}")
|
67
|
+
|
68
|
+
if response.status_code != 200:
|
69
|
+
raise Exception(f"Failed to download data from ICMBio. Status code: {response.status_code}")
|
70
|
+
|
71
|
+
# Create a temporary directory
|
72
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
73
|
+
# Extract the zip file
|
74
|
+
with ZipFile(BytesIO(response.content)) as zip_ref:
|
75
|
+
zip_ref.extractall(temp_dir)
|
76
|
+
|
77
|
+
# Find the shapefile
|
78
|
+
shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
|
79
|
+
if not shp_files:
|
80
|
+
raise Exception("No shapefile found in the downloaded data")
|
81
|
+
|
82
|
+
# Read the shapefile
|
83
|
+
gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
|
84
|
+
gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
|
85
|
+
|
86
|
+
if simplified:
|
87
|
+
# Keep only the most relevant columns
|
88
|
+
columns_to_keep = [
|
89
|
+
'geometry',
|
90
|
+
'nome', # RPPN name
|
91
|
+
'municipio', # Municipality
|
92
|
+
'uf', # State
|
93
|
+
'area_ha', # Area in hectares
|
94
|
+
'bioma' # Biome
|
95
|
+
]
|
96
|
+
|
97
|
+
# Filter columns that actually exist in the dataset
|
98
|
+
existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
|
99
|
+
gdf = gdf[existing_columns]
|
100
|
+
|
101
|
+
except Exception as e:
|
102
|
+
raise Exception(f"Error downloading RPPN data: {str(e)}")
|
103
|
+
|
104
|
+
return gdf
|
105
|
+
|
106
|
+
if __name__ == '__main__':
|
107
|
+
read_rppn()
|
@@ -0,0 +1,83 @@
|
|
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_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.
|
14
|
+
Original source: INCRA (Instituto Nacional de Colonização e Reforma Agrária)
|
15
|
+
|
16
|
+
Parameters
|
17
|
+
----------
|
18
|
+
simplified : boolean, by default False
|
19
|
+
If True, returns a simplified version of the dataset with fewer columns
|
20
|
+
|
21
|
+
Returns
|
22
|
+
-------
|
23
|
+
gpd.GeoDataFrame
|
24
|
+
Geodataframe with certified properties data
|
25
|
+
|
26
|
+
Example
|
27
|
+
-------
|
28
|
+
>>> from tunned_geobr import read_snci_properties
|
29
|
+
|
30
|
+
# Read certified properties data
|
31
|
+
>>> properties = read_snci_properties()
|
32
|
+
"""
|
33
|
+
|
34
|
+
url = "https://certificacao.incra.gov.br/csv_shp/zip/Sigef%20Brasil.zip"
|
35
|
+
if 1==1:
|
36
|
+
return "Essa camada está muito pesada, baixe manualmente no link: " + url
|
37
|
+
try:
|
38
|
+
# Download the zip file
|
39
|
+
# Disable SSL verification due to INCRA's certificate issues
|
40
|
+
import urllib3
|
41
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
42
|
+
|
43
|
+
response = requests.get(url, verify=False)
|
44
|
+
if response.status_code != 200:
|
45
|
+
raise Exception("Failed to download data from INCRA")
|
46
|
+
|
47
|
+
# Create a temporary directory
|
48
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
49
|
+
# Extract the zip file
|
50
|
+
with ZipFile(BytesIO(response.content)) as zip_ref:
|
51
|
+
zip_ref.extractall(temp_dir)
|
52
|
+
|
53
|
+
# Find the shapefile
|
54
|
+
shp_files = [f for f in os.listdir(temp_dir) if f.endswith('.shp')]
|
55
|
+
if not shp_files:
|
56
|
+
raise Exception("No shapefile found in the downloaded data")
|
57
|
+
|
58
|
+
# Read the shapefile
|
59
|
+
gdf = gpd.read_file(os.path.join(temp_dir, shp_files[0]))
|
60
|
+
gdf = gdf.to_crs(4674) # Convert to SIRGAS 2000
|
61
|
+
|
62
|
+
if simplified:
|
63
|
+
# Keep only the most relevant columns
|
64
|
+
columns_to_keep = [
|
65
|
+
'geometry',
|
66
|
+
'parcela', # Property ID
|
67
|
+
'municipio', # Municipality
|
68
|
+
'uf', # State
|
69
|
+
'area_ha', # Area in hectares
|
70
|
+
'status', # Certification status
|
71
|
+
'data_cert', # Certification date
|
72
|
+
'cod_imovel', # Property code
|
73
|
+
'nome_imov' # Property name
|
74
|
+
]
|
75
|
+
|
76
|
+
# Filter columns that actually exist in the dataset
|
77
|
+
existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
|
78
|
+
gdf = gdf[existing_columns]
|
79
|
+
|
80
|
+
except Exception as e:
|
81
|
+
raise Exception(f"Error downloading certified properties data: {str(e)}")
|
82
|
+
|
83
|
+
return gdf
|