Skip to content

Commit 4928bb3

Browse files
authored
expose createEmptyPolygon, reverse, makeValid (#169)
* expose createEmptyPolygon, reverse, makeValid * v0.8.2 * move tests for lineMerge and friends
1 parent 6000fce commit 4928bb3

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LibGEOS"
22
uuid = "a90b1aa1-3769-5649-ba7e-abc5a9d163eb"
33
license = "MIT"
4-
version = "0.8.1"
4+
version = "0.8.2"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"

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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using Test
2+
using LibGEOS
3+
14
@testset "WKTWriter" begin
25
# default writing options
36
p = readgeom("POINT(0.12345 2.000 0.1)")
@@ -60,7 +63,7 @@ end
6063
seq = Vector{Float64}[[-1, 0], [0, 0], [10, 0], [10, 10], [0, 10], [-1, 0]]
6164
a = LibGEOS.createCoordSeq(seq)
6265
@test LibGEOS.isCCW(a)
63-
a = LibGEOS.createCoordSeq(reverse(seq))
66+
a = LibGEOS.createCoordSeq(Base.reverse(seq))
6467
@test !LibGEOS.isCCW(a)
6568

6669
# Polygons and Holes
@@ -896,4 +899,19 @@ end
896899
# LibGEOS.getExtent(geom) == [0, 0, 1, 1]
897900
GeoInterface.extent(geom) == Extent(X = (0, 1), Y = (0, 1))
898901
end
902+
903+
p = LibGEOS.createEmptyPolygon()
904+
@test p == readgeom("POLYGON EMPTY")
905+
@test p isa Polygon
906+
907+
lss = readgeom("MULTILINESTRING((0 0, 0 1), (0 1, 0 2))")
908+
@test lineMerge(lss) == readgeom("MULTILINESTRING ((0 0, 0 1, 0 2))")
909+
910+
geo_invalid = readgeom("POLYGON((0 0, 0 1, 1 1, 1 0, -1 1, 0 0))")
911+
@test !LibGEOS.isValid(geo_invalid)
912+
geo_valid = LibGEOS.makeValid(geo_invalid)
913+
@test geo_valid isa LibGEOS.MultiPolygon
914+
@test LibGEOS.isValid(geo_valid)
915+
916+
@test LibGEOS.reverse(readgeom("LINESTRING(0 0, 1 1)")) == readgeom("LINESTRING(1 1, 0 0)")
899917
end

0 commit comments

Comments
 (0)