Module: RGeo::Geos::CAPIPolygonMethods

Included in:
CAPIPolygonImpl
Defined in:
ext/geos_c_impl/polygon.c

Instance Method Summary collapse

Instance Method Details

#areaObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/geos_c_impl/polygon.c', line 65

static VALUE
method_polygon_area(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  double area;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    if (GEOSArea(self_geom, &area)) {
      result = rb_float_new(area);
    }
  }
  return result;
}

#centroidObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'ext/geos_c_impl/polygon.c', line 84

static VALUE
method_polygon_centroid(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    result = rgeo_wrap_geos_geometry(
      self_data->factory, GEOSGetCentroid(self_geom), rgeo_geos_point_class);
  }
  return result;
}

#coordinatesObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'ext/geos_c_impl/polygon.c', line 118

static VALUE
method_polygon_coordinates(VALUE self)
{
  VALUE result = Qnil;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;

  int zCoordinate;

  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;

  if (self_geom) {
    zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
                  RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
    result = extract_points_from_polygon(self_geom, zCoordinate);
  }
  return result;
}

#eql?Boolean

Returns:

  • (Boolean)

#exterior_ringObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'ext/geos_c_impl/polygon.c', line 138

static VALUE
method_polygon_exterior_ring(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    result = rgeo_wrap_geos_geometry_clone(self_data->factory,
                                           GEOSGetExteriorRing(self_geom),
                                           rgeo_geos_linear_ring_class);
  }
  return result;
}

#geometry_typeObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/geos_c_impl/polygon.c', line 51

static VALUE
method_polygon_geometry_type(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  if (self_data->geom) {
    result = rgeo_feature_polygon_module;
  }
  return result;
}

#hashObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'ext/geos_c_impl/polygon.c', line 36

static VALUE
method_polygon_hash(VALUE self)
{
  st_index_t hash;
  RGeo_GeometryData* self_data;
  VALUE factory;

  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  factory = self_data->factory;
  hash = rb_hash_start(0);
  hash = rgeo_geos_objbase_hash(factory, rgeo_feature_polygon_module, hash);
  hash = rgeo_geos_polygon_hash(self_data->geom, hash);
  return LONG2FIX(rb_hash_end(hash));
}

#interior_ring_n(n) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'ext/geos_c_impl/polygon.c', line 176

static VALUE
method_polygon_interior_ring_n(VALUE self, VALUE n)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  int i;
  int num;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    i = RB_NUM2INT(n);
    if (i >= 0) {
      num = GEOSGetNumInteriorRings(self_geom);
      if (i < num) {
        result =
          rgeo_wrap_geos_geometry_clone(self_data->factory,
                                        GEOSGetInteriorRingN(self_geom, i),
                                        rgeo_geos_linear_ring_class);
      }
    }
  }
  return result;
}

#interior_ringsObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'ext/geos_c_impl/polygon.c', line 203

static VALUE
method_polygon_interior_rings(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  int count;
  VALUE factory;
  int i;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    count = GEOSGetNumInteriorRings(self_geom);
    if (count >= 0) {
      result = rb_ary_new2(count);
      factory = self_data->factory;
      for (i = 0; i < count; ++i) {
        rb_ary_store(
          result,
          i,
          rgeo_wrap_geos_geometry_clone(factory,
                                        GEOSGetInteriorRingN(self_geom, i),
                                        rgeo_geos_linear_ring_class));
      }
    }
  }
  return result;
}

#num_interior_ringsObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'ext/geos_c_impl/polygon.c', line 156

static VALUE
method_polygon_num_interior_rings(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  int num;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    num = GEOSGetNumInteriorRings(self_geom);
    if (num >= 0) {
      result = INT2NUM(num);
    }
  }
  return result;
}

#point_on_surfaceObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/geos_c_impl/polygon.c', line 101

static VALUE
method_polygon_point_on_surface(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    result = rgeo_wrap_geos_geometry(
      self_data->factory, GEOSPointOnSurface(self_geom), rgeo_geos_point_class);
  }
  return result;
}

#rep_equals?Boolean

Returns:

  • (Boolean)

#simplify_polygon_hull(vertex_fraction, is_outer) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'ext/geos_c_impl/polygon.c', line 235

static VALUE
method_polygon_simplify_polygon_hull(VALUE self,
                                     VALUE vertex_fraction,
                                     VALUE is_outer)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;

  unsigned int is_outer_uint = RTEST(is_outer) ? 1 : 0;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    result = rgeo_wrap_geos_geometry(
      factory,
      GEOSPolygonHullSimplify(
        self_geom, is_outer_uint, rb_num2dbl(vertex_fraction)),
      Qnil);
  }
  return result;
}