Created
May 4, 2019 14:04
-
-
Save pvanheus/d1c38c1589c309dfd4543b7ed530f424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vl = QgsVectorLayer("Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes", "temporary_points", "memory") | |
pr = vl.dataProvider() | |
pr.addAttributes([QgsField("name", QVariant.String), QgsField("age", QVariant.Int), QgsField("size", QVariant.Double)]) | |
vl.updateFields() | |
fet = QgsFeature() | |
fet.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10,10))) | |
fet.setAttributes(["Johny", 2, 0.3]) | |
pr.addFeatures([fet]) | |
vl.updateExtents() | |
("fields:", len(pr.fields())) | |
("features:", pr.featureCount()) | |
e = vl.extent() | |
print("extent:", e.xMinimum(), e.yMinimum(), e.xMaximum(), e.yMaximum()) | |
features = vl.getFeatures() | |
for fet in features: | |
print("F:", fet.id(), fet.attributes(), fet.geometry().asPoint()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment