layer = iface.activeLayer()
layer.startEditing()
layer.deleteAttribute(1)
layer.commitChanges()
--
მაგრამ თუ გინდა რომ წაშლილი ელემენტები ჯერ კიდევ უკან დააბრუნო სანამ შენახვას აწკაპებ
layer.rollBack()
გჭირდება
layer = iface.activeLayer() მოძებნა აქტიური შრე რომელიც არჩეული გვაქვს და გალურჯებულია
layer.startEditing() დაარედაქტირა
layer.deleteAttribute(1) წაშალა ელემენტი
layer.rollBack() უკან დააბრუნა
layer.commitChanges() შეინახა ცვლილებები
----
QGIS-ში, როცა გინდა ფენის (layer-ის) რომელიმე სვეტის წაშლა:
layer = iface.activeLayer()
📌 აიღე აქტიური ფენა — ანუ ის ფენა, რომელიც ამჟამად მონიშნულია QGIS-ში.
layer.startEditing()
✏️ გააქტიურე რედაქტირების რეჟიმი — საჭიროა, რომ ფენაზე ცვლილებები რომ შეიტანო (მაგ. წაშლა, დამატება), ჯერ რედაქტირება ჩართო.
layer.deleteAttribute(1)
🗑️ წაშალე ატრიბუტი ნომერი 1 — ეს ნიშნავს, რომ მეორე სვეტი (რადგან ნომერაცია იწყება 0-დან) წაიშლება ატრიბუტების ცხრილიდან.
მაგალითად:
თუ ატრიბუტები იყო: ID | Name | Type
მაშინ 1 = Name → წაიშლება Name
layer.commitChanges()
✅ შეინახე ცვლილებები — ანუ commit გაუკეთე რედაქტირებულ ფენას, რომ ცვლილებები საბოლოოდ ჩაიწეროს.
🔁 მოკლედ:
ეს კოდი აკეთებს შემდეგს:
"აიღე ამჟამინდელი ფენა, ჩართე რედაქტირება, წაშალე მეორე ატრიბუტის სვეტი და შეინახე ცვლილებები."
კოდს რამდენჯერაც გაუშვებ იმ რაოდენობით მოძებნის და წაშლის ამ შრეში ატრიბუტულ ცხრილში სვეტს იმავე ნუმერაციით.
# Define a base class called Car
class Car:
# Class variable (shared among all Car instances)
model = 'Civic'
# Constructor (runs when a Car object is created)
def __init__(self, color, type):
# Instance variables
self.color = color # Car color
self.type = type # Car type (e.g., automatic, manual)
self.started = False # Car status flags
self.stopped = False
# Method to start the car
def start(self):
print('Car Started')
self.started = True
self.stopped = False
# Method to stop the car
def stop(self):
print('Car Stopped')
self.stopped = True
self.started = False # ⚠️ Fixed typo: changed "sefl" to "self"
# Create a Car instance
my_car = Car('blue', 'automatic')
# Print object info (default prints object type unless __str__ is defined)
print(my_car)
# Call the start method
my_car.start()
# Print whether the car is started
print('Car Started?', my_car.started)
# Access class variable (same for all Car objects)
print('Car model', Car.model)
# ------------------------------------
# Inheritance
# Define a new class Sedan that inherits from Car
class Sedan(Car):
# Constructor with an additional parameter: seats
def __init__(self, color, type, seats):
# Call parent class constructor
super().__init__(color, type)
# Add a new property
self.seats = seats
# Define another class ElectricSedan that inherits from Sedan
class ElectricSedan(Sedan):
# Constructor with another parameter: range_km
def __init__(self, color, type, seats, range_km):
# Call parent class constructor
super().__init__(color, type, seats)
# Add new property
self.range_km = range_km
# Create a Sedan instance
my_car = Sedan('blue', 'automatic', 5)
print(my_car.color) # Output: blue
print(my_car.seats) # Output: 5
my_car.start() # Call inherited method
# Create an ElectricSedan instance
my_future_car = ElectricSedan('red', 'automatic', 5, 500)
print(my_future_car.color) # Output: red
print(my_future_car.seats) # Output: 5
print(my_future_car.range_km) # Output: 500
my_future_car.start() # Call inherited method