Skip to content

Commit 9c83f94

Browse files
authored
cleanup (#162)
* reorganise files so LibGEOS.jl is clean * move generated file to its own folder * geointerface never has an underscore * sort function names
1 parent 5264a1e commit 9c83f94

File tree

7 files changed

+226
-226
lines changed

7 files changed

+226
-226
lines changed

gen/generator.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[general]
22
library_name = "libgeos"
3-
output_file_path = "../src/libgeos_api.jl"
3+
output_file_path = "../src/generated/libgeos_api.jl"
44
# prologue_file_path = "prologue.jl"
55
use_julia_native_enum_type = false
66
print_using_CEnum = false

src/LibGEOS.jl

Lines changed: 72 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -8,253 +8,100 @@ using CEnum
88

99
const GI = GeoInterface
1010

11-
export Point,
12-
MultiPoint,
11+
export GeometryCollection,
1312
LineString,
14-
MultiLineString,
1513
LinearRing,
16-
Polygon,
14+
MultiLineString,
15+
MultiPoint,
1716
MultiPolygon,
18-
GeometryCollection,
19-
readgeom,
20-
writegeom,
21-
project,
22-
projectNormalized,
23-
interpolate,
24-
interpolateNormalized,
17+
Point,
18+
Polygon,
19+
STRtree
20+
21+
export
22+
area,
23+
boundary,
2524
buffer,
2625
bufferWithStyle,
27-
envelope,
28-
intersection,
29-
convexhull,
30-
difference,
31-
symmetricDifference,
32-
boundary,
33-
union,
34-
unaryUnion,
35-
pointOnSurface,
3626
centroid,
37-
node,
38-
polygonize,
39-
lineMerge,
40-
simplify,
41-
topologyPreserveSimplify,
42-
uniquePoints,
43-
sharedPaths,
44-
snap,
27+
constrainedDelaunayTriangulation,
28+
containsproperly,
29+
convexhull,
30+
coveredby,
31+
covers,
32+
crosses,
4533
delaunayTriangulation,
4634
delaunayTriangulationEdges,
47-
constrainedDelaunayTriangulation,
35+
difference,
4836
disjoint,
49-
touches,
50-
intersects,
51-
crosses,
52-
within,
53-
overlaps,
37+
distance,
38+
endPoint,
39+
envelope,
5440
equals,
5541
equalsexact,
56-
containsproperly,
57-
covers,
58-
coveredby,
59-
prepareGeom,
60-
isEmpty,
61-
isSimple,
62-
isRing,
63-
hasZ,
64-
isClosed,
65-
isValid,
66-
interiorRing,
67-
interiorRings,
6842
exteriorRing,
69-
numGeometries,
70-
numPoints,
71-
startPoint,
72-
endPoint,
73-
area,
7443
geomLength,
75-
distance,
76-
hausdorffdistance,
77-
nearestPoints,
44+
getGeometries,
45+
getGeometry,
7846
getPrecision,
79-
setPrecision,
80-
getXMin,
81-
getYMin,
8247
getXMax,
48+
getXMin,
8349
getYMax,
50+
getYMin,
51+
hasZ,
52+
hausdorffdistance,
53+
interiorRing,
54+
interiorRings,
55+
interpolate,
56+
interpolateNormalized,
57+
intersection,
58+
intersects,
59+
isClosed,
60+
isEmpty,
61+
isRing,
62+
isSimple,
63+
isValid,
64+
lineMerge,
8465
minimumRotatedRectangle,
85-
getGeometry,
86-
getGeometries,
87-
STRtree,
88-
query
89-
90-
mutable struct GEOSError <: Exception
91-
msg::String
92-
end
93-
Base.showerror(io::IO, err::GEOSError) = print(io, "GEOSError\n\t$(err.msg)")
94-
95-
function geosjl_errorhandler(message::Ptr{UInt8}, userdata)
96-
if unsafe_string(message) == "%s"
97-
throw(GEOSError(unsafe_string(Cstring(userdata))))
98-
else
99-
throw(GEOSError(unsafe_string(message)))
100-
end
101-
end
102-
103-
"""
104-
105-
GEOSContext
106-
107-
Every LibGEOS object needs to live somewhere in memory. Also many LibGEOS functions
108-
need scratch memory or caches to do their job.
109-
110-
A `GEOSContext` governs such memory. Almost every function in LibGEOS accepts a `context`
111-
argument, that allows passing a context explicitly. If no context is passed, a global context is used.
112-
113-
Using the global context is fine, as long as no multi threading is used.
114-
If multi threading is used, the global context should be avoided and every operation should only
115-
involve objects that live in the context passed to the operation.
116-
"""
117-
mutable struct GEOSContext
118-
ptr::Ptr{Cvoid} # GEOSContextHandle_t
119-
120-
function GEOSContext()
121-
context = new(GEOS_init_r())
122-
GEOSContext_setNoticeHandler_r(context, C_NULL)
123-
GEOSContext_setErrorHandler_r(
124-
context,
125-
@cfunction(geosjl_errorhandler, Ptr{Cvoid}, (Ptr{UInt8}, Ptr{Cvoid}))
126-
)
127-
finalizer(context -> (GEOS_finish_r(context); context.ptr = C_NULL), context)
128-
context
129-
end
130-
end
131-
132-
function Base.:(==)(c1::GEOSContext, c2::GEOSContext)
133-
(c1.ptr == c2.ptr)
134-
end
135-
function Base.hash(c::GEOSContext, h::UInt)
136-
hash(c.ptr, h)
137-
end
138-
139-
"Get a copy of a string from GEOS, freeing the GEOS managed memory."
140-
function string_copy_free(s::Cstring, context::GEOSContext = get_global_context())::String
141-
copy = unsafe_string(s)
142-
GEOSFree_r(context, pointer(s))
143-
return copy
144-
end
145-
146-
include("libgeos_api.jl")
147-
148-
mutable struct WKTReader
149-
ptr::Ptr{GEOSWKTReader}
150-
151-
function WKTReader(context::GEOSContext)
152-
reader = new(GEOSWKTReader_create_r(context))
153-
finalizer(function (reader)
154-
GEOSWKTReader_destroy_r(context, reader)
155-
reader.ptr = C_NULL
156-
end, reader)
157-
reader
158-
end
159-
end
160-
161-
mutable struct WKTWriter
162-
ptr::Ptr{GEOSWKTWriter}
163-
164-
function WKTWriter(
165-
context::GEOSContext;
166-
trim::Bool = true,
167-
outputdim::Int = 3,
168-
roundingprecision::Int = -1,
169-
)
170-
writer = new(GEOSWKTWriter_create_r(context))
171-
GEOSWKTWriter_setTrim_r(context, writer, UInt8(trim))
172-
GEOSWKTWriter_setOutputDimension_r(context, writer, outputdim)
173-
GEOSWKTWriter_setRoundingPrecision_r(context, writer, roundingprecision)
174-
finalizer(function (writer)
175-
GEOSWKTWriter_destroy_r(context, writer)
176-
writer.ptr = C_NULL
177-
end, writer)
178-
writer
179-
end
180-
end
181-
182-
mutable struct WKBReader
183-
ptr::Ptr{GEOSWKBReader}
184-
185-
function WKBReader(context::GEOSContext)
186-
reader = new(GEOSWKBReader_create_r(context))
187-
finalizer(function (reader)
188-
GEOSWKBReader_destroy_r(context, reader)
189-
reader.ptr = C_NULL
190-
end, reader)
191-
reader
192-
end
193-
end
194-
195-
mutable struct WKBWriter
196-
ptr::Ptr{GEOSWKBWriter}
197-
198-
function WKBWriter(context::GEOSContext)
199-
writer = new(GEOSWKBWriter_create_r(context))
200-
finalizer(function (writer)
201-
GEOSWKBWriter_destroy_r(context, writer)
202-
writer.ptr = C_NULL
203-
end, writer)
204-
writer
205-
end
206-
end
207-
208-
const _GLOBAL_CONTEXT = Ref{GEOSContext}()
209-
const _GLOBAL_CONTEXT_ALLOWED = Ref(false)
210-
211-
function get_global_context()::GEOSContext
212-
if _GLOBAL_CONTEXT_ALLOWED[]
213-
_GLOBAL_CONTEXT[]
214-
else
215-
msg = """
216-
LibGEOS global context disallowed, a `GEOSContext` must be passed explicitly.
217-
Alternatively you can allow the global context by calling:
218-
`LibGEOS.allow_global_context!(true)`
219-
"""
220-
error(msg)
221-
end
222-
end
223-
224-
"""
225-
226-
allow_global_context!(bool::Bool)
227-
228-
Allow (bool=true) or disallow (bool=false) using the global LibGEOS context.
229-
230-
231-
allow_global_context!(f, bool::Bool)
232-
233-
Call `f` with global context usage allowed according to `bool`
234-
235-
Generally this function should only be used as a debugging tool, mostly for multithreaded programs.
236-
See also [`GEOSContext`](@ref).
237-
"""
238-
function allow_global_context!(bool::Bool)
239-
_GLOBAL_CONTEXT_ALLOWED[] = bool
240-
end
66+
nearestPoints,
67+
node,
68+
numGeometries,
69+
numPoints,
70+
overlaps,
71+
pointOnSurface,
72+
polygonize,
73+
prepareGeom,
74+
project,
75+
projectNormalized,
76+
query,
77+
readgeom,
78+
setPrecision,
79+
sharedPaths,
80+
simplify,
81+
snap,
82+
startPoint,
83+
symmetricDifference,
84+
topologyPreserveSimplify,
85+
touches,
86+
unaryUnion,
87+
union,
88+
uniquePoints,
89+
within,
90+
writegeom
24191

242-
function allow_global_context!(f, bool::Bool)
243-
old = _GLOBAL_CONTEXT_ALLOWED[]
244-
allow_global_context!(bool)
245-
f()
246-
allow_global_context!(old)
247-
end
92+
include("generated/libgeos_api.jl")
93+
include("error.jl")
94+
include("context.jl")
95+
include("wellknown.jl")
96+
include("geos_types.jl")
97+
include("geos_functions.jl")
98+
include("geointerface.jl")
99+
include("strtree.jl")
100+
include("deprecated.jl")
248101

249102
function __init__()
250103
_GLOBAL_CONTEXT_ALLOWED[] = true
251104
_GLOBAL_CONTEXT[] = GEOSContext()
252105
end
253106

254-
include("geos_types.jl")
255-
include("geos_functions.jl")
256-
include("geo_interface.jl")
257-
include("strtree.jl")
258-
include("deprecated.jl")
259-
260107
end # module

0 commit comments

Comments
 (0)