# CrossCompute
geometries_text_path = 'geometries.txt'
target_folder = '/tmp'
from shapely import wkt
from shapely.geometry import GeometryCollection
geometries = []
for line in open(geometries_text_path):
geometries.append(wkt.loads(line))
GeometryCollection(geometries)
from shapely.geometry import Point
def sum_distances(xy):
return sum(Point(xy).distance(g) for g in geometries)
sum_distances((0, 0))
from numpy.random import rand
from scipy.optimize import minimize
initial_xy = rand(2)
r = minimize(sum_distances, initial_xy, method='L-BFGS-B')
r
store_point = Point(r.x)
print(store_point)
from geotable import ColorfulGeometryCollection
geometry_collection = ColorfulGeometryCollection([
GeometryCollection(geometries),
store_point,
], colors=['blue', 'yellow'])
geometry_collection
from cairosvg import svg2png
from os.path import join
target_path = join(target_folder, 'geometries.png')
svg2png(
bytestring=geometry_collection._repr_svg_(),
write_to=target_path)
print('geometry_image_path = %s' % target_path)
print('store_x = %s' % store_point.x)
print('store_y = %s' % store_point.y)