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
Add Polygon constructors and createPolygon functionality (#134)
* 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
Copy file name to clipboardExpand all lines: src/geos_types.jl
+17-3Lines changed: 17 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -74,20 +74,34 @@ end
74
74
75
75
mutable struct Polygon <:AbstractGeometry
76
76
ptr::GEOSGeom
77
-
77
+
# create polygon using GEOSGeom pointer - only makes sense if pointer points to a polygon or a linear ring to start with.
78
78
functionPolygon(ptr::GEOSGeom)
79
-
polygon =new(ptr)
79
+
id = LibGEOS.geomTypeId(ptr)
80
+
if id == GEOS_POLYGON
81
+
polygon =new(cloneGeom(ptr))
82
+
elseif id == GEOS_LINEARRING
83
+
polygon =new(cloneGeom(createPolygon(ptr)))
84
+
else
85
+
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
+
end
80
87
finalizer(destroyGeom, polygon)
81
88
polygon
82
89
end
90
+
# using vector of coordinates in following form:
91
+
# [[exterior], [hole1], [hole2], ...] where exterior and holeN are coordinates where the first and last point are the same
interiors = GEOSGeom[createLinearRing(lr) for lr in coords[2:end]]
86
95
polygon =new(createPolygon(exterior, interiors))
87
96
finalizer(destroyGeom, polygon)
88
97
polygon
89
98
end
90
-
99
+
# using 1 linear ring to form polygon with no holes - linear ring will be outer boundary of polygon
100
+
Polygon(ring::LinearRing) =Polygon(ring.ptr)
101
+
# using multiple linear rings to form polygon with holes - exterior linear ring will be polygon boundary and list of interior linear rings will form holes
0 commit comments