Skip to content

Instantly share code, notes, and snippets.

@hkayabilisim
Created February 16, 2023 20:35
Show Gist options
  • Save hkayabilisim/49601a1c0ecab30e8900d978fe983378 to your computer and use it in GitHub Desktop.
Save hkayabilisim/49601a1c0ecab30e8900d978fe983378 to your computer and use it in GitHub Desktop.
import geopandas as gp
from owslib.wms import WebMapService
import owslib.util as util
import matplotlib.pyplot as plt
collapsed = gp.read_file('bina_kirmizi_utm37.shp')
collapsed['centroid'] = collapsed.centroid
collapsed['centroid'] = collapsed['centroid'].to_crs(crs=4326)
collapsed = collapsed.to_crs(crs=4326)
buildings_pre = gp.read_file('bina_yesil_utm37.shp')
buildings_pre['centroid'] = buildings_pre.centroid
buildings_pre['centroid'] = buildings_pre['centroid'].to_crs(crs=4326)
buildings_pre = buildings_pre.to_crs(crs=4326)
wms = WebMapService('https://maps.cscrs.itu.edu.tr/geoserver/ows?service=WMS',
username='****',password='****', version='1.3.0')
for index, row in buildings_pre.iterrows():
x = row['centroid']
bpoly = x.buffer(0.0002,cap_style=3)
# bbox : tuple (left, bottom, right, top) in srs units.
img = wms.getmap(layers=['Deprem:Hatay_PHR1B_20230208'],
srs='CRS:84',
bbox=bpoly.bounds,
size=(224, 224),
format='image/jpeg',
transparent=True
)
out = open(f'images/pre/{index:04d}.jpg', 'wb')
out.write(img.read())
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment