Skip to content

Commit

Permalink
add bufferWithStyle (#55)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jaakkor2 authored and yeesian committed Oct 18, 2018
1 parent f2bd58f commit 1485489
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/LibGEOS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module LibGEOS
export Point, MultiPoint, LineString, MultiLineString, LinearRing, Polygon, MultiPolygon, GeometryCollection,
parseWKT, geomFromWKT, geomToWKT, readgeom, writegeom,
project, projectNormalized, interpolate, interpolateNormalized,
buffer, envelope, intersection, convexhull, difference, symmetricDifference,
buffer, bufferWithStyle, envelope, intersection, convexhull, difference, symmetricDifference,
boundary, union, unaryUnion, pointOnSurface, centroid, node,
polygonize, lineMerge, simplify, topologyPreserveSimplify, uniquePoints, sharedPaths,
snap, delaunayTriangulation, delaunayTriangulationEdges,
Expand Down
8 changes: 5 additions & 3 deletions src/geos_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,11 @@ end
buffer(ptr::GEOSGeom, width::Real, quadsegs::Integer=8, context::GEOSContext = _context) =
GEOSBuffer_r(context.ptr, ptr, width, Int32(quadsegs))

# enum GEOSBufCapStyles
# enum GEOSBufJoinStyles
@enum GEOSBufCapStyles::Int32 CAP_ROUND=1 CAP_FLAT=2 CAP_SQUARE=3
@enum GEOSBufJoinStyles::Int32 JOIN_ROUND=1 JOIN_MITRE=2 JOIN_BEVEL=3

bufferWithStyle(ptr::GEOSGeom, width::Real, quadsegs::Integer=8, endCapStyle::GEOSBufCapStyles=CAP_ROUND, joinStyle::GEOSBufJoinStyles=JOIN_ROUND, mitreLimit::Real=5.0, context::GEOSContext = _context) =
GEOSBufferWithStyle_r(context.ptr, ptr, width, Int32(quadsegs), Int32(endCapStyle), Int32(joinStyle), mitreLimit)

# GEOSBufferParams_create
# GEOSBufferParams_destroy
Expand All @@ -335,7 +338,6 @@ buffer(ptr::GEOSGeom, width::Real, quadsegs::Integer=8, context::GEOSContext = _
# GEOSBufferParams_setQuadrantSegments
# GEOSBufferParams_setSingleSided
# GEOSBufferWithParams
# GEOSBufferWithStyle
# GEOSOffsetCurve

# -----
Expand Down
1 change: 1 addition & 0 deletions src/geos_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interpolateNormalized(line::LineString, dist::Real) = Point(interpolateNormalize
# # -----
for geom in (:Point, :MultiPoint, :LineString, :MultiLineString, :LinearRing, :Polygon, :MultiPolygon, :GeometryCollection)
@eval buffer(obj::$geom, dist::Real, quadsegs::Integer=8) = geomFromGEOS(buffer(obj.ptr, dist, quadsegs))
@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))
@eval envelope(obj::$geom) = geomFromGEOS(envelope(obj.ptr))
@eval convexhull(obj::$geom) = geomFromGEOS(convexhull(obj.ptr))
@eval boundary(obj::$geom) = geomFromGEOS(boundary(obj.ptr))
Expand Down
13 changes: 13 additions & 0 deletions test/test_geos_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,17 @@ end
# Buffer should return Polygon or MultiPolygon
@test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 0.1) isa LibGEOS.MultiPolygon
@test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 10) isa LibGEOS.Polygon

# bufferWithStyle
g1 = bufferWithStyle(readgeom("LINESTRING(0 0,0 1,1 1)"), 0.1, endCapStyle=LibGEOS.CAP_FLAT, joinStyle=LibGEOS.JOIN_BEVEL)
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))")
@test equals(g1, g2)

g1 = bufferWithStyle(readgeom("LINESTRING(0 0,0 1,1 1)"), 0.1, endCapStyle=LibGEOS.CAP_SQUARE, joinStyle=LibGEOS.JOIN_MITRE)
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))")
@test equals(g1, g2)

g1 = bufferWithStyle(readgeom("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"), 0.2, joinStyle=LibGEOS.JOIN_MITRE)
g2 = readgeom("POLYGON((-1.2 1.2,1.2 1.2,1.2 -1.2,-1.2 -1.2,-1.2 1.2))")
@test equals(g1, g2)
end

0 comments on commit 1485489

Please sign in to comment.