I managed to calculate a single polygon form a Json file, but when i want to calculate the total surface of the Json file i donât get the expected results.
This code works for a single Polygon, but it cant run the total file:
f = open(âwijken.jsonâ)
data2 = json.load(f)
color = Color(85, 191, 19)
list_features1 = []
list_x = []
list_y = []
list_coordinates_1 = []
for j in range(len(data2[âfeaturesâ][0][âgeometryâ][âcoordinatesâ][0])):
coordinates_rd = tuple(data2[âfeaturesâ][0][âgeometryâ][âcoordinatesâ][0][j])
lat, lon = RDWGSConverter.from_rd_to_wgs(coordinates_rd)
list_x.append(coordinates_rd[0])
list_y.append(coordinates_rd[1])
list_coordinates_1.append(MapPoint(lat, lon))
list_features1.append(MapPolygon(list_coordinates_1, color=color))
optellen = 0
for k in range(len(list_x)):
if k < (len(list_x) - 1):
values_x = list_x[k] * list_y[k+1]
optellen += values_x
values_y = list_y[k] * list_x[k+1]
optellen -= values_y
shoelace = abs(optellen/2)
print(shoelace)
This is the code for the total file with all the polygons but this is not the right answer:
f = open(âwijken.jsonâ)
data = json.load(f)
color = Color(85, 191, 19)
list_features2 = []
list_x = []
list_y = []
for i in range(len(data[âfeaturesâ])):
list_coordinates = []
for j in range(len(data[âfeaturesâ][i][âgeometryâ][âcoordinatesâ][0])):
coordinates_rd = tuple(data[âfeaturesâ][i][âgeometryâ][âcoordinatesâ][0][j])
lat, lon = RDWGSConverter.from_rd_to_wgs(coordinates_rd)
list_x.append(coordinates_rd[0])
list_y.append(coordinates_rd[1])
list_coordinates.append(MapPoint(lat, lon))
list_features2.append(MapPolygon(list_coordinates, color=color))
optellen = 0
for k in range(len(list_x)):
if k < (len(list_x) - 1):
values_x = list_x[k] * list_y[k+1]
optellen += values_x
values_y = list_y[k] * list_x[k+1]
optellen -= values_y
shoelace = abs(optellen/2)
print(shoelace)
Json file: https://denhaag.dataplatform.nl/#/data/c1059cef-be66-4a7a-9657-2f38f55794ed
Can somebody help me?