Skip to content

Commit 9bc556b

Browse files
authored
apply WKTWriter options after construction (#82)
* apply WKTWriter options after construction Instead of after destruction :) * trim trailing whitespace * update CI badge
1 parent dee5aa0 commit 9bc556b

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
LibGEOS.jl
22
==========
3-
[![Build Status](https://travis-ci.com/JuliaGeo/LibGEOS.jl.svg?branch=master)](https://travis-ci.com/JuliaGeo/LibGEOS.jl)
4-
[![Build Status](https://ci.appveyor.com/api/projects/status/github/JuliaGeo/LibGEOS.jl?svg=true&branch=master)](https://ci.appveyor.com/project/JuliaGeo/LibGEOS-jl/branch/master)
3+
[![CI](https://github.com/JuliaGeo/LibGEOS.jl/workflows/CI/badge.svg)](https://github.com/JuliaGeo/LibGEOS.jl/actions?query=workflow%3ACI)
54
[![Coverage Status](https://coveralls.io/repos/github/JuliaGeo/LibGEOS.jl/badge.svg)](https://coveralls.io/github/JuliaGeo/LibGEOS.jl)
65

76
LibGEOS is a package for manipulation and analysis of planar geometric objects, based on the libraries [GEOS](https://trac.osgeo.org/geos/) (the engine of PostGIS) and JTS (from which GEOS is ported). This package wraps the [GEOS C API](https://geos.osgeo.org/doxygen/geos__c_8h_source.html).

src/LibGEOS.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ module LibGEOS
7272

7373
function WKTWriter(context::GEOSContext; trim::Bool=true, outputdim::Int=3, roundingprecision::Int=-1)
7474
writer = new(GEOSWKTWriter_create_r(context.ptr))
75+
GEOSWKTWriter_setTrim_r(context.ptr, writer.ptr, UInt8(trim))
76+
GEOSWKTWriter_setOutputDimension_r(context.ptr, writer.ptr, outputdim)
77+
GEOSWKTWriter_setRoundingPrecision_r(context.ptr, writer.ptr, roundingprecision)
7578
finalizer(function(writer)
7679
GEOSWKTWriter_destroy_r(context.ptr, writer.ptr)
77-
GEOSWKTWriter_setTrim_r(context.ptr, writer.ptr, UInt8(trim))
78-
GEOSWKTWriter_setOutputDimension_r(context.ptr, writer.ptr, outputdim)
79-
GEOSWKTWriter_setRoundingPrecision_r(context.ptr, writer.ptr, roundingprecision)
8080
writer.ptr = C_NULL
8181
end, writer)
8282
writer

test/test_geos_functions.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
@testset "WKTWriter" begin
2+
# default writing options
3+
p = readgeom("POINT(0.12345 2.000 0.1)")
4+
@test writegeom(p) == "POINT Z (0.12345 2 0.1)"
5+
6+
p = readgeom("POINT(0.12345 2.000)")
7+
@test writegeom(p) == "POINT (0.12345 2)"
8+
9+
# round to 2 decimals
10+
writer = LibGEOS.WKTWriter(LibGEOS._context, trim=true, outputdim=3, roundingprecision=2)
11+
@test writegeom(p, writer) == "POINT (0.12 2)"
12+
13+
# round to 2 decimals and don't trim trailing zeros
14+
writer = LibGEOS.WKTWriter(LibGEOS._context, trim=false, outputdim=3, roundingprecision=2)
15+
@test writegeom(p, writer) == "POINT (0.12 2.00)"
16+
17+
# don't output the Z dimension
18+
p = readgeom("POINT(0.12345 2.000 0.1)")
19+
writer = LibGEOS.WKTWriter(LibGEOS._context, trim=false, outputdim=2, roundingprecision=2)
20+
@test writegeom(p, writer) == "POINT (0.12 2.00)"
21+
end
22+
123
@testset "GEOS functions" begin
224
a = LibGEOS.createCoordSeq(Vector{Float64}[[1,2,3],[4,5,6]])
325
b = LibGEOS.cloneCoordSeq(a)
@@ -693,7 +715,7 @@
693715
geom_ = LibGEOS._readgeom("LINESTRING(0 0, 0 1, 1 1, 0 0)")
694716
@test LibGEOS.isClosed(geom_)
695717
LibGEOS.destroyGeom(geom_)
696-
718+
697719
# setPrecision, getPrecision
698720
# Taken from https://git.osgeo.org/gitea/geos/geos/src/branch/master/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp
699721

@@ -733,7 +755,7 @@
733755
geom3_ = setPrecision(geom1_, 5.0, flags = LibGEOS.GEOS_PREC_KEEP_COLLAPSED)
734756
# @test equals(geom3_, readgeom("LINESTRING (0 0, 0 0)")) # false ??
735757
@test writegeom(geom3_) == "LINESTRING (0 0, 0 0)"
736-
758+
737759
LibGEOS.destroyGeom(geom1_)
738760
LibGEOS.destroyGeom(geom2_)
739761
LibGEOS.destroyGeom(geom3_)

test/test_geos_operations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ end
248248
# Buffer should return Polygon or MultiPolygon
249249
@test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 0.1) isa LibGEOS.MultiPolygon
250250
@test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 10) isa LibGEOS.Polygon
251-
251+
252252
# bufferWithStyle
253253
g1 = bufferWithStyle(readgeom("LINESTRING(0 0,0 1,1 1)"), 0.1, endCapStyle=LibGEOS.GEOSBUF_CAP_FLAT, joinStyle=LibGEOS.GEOSBUF_JOIN_BEVEL)
254254
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))")
255255
@test equals(g1, g2)
256-
256+
257257
g1 = bufferWithStyle(readgeom("LINESTRING(0 0,0 1,1 1)"), 0.1, endCapStyle=LibGEOS.GEOSBUF_CAP_SQUARE, joinStyle=LibGEOS.GEOSBUF_JOIN_MITRE)
258258
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))")
259259
@test equals(g1, g2)

0 commit comments

Comments
 (0)