GeoServer는 모든 관리 기능(워크스페이스, 데이터스토어, 커버리지스토어, 스타일, 레이어 등)을
HTTP REST 요청으로 제어할 수 있게 되어 있습니다.
즉, 관리 UI 없이도 코드 한 줄로 워크스페이스를 만들고, DB 연결하고, 스타일까지 설정 가능하죠.
http://localhost:8090/geoserver/rest/
저는 스프링 부트 톰켓 기본 포트가 8080라 8090으로 설정했습니다.
GeoServer가 로컬에서 실행 중이라면, 위 URL 뒤에 엔드포인트를 붙여서 요청을 보냅니다.
예:
/workspaces : 워크스페이스 관리/workspaces/{workspace}/datastores : 데이터 저장소 관리/workspaces/{workspace}/datastores/{store}/featuretypes : 피처 타입(레이어) 관리/styles : 스타일 관리Method: POST
URL:
http://localhost:8080/geoserver/rest/workspaces
Header:
Content-Type: application/json
Authorization: Basic [base64(postgres:비밀번호)]
Body (JSON):
{
"workspace": {
"name": "seoul"
}
}
{
"success": true
}
💡 이렇게 하면
C:\ProgramData\GeoServer\workspaces\seoul폴더가 자동 생성됩니다.
UI에서 “새 작업공간 추가” 클릭하는 것과 동일한 효과입니다.
POST http://localhost:8080/geoserver/rest/workspaces/seoul/datastores
<dataStore>
<name>seoul_postgis</name>
<connectionParameters>
<host>localhost</host>
<port>5432</port>
<database>korea</database>
<schema>public</schema>
<user>postgres</user>
<passwd>비밀번호</passwd>
<dbtype>postgis</dbtype>
</connectionParameters>
</dataStore>
JSON 형식도 가능하지만, 일부 버전에서는 XML을 더 안정적으로 처리합니다.
POST http://localhost:8080/geoserver/rest/workspaces/seoul/datastores/seoul_postgis/featuretypes
Body (JSON):
{
"featureType": {
"name": "admin_emd",
"title": "서울 행정동",
"srs": "EPSG:5174"
}
}
POST http://localhost:8080/geoserver/rest/styles
Body:
{
"style": {
"name": "emd_style",
"filename": "emd_style.sld"
}
}
그리고 실제 .sld 파일을 업로드하려면 별도의 PUT 요청으로 전송합니다:
PUT http://localhost:8080/geoserver/rest/styles/emd_style
Body에 SLD XML 내용을 그대로 담으면 됩니다.
import requests
from requests.auth import HTTPBasicAuth
url = "http://localhost:8080/geoserver/rest/workspaces"
auth = HTTPBasicAuth("admin", "geoserver")
data = {
"workspace": {
"name": "seoul"
}
}
res = requests.post(url, json=data, auth=auth)
print(res.status_code, res.text)
💡 이런 식으로 Python, Node.js, Shell Script 등으로 GeoServer 설정을 완전 자동화할 수 있습니다.
| 기능 | REST 경로 | 메서드 | 설명 |
|---|---|---|---|
| 워크스페이스 생성 | /rest/workspaces | POST | 새 워크스페이스 등록 |
| 데이터 저장소 생성 | /rest/workspaces/{ws}/datastores | POST | PostGIS, GeoTIFF 등 연결 |
| 피처타입 등록 | /rest/workspaces/{ws}/datastores/{store}/featuretypes | POST | 테이블 레이어 발행 |
| 스타일 등록 | /rest/styles | POST | SLD 파일 메타 등록 |
| 스타일 업로드 | /rest/styles/{style} | PUT | 실제 SLD 코드 전송 |