Module: RGeo::Geos::CAPIGeometryMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#*(rhs) ⇒ Object


820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'ext/geos_c_impl/geometry.c', line 820

static VALUE method_geometry_intersection(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;
  const GEOSGeometry* rhs_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSIntersection_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}

#+(rhs) ⇒ Object


842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
# File 'ext/geos_c_impl/geometry.c', line 842

static VALUE method_geometry_union(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;
  const GEOSGeometry* rhs_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSUnion_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}

#-(rhs) ⇒ Object


887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'ext/geos_c_impl/geometry.c', line 887

static VALUE method_geometry_difference(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;
  const GEOSGeometry* rhs_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSDifference_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}

#==(rhs) ⇒ Object


379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'ext/geos_c_impl/geometry.c', line 379

static VALUE method_geometry_equals(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  GEOSContextHandle_t self_context;
  char val;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_get_geos_geometry_safe(rhs);
    if (rhs_geom) {
      self_context = self_data->geos_context;
      // GEOS has a bug where empty geometries are not spatially equal
      // to each other. Work around this case first.
      if (GEOSisEmpty_r(self_context, self_geom) == 1 &&
          GEOSisEmpty_r(RGEO_GEOMETRY_DATA_PTR(rhs)->geos_context, rhs_geom) == 1) {
        result = Qtrue;
      }
      else {
        val = GEOSEquals_r(self_context, self_geom, rhs_geom);
        if (val == 0) {
          result = Qfalse;
        }
        else if (val == 1) {
          result = Qtrue;
        }
      }
    }
  }
  return result;
}

#_as_textObject


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'ext/geos_c_impl/geometry.c', line 256

static VALUE method_geometry_as_text(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  RGeo_FactoryData* factory_data;
  VALUE wkt_generator;
  GEOSWKTWriter* wkt_writer;
  GEOSContextHandle_t geos_context;
  char* str;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
    wkt_generator = factory_data->wkrep_wkt_generator;
    if (!NIL_P(wkt_generator)) {
      result = rb_funcall(wkt_generator, rb_intern("generate"), 1, self);
    }
    else {
      wkt_writer = factory_data->wkt_writer;
      geos_context = self_data->geos_context;
      if (!wkt_writer) {
        wkt_writer = GEOSWKTWriter_create_r(geos_context);
        factory_data->wkt_writer = wkt_writer;
      }
      str = GEOSWKTWriter_write_r(geos_context, wkt_writer, self_geom);
      if (str) {
        result = rb_str_new2(str);
        GEOSFree_r(geos_context, str);
      }
    }
  }
  return result;
}

#_steal(orig) ⇒ Object


977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
# File 'ext/geos_c_impl/geometry.c', line 977

static VALUE method_geometry_steal(VALUE self, VALUE orig)
{
  RGeo_GeometryData* self_data;
  const GEOSPreparedGeometry* prep;
  const GEOSGeometry* geom;
  RGeo_GeometryData* orig_data;

  geom = rgeo_get_geos_geometry_safe(orig);
  if (geom) {
    // Clear out any existing value
    self_data = RGEO_GEOMETRY_DATA_PTR(self);
    if (self_data->geom) {
      GEOSGeom_destroy_r(self_data->geos_context, self_data->geom);
    }
    prep = self_data->prep;
    if (prep && prep != (GEOSPreparedGeometry*)1 && prep != (GEOSPreparedGeometry*)2) {
      GEOSPreparedGeom_destroy_r(self_data->geos_context, prep);
    }

    // Steal value from orig
    orig_data = RGEO_GEOMETRY_DATA_PTR(orig);
    self_data->geom = orig_data->geom;
    self_data->prep = orig_data->prep;
    self_data->geos_context = orig_data->geos_context;
    self_data->factory = orig_data->factory;
    self_data->klasses = orig_data->klasses;

    // Clear out orig
    orig_data->geom = NULL;
    orig_data->prep = NULL;
    orig_data->geos_context = NULL;
    orig_data->factory = Qnil;
    orig_data->klasses = Qnil;
  }
  return self;
}

#as_binaryObject


294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'ext/geos_c_impl/geometry.c', line 294

