ANSWERED! :)
I have to create a function that
- Initializes a new object
- Creates and adds data to that object
- Returns the object containing the data.
The object basically contains a json dict (geojson) and offers a way of oop with geojson data.
In the python script in question, I create multiple instances of the class Feature. However, for some reason, the second Feature object I create already has the attributes of the first Feature object - at a different RAM address AND without passing anything to the 2nd object (obj_1 and obj_2 are created in different functions, completely unrelated to each other...)
I am relatively new to OOP with Python so maybe I am missing something obvious. This is also my first question on stackoverflow so just keep that in mind :) I just can't wrap my head around this problem though.
This is the code I use (I will only give you the Feature init, if you need more I'll happily provide more!):
class Feature:
def __init__(self, featuretype: str="Point", coordinates: list=[], \
properties: dict={}, dictionary: dict={}):
# basically loads a provided dictionary or auto-creates one in json format
if dictionary:
self.dict = dictionary
else:
self.new(featuretype, coordinates, properties)
self.update()
First function (outside class):
def create_checkerboard(extent, dist_x, dist_y) -> bk.Feature:
checker_ft = bk.Feature(featuretype="MultiPoint") #init
checker_ft.gen_grid_adv(extent, dist_x, dist_y, matrixname="checkerboard") #populate
return checker_ft
The returned checker_ft object now has a checker_ft.dict which is now populated with a MultiPoint grid. All is well.
Second function (outside class):
def random_grid(extent, grid_spacing_x, grid_spacing_y, shift) -> bk.Feature:
shift_ft = bk.Feature(featuretype="MultiPoint") #init
shift_ft.gen_grid(extent, grid_spacing_x, grid_spacing_y) #populate
return shift_ft
Now, for a reason which is obviously beyond me, the shift_ft.dict contains data from the checker_ft. And both objects are at different RAM locations:
<bk_functions.Feature object at 0x000001A726A3CF70>
<bk_functions.Feature object at 0x000001A726A1F190>
I hope that this is a simple oversight on my part. Thank you for your kind attention!