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?

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, #is_3d?, #is_empty?, #is_simple?, #make_valid, #marshal_dump, #marshal_load, #measured?, #overlaps?, #point_on_surface, #prepare!, #prepared?, #relate?, #rep_equals?, #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?, #is_empty?, #is_simple?, #locate_along, #locate_between, #measured?, #overlaps?, #relate?, #rep_equals?, #simple?, #spatial_dimension, #srid, #sym_difference, #touches?, #unary_union, #union, #within?

Class Method Details

.create(factory, exterior, interior_array) ⇒ Object

Class methods for CAPIPolygonImpl


232
233
234
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'ext/geos_c_impl/polygon.c', line 232

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

  Check_Type(interior_array, T_ARRAY);
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
  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_exc_raise(rb_errinfo()); }
  if (!exterior_geom) { return Qnil; }

  context = factory_data->geos_context;
  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 (interior_geom) {
        interior_geoms[actual_len++] = interior_geom;
      }
      if (state) {
        break;
      }
    }
    if (len == actual_len) {
      polygon = GEOSGeom_createPolygon_r(context, 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_r(context, interior_geoms[i]);
    }
    FREE(interior_geoms);
  }
  GEOSGeom_destroy_r(context, exterior_geom);
  if (state) { rb_exc_raise(rb_errinfo()); }
  return Qnil;
}