static VALUE method_geometry_as_binary(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  RGeo_FactoryData* factory_data;
  VALUE wkb_generator;
  GEOSWKBWriter* wkb_writer;
  GEOSContextHandle_t geos_context;
  size_t size;
  char* str;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
    wkb_generator = factory_data->wkrep_wkb_generator;
    if (!NIL_P(wkb_generator)) {
      result = rb_funcall(wkb_generator, rb_intern("generate"), 1, self);
    }
    else {
      wkb_writer = factory_data->wkb_writer;
      geos_context = self_data->geos_context;
      if (!wkb_writer) {
        wkb_writer = GEOSWKBWriter_create_r(geos_context);
        factory_data->wkb_writer = wkb_writer;
      }
      str = (char*)GEOSWKBWriter_write_r(geos_context, wkb_writer, self_geom, &size);
      if (str) {
        result = rb_str_new(str, size);
        GEOSFree_r(geos_context, str);
      }
    }
  }
  return result;
}

#as_textObject Also known as: to_s


55
56
57
58
59
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 55

def as_text
  str = _as_text
  str.force_encoding("US-ASCII") if str.respond_to?(:force_encoding)
  str
end

#boundaryObject


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

static VALUE method_geometry_boundary(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  GEOSContextHandle_t geos_context;
  GEOSGeometry* boundary;

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

#buffer(distance) ⇒ Object


725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'ext/geos_c_impl/geometry.c', line 725

static VALUE method_geometry_buffer(VALUE self, VALUE distance)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;

  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, GEOSBuffer_r(self_data->geos_context, self_geom,
      rb_num2dbl(distance), RGEO_FACTORY_DATA_PTR(factory)->buffer_resolution), Qnil);
  }
  return result;
}

#buffer_with_style(distance, endCapStyle, joinStyle, mitreLimit) ⇒ Object


743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'ext/geos_c_impl/geometry.c', line 743

static VALUE method_geometry_buffer_with_style(VALUE self, VALUE distance, VALUE endCapStyle, VALUE joinStyle, VALUE mitreLimit)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;

  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,
                                     GEOSBufferWithStyle_r(self_data->geos_context, self_geom,
                                                           rb_num2dbl(distance),
                                                           RGEO_FACTORY_DATA_PTR(factory)->buffer_resolution,
                                                           rb_num2int(endCapStyle),
                                                           rb_num2int(joinStyle),
                                                           rb_num2dbl(mitreLimit)),
                                     Qnil);
  }
  return result;
}

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'ext/geos_c_impl/geometry.c', line 603

static VALUE method_geometry_contains(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
  const GEOSPreparedGeometry* prep;
#endif

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
      prep = rgeo_request_prepared_geometry(self_data);
      if (prep)
        val = GEOSPreparedContains_r(self_data->geos_context, prep, rhs_geom);
      else
#endif
        val = GEOSContains_r(self_data->geos_context, self_geom, rhs_geom);
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}

#convex_hullObject


804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'ext/geos_c_impl/geometry.c', line 804

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

#crosses?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'ext/geos_c_impl/geometry.c', line 531

static VALUE method_geometry_crosses(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
  const GEOSPreparedGeometry* prep;
#endif

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
      prep = rgeo_request_prepared_geometry(self_data);
      if (prep)
        val = GEOSPreparedCrosses_r(self_data->geos_context, prep, rhs_geom);
      else
#endif
        val = GEOSCrosses_r(self_data->geos_context, self_geom, rhs_geom);
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}

#difference(rhs) ⇒ Object


887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'ext/geos_c_impl/geometry.c', line 887

static VALUE method_geometry_difference(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;
  const GEOSGeometry* rhs_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSDifference_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}

#dimensionObject


165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'ext/geos_c_impl/geometry.c', line 165

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

#disjoint?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'ext/geos_c_impl/geometry.c', line 423

static VALUE method_geometry_disjoint(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
  const GEOSPreparedGeometry* prep;
#endif

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
      prep = rgeo_request_prepared_geometry(self_data);
      if (prep)
        val = GEOSPreparedDisjoint_r(self_data->geos_context, prep, rhs_geom);
      else
#endif
        val = GEOSDisjoint_r(self_data->geos_context, self_geom, rhs_geom);
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}

#distance(rhs) ⇒ Object


702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'ext/geos_c_impl/geometry.c', line 702

static VALUE method_geometry_distance(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  double dist;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
      if (GEOSDistance_r(self_data->geos_context, self_geom, rhs_geom, &dist)) {
        result = rb_float_new(dist);
      }
    }
  }
  return result;
}

#empty?Boolean

Returns:

  • (Boolean)

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'ext/geos_c_impl/geometry.c', line 333

static VALUE method_geometry_is_empty(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 = GEOSisEmpty_r(self_data->geos_context, self_geom);
    if (val == 0) {
      result = Qfalse;
    }
    else if (val == 1) {
      result = Qtrue;
    }
  }
  return result;
}

