Module: RGeo::Geos::CAPILineStringMethods

Included in:
CAPILineImpl, CAPILineStringImpl, CAPILinearRingImpl
Defined in:
ext/geos_c_impl/line_string.c

Instance Method Summary collapse

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


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

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_geom);
  }
  return result;
}

#coordinatesObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'ext/geos_c_impl/line_string.c', line 99

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

  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;
    coord_sequence = GEOSGeom_getCoordSeq(self_geom);
    if (coord_sequence) {
      result =
        extract_points_from_coordinate_sequence(coord_sequence, zCoordinate);
    }
  }
  return result;
}

#end_pointObject



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/geos_c_impl/line_string.c', line 225

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(self_geom);
    if (n > 0) {
      result = method_line_string_point_n(self, INT2NUM(n - 1));
    }
  }
  return result;
}

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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_geometries_strict_eql(self_data->geom,
                                             RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
  }
  return result;
}

#geometry_typeObject

#hashObject



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

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->geom, hash);
  return LONG2FIX(rb_hash_end(hash));
}

#interpolate_point(loc_num) ⇒ Object



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

static VALUE
method_line_string_interpolate_point(VALUE self, VALUE loc_num)
{
  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;
  self_geom = self_data->geom;

  if (self_geom) {
    geos_point = GEOSInterpolate(self_geom, location);
    result =
      rgeo_wrap_geos_geometry(factory, geos_point, rgeo_geos_point_class);
  }

  return result;
}

#lengthObject



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

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(self_geom, &len)) {
      result = rb_float_new(len);
    }
  }
  return result;
}

#num_pointsObject



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

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(self_geom));
  }
  return result;
}

#point_n(n) ⇒ Object



151
152
153
154
155
156
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
# File 'ext/geos_c_impl/line_string.c', line 151

static VALUE
method_line_string_point_n(VALUE self, VALUE n)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  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) {
    coord_seq = GEOSGeom_getCoordSeq(self_geom);
    if (coord_seq) {
      has_z = (char)(RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
                     RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
      si = RB_NUM2INT(n);
      if (si >= 0) {
        i = si;
        if (GEOSCoordSeq_getSize(coord_seq, &size)) {
          if (i < size) {
            result = get_point_from_coordseq(self, coord_seq, i, has_z);
          }
        }
      }
    }
  }
  return result;
}

#pointsObject



185
186
187
188
189
190
191
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
# File 'ext/geos_c_impl/line_string.c', line 185

static VALUE
method_line_string_points(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  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) {
    coord_seq = GEOSGeom_getCoordSeq(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(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



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'ext/geos_c_impl/line_string.c', line 245

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

  double location;

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

  if (self_geom && point) {
    geos_point = rgeo_convert_to_geos_geometry(
      factory, point, rgeo_geos_point_class, &state);
    if (state) {
      rb_jump_tag(state);
    }

    location = GEOSProject(self_geom, geos_point);
    result = DBL2NUM(location);
  }
  return result;
}

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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_geometries_strict_eql(self_data->geom,
                                             RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
  }
  return result;
}

#ring?Boolean

Returns:

  • (Boolean)


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

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(self_geom);
    if (val == 0) {
      result = Qfalse;
    } else if (val == 1) {
      result = Qtrue;
    }
  }
  return result;
}

#start_pointObject



219
220
221
222
223
# File 'ext/geos_c_impl/line_string.c', line 219

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