Class: RGeo::Geos::CAPIPolygonImpl

Inherits:
Object
  • Object
show all
Includes:
Feature::Polygon, CAPIGeometryMethods, CAPIPolygonMethods, ImplHelper::ValidityCheck
Defined in:
lib/rgeo/geos/capi_feature_classes.rb,
ext/geos_c_impl/globals.c

Class Method Summary collapse

Methods included from CAPIPolygonMethods

#area, #centroid, #coordinates, #eql?, #exterior_ring, #geometry_type, #hash, #interior_ring_n, #interior_rings, #num_interior_rings, #point_on_surface, #rep_equals?, #simplify_polygon_hull

Methods included from CAPIGeometryMethods

#*, #+, #-, #==, #_as_text, #_steal, #as_binary, #as_text, #boundary, #buffer, #buffer_with_style, #contains?, #convex_hull, #coordinate_dimension, #crosses?, #difference, #dimension, #disjoint?, #distance, #empty?, #encode_with, #envelope, #eql?, #equals?, #factory, #factory=, #geometry_type, #init_with, #initialize_copy, #initialized?, #inspect, #intersection, #intersects?, #invalid_reason, #invalid_reason_location, #is_3d?, #make_valid, #marshal_dump, #marshal_load, #measured?, #overlaps?, #point_on_surface, #polygonize, #prepare!, #prepared?, #relate?, #rep_equals?, #segmentize, #simple?, #simplify, #simplify_preserve_topology, #spatial_dimension, #srid, #sym_difference, #touches?, #unary_union, #union, #valid?, #within?

Methods included from ImplHelper::ValidityCheck

#check_validity!, included, #invalid_reason, #make_valid, override_classes

Methods included from Feature::Polygon

#exterior_ring, #interior_ring_n, #interior_rings, #num_interior_rings

Methods included from Feature::Type

#add_subtype, #check_type, #each_immediate_subtype, extended, #subtype_of?, #supertype, #type_name

Methods included from Feature::Surface

#area, #centroid, #point_on_surface

Methods included from Feature::Geometry

#*, #+, #-, #==, #as_binary, #as_text, #boundary, #buffer, #contains?, #convex_hull, #coordinate_dimension, #crosses?, #difference, #dimension, #disjoint?, #distance, #empty?, #envelope, #eql?, #equals?, #factory, #geometry_type, #intersection, #intersects?, #is_3d?, #locate_along, #locate_between, #measured?, #overlaps?, #relate?, #rep_equals?, #simple?, #spatial_dimension, #srid, #sym_difference, #touches?, #transform, #unary_union, #union, #within?

Class Method Details

.create(factory, exterior, interior_array) ⇒ Object

Class methods for CAPIPolygonImpl



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
292
293
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
# File 'ext/geos_c_impl/polygon.c', line 262

static VALUE
cmethod_create(VALUE module,
               VALUE factory,
               VALUE exterior,
               VALUE interior_array)
{
  VALUE linear_ring_type;
  GEOSGeometry* exterior_geom;
  unsigned int len;
  GEOSGeometry** interior_geoms;
  unsigned int actual_len;
  unsigned int i;
  unsigned int j;
  GEOSGeometry* interior_geom;
  GEOSGeometry* polygon;
  int state = 0;

  Check_Type(interior_array, T_ARRAY);
  linear_ring_type = rgeo_feature_linear_ring_module;
  exterior_geom = rgeo_convert_to_detached_geos_geometry(
    exterior, factory, linear_ring_type, NULL, &state);
  if (state) {
    rb_jump_tag(state);
  }

  len = (unsigned int)RARRAY_LEN(interior_array);
  interior_geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
  if (interior_geoms) {
    actual_len = 0;
    for (i = 0; i < len; ++i) {
      interior_geom =
        rgeo_convert_to_detached_geos_geometry(rb_ary_entry(interior_array, i),
                                               factory,
                                               linear_ring_type,
                                               NULL,
                                               &state);
      if (state) {
        for (j = 0; j < i; j++) {
          GEOSGeom_destroy(interior_geoms[j]);
        }
        GEOSGeom_destroy(exterior_geom);
        FREE(interior_geoms);
        rb_jump_tag(state);
      }
      interior_geoms[actual_len++] = interior_geom;
    }
    if (len == actual_len) {
      polygon =
        GEOSGeom_createPolygon(exterior_geom, interior_geoms, actual_len);
      if (polygon) {
        FREE(interior_geoms);
        // NOTE: we can return safely here, state cannot be other than 0.
        return rgeo_wrap_geos_geometry(
          factory, polygon, rgeo_geos_polygon_class);
      }
    }
    for (i = 0; i < actual_len; ++i) {
      GEOSGeom_destroy(interior_geoms[i]);
    }
    FREE(interior_geoms);
  }
  GEOSGeom_destroy(exterior_geom);
  if (state) {
    rb_jump_tag(state);
  }
  return Qnil;
}