Class: RGeo::Geos::CAPIPolygonImpl

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

Overview

:nodoc:

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, #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_empty?, #is_simple?, #marshal_dump, #marshal_load, #overlaps?, #point_on_surface, #prepare!, #prepared?, #relate?, #rep_equals?, #simple?, #simplify, #simplify_preserve_topology, #srid, #sym_difference, #touches?, #unary_union, #union, #valid?, #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
# 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;

  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);
  if (exterior_geom) {
    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);
        if (interior_geom) {
          interior_geoms[actual_len++] = interior_geom;
        }
      }
      if (len == actual_len) {
        polygon = GEOSGeom_createPolygon_r(context, exterior_geom, interior_geoms, actual_len);
        if (polygon) {
          free(interior_geoms);
          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);
  }
  return Qnil;
}