#encode_with(coder) ⇒ Object

Psych support


42
43
44
45
46
47
48
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 42

def encode_with(coder) # :nodoc:
  my_factory = factory
  coder["factory"] = my_factory
  str = my_factory.write_for_psych(self)
  str = str.encode("US-ASCII") if str.respond_to?(:encode)
  coder["wkt"] = str
end

#envelopeObject


211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'ext/geos_c_impl/geometry.c', line 211

static VALUE method_geometry_envelope(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  GEOSContextHandle_t geos_context;
  GEOSGeometry* envelope;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    geos_context = self_data->geos_context;
    envelope = GEOSEnvelope_r(geos_context, self_geom);
    if (!envelope) {
      envelope = GEOSGeom_createCollection_r(geos_context, GEOS_GEOMETRYCOLLECTION, NULL, 0);
    }
    result = rgeo_wrap_geos_geometry(self_data->factory, envelope, Qnil);
  }
  return result;
}

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

416
417
418
419
420
# File 'ext/geos_c_impl/geometry.c', line 416

static VALUE method_geometry_eql(VALUE self, VALUE rhs)
{
  // This should be overridden by the subclass.
  return self == rhs ? Qtrue : Qfalse;
}

#equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'ext/geos_c_impl/geometry.c', line 379

static VALUE method_geometry_equals(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  GEOSContextHandle_t self_context;
  char val;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_get_geos_geometry_safe(rhs);
    if (rhs_geom) {
      self_context = self_data->geos_context;
      // GEOS has a bug where empty geometries are not spatially equal
      // to each other. Work around this case first.
      if (GEOSisEmpty_r(self_context, self_geom) == 1 &&
          GEOSisEmpty_r(RGEO_GEOMETRY_DATA_PTR(rhs)->geos_context, rhs_geom) == 1) {
        result = Qtrue;
      }
      else {
        val = GEOSEquals_r(self_context, self_geom, rhs_geom);
        if (val == 0) {
          result = Qfalse;
        }
        else if (val == 1) {
          result = Qtrue;
        }
      }
    }
  }
  return result;
}

#factoryObject


119
120
121
122
# File 'ext/geos_c_impl/geometry.c', line 119

static VALUE method_geometry_factory(VALUE self)
{
  return RGEO_GEOMETRY_DATA_PTR(self)->factory;
}

#factory=(factory) ⇒ Object


125
126
127
128
129
# File 'ext/geos_c_impl/geometry.c', line 125

static VALUE method_geometry_set_factory(VALUE self, VALUE factory)
{
  RGEO_GEOMETRY_DATA_PTR(self)->factory = factory;
  return factory;
}

#geometry_typeObject


181
182
183
184
185
186
187
188
189
190
191
192
# File 'ext/geos_c_impl/geometry.c', line 181

static VALUE method_geometry_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_geometry_module;
  }
  return result;
}

#init_with(coder) ⇒ Object

:nodoc:


50
51
52
53
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 50

def init_with(coder) # :nodoc:
  obj = coder["factory"].read_for_psych(coder["wkt"])
  _steal(obj)
end

#initialize_copy(orig) ⇒ Object


931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
# File 'ext/geos_c_impl/geometry.c', line 931

static VALUE method_geometry_initialize_copy(VALUE self, VALUE orig)
{
  RGeo_GeometryData* self_data;
  const GEOSPreparedGeometry* prep;
  const GEOSGeometry* geom;
  RGeo_GeometryData* orig_data;
  GEOSContextHandle_t orig_context;
  GEOSGeometry* clone_geom;
  RGeo_FactoryData* factory_data;

  // Clear out any existing value
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  if (self_data->geom) {
    GEOSGeom_destroy_r(self_data->geos_context, self_data->geom);
    self_data->geom = NULL;
  }
  prep = self_data->prep;
  if (prep && prep != (GEOSPreparedGeometry*)1 && prep != (GEOSPreparedGeometry*)2) {
    GEOSPreparedGeom_destroy_r(self_data->geos_context, prep);
  }
  self_data->prep = NULL;
  self_data->geos_context = NULL;
  self_data->factory = Qnil;
  self_data->klasses = Qnil;

  // Copy value from orig
  geom = rgeo_get_geos_geometry_safe(orig);
  if (geom) {
    orig_data = RGEO_GEOMETRY_DATA_PTR(orig);
    orig_context = orig_data->geos_context;
    clone_geom = GEOSGeom_clone_r(orig_context, geom);
    if (clone_geom) {
      factory_data = RGEO_FACTORY_DATA_PTR(orig_data->factory);
      GEOSSetSRID_r(orig_context, clone_geom, GEOSGetSRID_r(orig_context, geom));
      self_data->geom = clone_geom;
      self_data->geos_context = orig_context;
      self_data->prep = factory_data && ((factory_data->flags & RGEO_FACTORYFLAGS_PREPARE_HEURISTIC) != 0) ?
        (GEOSPreparedGeometry*)1 : NULL;
      self_data->factory = orig_data->factory;
      self_data->klasses = orig_data->klasses;
    }
  }
  return self;
}

