hossam.my_gis¶
hossam.my_gis ¶
AddressNotFoundError ¶
Bases: Exception
주소를 찾을 수 없는 경우(소프트 실패). 해당 행만 건너뛰고 계속 진행합니다.
Source code in hossam/my_gis.py
24 25 | |
GeocodingError ¶
Bases: Exception
지오코딩 중 발생한 HTTP/API 오류.
Attributes:
| Name | Type | Description |
|---|---|---|
fatal |
bool
|
True면 배치 전체를 중단해야 하는 치명적 오류(예: 인증 키 오류). |
Source code in hossam/my_gis.py
28 29 30 31 32 33 34 35 36 37 | |
geocode ¶
geocode(
df, addr, key, max_workers=8, requests_per_second=10.0
)
주소 컬럼을 일괄 지오코딩하여 위도/경도 컬럼을 추가합니다.
여러 요청을 스레드 풀로 병렬 처리하며, requests_per_second로 호출 속도를 제어합니다.
개별 주소의 실패(주소 없음/찾지 못함/일반 API 오류)는 해당 행만 결측 처리한 뒤
계속 진행하고, 인증 키 오류 같은 치명적 오류만 배치 전체를 중단합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
입력 |
required |
addr
|
str
|
주소가 들어있는 컬럼명. |
required |
key
|
str
|
VWorld API 키. |
required |
max_workers
|
int
|
동시 요청 스레드 수. |
8
|
requests_per_second
|
float
|
초당 최대 요청 수(0 이하면 제한 없음). |
10.0
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
위도( |
Raises:
| Type | Description |
|---|---|
GeocodingError
|
치명적 오류(예: 잘못된 API 키)가 발생한 경우. |
Examples:
from hossam import *
result = my_gis.geocode(df, addr="address", key="YOUR_VWORLD_KEY")
set(["latitude","longitude"]).issubset(result.columns)
# True
Source code in hossam/my_gis.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
load_shape ¶
load_shape(path)
Shapefile을 읽어 GeoDataFrame으로 로드합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
읽을 Shapefile(.shp) 경로. |
required |
info
|
bool
|
True면 데이터 프리뷰와 통계를 출력. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
로드된 |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
파일이 존재하지 않는 경우. |
Examples:
from hossam import *
gdf = my_gis.load_shape("path/to/file.shp", info=False)
Source code in hossam/my_gis.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
save_shape ¶
save_shape(
gdf,
path,
crs=None,
lat_col="latitude",
lon_col="longitude",
)
전처리된 데이터(GeoDataFrame 또는 DataFrame)를 Shapefile 또는 GeoPackage로 저장합니다.
- GeoDataFrame 입력:
- CRS가 있으면 그대로 유지합니다.
- CRS가 없으면
crs(기본 WGS84)를 지정합니다. - DataFrame 입력:
- 오직 이 경우에만
lat_col,lon_col을 사용해 포인트 지오메트리를 생성합니다. - 좌표가 유효하지 않거나 범위를 벗어난 행은 제외되며, 유효한 좌표가 하나도 없으면 예외를 발생시킵니다.
파일 형식
- .shp: ESRI Shapefile (필드명 10자 제한, ASCII 권장)
- .gpkg: GeoPackage (필드명 제약 없음, 한글 가능)
- 확장자 없으면 .shp로 저장
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame | DataFrame
|
저장할 |
required |
path
|
str
|
저장 경로(.shp 또는 .gpkg, 확장자 없으면 .shp 자동 추가). |
required |
crs
|
str | None
|
좌표계 문자열(e.g., "EPSG:4326"). 미지정 시 WGS84. |
None
|
lat_col
|
str
|
DataFrame 입력 시 위도 컬럼명. |
'latitude'
|
lon_col
|
str
|
DataFrame 입력 시 경도 컬럼명. |
'longitude'
|
Returns: None: 파일을 저장하고 반환값이 없습니다.
Raises:
| Type | Description |
|---|---|
TypeError
|
입력 타입이 잘못된 경우. |
ValueError
|
경로가 잘못되었거나 CRS가 유효하지 않은 경우, 또는 DataFrame에서 유효 좌표가 하나도 없는 경우. |
Source code in hossam/my_gis.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |