์นดํ
๊ณ ๋ฆฌ ์์
# openlayers - OpenLayers์์ WKT๋? ๊ณต๊ฐ ๋ฐ์ดํฐ๋ฅผ ๋ฌธ์์ด๋ก ํํํ๋ ๋ฐฉ๋ฒ
๋ญ์ง๋ง
2025. 5. 19. 09:57
POINT(127.123 37.456)
์ขํ์ธ๊ฒ ๊ฐ๊ธด ํ๋ฐ ์์ด๊ฐ ์์ฌ์๋๊ฒ `WKT`
์ง๋ฆฌ์ ๋ณด ์์คํ (GIS)์์ ๊ณต๊ฐ ๋ฐ์ดํฐ๋ฅผ **๋ฌธ์ ํํ๋ก ํํ**ํ๊ธฐ ์ํ ๊ตญ์ ํ์ค์ด๋ค.
์๋ฅผ ๋ค์ด,
- ์ (Point): `POINT(127.123 37.456)`
- ์ (LineString): `LINESTRING(127.123 37.456, 127.124 37.457)`
- ๋ฉด(Polygon):
`POLYGON((127.123 37.456, 127.124 37.457, 127.125 37.456, 127.123 37.456))`
์ด๋ฐ ํ์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค(PostGIS ๋ฑ)์์๋ ์์ฃผ ์ฐ์ด๊ณ , OpenLayers ๊ฐ์ ์น ์ง๋์์๋ ํ์ฉ๋๋ค.
OpenLayers์์๋ `ol.format.WKT()` ํด๋์ค๋ฅผ ์ด์ฉํด์ WKT ๋ฌธ์์ด์ **Feature ๊ฐ์ฒด๋ก ๋ณํ**ํ๊ฑฐ๋, ๊ทธ ๋ฐ๋๋ก๋ ๋ณํํ ์ ์๋ค.
Feature ๊ฐ์ฒด๋ก ๋ณํ
const wktFormat = new ol.format.WKT();
const feature = wktFormat.readFeature("POINT(127.123 37.456)", {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
Feature → WKT
const wktString = wktFormat.writeFeature(feature);
console.log(wktString); // ์: POINT(127.123 37.456)