Skip to content

Commit 327f67f

Browse files
jaakkor2visr
authored andcommitted
add minimumRotatedRectangle-function
1 parent e9585f5 commit 327f67f

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/LibGEOS.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module LibGEOS
1717
prepdisjoint, prepintersects, prepoverlaps, preptouches, prepwithin,
1818
isEmpty, isSimple, isRing, hasZ, isClosed, isValid, interiorRings, exteriorRing,
1919
numPoints, startPoint, endPoint, area, geomLength, distance, hausdorffdistance, nearestPoints,
20-
getPrecision, setPrecision
20+
getPrecision, setPrecision, minimumRotatedRectangle
2121

2222
include("geos_common.jl")
2323
include("geos_c.jl")

src/geos_functions.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,24 @@ function envelope(ptr::GEOSGeom, context::GEOSContext = _context)
402402
result
403403
end
404404

405+
406+
"""
407+
minimumRotatedRectangle(geom)
408+
409+
Returns the minimum rotated rectangular POLYGON which encloses the input geometry. The rectangle
410+
has width equal to the minimum diameter, and a longer length. If the convex hill of the input is
411+
degenerate (a line or point) a LINESTRING or POINT is returned. The minimum rotated rectangle can
412+
be used as an extremely generalized representation for the given geometry.
413+
"""
414+
function minimumRotatedRectangle(ptr::GEOSGeom, context::GEOSContext = _context)
415+
result = GEOSMinimumRotatedRectangle_r(context.ptr, ptr)
416+
if result == C_NULL
417+
error("LibGEOS: Error in GEOSMinimumRotatedRectangle")
418+
end
419+
result
420+
end
421+
422+
405423
function intersection(g1::GEOSGeom, g2::GEOSGeom, context::GEOSContext = _context)
406424
result = GEOSIntersection_r(context.ptr, g1, g2)
407425
if result == C_NULL

src/geos_operations.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ for geom in (:Point, :MultiPoint, :LineString, :MultiLineString, :LinearRing, :P
5858
@eval buffer(obj::$geom, dist::Real, quadsegs::Integer=8) = geomFromGEOS(buffer(obj.ptr, dist, quadsegs))
5959
@eval bufferWithStyle(obj::$geom, dist::Real; quadsegs::Integer=8, endCapStyle::GEOSBufCapStyles=GEOSBUF_CAP_ROUND, joinStyle::GEOSBufJoinStyles=GEOSBUF_JOIN_ROUND, mitreLimit::Real=5.0) = geomFromGEOS(bufferWithStyle(obj.ptr, dist, quadsegs, endCapStyle, joinStyle, mitreLimit))
6060
@eval envelope(obj::$geom) = geomFromGEOS(envelope(obj.ptr))
61+
@eval minimumRotatedRectangle(obj::$geom) = geomFromGEOS(minimumRotatedRectangle(obj.ptr))
6162
@eval convexhull(obj::$geom) = geomFromGEOS(convexhull(obj.ptr))
6263
@eval boundary(obj::$geom) = geomFromGEOS(boundary(obj.ptr))
6364
@eval unaryUnion(obj::$geom) = geomFromGEOS(unaryUnion(obj.ptr))

test/test_geos_functions.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,5 +730,13 @@
730730
LibGEOS.destroyGeom(geom2_)
731731
LibGEOS.destroyGeom(geom3_)
732732
LibGEOS.destroyGeom(g)
733-
733+
734+
# GEOSMinimumRotatedRectangleTest
735+
input_ = readgeom("POLYGON ((1 6, 6 11, 11 6, 6 1, 1 6))")
736+
output_ = minimumRotatedRectangle(input_)
737+
expected_ = readgeom("POLYGON ((6 1, 11 6, 6 11, 1 6, 6 1))")
738+
@test writegeom(output_) == writegeom(expected_)
739+
LibGEOS.destroyGeom(input_)
740+
LibGEOS.destroyGeom(output_)
741+
LibGEOS.destroyGeom(expected_)
734742
end

0 commit comments

Comments
 (0)