#initialized?Boolean

** RUBY METHOD DEFINITIONS ***

Returns:

  • (Boolean)

113
114
115
116
# File 'ext/geos_c_impl/geometry.c', line 113

static VALUE method_geometry_initialized_p(VALUE self)
{
  return RGEO_GEOMETRY_DATA_PTR(self)->geom ? Qtrue : Qfalse;
}

#inspectObject


24
25
26
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 24

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
end

#intersection(rhs) ⇒ Object


820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'ext/geos_c_impl/geometry.c', line 820

static VALUE method_geometry_intersection(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;
  const GEOSGeometry* rhs_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSIntersection_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}

#intersects?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'ext/geos_c_impl/geometry.c', line 459

static VALUE method_geometry_intersects(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
  const GEOSPreparedGeometry* prep;
#endif

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
      prep = rgeo_request_prepared_geometry(self_data);
      if (prep)
        val = GEOSPreparedIntersects_r(self_data->geos_context, prep, rhs_geom);
      else
#endif
        val = GEOSIntersects_r(self_data->geos_context, self_geom, rhs_geom);
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}

#invalid_reasonObject


1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File 'ext/geos_c_impl/geometry.c', line 1036

static VALUE method_geometry_invalid_reason(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  char* str;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    str = GEOSisValidReason_r(self_data->geos_context, self_geom);
    // Per documentation, a valid geometry should give an empty string.
    // However it seems not to be the case. Hence the comparison against
    // the string that is really given: `"Valid Geometry"`.
    // See https://github.com/libgeos/geos/issues/431.
    if (str) result = (str[0] == '\0' || !strcmp(str, "Valid Geometry")) ? Qnil : rb_str_new2(str);
    else result = rb_str_new2("Exception");
    GEOSFree_r(self_data->geos_context, str);
  }
  return result;
}

#is_empty?Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)

14
15
16
17
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 14

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

#is_simple?Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)

19
20
21
22
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 19

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

#marshal_dumpObject

Marshal support


30
31
32
33
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 30

def marshal_dump # :nodoc:
  my_factory = factory
  [my_factory, my_factory.write_for_marshal(self)]
end

#marshal_load(data_) ⇒ Object

:nodoc:


35
36
37
38
# File 'lib/rgeo/geos/capi_feature_classes.rb', line 35

def marshal_load(data_) # :nodoc:
  obj = data_[0].read_for_marshal(data_[1])
  _steal(obj)
end

#overlaps?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'ext/geos_c_impl/geometry.c', line 639

static VALUE method_geometry_overlaps(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
  const GEOSPreparedGeometry* prep;
#endif

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
      prep = rgeo_request_prepared_geometry(self_data);
      if (prep)
        val = GEOSPreparedOverlaps_r(self_data->geos_context, prep, rhs_geom);
      else
#endif
        val = GEOSOverlaps_r(self_data->geos_context, self_geom, rhs_geom);
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}

#point_on_surfaceObject


1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
# File 'ext/geos_c_impl/geometry.c', line 1059

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

#prepare!Object


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'ext/geos_c_impl/geometry.c', line 143

static VALUE method_geometry_prepare(VALUE self)
{
  RGeo_GeometryData* self_data;
  const GEOSPreparedGeometry* prep;

  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  if (self_data->geom) {
    prep = self_data->prep;
    if (!prep || prep == (const GEOSPreparedGeometry*)1 || prep == (const GEOSPreparedGeometry*)2) {
      prep = GEOSPrepare_r(self_data->geos_context, self_data->geom);
      if (prep) {
        self_data->prep = prep;
      }
      else {
        self_data->prep = (const GEOSPreparedGeometry*)3;
      }
    }
  }
  return self;
}

#prepared?Boolean

Returns:

  • (Boolean)

132
133
134
135
136
137
138
139
140
# File 'ext/geos_c_impl/geometry.c', line 132

static VALUE method_geometry_prepared_p(VALUE self)
{
  const GEOSPreparedGeometry* prep;

  prep = RGEO_GEOMETRY_DATA_PTR(self)->prep;
  return (prep && prep != (const GEOSPreparedGeometry*)1 &&
    prep != (const GEOSPreparedGeometry*)2 &&
    prep != (GEOSPreparedGeometry*)3) ? Qtrue : Qfalse;
}

#relate?(rhs, pattern) ⇒ Boolean

Returns:

  • (Boolean)

675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# File 'ext/geos_c_impl/geometry.c', line 675

static VALUE method_geometry_relate(VALUE self, VALUE rhs, VALUE pattern)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
      val = GEOSRelatePattern_r(self_data->geos_context, self_geom, rhs_geom, StringValuePtr(pattern));
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

416
417
418
419
420
# File 'ext/geos_c_impl/geometry.c', line 416

static VALUE method_geometry_eql(VALUE self, VALUE rhs)
{
  // This should be overridden by the subclass.
  return self == rhs ? Qtrue : Qfalse;
}

#simple?Boolean

Returns:

  • (Boolean)

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'ext/geos_c_impl/geometry.c', line 356

static VALUE method_geometry_is_simple(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 = GEOSisSimple_r(self_data->geos_context, self_geom);
    if (val == 0) {
      result = Qfalse;
    }
    else if (val == 1) {
      result = Qtrue;
    }
  }
  return result;
}

#simplify(tolerance) ⇒ Object


767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
# File 'ext/geos_c_impl/geometry.c', line 767

static VALUE method_geometry_simplify(VALUE self, VALUE tolerance)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;

  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, GEOSSimplify_r(self_data->geos_context, self_geom,
      rb_num2dbl(tolerance)), Qnil);
  }
  return result;
}

#simplify_preserve_topology(tolerance) ⇒ Object


785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# File 'ext/geos_c_impl/geometry.c', line 785

static VALUE method_geometry_simplify_preserve_topology(VALUE self, VALUE tolerance)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;

  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, GEOSTopologyPreserveSimplify_r(self_data->geos_context, self_geom,
      rb_num2dbl(tolerance)), Qnil);
  }
  return result;
}

#sridObject


195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'ext/geos_c_impl/geometry.c', line 195

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

#sym_difference(rhs) ⇒ Object


909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# File 'ext/geos_c_impl/geometry.c', line 909

static VALUE method_geometry_sym_difference(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;
  const GEOSGeometry* rhs_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSSymDifference_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}

#touches?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'ext/geos_c_impl/geometry.c', line 495

static VALUE method_geometry_touches(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
  const GEOSPreparedGeometry* prep;
#endif

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
      prep = rgeo_request_prepared_geometry(self_data);
      if (prep)
        val = GEOSPreparedTouches_r(self_data->geos_context, prep, rhs_geom);
      else
#endif
        val = GEOSTouches_r(self_data->geos_context, self_geom, rhs_geom);
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}

#unary_unionObject


864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
# File 'ext/geos_c_impl/geometry.c', line 864

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

  result = Qnil;

#ifdef RGEO_GEOS_SUPPORTS_UNARYUNION
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    GEOSContextHandle_t self_context = self_data->geos_context;
    result = rgeo_wrap_geos_geometry(self_data->factory,
      GEOSUnaryUnion_r(self_context, self_geom),
      Qnil);
  }
#endif

  return result;
}

#union(rhs) ⇒ Object


842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
# File 'ext/geos_c_impl/geometry.c', line 842

static VALUE method_geometry_union(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  VALUE factory;
  const GEOSGeometry* rhs_geom;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory = self_data->factory;
    rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSUnion_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}

#valid?Boolean

Returns:

  • (Boolean)

1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'ext/geos_c_impl/geometry.c', line 1014

static VALUE method_geometry_is_valid(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 = GEOSisValid_r(self_data->geos_context, self_geom);
    if (val == 0) {
      result = Qfalse;
    }
    else if (val == 1) {
      result = Qtrue;
    }
  }
  return result;
}

#within?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'ext/geos_c_impl/geometry.c', line 567

static VALUE method_geometry_within(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
  const GEOSPreparedGeometry* prep;
#endif

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil);
    if (rhs_geom) {
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
      prep = rgeo_request_prepared_geometry(self_data);
      if (prep)
        val = GEOSPreparedWithin_r(self_data->geos_context, prep, rhs_geom);
      else
#endif
        val = GEOSWithin_r(self_data->geos_context, self_geom, rhs_geom);
      if (val == 0) {
        result = Qfalse;
      }
      else if (val == 1) {
        result = Qtrue;
      }
    }
  }
  return result;
}