Skip to content

Commit fd06924

Browse files
committed
expose createEmptyPolygon, reverse, makeValid
1 parent 6000fce commit fd06924

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/geos_functions.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,30 @@ function createEmptyCollection(geomtype::GEOSGeomTypes, context::GEOSContext = g
490490
result
491491
end
492492

493+
function createEmptyPolygon(context::GEOSContext = get_global_context())::Polygon
494+
result = GEOSGeom_createEmptyPolygon_r(context)
495+
if result == C_NULL
496+
error("LibGEOS: Error in GEOSGeom_createEmptyPolygon")
497+
end
498+
Polygon(result, context)
499+
end
500+
501+
function reverse(obj::Geometry, context::GEOSContext = get_context(obj))::LibGEOS.AbstractGeometry
502+
result = GEOSReverse_r(context, obj)
503+
if result == C_NULL
504+
error("LibGEOS: Error in GEOSReverse_r")
505+
end
506+
geomFromGEOS(result, context)
507+
end
508+
509+
function makeValid(obj::Geometry, context::GEOSContext = get_context(obj))::LibGEOS.AbstractGeometry
510+
result = GEOSMakeValid_r(context, obj)
511+
if result == C_NULL
512+
error("LibGEOS: Error in GEOSMakeValid_r")
513+
end
514+
geomFromGEOS(result, context)
515+
end
516+
493517
# Memory management
494518
# cloneGeom result needs to be wrapped in Geometry type
495519
function cloneGeom(ptr::Union{Geometry,GEOSGeom}, context::GEOSContext = get_global_context())
@@ -639,12 +663,12 @@ end
639663
# GEOSPolygonizer_getCutEdges
640664
# GEOSPolygonize_full
641665

642-
function lineMerge(obj::Geometry, context::GEOSContext = get_context(obj))
666+
function lineMerge(obj::Geometry, context::GEOSContext = get_context(obj))::MultiLineString
643667
result = GEOSLineMerge_r(context, obj)
644668
if result == C_NULL
645669
error("LibGEOS: Error in GEOSLineMerge")
646670
end
647-
LineString(result, context)
671+
MultiLineString(result, context)
648672
end
649673

650674
function simplify(obj::Geometry, tol::Real, context::GEOSContext = get_context(obj))

test/test_geos_functions.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
using Test
2+
using LibGEOS
3+
@testset "smoketests" begin
4+
p = LibGEOS.createEmptyPolygon()
5+
@test p == readgeom("POLYGON EMPTY")
6+
@test p isa Polygon
7+
8+
lss = readgeom("MULTILINESTRING((0 0, 0 1), (0 1, 0 2))")
9+
@test lineMerge(lss) == readgeom("MULTILINESTRING ((0 0, 0 1, 0 2))")
10+
11+
geo_invalid = readgeom("POLYGON((0 0, 0 1, 1 1, 1 0, -1 1, 0 0))")
12+
@test !LibGEOS.isValid(geo_invalid)
13+
geo_valid = LibGEOS.makeValid(geo_invalid)
14+
@test geo_valid isa LibGEOS.MultiPolygon
15+
@test LibGEOS.isValid(geo_valid)
16+
17+
@test LibGEOS.reverse(readgeom("LINESTRING(0 0, 1 1)")) == readgeom("LINESTRING(1 1, 0 0)")
18+
19+
20+
end
21+
122
@testset "WKTWriter" begin
223
# default writing options
324
p = readgeom("POINT(0.12345 2.000 0.1)")
@@ -60,7 +81,7 @@ end
6081
seq = Vector{Float64}[[-1, 0], [0, 0], [10, 0], [10, 10], [0, 10], [-1, 0]]
6182
a = LibGEOS.createCoordSeq(seq)
6283
@test LibGEOS.isCCW(a)
63-
a = LibGEOS.createCoordSeq(reverse(seq))
84+
a = LibGEOS.createCoordSeq(Base.reverse(seq))
6485
@test !LibGEOS.isCCW(a)
6586

6687
# Polygons and Holes

0 commit comments

Comments
 (0)