Skip to content

Commit 1485489

Browse files
jaakkor2yeesian
authored andcommitted
add bufferWithStyle (#55)
* add bufferWithStyle to geos_functions.jl * add bufferWithStyle to geos_operations.jl * export bufferWithStyle * add GEOSBufCapStyles, GEOSBufJoinStyles * Update geos_operations.jl * bufferWithStyle keyword arguments optional arguments as keyword arguments * add tests for bufferWithStyle
1 parent f2bd58f commit 1485489

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/LibGEOS.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module LibGEOS
1313
export Point, MultiPoint, LineString, MultiLineString, LinearRing, Polygon, MultiPolygon, GeometryCollection,
1414
parseWKT, geomFromWKT, geomToWKT, readgeom, writegeom,
1515
project, projectNormalized, interpolate, interpolateNormalized,
16-
buffer, envelope, intersection, convexhull, difference, symmetricDifference,
16+
buffer, bufferWithStyle, envelope, intersection, convexhull, difference, symmetricDifference,
1717
boundary, union, unaryUnion, pointOnSurface, centroid, node,
1818
polygonize, lineMerge, simplify, topologyPreserveSimplify, uniquePoints, sharedPaths,
1919
snap, delaunayTriangulation, delaunayTriangulationEdges,

src/geos_functions.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ end
324324
buffer(ptr::GEOSGeom, width::Real, quadsegs::Integer=8, context::GEOSContext = _context) =
325325
GEOSBuffer_r(context.ptr, ptr, width, Int32(quadsegs))
326326

327-
# enum GEOSBufCapStyles
328-
# enum GEOSBufJoinStyles
327+
@enum GEOSBufCapStyles::Int32 CAP_ROUND=1 CAP_FLAT=2 CAP_SQUARE=3
328+
@enum GEOSBufJoinStyles::Int32 JOIN_ROUND=1 JOIN_MITRE=2 JOIN_BEVEL=3
329+
330+
bufferWithStyle(ptr::GEOSGeom, width::Real, quadsegs::Integer=8, endCapStyle::GEOSBufCapStyles=CAP_ROUND, joinStyle::GEOSBufJoinStyles=JOIN_ROUND, mitreLimit::Real=5.0, context::GEOSContext = _context) =
331+
GEOSBufferWithStyle_r(context.ptr, ptr, width, Int32(quadsegs), Int32(endCapStyle), Int32(joinStyle), mitreLimit)
329332

330333
# GEOSBufferParams_create
331334
# GEOSBufferParams_destroy
@@ -335,7 +338,6 @@ buffer(ptr::GEOSGeom, width::Real, quadsegs::Integer=8, context::GEOSContext = _
335338
# GEOSBufferParams_setQuadrantSegments
336339
# GEOSBufferParams_setSingleSided
337340
# GEOSBufferWithParams
338-
# GEOSBufferWithStyle
339341
# GEOSOffsetCurve
340342

341343
# -----

src/geos_operations.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ interpolateNormalized(line::LineString, dist::Real) = Point(interpolateNormalize
5656
# # -----
5757
for geom in (:Point, :MultiPoint, :LineString, :MultiLineString, :LinearRing, :Polygon, :MultiPolygon, :GeometryCollection)
5858
@eval buffer(obj::$geom, dist::Real, quadsegs::Integer=8) = geomFromGEOS(buffer(obj.ptr, dist, quadsegs))
59+
@eval bufferWithStyle(obj::$geom, dist::Real; quadsegs::Integer=8, endCapStyle::GEOSBufCapStyles=CAP_ROUND, joinStyle::GEOSBufJoinStyles=JOIN_ROUND, mitreLimit::Real=5.0) = geomFromGEOS(bufferWithStyle(obj.ptr, dist, quadsegs, endCapStyle, joinStyle, mitreLimit))
5960
@eval envelope(obj::$geom) = geomFromGEOS(envelope(obj.ptr))
6061
@eval convexhull(obj::$geom) = geomFromGEOS(convexhull(obj.ptr))
6162
@eval boundary(obj::$geom) = geomFromGEOS(boundary(obj.ptr))

test/test_geos_operations.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,17 @@ end
247247
# Buffer should return Polygon or MultiPolygon
248248
@test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 0.1) isa LibGEOS.MultiPolygon
249249
@test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 10) isa LibGEOS.Polygon
250+
251+
# bufferWithStyle
252+
g1 = bufferWithStyle(readgeom("LINESTRING(0 0,0 1,1 1)"), 0.1, endCapStyle=LibGEOS.CAP_FLAT, joinStyle=LibGEOS.JOIN_BEVEL)
253+
g2 = readgeom("POLYGON((-0.1 0.0,-0.1 1.0,0.0 1.1,1.0 1.1,1.0 0.9,0.1 0.9,0.1 0.0,-0.1 0.0))")
254+
@test equals(g1, g2)
255+
256+
g1 = bufferWithStyle(readgeom("LINESTRING(0 0,0 1,1 1)"), 0.1, endCapStyle=LibGEOS.CAP_SQUARE, joinStyle=LibGEOS.JOIN_MITRE)
257+
g2 = readgeom("POLYGON((-0.1 -0.1,-0.1 1.1,1.1 1.1,1.1 0.9,0.1 0.9,0.1 -0.1,-0.1 -0.1))")
258+
@test equals(g1, g2)
259+
260+
g1 = bufferWithStyle(readgeom("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"), 0.2, joinStyle=LibGEOS.JOIN_MITRE)
261+
g2 = readgeom("POLYGON((-1.2 1.2,1.2 1.2,1.2 -1.2,-1.2 -1.2,-1.2 1.2))")
262+
@test equals(g1, g2)
250263
end

0 commit comments

Comments
 (0)