GeoServer Rest API

키요·2025년 10월 28일

공부

목록 보기
29/32

🌐 GeoServer REST API 개요

GeoServer는 모든 관리 기능(워크스페이스, 데이터스토어, 커버리지스토어, 스타일, 레이어 등)을
HTTP REST 요청으로 제어할 수 있게 되어 있습니다.
즉, 관리 UI 없이도 코드 한 줄로 워크스페이스를 만들고, DB 연결하고, 스타일까지 설정 가능하죠.


1️⃣ 기본 REST API 경로

http://localhost:8090/geoserver/rest/

저는 스프링 부트 톰켓 기본 포트가 8080라 8090으로 설정했습니다.

GeoServer가 로컬에서 실행 중이라면, 위 URL 뒤에 엔드포인트를 붙여서 요청을 보냅니다.
예:

  • /workspaces : 워크스페이스 관리
  • /workspaces/{workspace}/datastores : 데이터 저장소 관리
  • /workspaces/{workspace}/datastores/{store}/featuretypes : 피처 타입(레이어) 관리
  • /styles : 스타일 관리

2️⃣ 워크스페이스 생성 (예시)

🧠 요청 정보

  • 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에서 “새 작업공간 추가” 클릭하는 것과 동일한 효과입니다.


3️⃣ PostGIS 데이터 저장소 생성 (예시)

요청

POST http://localhost:8080/geoserver/rest/workspaces/seoul/datastores

Body (XML or JSON)

<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을 더 안정적으로 처리합니다.


4️⃣ 피처타입(레이어) 등록

POST http://localhost:8080/geoserver/rest/workspaces/seoul/datastores/seoul_postgis/featuretypes

Body (JSON):

{
  "featureType": {
    "name": "admin_emd",
    "title": "서울 행정동",
    "srs": "EPSG:5174"
  }
}

5️⃣ 스타일 등록

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 내용을 그대로 담으면 됩니다.


6️⃣ 예시: Python으로 자동 등록

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/workspacesPOST새 워크스페이스 등록
데이터 저장소 생성/rest/workspaces/{ws}/datastoresPOSTPostGIS, GeoTIFF 등 연결
피처타입 등록/rest/workspaces/{ws}/datastores/{store}/featuretypesPOST테이블 레이어 발행
스타일 등록/rest/stylesPOSTSLD 파일 메타 등록
스타일 업로드/rest/styles/{style}PUT실제 SLD 코드 전송

profile
운도 실력

0개의 댓글