def dist_point_multi(point, multi): if multi is not None: wktMulti = dumps(multi) # create geometries from wkt Multi = ogr.CreateGeometryFromWkt(wktMulti) # transform both geometries to the fittest projection if Multi is not None: Point = ogr.CreateGeometryFromWkt(dumps(point)) # transform both geometries to the fittest projection source = osr.SpatialReference() source.ImportFromEPSG(4326) target = osr.SpatialReference() target.ImportFromEPSG(26918) transform = osr.CoordinateTransformation(source, target) Point.Transform(transform) # create a line for each point in the first geometry of the polygon # initialize x0 = Point.GetX() y0 = Point.GetY() distance1 = [] for line in Multi: for i in range(0, line.GetPointCount() - 1): xi, yi, zi = line.GetPoint(i) ai, bi, ci = line.GetPoint(i + 1) # create line and check length distance1.append(dist(xi, yi, ai, bi, x0, y0)) return min(distance1)
def coordinates(point): Point = ogr.CreateGeometryFromWkt(dumps(point)) # transform both geometries to the fittest projection source = osr.SpatialReference() source.ImportFromEPSG(4326) target = osr.SpatialReference() target.ImportFromEPSG(26918) transform = osr.CoordinateTransformation(source, target) Point.Transform(transform) x0 = Point.GetX() y0 = Point.GetY() return x0, y0