What will be the conditions if I want to check whether two geometries are same or not.
I have coordinates of two geometries. Both geometries are same. But First geometry is rotated and second geometry is not rotated, however, input order (coordinates numbers) of the geometry is now changed. How can I prove in python code that both geometries are same even after oriented in different way in 2D space.
#Coordinates for first geometry,
X1 = [0.0, 0.87, 1.37, 1.87, 2.73, 3.6, 4.46, 4.96, 5.46, 4.6, 3.73, 2.87, 2.0, 1.5, 1.0, 0.5, 2.37, 3.23, 4.1]
Y1 = [0.0, 0.5, -0.37, -1.23, -0.73, -0.23, 0.27, -0.6, -1.46, -1.96, -2.46, -2.96, -3.46, -2.6, -1.73, -0.87, -2.1, -1.6, -1.1]
#Coordinates for second geometry,
X2 = [2, 4, 4, 2, 3, 2, 4, 3, 1, 3, 4, 3, 1, 2, 0, 3, 4, 2, 0]
Y2 = [3, 4, 2, 1, 3, 2, 1, 0, 0, 2, 3, 4, 1, 4, 0, 1, 0, 0, 1]
What I have tried so far: I tried to verify using below conditions.
(1) Number of node in both geometries should be same in both geometries.
#---------------------------CONDITION: 1------------------------------------------------#
# Condition: Number of nodes in both geometries should be same
node_number1 = df_1['node_number'].tolist() # converting 'node number' column from first dataframe to a list
node_number2 = df_2['node_number'].tolist() # converting 'X_coordinate' column from second dataframe to a list
(2) Distance between two consecutive nodes (such as Node 1 & node2, Node 2 & Node 3) should be same in both geometries.
#---------------------------CONDITION: 2------------------------------------------------#
# Condition: Distance between two successive nodes must be 1.
x_shift1 = df_1['New_X_coordinate_reformed'].shift(-1) # In first dataframe shift the index by (-1) from X_coordinate values
y_shift1 = df_1['New_Y_coordinate_reformed'].shift(-1) # In first dataframe shift the index by (-1) from Y_coordinate values
# Finding a distance between two coordinates (nodes)
# General formula for this: square root of [(x2 - x1)^2 - (y2 - y1)^2]
nodal_dist_df_1 = np.sqrt((x_shift1 - df_1['New_X_coordinate_reformed'])**2 + (y_shift1 - df_1['New_Y_coordinate_reformed'])**2).dropna().to_list()
nodal_dist_df_1 = [round(num,2) for num in nodal_dist_df_1] # rounding a obtained values in 'nodal_dist_df1' by 2 decimals
x_shift2 = df_2['New_X_coordinate_reformed'].shift(-1) # In second dataframe shift the index by (-1) from X_coordinate values
y_shift2 = df_2['New_Y_coordinate_reformed'].shift(-1) # In second dataframe shift the index by (-1) from Y_coordinate values
# Finding a distance between two coordinates (nodes)
# General formula for this: square root of [(x2 - x1)^2 - (y2 - y1)^2]
nodal_dist_df_2 = np.sqrt((x_shift2 - df_2['New_X_coordinate_reformed'])**2 + (y_shift2 - df_2['New_Y_coordinate_reformed'])**2).dropna().to_list()
nodal_dist_df_2 = [round(num,2) for num in nodal_dist_df_2] # rounding a obtained values in 'nodal_dist_df1' by 2 decimals
(3) Distance to every node of geometry from 1st node should be same in both geometries.
#---------------------------CONDITION: 3------------------------------------------------#
# Condition: Distances between first node to each node should be same in both geometries.
i=0
dist_from_N1_1 = [] # For first dataframe initializng a blank list
for i in range(len(df_1['New_X_coordinate_reformed'])-1):
# Finding a distance between two coordinates (nodes) in first dataframe
# General formula for this: square root of [(x2 - x1)^2 - (y2 - y1)^2] where x1 and y1 will be constant and second coordinate will vary from x2 to x15
d = np.sqrt((df_1['New_X_coordinate_reformed'][i+1]-df_1['New_X_coordinate_reformed'][0])**2 + (df_1['New_Y_coordinate_reformed'][i+1]-df_1['New_Y_coordinate_reformed'][0])**2)
dist_from_N1_1.append(d) # appending a distance value in a list initialized before 'for' loop
i = i+1
dist_from_N1_1 = [round(num,2) for num in dist_from_N1_1] # rounding a obtained values in 'nodal_dist_df1' by 2 decimals
i=0
dist_from_N1_2 = [] # For second dataframe initializng a blank list
for i in range(len(df_2['New_X_coordinate_reformed'])-1):
# Finding a distance between two coordinates (nodes) in second dataframe
# General formula for this: square root of [(x2 - x1)^2 - (y2 - y1)^2] where x1 and y1 will be constant and second coordinate will vary from x2 to x15
d_N2 = np.sqrt((df_2['New_X_coordinate_reformed'][i+1]-df_2['New_X_coordinate_reformed'][0])**2 + (df_2['New_Y_coordinate_reformed'][i+1]-df_2['New_Y_coordinate_reformed'][0])**2)
dist_from_N1_2.append(d_N2)
i = i+1
dist_from_N1_2 = [round(num,2) for num in dist_from_N1_2] # rounding a obtained values in 'nodal_dist_df1' by 2 decimals
Now after analysing three conditions, I have checked them whether they satisfy or not.
#---------------------------Checking of all three condition-----------------------------#
if (len(node_number2) == len(node_number1) and (nodal_dist_df_1 == nodal_dist_df_2) and dist_from_N1_1 == dist_from_N1_2):
print('All three conditions are satisfied.')
print('Hence Yes, two geometries are same.')
else:
print('No, two geometries are not same.')
But this approach gives oncorrect result. Kindly help me by giving your suggestions.