<jupyter_start><jupyter_text>Shapely<jupyter_code>from shapely.geometry import Polygon
p1 = Polygon(((1,2), (5,3), (5,7), (1,9), (1,2)))
p1
p2 = Polygon(((6,6), (7,6), (10,4), (11,8), (6,6)))
p2
from shapely.geometry import Point
point = Point(2.0, 2.0)
point
from shapely.geometry import LineString
line = LineString([(0,0), (10,10)])
line
from shapely.geometry.polygon import LinearRing
ring = LinearRing([(0,0), (3,3), (3,0)])
ring
from shapely.geometry import MultiPoint
points = MultiPoint([(0,0), (3,3)])
points
from shapely.geometry import MultiLineString
coords = MultiLineString([((0,0), (1,1)),((-1,0), (1,0))])
coords
from shapely.geometry import MultiPolygon
polygons = MultiPolygon([p1,p2])
polygons

# 면적 구하기
print(p1.area)
# 경계 구하기
print(p1.bounds)
# 길이 구하기
print(p1.length)
# geometry Type 구하기
print(p1.geom_type)
import json
from shapely.geometry import mapping, shape
jData = json.loads('{"type":"Polygon","coordinates":[[[1,1],[1,3],[3,3]]]}')
p = shape(jData)
p
mapping(p)
import fiona
c = fiona.open(r'data/node.shp')
rec = next(iter(c))
print('keys = ', rec.keys())
print('type = ', rec['type'])
print('prop = ', rec['properties'])
print('id   = ', rec['id'])
print('geom = ', rec['geometry'])
print(len(c))
print(c.driver)
print(c.crs)
import fiona
with fiona.open(r'data/node.shp') as src:
    print(src[0])
import geopandas as gpd 
%matplotlib inline
df = gpd.read_file(r'data/link.shp')
type(df)
df.shape
df.columns
df.loc[0]
df['ROAD_NAME']
서울문산고속도로 = df[df['ROAD_NAME'] == '서울문산고속도로']
서울문산고속도로
서울문산고속도로.plot(figsize=(7,7))
df.plot(cmap="Set1", figsize=(7,7))
seoul = gpd.read_file(r'data/seoul.shp')
seoul.plot()
df.crs
gpd.sjoin(df, seoul, op='within')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup