tunned-geobr 1.0.14__py3-none-any.whl → 1.0.16__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 +3 -0
- tunned_geobr/list_geobr.py +4 -1
- tunned_geobr/read_sigel_hydroelectric_developments.py +159 -0
- tunned_geobr/read_sigel_thermoelectric_plants.py +159 -0
- tunned_geobr/read_sigel_windpower_polygons.py +159 -0
- {tunned_geobr-1.0.14.dist-info → tunned_geobr-1.0.16.dist-info}/METADATA +1 -1
- {tunned_geobr-1.0.14.dist-info → tunned_geobr-1.0.16.dist-info}/RECORD +10 -7
- {tunned_geobr-1.0.14.dist-info → tunned_geobr-1.0.16.dist-info}/WHEEL +0 -0
- {tunned_geobr-1.0.14.dist-info → tunned_geobr-1.0.16.dist-info}/entry_points.txt +0 -0
- {tunned_geobr-1.0.14.dist-info → tunned_geobr-1.0.16.dist-info}/licenses/LICENSE.txt +0 -0
tunned_geobr/__init__.py
CHANGED
@@ -133,3 +133,6 @@ from .read_production_fields import read_production_fields
|
|
133
133
|
from .read_oil_wells import read_oil_wells
|
134
134
|
from .read_sigel_wind_turbines import read_sigel_wind_turbines
|
135
135
|
from .read_sigel_windpower_transmission_lines import read_sigel_windpower_transmission_lines
|
136
|
+
from .read_sigel_hydroelectric_developments import read_sigel_hydroelectric_developments
|
137
|
+
from .read_sigel_windpower_polygons import read_sigel_windpower_polygons
|
138
|
+
from .read_sigel_thermoelectric_plants import read_sigel_thermoelectric_plants
|
tunned_geobr/list_geobr.py
CHANGED
@@ -109,6 +109,7 @@ def list_geobr():
|
|
109
109
|
{"Function": "read_planned_eolic", "Geography": "Planned Wind Power Plants", "Years": "All", "Source": "EPE"},
|
110
110
|
{"Function": "read_sigel_wind_turbines", "Geography": "Wind Turbines", "Years": "All", "Source": "ANEEL"},
|
111
111
|
{"Function": "read_sigel_windpower_transmission_lines", "Geography": "Wind Power Transmission Lines", "Years": "All", "Source": "ANEEL"},
|
112
|
+
{"Function": "read_sigel_windpower_polygons", "Geography": "Wind Power Plant Polygons", "Years": "All", "Source": "ANEEL"},
|
112
113
|
|
113
114
|
# Energy infrastructure datasets - Hydroelectric
|
114
115
|
{"Function": "read_existent_uhe", "Geography": "Existing Large Hydroelectric Plants", "Years": "All", "Source": "EPE"},
|
@@ -175,11 +176,13 @@ def list_geobr():
|
|
175
176
|
{"Function": "read_hydroelectric_feasibility_studies", "Geography": "Hydroelectric Feasibility Studies", "Years": "All", "Source": "EPE"},
|
176
177
|
{"Function": "read_hydroelectric_inventory_aai_studies", "Geography": "Hydroelectric Inventory and AAI Studies", "Years": "All", "Source": "EPE"},
|
177
178
|
{"Function": "read_ama_anemometric_towers", "Geography": "AMA Anemometric Towers", "Years": "All", "Source": "EPE"},
|
179
|
+
{"Function": "read_sigel_hydroelectric_developments", "Geography": "Hydroelectric Developments", "Years": "All", "Source": "ANEEL"},
|
178
180
|
|
179
181
|
# Environmental Enforcement Data
|
180
182
|
{"Function": "read_icmbio_embargoes", "Geography": "ICMBio Embargoed Areas", "Years": "All", "Source": "ICMBio"},
|
181
183
|
{"Function": "read_icmbio_infractions", "Geography": "ICMBio Infraction Notices", "Years": "All", "Source": "ICMBio"},
|
182
|
-
{"Function": "read_ibama_embargoes", "Geography": "IBAMA Embargoed Areas", "Years": "All", "Source": "IBAMA"}
|
184
|
+
{"Function": "read_ibama_embargoes", "Geography": "IBAMA Embargoed Areas", "Years": "All", "Source": "IBAMA"},
|
185
|
+
{"Function": "read_sigel_thermoelectric_plants", "Geography": "Thermoelectric Plants", "Years": "All", "Source": "ANEEL"}
|
183
186
|
|
184
187
|
# update later
|
185
188
|
]
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import geopandas as gpd
|
2
|
+
import os
|
3
|
+
import tempfile
|
4
|
+
import urllib.parse
|
5
|
+
import requests
|
6
|
+
import shutil
|
7
|
+
from zipfile import ZipFile
|
8
|
+
from pathlib import Path
|
9
|
+
from io import BytesIO
|
10
|
+
import warnings
|
11
|
+
import json
|
12
|
+
|
13
|
+
def read_sigel_hydroelectric_developments(simplified=False, verbose=False):
|
14
|
+
"""Download Hydroelectric Developments data from Sigel.
|
15
|
+
|
16
|
+
This function downloads and processes hydroelectric developments data from Sigel (ANEEL).
|
17
|
+
Original source: ANEEL (Agência Nacional de Energia Elétrica)
|
18
|
+
|
19
|
+
Parameters
|
20
|
+
----------
|
21
|
+
simplified : boolean, by default False
|
22
|
+
If True, returns a simplified version of the dataset with fewer columns
|
23
|
+
verbose : boolean, by default False
|
24
|
+
If True, prints detailed information about the download process
|
25
|
+
|
26
|
+
Returns
|
27
|
+
-------
|
28
|
+
gpd.GeoDataFrame
|
29
|
+
Geodataframe with hydroelectric developments data
|
30
|
+
|
31
|
+
Example
|
32
|
+
-------
|
33
|
+
>>> from tunned_geobr import read_sigel_hydroelectric_developments
|
34
|
+
|
35
|
+
# Read hydroelectric developments data
|
36
|
+
>>> hydroelectric_developments = read_sigel_hydroelectric_developments()
|
37
|
+
"""
|
38
|
+
|
39
|
+
# URL for the Sigel geoserver WFS service
|
40
|
+
url = r'https://sigel.aneel.gov.br/arcgis/rest/services/PORTAL/ExtractDataTaskAneel/GPServer/Extract%20Data%20Task/execute?f=json&env:outSR=102100&Layers_to_Clip=["Aproveitamento Hidrelétricos - AHE"]&Area_of_Interest={"geometryType":"esriGeometryPolygon","features":[{"geometry":{"rings":[[[-9516149.425610308,-4850876.415440153],[-9516149.425610308,1469548.57940282],[-2119491.07251234,1469548.57940282],[-2119491.07251234,-4850876.415440153],[-9516149.425610308,-4850876.415440153]]],"spatialReference":{"wkid":102100}}}],"sr":{"wkid":102100}}&Feature_Format=Shapefile - SHP - .shp&Raster_Format=Tagged Image File Format - TIFF - .tif'
|
41
|
+
|
42
|
+
try:
|
43
|
+
# Disable SSL verification warning
|
44
|
+
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
|
45
|
+
|
46
|
+
if verbose:
|
47
|
+
print("Requesting data from Sigel server...")
|
48
|
+
|
49
|
+
response = requests.get(url, timeout=60, verify=False)
|
50
|
+
if not response.ok:
|
51
|
+
raise Exception(f"Error getting JSON response: {response.status_code}")
|
52
|
+
|
53
|
+
json_response = response.json()
|
54
|
+
|
55
|
+
if verbose:
|
56
|
+
print(f"JSON response received: {json.dumps(json_response, indent=2)[:500]}...")
|
57
|
+
|
58
|
+
if 'results' not in json_response or len(json_response['results']) == 0:
|
59
|
+
raise Exception("Invalid JSON response structure")
|
60
|
+
|
61
|
+
if 'value' not in json_response['results'][0] or 'url' not in json_response['results'][0]['value']:
|
62
|
+
raise Exception("URL not found in JSON response")
|
63
|
+
|
64
|
+
file_url = json_response['results'][0]['value']['url']
|
65
|
+
|
66
|
+
if verbose:
|
67
|
+
print(f"Downloading file from: {file_url}")
|
68
|
+
|
69
|
+
file_response = requests.get(file_url, stream=True, timeout=60, verify=False)
|
70
|
+
if not file_response.ok:
|
71
|
+
raise Exception(f"Error downloading file: {file_response.status_code}")
|
72
|
+
|
73
|
+
# Check if content is actually a zip file
|
74
|
+
content = file_response.content
|
75
|
+
if len(content) < 100:
|
76
|
+
if verbose:
|
77
|
+
print(f"Warning: Downloaded content is very small ({len(content)} bytes)")
|
78
|
+
print(f"Content preview: {content[:100]}")
|
79
|
+
|
80
|
+
# Create a temporary directory to extract the files
|
81
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
82
|
+
if verbose:
|
83
|
+
print(f"Extracting files to temporary directory: {temp_dir}")
|
84
|
+
|
85
|
+
try:
|
86
|
+
# Extract the zip file
|
87
|
+
with ZipFile(BytesIO(content)) as zip_ref:
|
88
|
+
zip_ref.extractall(temp_dir)
|
89
|
+
|
90
|
+
if verbose:
|
91
|
+
print(f"Files in zip: {zip_ref.namelist()}")
|
92
|
+
except Exception as zip_error:
|
93
|
+
if verbose:
|
94
|
+
print(f"Error extracting zip: {str(zip_error)}")
|
95
|
+
print(f"Saving content to debug.zip for inspection")
|
96
|
+
with open("debug.zip", "wb") as f:
|
97
|
+
f.write(content)
|
98
|
+
raise Exception(f"Failed to extract zip file: {str(zip_error)}")
|
99
|
+
|
100
|
+
# Find the shapefile
|
101
|
+
all_files = os.listdir(temp_dir)
|
102
|
+
if verbose:
|
103
|
+
print(f"Files in temp directory: {all_files}")
|
104
|
+
|
105
|
+
shp_files = [f for f in all_files if f.endswith('.shp')]
|
106
|
+
if not shp_files:
|
107
|
+
# Try looking in subdirectories
|
108
|
+
for root, dirs, files in os.walk(temp_dir):
|
109
|
+
shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
|
110
|
+
|
111
|
+
if not shp_files:
|
112
|
+
raise Exception("No shapefile found in the downloaded data")
|
113
|
+
|
114
|
+
# Read the shapefile
|
115
|
+
shp_path = shp_files[0] if os.path.isabs(shp_files[0]) else os.path.join(temp_dir, shp_files[0])
|
116
|
+
if verbose:
|
117
|
+
print(f"Reading shapefile: {shp_path}")
|
118
|
+
|
119
|
+
gdf = gpd.read_file(shp_path)
|
120
|
+
|
121
|
+
# Convert to SIRGAS 2000 (EPSG:4674)
|
122
|
+
gdf = gdf.to_crs(4674)
|
123
|
+
|
124
|
+
if verbose:
|
125
|
+
print(f"Data loaded successfully with {len(gdf)} records")
|
126
|
+
print(f"Columns: {gdf.columns.tolist()}")
|
127
|
+
|
128
|
+
if simplified:
|
129
|
+
# Keep only the most relevant columns based on actual data structure
|
130
|
+
columns_to_keep = [
|
131
|
+
'geometry',
|
132
|
+
# Add relevant columns for hydroelectric developments here
|
133
|
+
]
|
134
|
+
|
135
|
+
# Filter columns that actually exist in the dataset
|
136
|
+
existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
|
137
|
+
if len(existing_columns) <= 1:
|
138
|
+
if verbose:
|
139
|
+
print("Warning: No matching columns found for simplified version. Returning all columns.")
|
140
|
+
else:
|
141
|
+
gdf = gdf[existing_columns]
|
142
|
+
|
143
|
+
except Exception as e:
|
144
|
+
raise Exception(f"Error downloading or processing hydroelectric developments data: {str(e)}")
|
145
|
+
|
146
|
+
return gdf
|
147
|
+
|
148
|
+
if __name__ == '__main__':
|
149
|
+
try:
|
150
|
+
hydroelectric_developments_data = read_sigel_hydroelectric_developments(verbose=True)
|
151
|
+
print(f"Downloaded hydroelectric developments data with {len(hydroelectric_developments_data)} records and {len(hydroelectric_developments_data.columns)} columns")
|
152
|
+
|
153
|
+
# Test simplified version
|
154
|
+
simplified_data = read_sigel_hydroelectric_developments(simplified=True)
|
155
|
+
print(f"Simplified data has {len(simplified_data.columns)} columns: {simplified_data.columns.tolist()}")
|
156
|
+
except Exception as e:
|
157
|
+
print(f"Error: {str(e)}")
|
158
|
+
import traceback
|
159
|
+
traceback.print_exc()
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import geopandas as gpd
|
2
|
+
import os
|
3
|
+
import tempfile
|
4
|
+
import urllib.parse
|
5
|
+
import requests
|
6
|
+
import shutil
|
7
|
+
from zipfile import ZipFile
|
8
|
+
from pathlib import Path
|
9
|
+
from io import BytesIO
|
10
|
+
import warnings
|
11
|
+
import json
|
12
|
+
|
13
|
+
def read_sigel_thermoelectric_plants(simplified=False, verbose=False):
|
14
|
+
"""Download Thermoelectric Plants data from Sigel.
|
15
|
+
|
16
|
+
This function downloads and processes thermoelectric plants data from Sigel (ANEEL).
|
17
|
+
Original source: ANEEL (Agência Nacional de Energia Elétrica)
|
18
|
+
|
19
|
+
Parameters
|
20
|
+
----------
|
21
|
+
simplified : boolean, by default False
|
22
|
+
If True, returns a simplified version of the dataset with fewer columns
|
23
|
+
verbose : boolean, by default False
|
24
|
+
If True, prints detailed information about the download process
|
25
|
+
|
26
|
+
Returns
|
27
|
+
-------
|
28
|
+
gpd.GeoDataFrame
|
29
|
+
Geodataframe with thermoelectric plants data
|
30
|
+
|
31
|
+
Example
|
32
|
+
-------
|
33
|
+
>>> from tunned_geobr import read_sigel_thermoelectric_plants
|
34
|
+
|
35
|
+
# Read thermoelectric plants data
|
36
|
+
>>> thermoelectric_plants = read_sigel_thermoelectric_plants()
|
37
|
+
"""
|
38
|
+
|
39
|
+
# URL for the Sigel geoserver WFS service
|
40
|
+
url = r'https://sigel.aneel.gov.br/arcgis/rest/services/PORTAL/ExtractDataTaskAneel/GPServer/Extract%20Data%20Task/execute?f=json&env:outSR=102100&Layers_to_Clip=["Usinas Termelétricas - UTE"]&Area_of_Interest={"geometryType":"esriGeometryPolygon","features":[{"geometry":{"rings":[[[-9516149.425610308,-4850876.415440153],[-9516149.425610308,1469548.57940282],[-2119491.07251234,1469548.57940282],[-2119491.07251234,-4850876.415440153],[-9516149.425610308,-4850876.415440153]]],"spatialReference":{"wkid":102100}}}],"sr":{"wkid":102100}}&Feature_Format=Shapefile - SHP - .shp&Raster_Format=Tagged Image File Format - TIFF - .tif'
|
41
|
+
|
42
|
+
try:
|
43
|
+
# Disable SSL verification warning
|
44
|
+
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
|
45
|
+
|
46
|
+
if verbose:
|
47
|
+
print("Requesting data from Sigel server...")
|
48
|
+
|
49
|
+
response = requests.get(url, timeout=60, verify=False)
|
50
|
+
if not response.ok:
|
51
|
+
raise Exception(f"Error getting JSON response: {response.status_code}")
|
52
|
+
|
53
|
+
json_response = response.json()
|
54
|
+
|
55
|
+
if verbose:
|
56
|
+
print(f"JSON response received: {json.dumps(json_response, indent=2)[:500]}...")
|
57
|
+
|
58
|
+
if 'results' not in json_response or len(json_response['results']) == 0:
|
59
|
+
raise Exception("Invalid JSON response structure")
|
60
|
+
|
61
|
+
if 'value' not in json_response['results'][0] or 'url' not in json_response['results'][0]['value']:
|
62
|
+
raise Exception("URL not found in JSON response")
|
63
|
+
|
64
|
+
file_url = json_response['results'][0]['value']['url']
|
65
|
+
|
66
|
+
if verbose:
|
67
|
+
print(f"Downloading file from: {file_url}")
|
68
|
+
|
69
|
+
file_response = requests.get(file_url, stream=True, timeout=60, verify=False)
|
70
|
+
if not file_response.ok:
|
71
|
+
raise Exception(f"Error downloading file: {file_response.status_code}")
|
72
|
+
|
73
|
+
# Check if content is actually a zip file
|
74
|
+
content = file_response.content
|
75
|
+
if len(content) < 100:
|
76
|
+
if verbose:
|
77
|
+
print(f"Warning: Downloaded content is very small ({len(content)} bytes)")
|
78
|
+
print(f"Content preview: {content[:100]}")
|
79
|
+
|
80
|
+
# Create a temporary directory to extract the files
|
81
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
82
|
+
if verbose:
|
83
|
+
print(f"Extracting files to temporary directory: {temp_dir}")
|
84
|
+
|
85
|
+
try:
|
86
|
+
# Extract the zip file
|
87
|
+
with ZipFile(BytesIO(content)) as zip_ref:
|
88
|
+
zip_ref.extractall(temp_dir)
|
89
|
+
|
90
|
+
if verbose:
|
91
|
+
print(f"Files in zip: {zip_ref.namelist()}")
|
92
|
+
except Exception as zip_error:
|
93
|
+
if verbose:
|
94
|
+
print(f"Error extracting zip: {str(zip_error)}")
|
95
|
+
print(f"Saving content to debug.zip for inspection")
|
96
|
+
with open("debug.zip", "wb") as f:
|
97
|
+
f.write(content)
|
98
|
+
raise Exception(f"Failed to extract zip file: {str(zip_error)}")
|
99
|
+
|
100
|
+
# Find the shapefile
|
101
|
+
all_files = os.listdir(temp_dir)
|
102
|
+
if verbose:
|
103
|
+
print(f"Files in temp directory: {all_files}")
|
104
|
+
|
105
|
+
shp_files = [f for f in all_files if f.endswith('.shp')]
|
106
|
+
if not shp_files:
|
107
|
+
# Try looking in subdirectories
|
108
|
+
for root, dirs, files in os.walk(temp_dir):
|
109
|
+
shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
|
110
|
+
|
111
|
+
if not shp_files:
|
112
|
+
raise Exception("No shapefile found in the downloaded data")
|
113
|
+
|
114
|
+
# Read the shapefile
|
115
|
+
shp_path = shp_files[0] if os.path.isabs(shp_files[0]) else os.path.join(temp_dir, shp_files[0])
|
116
|
+
if verbose:
|
117
|
+
print(f"Reading shapefile: {shp_path}")
|
118
|
+
|
119
|
+
gdf = gpd.read_file(shp_path)
|
120
|
+
|
121
|
+
# Convert to SIRGAS 2000 (EPSG:4674)
|
122
|
+
gdf = gdf.to_crs(4674)
|
123
|
+
|
124
|
+
if verbose:
|
125
|
+
print(f"Data loaded successfully with {len(gdf)} records")
|
126
|
+
print(f"Columns: {gdf.columns.tolist()}")
|
127
|
+
|
128
|
+
if simplified:
|
129
|
+
# Keep only the most relevant columns based on actual data structure
|
130
|
+
columns_to_keep = [
|
131
|
+
'geometry',
|
132
|
+
# Add relevant columns for thermoelectric plants here
|
133
|
+
]
|
134
|
+
|
135
|
+
# Filter columns that actually exist in the dataset
|
136
|
+
existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
|
137
|
+
if len(existing_columns) <= 1:
|
138
|
+
if verbose:
|
139
|
+
print("Warning: No matching columns found for simplified version. Returning all columns.")
|
140
|
+
else:
|
141
|
+
gdf = gdf[existing_columns]
|
142
|
+
|
143
|
+
except Exception as e:
|
144
|
+
raise Exception(f"Error downloading or processing thermoelectric plants data: {str(e)}")
|
145
|
+
|
146
|
+
return gdf
|
147
|
+
|
148
|
+
if __name__ == '__main__':
|
149
|
+
try:
|
150
|
+
thermoelectric_plants_data = read_sigel_thermoelectric_plants(verbose=True)
|
151
|
+
print(f"Downloaded thermoelectric plants data with {len(thermoelectric_plants_data)} records and {len(thermoelectric_plants_data.columns)} columns")
|
152
|
+
|
153
|
+
# Test simplified version
|
154
|
+
simplified_data = read_sigel_thermoelectric_plants(simplified=True)
|
155
|
+
print(f"Simplified data has {len(simplified_data.columns)} columns: {simplified_data.columns.tolist()}")
|
156
|
+
except Exception as e:
|
157
|
+
print(f"Error: {str(e)}")
|
158
|
+
import traceback
|
159
|
+
traceback.print_exc()
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import geopandas as gpd
|
2
|
+
import os
|
3
|
+
import tempfile
|
4
|
+
import urllib.parse
|
5
|
+
import requests
|
6
|
+
import shutil
|
7
|
+
from zipfile import ZipFile
|
8
|
+
from pathlib import Path
|
9
|
+
from io import BytesIO
|
10
|
+
import warnings
|
11
|
+
import json
|
12
|
+
|
13
|
+
def read_sigel_windpower_polygons(simplified=False, verbose=False):
|
14
|
+
"""Download Wind Power Plant Polygons data from Sigel.
|
15
|
+
|
16
|
+
This function downloads and processes wind power plant polygons data from Sigel (ANEEL).
|
17
|
+
Original source: ANEEL (Agência Nacional de Energia Elétrica)
|
18
|
+
|
19
|
+
Parameters
|
20
|
+
----------
|
21
|
+
simplified : boolean, by default False
|
22
|
+
If True, returns a simplified version of the dataset with fewer columns
|
23
|
+
verbose : boolean, by default False
|
24
|
+
If True, prints detailed information about the download process
|
25
|
+
|
26
|
+
Returns
|
27
|
+
-------
|
28
|
+
gpd.GeoDataFrame
|
29
|
+
Geodataframe with wind power plant polygons data
|
30
|
+
|
31
|
+
Example
|
32
|
+
-------
|
33
|
+
>>> from tunned_geobr import read_sigel_windpower_polygons
|
34
|
+
|
35
|
+
# Read wind power plant polygons data
|
36
|
+
>>> wind_polygons = read_sigel_windpower_polygons()
|
37
|
+
"""
|
38
|
+
|
39
|
+
# URL for the Sigel geoserver WFS service
|
40
|
+
url = r'https://sigel.aneel.gov.br/arcgis/rest/services/PORTAL/ExtractDataTaskAneel/GPServer/Extract%20Data%20Task/execute?f=json&env:outSR=102100&Layers_to_Clip=["Polígono do Parque Eólico - EOL"]&Area_of_Interest={"geometryType":"esriGeometryPolygon","features":[{"geometry":{"rings":[[[-9516149.425610308,-4850876.415440153],[-9516149.425610308,1469548.57940282],[-2119491.07251234,1469548.57940282],[-2119491.07251234,-4850876.415440153],[-9516149.425610308,-4850876.415440153]]],"spatialReference":{"wkid":102100}}}],"sr":{"wkid":102100}}&Feature_Format=Shapefile - SHP - .shp&Raster_Format=Tagged Image File Format - TIFF - .tif'
|
41
|
+
|
42
|
+
try:
|
43
|
+
# Disable SSL verification warning
|
44
|
+
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
|
45
|
+
|
46
|
+
if verbose:
|
47
|
+
print("Requesting data from Sigel server...")
|
48
|
+
|
49
|
+
response = requests.get(url, timeout=60, verify=False)
|
50
|
+
if not response.ok:
|
51
|
+
raise Exception(f"Error getting JSON response: {response.status_code}")
|
52
|
+
|
53
|
+
json_response = response.json()
|
54
|
+
|
55
|
+
if verbose:
|
56
|
+
print(f"JSON response received: {json.dumps(json_response, indent=2)[:500]}...")
|
57
|
+
|
58
|
+
if 'results' not in json_response or len(json_response['results']) == 0:
|
59
|
+
raise Exception("Invalid JSON response structure")
|
60
|
+
|
61
|
+
if 'value' not in json_response['results'][0] or 'url' not in json_response['results'][0]['value']:
|
62
|
+
raise Exception("URL not found in JSON response")
|
63
|
+
|
64
|
+
file_url = json_response['results'][0]['value']['url']
|
65
|
+
|
66
|
+
if verbose:
|
67
|
+
print(f"Downloading file from: {file_url}")
|
68
|
+
|
69
|
+
file_response = requests.get(file_url, stream=True, timeout=60, verify=False)
|
70
|
+
if not file_response.ok:
|
71
|
+
raise Exception(f"Error downloading file: {file_response.status_code}")
|
72
|
+
|
73
|
+
# Check if content is actually a zip file
|
74
|
+
content = file_response.content
|
75
|
+
if len(content) < 100:
|
76
|
+
if verbose:
|
77
|
+
print(f"Warning: Downloaded content is very small ({len(content)} bytes)")
|
78
|
+
print(f"Content preview: {content[:100]}")
|
79
|
+
|
80
|
+
# Create a temporary directory to extract the files
|
81
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
82
|
+
if verbose:
|
83
|
+
print(f"Extracting files to temporary directory: {temp_dir}")
|
84
|
+
|
85
|
+
try:
|
86
|
+
# Extract the zip file
|
87
|
+
with ZipFile(BytesIO(content)) as zip_ref:
|
88
|
+
zip_ref.extractall(temp_dir)
|
89
|
+
|
90
|
+
if verbose:
|
91
|
+
print(f"Files in zip: {zip_ref.namelist()}")
|
92
|
+
except Exception as zip_error:
|
93
|
+
if verbose:
|
94
|
+
print(f"Error extracting zip: {str(zip_error)}")
|
95
|
+
print(f"Saving content to debug.zip for inspection")
|
96
|
+
with open("debug.zip", "wb") as f:
|
97
|
+
f.write(content)
|
98
|
+
raise Exception(f"Failed to extract zip file: {str(zip_error)}")
|
99
|
+
|
100
|
+
# Find the shapefile
|
101
|
+
all_files = os.listdir(temp_dir)
|
102
|
+
if verbose:
|
103
|
+
print(f"Files in temp directory: {all_files}")
|
104
|
+
|
105
|
+
shp_files = [f for f in all_files if f.endswith('.shp')]
|
106
|
+
if not shp_files:
|
107
|
+
# Try looking in subdirectories
|
108
|
+
for root, dirs, files in os.walk(temp_dir):
|
109
|
+
shp_files.extend([os.path.join(root, f) for f in files if f.endswith('.shp')])
|
110
|
+
|
111
|
+
if not shp_files:
|
112
|
+
raise Exception("No shapefile found in the downloaded data")
|
113
|
+
|
114
|
+
# Read the shapefile
|
115
|
+
shp_path = shp_files[0] if os.path.isabs(shp_files[0]) else os.path.join(temp_dir, shp_files[0])
|
116
|
+
if verbose:
|
117
|
+
print(f"Reading shapefile: {shp_path}")
|
118
|
+
|
119
|
+
gdf = gpd.read_file(shp_path)
|
120
|
+
|
121
|
+
# Convert to SIRGAS 2000 (EPSG:4674)
|
122
|
+
gdf = gdf.to_crs(4674)
|
123
|
+
|
124
|
+
if verbose:
|
125
|
+
print(f"Data loaded successfully with {len(gdf)} records")
|
126
|
+
print(f"Columns: {gdf.columns.tolist()}")
|
127
|
+
|
128
|
+
if simplified:
|
129
|
+
# Keep only the most relevant columns based on actual data structure
|
130
|
+
columns_to_keep = [
|
131
|
+
'geometry',
|
132
|
+
# Add relevant columns for wind power plant polygons here
|
133
|
+
]
|
134
|
+
|
135
|
+
# Filter columns that actually exist in the dataset
|
136
|
+
existing_columns = ['geometry'] + [col for col in columns_to_keep[1:] if col in gdf.columns]
|
137
|
+
if len(existing_columns) <= 1:
|
138
|
+
if verbose:
|
139
|
+
print("Warning: No matching columns found for simplified version. Returning all columns.")
|
140
|
+
else:
|
141
|
+
gdf = gdf[existing_columns]
|
142
|
+
|
143
|
+
except Exception as e:
|
144
|
+
raise Exception(f"Error downloading or processing wind power plant polygons data: {str(e)}")
|
145
|
+
|
146
|
+
return gdf
|
147
|
+
|
148
|
+
if __name__ == '__main__':
|
149
|
+
try:
|
150
|
+
wind_polygons_data = read_sigel_windpower_polygons(verbose=True)
|
151
|
+
print(f"Downloaded wind power plant polygons data with {len(wind_polygons_data)} records and {len(wind_polygons_data.columns)} columns")
|
152
|
+
|
153
|
+
# Test simplified version
|
154
|
+
simplified_data = read_sigel_windpower_polygons(simplified=True)
|
155
|
+
print(f"Simplified data has {len(simplified_data.columns)} columns: {simplified_data.columns.tolist()}")
|
156
|
+
except Exception as e:
|
157
|
+
print(f"Error: {str(e)}")
|
158
|
+
import traceback
|
159
|
+
traceback.print_exc()
|
@@ -1,10 +1,10 @@
|
|
1
|
-
tunned_geobr-1.0.
|
2
|
-
tunned_geobr-1.0.
|
3
|
-
tunned_geobr-1.0.
|
4
|
-
tunned_geobr-1.0.
|
5
|
-
tunned_geobr/__init__.py,sha256=
|
1
|
+
tunned_geobr-1.0.16.dist-info/METADATA,sha256=B0OLUI5lgFKyLGIOPYDkEQtYjZuCIWCJ04plDyggmiM,5019
|
2
|
+
tunned_geobr-1.0.16.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
+
tunned_geobr-1.0.16.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
+
tunned_geobr-1.0.16.dist-info/licenses/LICENSE.txt,sha256=mECZRcbde3HssOKe1Co4zgqBLGVN0OWpTsEy3LIbcRA,75
|
5
|
+
tunned_geobr/__init__.py,sha256=H0SEIUWlvfy7Jv4Q-1_13bWu_pnr7QpZa3IgXDAT3co,7991
|
6
6
|
tunned_geobr/data/grid_state_correspondence_table.csv,sha256=FpkBuX_-lRXQ1yBrQODxQgG9oha9Fd8A8zGKfdsDAmk,2660
|
7
|
-
tunned_geobr/list_geobr.py,sha256=
|
7
|
+
tunned_geobr/list_geobr.py,sha256=JXQeF8bKmXlNVOHUyNKaYgOtLZQ9e2mb2b2PSLfzIhU,18426
|
8
8
|
tunned_geobr/lookup_muni.py,sha256=ny1zU4i6OagvL4Mrc6XQWPgn2RrJa_mXlKXh81oVYsM,3462
|
9
9
|
tunned_geobr/read_ama_anemometric_towers.py,sha256=M3qKBTBYdqHzTuWtRrBiLA88Ymt6g0cf7sakJd5mTRo,4686
|
10
10
|
tunned_geobr/read_amazon.py,sha256=HiwKnYebWe3nDMDRUqHpKJIO76bA4ERm4iJlCPhagQg,1286
|
@@ -127,7 +127,10 @@ tunned_geobr/read_sedimentary_basins.py,sha256=mpCde4-WRdAAuHF-AwrODd0GpxRhzJOuP
|
|
127
127
|
tunned_geobr/read_semiarid.py,sha256=pxxYTWq8_UPUyblA7_FXXXRz-XOCrrebCvYQ-kgDSrU,1358
|
128
128
|
tunned_geobr/read_settlements.py,sha256=C47Wj4DhSDa-pSFfYK4uGDwtu4sUwqPMr-CuuxS95xg,3060
|
129
129
|
tunned_geobr/read_sigef_properties.py,sha256=rYdh8o_fhXom1A9wQsd5d9dKhT02wTpGRY2ACTpQZ4A,4735
|
130
|
+
tunned_geobr/read_sigel_hydroelectric_developments.py,sha256=As4VPAIRstNVn_dTojkJ1rDJALIGF4UXUctpfgV1EmY,7080
|
131
|
+
tunned_geobr/read_sigel_thermoelectric_plants.py,sha256=bh80biQHJFo_2YeUnNSXOfncJpfzkDAYbuEG2e8_-K4,6992
|
130
132
|
tunned_geobr/read_sigel_wind_turbines.py,sha256=uobMxbB4M_npQfoGGkYKuImoFxaNy_OpNT1ZDLlUjzs,7112
|
133
|
+
tunned_geobr/read_sigel_windpower_polygons.py,sha256=UrRpgeP0A6UHDt5Ec2LsgDSGGUJBu0Wgyrp82Cd6eWs,6967
|
131
134
|
tunned_geobr/read_sigel_windpower_transmission_lines.py,sha256=pCyDZ7wrHwcb1j76tHMGW9tmRWUriHFSyXNxoF9zDvY,7077
|
132
135
|
tunned_geobr/read_snci_properties.py,sha256=80VUN5NesYiNTfioaw7aybLHDNpYJObQT-kV90big-c,3233
|
133
136
|
tunned_geobr/read_state.py,sha256=JgV3cR0LFbmwIzuzPbR_Zfy1bR_2eBeEPxunozctuag,3819
|
@@ -143,4 +146,4 @@ tunned_geobr/read_water_bodies_ana.py,sha256=Z-dpTPVgRHVndTeSFxx8uXn7ufMg2jm0Dlz
|
|
143
146
|
tunned_geobr/read_waterways.py,sha256=mEdoVogYWr5EYZ8bE3xMCVWyLrHYU7xTL2lUE0XbDAM,2951
|
144
147
|
tunned_geobr/read_weighting_area.py,sha256=m2X5Ua3jRqLlkqCQbIzR2jmo58pzqkyR3UYcGtgy20E,2325
|
145
148
|
tunned_geobr/utils.py,sha256=WT9PSGWvcERjj3yhfTvyWSE5ZiEjO4tYK5xIj5jJCg8,8170
|
146
|
-
tunned_geobr-1.0.
|
149
|
+
tunned_geobr-1.0.16.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|