You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Constructors with new functionality and test memory safety (#136)
* Add createPolygon with single argument and update Polygon constructor
New createPolygon function allows creation of polygons without user
specified holes. Polygon constructor added to convert a LinearRing
to Polygon. Polygon constructor that takes a pointer limited by type.
* Add tests for Polygon constructors - ERROR thrown
Create a test file for GEOSGeom constructors found in geos_types.jl.
Tests pass for Polygon constructed from vectors, but an "illegal
instruction" error is thrown when one is constructed from a pointer.
The error messages mentions destroyGeom. There are more tests below
for constructing from a linear ring but these depend on the pointer
constructor and thus cause a seg fault.
* Add cloneGeom around pointers in Polygon constructor and finish tests
Adding cloneGeom around pointers sent to Polygon constructor that takes
in a pointer has stopped the tests from seg faulting. All desired
Polygon constructors and createPolygon functionality added and tested.
* Fix requested pull request changes
Typo in comments, remove magic numbers, change variable name
* Update Point constructror and add tests
Added cloneGeom to Point constructor to stop seg fault and tested
each method to construct a point.
* Update MultiPoint constructors and add tests
Update existing multipoint constructors to clone pointers and add
constructors to take in a vector of points and a point pointer.
* Update LineString and MultiLineString constructors and add tests
Update LineString and MultiLineString constructors so that they use
cloneGeom when needed and only accept appropriate type pointers.
Added tests for all constructor functionality.
* Update LinearRing constructor and add tests
Add cloneGeom to LinearRing constructor and add tests for all
functionality. Also refactor names and add comments.
* Update MultiPolygon and GeometryCollection constructors and add tests
Add cloneGeom to constructors, add MultiPolygon constructor from list
of polygons, and test all functionality.
Copy file name to clipboardExpand all lines: src/geos_types.jl
+96-25Lines changed: 96 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -2,55 +2,93 @@ abstract type AbstractGeometry end
2
2
3
3
mutable struct Point <:AbstractGeometry
4
4
ptr::GEOSGeom
5
-
5
+
# create a point from a pointer - only makese sense if it is a pointer to a point, otherwise error
6
6
functionPoint(ptr::GEOSGeom)
7
-
point =new(ptr)
8
-
finalizer(destroyGeom, point)
9
-
point
7
+
id = LibGEOS.geomTypeId(ptr)
8
+
if id == GEOS_POINT
9
+
point =new(cloneGeom(ptr))
10
+
finalizer(destroyGeom, point)
11
+
point
12
+
else
13
+
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a point (yet). Please open an issue if you think this conversion makes sense.")
Point(x::Real, y::Real, z::Real) =Point(createPoint(x, y, z))
14
-
15
20
end
16
21
17
22
mutable struct MultiPoint <:AbstractGeometry
18
23
ptr::GEOSGeom
19
-
24
+
# create a multipoint from a pointer - only makes sense if it is a pointer to a multipoint or to a point, otherwise error
20
25
functionMultiPoint(ptr::GEOSGeom)
21
-
multipoint =new(ptr)
26
+
id = LibGEOS.geomTypeId(ptr)
27
+
if id == GEOS_MULTIPOINT
28
+
multipoint =new(cloneGeom(ptr))
29
+
elseif id == GEOS_POINT
30
+
multipoint =new(createCollection(GEOS_MULTIPOINT,
31
+
GEOSGeom[cloneGeom(ptr)]))
32
+
else
33
+
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multipoint (yet). Please open an issue if you think this conversion makes sense.")
34
+
end
22
35
finalizer(destroyGeom, multipoint)
23
36
multipoint
24
37
end
38
+
# create a multipoint frome a vector of vector coordinates
# create a linestring from a linestring pointer, otherwise error
37
57
functionLineString(ptr::GEOSGeom)
38
-
line =new(ptr)
58
+
id = LibGEOS.geomTypeId(ptr)
59
+
if id == GEOS_LINESTRING
60
+
line =new(cloneGeom(ptr))
61
+
finalizer(destroyGeom, line)
62
+
line
63
+
else
64
+
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a linestring (yet). Please open an issue if you think this conversion makes sense.")
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multi-linestring (yet). Please open an issue if you think this conversion makes sense.")
87
+
end
51
88
finalizer(destroyGeom, multiline)
52
89
multiline
53
90
end
91
+
# create a multilinestring from a list of linestring coordiantes
# create a linear ring from a linear ring pointer, otherwise error
66
104
functionLinearRing(ptr::GEOSGeom)
67
-
ring =new(ptr)
105
+
id = LibGEOS.geomTypeId(ptr)
106
+
if id == GEOS_LINEARRING
107
+
ring =new(cloneGeom(ptr))
108
+
finalizer(destroyGeom, ring)
109
+
ring
110
+
else
111
+
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a linear ring (yet). Please open an issue if you think this conversion makes sense.")
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a polygon (yet). Please open an issue if you think this conversion makes sense.")
134
+
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a polygon (yet). Please open an issue if you think this conversion makes sense.")
86
135
end
87
136
finalizer(destroyGeom, polygon)
88
137
polygon
@@ -106,12 +155,29 @@ end
106
155
107
156
mutable struct MultiPolygon <:AbstractGeometry
108
157
ptr::GEOSGeom
109
-
158
+
# create multipolygon using a multipolygon or polygon pointer, else error
110
159
functionMultiPolygon(ptr::GEOSGeom)
111
-
multipolygon =new(ptr)
160
+
id = LibGEOS.geomTypeId(ptr)
161
+
if id == GEOS_MULTIPOLYGON
162
+
multipolygon =new(cloneGeom(ptr))
163
+
elseif id == GEOS_POLYGON
164
+
multipolygon =new(createCollection(
165
+
GEOS_MULTIPOLYGON,
166
+
GEOSGeom[cloneGeom(ptr)]))
167
+
else
168
+
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multi-polygon (yet). Please open an issue if you think this conversion makes sense.")
169
+
end
112
170
finalizer(destroyGeom, multipolygon)
113
171
multipolygon
114
172
end
173
+
174
+
# create multipolygon from list of Polygon objects
# create a geometric collection from a pointer to a geometric collection, else error
132
197
functionGeometryCollection(ptr::GEOSGeom)
133
-
geometrycollection =new(ptr)
134
-
finalizer(destroyGeom, geometrycollection)
135
-
geometrycollection
198
+
id = LibGEOS.geomTypeId(ptr)
199
+
if id == GEOS_GEOMETRYCOLLECTION
200
+
geometrycollection =new(cloneGeom(ptr))
201
+
finalizer(destroyGeom, geometrycollection)
202
+
geometrycollection
203
+
else
204
+
error("LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a geometry collection (yet). Please open an issue if you think this conversion makes sense.")
205
+
end
136
206
end
207
+
# create a geometric collection from a list of pointers to geometric objects
0 commit comments