Skip to content

Instantly share code, notes, and snippets.

@hkayabilisim
Last active February 11, 2023 12:40
Show Gist options
  • Save hkayabilisim/56ea4b824b2ee69d37a55d137a0374da to your computer and use it in GitHub Desktop.
Save hkayabilisim/56ea4b824b2ee69d37a55d137a0374da to your computer and use it in GitHub Desktop.
from qgis.core import QgsProject
# modelin istedigi boyut bu
# poligon bir sekilde bundan buyuk veya kucuk olursa
# stretch/shrink etmek gerekecek.
width, height, nchannels = (224, 244, 3)
project = QgsProject.instance()
# Post-earthquake raster katmani
post_eq_rlayer = project.mapLayersByName('Hatay_PHR1B_20230208_3')[0]
print(post_eq_rlayer)
# hasarli bina poligonlari
collapsed_buildings_vlayer = project.mapLayersByName('kirmizi_10x10_utm37')[0]
# (samples, width, height, channels)
X_training = np.zeros((0,width,height,nchannels))
y_training = np.zeros((0,0)) # (samples, class)
collapsed_buildings_features = collapsed_buildings_vlayer.getFeatures()
for feature in collapsed_buildings_features:
geom = feature.geometry()
geomSingleType = QgsWkbTypes.isSingleType(geom.wkbType())
if geom.type() == QgsWkbTypes.PolygonGeometry:
if geomSingleType:
x = geom.asPolygon()
print("Polygon: ", x, "Area: ", geom.area())
else:
x = geom.asMultiPolygon()
print("MultiPolygon: ", x, "Area: ", geom.area())
attrs = feature.attributes()
print(attrs)
label, set_type, sample_id, dummy = attrs
if set_type == 'training':
# raster layer'dan veri cek
# simdilik sifirlardan olusmus bir matris uretiyorum
pixels = np.zeros((1, width, height, nchannels))
X_training = np.append(X_training,pixels,axis=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment