In [12]:
import numpy as np
import jsonlines
%pylab inline
%matplotlib inline
In [14]:
count = 0
count_cl = 0 # Clockwise winding count
count_ccl = 0 # Clockwise winding count
with jsonlines.open('circle.ndjson') as reader:
for obj in reader:
if obj['countrycode'] == 'IN': # Insert country code - https://www.wikiwand.com/en/ISO_3166-1_alpha-2
count = count + 1
abc = obj['drawing'][0]
sum = 0
for i in range(np.shape(abc)[1]-1):
sum = sum - (abc[0][i+1]-abc[0][i])*(abc[1][i+1]+abc[1][i]) # negative sign because of change in handedness
if sum > 0:
count_cl = count_cl + 1
elif sum < 0:
count_ccl = count_ccl + 1
#if count == 6: # If you want to visualise a particular drawing
# break
print count, count_cl, count_ccl
In [15]:
print abc[0][0], abc[1][0]
print sum
plot(abc[0][0:50],abc[1][0:50]) # in equivalent right handed coordinate system: so reverse winding
Out[15]:
In [16]:
(1 - (count_cl+count_ccl)*1./count*1.)*100
Out[16]:
In [17]:
count_cl*100./count
Out[17]:
In [18]:
count_ccl*100./count
Out[18]:
In [19]:
count
Out[19]: