parallel_offset
๋๋ buffer
๋ฅผ ์ฌ์ฉํ ๋ ๊ฒฐ๊ณผ ์ค๊ณฝ์ ์ด ์ฌ๋ฐ๋ฅด๊ฒ ๋ซํ์ง ์๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ์ค๊ณฝ์ด ์ฌ๋ฐ๋ฅด๊ฒ ๋ซํ์ง ์์ ์ง์ ์ ํญ์ ์ค๊ณฝ์ ์ฒซ ๋ฒ์งธ / ๋ง์ง๋ง ์ง์ ์ธ ๊ฒ์ฒ๋ผ ๋ณด์
๋๋ค.
๋ค์์ ์ฒ์์ StackExchange์ ๊ฒ์ ํ ๋ฌธ์ ์ ๋๋ค.
๋ค์์ parallel_offset
์ฌ์ฉํ ๋ ๋ซํ์ง ์๋ ์ค๊ณฝ์ ์ ์์ฑํ๋ ์ต์ํ์ ์์
์์ ์
๋๋ค. buffer
ํ๋ฉด mitred
์คํ์ผ์๋ ๋ถ๊ตฌํ๊ณ ๋ฅ๊ทผ ๋ชจ์๋ฆฌ๊ฐ ์์ฑ๋ฉ๋๋ค.
ํฅ๋ฏธ๋กญ๊ฒ๋ ๋ ํฐ ๋ฐ์ดํฐ ์ธํธ์๋ ์ฑ๊ณต์ ์ผ๋ก ๋ซํ๋ ๋ค๋ฅธ ๋งค์ฐ ์ ์ฌํ ์ค๊ณฝ์ด ์์ต๋๋ค.
import matplotlib.pyplot as plt
from shapely.geometry.polygon import LinearRing
def plot_line(ax, ob, color):
x, y = ob.xy
ax.plot(x, y, color=color, alpha=0.7, linewidth=3,
solid_capstyle='round', zorder=2)
polygon = [[-29.675, -30.675],
[-28.4094, -29.4094],
[-28.325, -29.325],
[-28.325, -29.764],
[-28.325, -29.7933],
[-28.4587, -29.8274],
[-28.4676, -29.8297],
[-28.5956, -29.8814],
[-28.6041, -29.8848],
[-28.724, -29.953],
[-28.732, -29.9576],
[-28.8417, -30.0413],
[-28.849, -30.0469],
[-28.9466, -30.1445],
[-28.9531, -30.151],
[-29.0368, -30.2607],
[-29.0424, -30.268],
[-29.1106, -30.3879],
[-29.1152, -30.3959],
[-29.1669, -30.5239],
[-29.1703, -30.5324],
[-29.2044, -30.6661],
[-29.2067, -30.675],
[-29.6457, -30.675],
[-29.675, -30.675]]
poly_line = LinearRing(polygon)
poly_line_offset = poly_line.parallel_offset(0.05, side="left", resolution=16,
join_style=2, mitre_limit=1)
# Alternative:
# poly_line_offset = poly_line.buffer(0.05, resolution=16, join_style=2, mitre_limit=1).exterior
fig = plt.figure()
ax = fig.add_subplot(111)
plot_line(ax, poly_line, "blue")
plot_line(ax, poly_line_offset, "green")
plt.show()
Windows 7, Python 3.6.2
Shapely 1.6.3 (PyPI์์ ์ค์น)
@ doctor-ian ์ด๊ฒ์ ํฅ๋ฏธ๋ก์ด ์์ฉ ํ๋ก๊ทธ๋จ์ด๋ฉฐ ์ค์ ๋ก Python๊ณผ ์ถฉ๋ํฉ๋๋ค. ์ฌ๊ธฐ GEOS ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ฒ๊ทธ๊ฐ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ํํ ์คํ์ ์ ๋ซํ ๋ง์ฉ์ผ๋ก ์ค๊ณ๋์ง ์์์ง๋ง ๋ ์ฐ์ํ๊ฒ ์คํจํด์ผํฉ๋๋ค. ๋ฐ๋ฉด์ ๋ค๊ฐํ์ ์์ ๋ฒํผ๋ ๋ค์๊ณผ ๊ฐ์ด ์๋ํฉ๋๋ค.
@sgillies ๋๋ ์ด๋ฏธ ๊ทผ๋ณธ์ ์ธ ๋ฌธ์ ๊ฐ ๋งค๋ํ์ง ์๋ค๋ ๊ฒ์ ๋๋ ค์ํ์ต๋๋ค. ๋ฒํผ์ ๊ด๋ จํ์ฌ : ๊ฐ์ด ํน์ ์์ ๊ฐ์ ์ด๊ณผํ๋ ๊ฒฝ์ฐ, ์ฆ ์๊ธฐ ๊ต์ฐจ๊ฐ ๋ฐ์ํ ๋๋ ์คํจํฉ๋๋ค. ์ด๊ฒ๋ ๋ฒ๊ทธ์ ๋๊น?
๋ฒ๊ทธ๋ผ๊ณ ์๊ฐํฉ๋๋ค.
C-API์์ GEOSOffsetCurve_r ์ LINESTRING ๋ง ํ์ฉํ๋๋ก ๋ฌธ์ํ๋์ด ์์ต๋๋ค. LinearRing๋ ํ์ฉํ๋ ค๋ฉด ํด๋น ์ง์์ ์ด๋ป๊ฒ ๋ ์ถ๊ฐํด์ผํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@ doctor-ian ์ด๊ฒ์ ํฅ๋ฏธ๋ก์ด ์์ฉ ํ๋ก๊ทธ๋จ์ด๋ฉฐ ์ค์ ๋ก Python๊ณผ ์ถฉ๋ํฉ๋๋ค. ์ฌ๊ธฐ GEOS ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ฒ๊ทธ๊ฐ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ํํ ์คํ์ ์ ๋ซํ ๋ง์ฉ์ผ๋ก ์ค๊ณ๋์ง ์์์ง๋ง ๋ ์ฐ์ํ๊ฒ ์คํจํด์ผํฉ๋๋ค. ๋ฐ๋ฉด์ ๋ค๊ฐํ์ ์์ ๋ฒํผ๋ ๋ค์๊ณผ ๊ฐ์ด ์๋ํฉ๋๋ค.