Module: RGeo::Geos::CAPILineStringMethods

Included in:
CAPILineImpl, CAPILineStringImpl, CAPILinearRingImpl
Defined in:
lib/rgeo/geos/capi_feature_classes.rb,
ext/geos_c_impl/line_string.c

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)

301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'ext/geos_c_impl/line_string.c', line 301

static VALUE method_line_string_is_closed(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_is_geos_line_string_closed(self_data->geos_context, self_geom);
  }
  return result;
}

#coordinatesObject


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'ext/geos_c_impl/line_string.c', line 103

static VALUE method_line_string_coordinates(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSCoordSequence* coord_sequence;
  int zCoordinate;

  GEOSContextHandle_t context;

  result = Qnil;
  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;
    context = self_data->geos_context;
    coord_sequence = GEOSGeom_getCoordSeq_r(context, self_geom);
    if(coord_sequence) {
      result = extract_points_from_coordinate_sequence(context, coord_sequence, zCoordinate);
    }
  }
  return result;
}

#end_pointObject


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'ext/geos_c_impl/line_string.c', line 233

static VALUE method_line_string_end_point(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  unsigned int n;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    n = GEOSGetNumCoordinates_r(self_data->geos_context, self_geom);
    if (n > 0) {
      result = method_line_string_point_n(self, INT2NUM(n-1));
    }
  }
  return result;
}

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

340
341
342
343
344
345
346
347
348
349
350
351
# File 'ext/geos_c_impl/line_string.c', line 340

static VALUE method_line_string_eql(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;

  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
  if (RTEST(result)) {
    self_data = RGEO_GEOMETRY_DATA_PTR(self);
    result = rgeo_geos_coordseqs_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
  }
  return result;
}

#geometry_typeObject

#hashObject


354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'ext/geos_c_impl/line_string.c', line 354

static VALUE method_line_string_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_line_string_module, hash);
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
  return LONG2FIX(rb_hash_end(hash));
}

#interpolate_point(loc_num) ⇒ Object


276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'ext/geos_c_impl/line_string.c', line 276

static VALUE method_line_string_interpolate_point(VALUE self, VALUE loc_num)
{
  RGeo_FactoryData* factory_data;
  VALUE result = Qnil;
  VALUE factory;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  GEOSGeometry* geos_point;

  double location;

  location = NUM2DBL(loc_num);
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  factory = self_data->factory;
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
  self_geom = self_data->geom;

  if(self_geom) {
    geos_point = GEOSInterpolate_r(self_data->geos_context, self_geom, location);
    result = rgeo_wrap_geos_geometry(factory, geos_point, rgeo_geos_point_class);
  }

  return result;
}

#is_closed?Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)

71
72
73
74
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 71

def is_closed? # rubocop:disable Naming/PredicateName
  warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  closed?
end

#is_ring?Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)

76
77
78
79
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 76

def is_ring? # rubocop:disable Naming/PredicateName
  warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  ring?
end

#lengthObject


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'ext/geos_c_impl/line_string.c', line 68

static VALUE method_line_string_length(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  double len;

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

#num_pointsObject


87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'ext/geos_c_impl/line_string.c', line 87

static VALUE method_line_string_num_points(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 = INT2NUM(GEOSGetNumCoordinates_r(self_data->geos_context, self_geom));
  }
  return result;
}

#point_n(n) ⇒ Object


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'ext/geos_c_impl/line_string.c', line 157

static VALUE method_line_string_point_n(VALUE self, VALUE n)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  GEOSContextHandle_t self_context;
  const GEOSCoordSequence* coord_seq;
  char has_z;
  int si;
  unsigned int i;
  unsigned int size;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    self_context = self_data->geos_context;
    coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
    if (coord_seq) {
      has_z = (char)(RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
      si = NUM2INT(n);
      if (si >= 0) {
        i = si;
        if (GEOSCoordSeq_getSize_r(self_context, coord_seq, &size)) {
          if (i < size) {
            result = get_point_from_coordseq(self, coord_seq, i, has_z);
          }
        }
      }
    }
  }
  return result;
}

#pointsObject


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'ext/geos_c_impl/line_string.c', line 192

static VALUE method_line_string_points(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  GEOSContextHandle_t self_context;
  const GEOSCoordSequence* coord_seq;
  char has_z;
  unsigned int size;
  unsigned int i;
  VALUE point;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    self_context = self_data->geos_context;
    coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
    if (coord_seq) {
      has_z = (char)(RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
      if (GEOSCoordSeq_getSize_r(self_context, coord_seq, &size)) {
        result = rb_ary_new2(size);
        for (i=0; i<size; ++i) {
          point = get_point_from_coordseq(self, coord_seq, i, has_z);
          if (!NIL_P(point)) {
            rb_ary_store(result, i, point);
          }
        }
      }
    }
  }
  return result;
}

#project_point(point) ⇒ Object


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'ext/geos_c_impl/line_string.c', line 252

static VALUE method_line_string_project_point(VALUE self, VALUE point)
{
  RGeo_FactoryData* factory_data;
  VALUE result = Qnil;
  VALUE factory;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry *geos_point;

  double location;

  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  factory = self_data->factory;
  self_geom = self_data->geom;
  factory_data = RGEO_FACTORY_DATA_PTR(factory);

  if(self_geom && point) {
    geos_point = rgeo_convert_to_geos_geometry(factory, point, rgeo_geos_point_class);
    location = GEOSProject_r(self_data->geos_context, self_geom, geos_point);
    result = DBL2NUM(location);
  }
  return result;
}

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

340
341
342
343
344
345
346
347
348
349
350
351
# File 'ext/geos_c_impl/line_string.c', line 340

static VALUE method_line_string_eql(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;

  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
  if (RTEST(result)) {
    self_data = RGEO_GEOMETRY_DATA_PTR(self);
    result = rgeo_geos_coordseqs_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
  }
  return result;
}

#ring?Boolean

Returns:

  • (Boolean)

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'ext/geos_c_impl/line_string.c', line 317

static VALUE method_line_string_is_ring(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  char val;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    val = GEOSisRing_r(self_data->geos_context, self_geom);
    if (val == 0) {
      result = Qfalse;
    }
    else if (val == 1) {
      result = Qtrue;
    }
  }
  return result;
}

#start_pointObject


227
228
229
230
# File 'ext/geos_c_impl/line_string.c', line 227

static VALUE method_line_string_start_point(VALUE self)
{
  return method_line_string_point_n(self, INT2NUM(0));
}