Class: TG::Geometry::Geom

Inherits:
Object
  • Object
show all
Defined in:
lib/tg/geometry.rb,
ext/tg_geometry/tg_geometry_ext.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.line_string(points, index: :natural, srid: nil) ⇒ TG::Geometry::Geom

Parameters:

  • points (Array<Array<Float>>)
  • index (:default, :none, :natural, :ystripes) (defaults to: :natural)
  • srid (Integer, nil) (defaults to: nil)

Returns:



42
43
44
45
46
47
48
49
50
# File 'lib/tg/geometry.rb', line 42

class Geom
  # @!method srid
  #   @return [Integer, nil] SRID metadata; not used for reprojection
  #
  # @!method to_ewkb(srid: nil)
  #   Writes EWKB with the SRID flag set. Uses explicit srid: when provided,
  #   otherwise Geom#srid. Raises if no SRID is available. to_wkb remains plain.
  #   @return [String] frozen ASCII-8BIT EWKB string
end

.multi_polygon(polygons, index: :ystripes, srid: nil) ⇒ TG::Geometry::Geom

Each polygon is a Hash with :exterior and optional :holes, or an Array shorthand for an exterior with no holes.

Parameters:

  • polygons (Array<Hash, Array>)

Returns:



42
43
44
45
46
47
48
49
50
# File 'lib/tg/geometry.rb', line 42

class Geom
  # @!method srid
  #   @return [Integer, nil] SRID metadata; not used for reprojection
  #
  # @!method to_ewkb(srid: nil)
  #   Writes EWKB with the SRID flag set. Uses explicit srid: when provided,
  #   otherwise Geom#srid. Raises if no SRID is available. to_wkb remains plain.
  #   @return [String] frozen ASCII-8BIT EWKB string
end

.parse_hex(hex, index: :ystripes) ⇒ TG::Geometry::Geom

Parses HEXWKB or HEXEWKB. SRID is preserved when the EWKB SRID flag is set.

Returns:



42
43
44
45
46
47
48
49
50
# File 'lib/tg/geometry.rb', line 42

class Geom
  # @!method srid
  #   @return [Integer, nil] SRID metadata; not used for reprojection
  #
  # @!method to_ewkb(srid: nil)
  #   Writes EWKB with the SRID flag set. Uses explicit srid: when provided,
  #   otherwise Geom#srid. Raises if no SRID is available. to_wkb remains plain.
  #   @return [String] frozen ASCII-8BIT EWKB string
end

.parse_wkb(bytes, index: :ystripes) ⇒ TG::Geometry::Geom

Parses WKB or EWKB. SRID is preserved when the EWKB SRID flag is set.

Returns:



42
43
44
45
46
47
48
49
50
# File 'lib/tg/geometry.rb', line 42

class Geom
  # @!method srid
  #   @return [Integer, nil] SRID metadata; not used for reprojection
  #
  # @!method to_ewkb(srid: nil)
  #   Writes EWKB with the SRID flag set. Uses explicit srid: when provided,
  #   otherwise Geom#srid. Raises if no SRID is available. to_wkb remains plain.
  #   @return [String] frozen ASCII-8BIT EWKB string
end

.polygon(exterior, holes: [], index: :ystripes, srid: nil) ⇒ TG::Geometry::Geom

Parameters:

  • exterior (Array<Array<Float>>)
  • holes (Array<Array<Array<Float>>>) (defaults to: [])
  • index (:default, :none, :natural, :ystripes) (defaults to: :ystripes)
  • srid (Integer, nil) (defaults to: nil)

Returns:



42
43
44
45
46
47
48
49
50
# File 'lib/tg/geometry.rb', line 42

class Geom
  # @!method srid
  #   @return [Integer, nil] SRID metadata; not used for reprojection
  #
  # @!method to_ewkb(srid: nil)
  #   Writes EWKB with the SRID flag set. Uses explicit srid: when provided,
  #   otherwise Geom#srid. Raises if no SRID is available. to_wkb remains plain.
  #   @return [String] frozen ASCII-8BIT EWKB string
end

Instance Method Details

#bboxObject



1994
1995
1996
1997
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1994

static VALUE rb_tg_geometry_geom_bbox(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return rect_from_tg_rect(tg_geom_rect(w->geom));
}

#contains?(other) ⇒ Boolean

Returns:

  • (Boolean)


2042
2043
2044
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2042

static VALUE rb_tg_geometry_geom_contains_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_contains);
}

#covered_by?(other) ⇒ Boolean

Returns:

  • (Boolean)


2062
2063
2064
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2062

static VALUE rb_tg_geometry_geom_covered_by_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_coveredby);
}

#covers?(other) ⇒ Boolean

Returns:

  • (Boolean)


2058
2059
2060
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2058

static VALUE rb_tg_geometry_geom_covers_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_covers);
}

#covers_xy?(x_value, y_value) ⇒ Boolean

Returns:

  • (Boolean)


1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1999

static VALUE rb_tg_geometry_geom_covers_xy_p(VALUE self, VALUE x_value, VALUE y_value) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    double x = NUM2DBL(x_value);
    double y = NUM2DBL(y_value);
    struct tg_geom *point;
    bool result;

    check_finite_double(x, "x");
    check_finite_double(y, "y");

    {
        struct tg_point tg_point = {x, y};
        point = tg_geom_new_point(tg_point);
    }
    if (!point) {
        rb_raise(rb_eNoMemError, "TG point geometry allocation failed");
    }

    if (tg_geom_error(point)) {
        raise_geom_error_and_free_as(point, eTGGeometryArgumentError,
                                     "TG point geometry allocation failed",
                                     "TG point geometry error message is too large",
                                     "TG point geometry error message allocation failed");
    }

    result = tg_geom_covers(w->geom, point);
    tg_geom_free(point);
    return result ? Qtrue : Qfalse;
}

#dimsObject



2329
2330
2331
2332
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2329

static VALUE rb_tg_geometry_geom_dims(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return INT2NUM(tg_geom_dims(w->geom));
}

#disjoint?(other) ⇒ Boolean

Returns:

  • (Boolean)


2050
2051
2052
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2050

static VALUE rb_tg_geometry_geom_disjoint_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_disjoint);
}

#empty?Boolean

Returns:

  • (Boolean)


2324
2325
2326
2327
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2324

static VALUE rb_tg_geometry_geom_empty_p(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return tg_geom_is_empty(w->geom) ? Qtrue : Qfalse;
}

#equals?(other) ⇒ Boolean

Returns:

  • (Boolean)


2038
2039
2040
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2038

static VALUE rb_tg_geometry_geom_equals_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_equals);
}

#extra_coordsObject



2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2360

static VALUE rb_tg_geometry_geom_extra_coords(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int count = tg_geom_num_extra_coords(w->geom);
    const double *coords = tg_geom_extra_coords(w->geom);
    VALUE result = rb_ary_new_capa(count);

    for (int i = 0; i < count; i++) {
        rb_ary_push(result, rb_float_new(coords[i]));
    }

    RB_GC_GUARD(self);
    RB_GC_GUARD(result);
    return result;
}

#extra_jsonObject



2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2269

static VALUE rb_tg_geometry_geom_extra_json(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    const char *extra_json = tg_geom_extra_json(w->geom);
    VALUE str;

    if (!extra_json) {
        return Qnil;
    }

    str = rb_str_new_cstr(extra_json);
    rb_enc_associate(str, rb_utf8_encoding());
    RB_GC_GUARD(str);
    return str;
}

#feature?Boolean

Returns:

  • (Boolean)


2314
2315
2316
2317
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2314

static VALUE rb_tg_geometry_geom_feature_p(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return tg_geom_is_feature(w->geom) ? Qtrue : Qfalse;
}

#feature_collection?Boolean

Returns:

  • (Boolean)


2319
2320
2321
2322
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2319

static VALUE rb_tg_geometry_geom_feature_collection_p(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return tg_geom_is_featurecollection(w->geom) ? Qtrue : Qfalse;
}

#geometriesObject



2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2462

static VALUE rb_tg_geometry_geom_geometries(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int count = tg_geom_num_geometries(w->geom);
    VALUE geometries = rb_ary_new_capa(count);

    for (int i = 0; i < count; i++) {
        rb_ary_push(geometries, geom_wrap_borrowed(self, tg_geom_geometry_at(w->geom, i)));
    }

    RB_GC_GUARD(self);
    RB_GC_GUARD(geometries);
    return geometries;
}

#geometry_at(index_value) ⇒ Object



2455
2456
2457
2458
2459
2460
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2455

static VALUE rb_tg_geometry_geom_geometry_at(VALUE self, VALUE index_value) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int index = checked_child_index(index_value, tg_geom_num_geometries(w->geom),
                                    "geometry collection child");
    return geom_wrap_borrowed(self, tg_geom_geometry_at(w->geom, index));
}

#has_m?Boolean

Returns:

  • (Boolean)


2339
2340
2341
2342
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2339

static VALUE rb_tg_geometry_geom_has_m_p(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return tg_geom_has_m(w->geom) ? Qtrue : Qfalse;
}

#has_z?Boolean

Returns:

  • (Boolean)


2334
2335
2336
2337
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2334

static VALUE rb_tg_geometry_geom_has_z_p(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return tg_geom_has_z(w->geom) ? Qtrue : Qfalse;
}

#intersects?(other) ⇒ Boolean

Returns:

  • (Boolean)


2046
2047
2048
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2046

static VALUE rb_tg_geometry_geom_intersects_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_intersects);
}

#intersects_rect?(*args) ⇒ Boolean

Returns:

  • (Boolean)


2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2081

static VALUE rb_tg_geometry_geom_intersects_rect_p(int argc, VALUE *argv, VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    struct tg_rect rect;

    if (argc == 1) {
        tg_rect_wrapper_t *rect_data = get_rect_wrapper(argv[0]);
        rect.min.x = rect_data->min_x;
        rect.min.y = rect_data->min_y;
        rect.max.x = rect_data->max_x;
        rect.max.y = rect_data->max_y;
    } else if (argc == 4) {
        double min_x = NUM2DBL(argv[0]);
        double min_y = NUM2DBL(argv[1]);
        double max_x = NUM2DBL(argv[2]);
        double max_y = NUM2DBL(argv[3]);

        validate_rect_coordinates(min_x, min_y, max_x, max_y);
        rect.min.x = min_x;
        rect.min.y = min_y;
        rect.max.x = max_x;
        rect.max.y = max_y;
    } else {
        rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 1 or 4)", argc);
    }

    return tg_geom_intersects_rect(w->geom, rect) ? Qtrue : Qfalse;
}

#intersects_xy?(x_value, y_value) ⇒ Boolean

Returns:

  • (Boolean)


2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2070

static VALUE rb_tg_geometry_geom_intersects_xy_p(VALUE self, VALUE x_value, VALUE y_value) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    double x = NUM2DBL(x_value);
    double y = NUM2DBL(y_value);

    check_finite_double(x, "x");
    check_finite_double(y, "y");

    return tg_geom_intersects_xy(w->geom, x, y) ? Qtrue : Qfalse;
}

#lineObject



2294
2295
2296
2297
2298
2299
2300
2301
2302
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2294

static VALUE rb_tg_geometry_geom_line(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);

    if (tg_geom_typeof(w->geom) != TG_LINESTRING) {
        return Qnil;
    }

    return line_wrap_borrowed(self, tg_geom_line(w->geom));
}

#line_at(index_value) ⇒ Object



2405
2406
2407
2408
2409
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2405

static VALUE rb_tg_geometry_geom_line_at(VALUE self, VALUE index_value) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int index = checked_child_index(index_value, tg_geom_num_lines(w->geom), "geometry line");
    return line_wrap_borrowed(self, tg_geom_line_at(w->geom, index));
}

#linesObject



2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2411

static VALUE rb_tg_geometry_geom_lines(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int count = tg_geom_num_lines(w->geom);
    VALUE lines = rb_ary_new_capa(count);

    for (int i = 0; i < count; i++) {
        rb_ary_push(lines, line_wrap_borrowed(self, tg_geom_line_at(w->geom, i)));
    }

    RB_GC_GUARD(self);
    RB_GC_GUARD(lines);
    return lines;
}

#mObject



2352
2353
2354
2355
2356
2357
2358
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2352

static VALUE rb_tg_geometry_geom_m(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    if (!tg_geom_has_m(w->geom)) {
        return Qnil;
    }
    return rb_float_new(tg_geom_m(w->geom));
}

#num_geometriesObject



2450
2451
2452
2453
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2450

static VALUE rb_tg_geometry_geom_num_geometries(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return INT2NUM(tg_geom_num_geometries(w->geom));
}

#num_linesObject



2400
2401
2402
2403
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2400

static VALUE rb_tg_geometry_geom_num_lines(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return INT2NUM(tg_geom_num_lines(w->geom));
}

#num_pointsObject



2375
2376
2377
2378
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2375

static VALUE rb_tg_geometry_geom_num_points(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return INT2NUM(tg_geom_num_points(w->geom));
}

#num_polygonsObject



2425
2426
2427
2428
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2425

static VALUE rb_tg_geometry_geom_num_polygons(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return INT2NUM(tg_geom_num_polys(w->geom));
}

#pointObject



2284
2285
2286
2287
2288
2289
2290
2291
2292
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2284

static VALUE rb_tg_geometry_geom_point(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);

    if (tg_geom_typeof(w->geom) != TG_POINT) {
        return Qnil;
    }

    return point_array_from_tg_point(tg_geom_point(w->geom));
}

#point_at(index_value) ⇒ Object



2380
2381
2382
2383
2384
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2380

static VALUE rb_tg_geometry_geom_point_at(VALUE self, VALUE index_value) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int index = checked_child_index(index_value, tg_geom_num_points(w->geom), "geometry point");
    return point_array_from_tg_point(tg_geom_point_at(w->geom, index));
}

#pointsObject



2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2386

static VALUE rb_tg_geometry_geom_points(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int count = tg_geom_num_points(w->geom);
    VALUE points = rb_ary_new_capa(count);

    for (int i = 0; i < count; i++) {
        rb_ary_push(points, point_array_from_tg_point(tg_geom_point_at(w->geom, i)));
    }

    RB_GC_GUARD(self);
    RB_GC_GUARD(points);
    return points;
}

#polygonObject



2304
2305
2306
2307
2308
2309
2310
2311
2312
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2304

static VALUE rb_tg_geometry_geom_polygon(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);

    if (tg_geom_typeof(w->geom) != TG_POLYGON) {
        return Qnil;
    }

    return polygon_wrap_borrowed(self, tg_geom_poly(w->geom));
}

#polygon_at(index_value) ⇒ Object



2430
2431
2432
2433
2434
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2430

static VALUE rb_tg_geometry_geom_polygon_at(VALUE self, VALUE index_value) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int index = checked_child_index(index_value, tg_geom_num_polys(w->geom), "geometry polygon");
    return polygon_wrap_borrowed(self, tg_geom_poly_at(w->geom, index));
}

#polygonsObject



2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2436

static VALUE rb_tg_geometry_geom_polygons(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    int count = tg_geom_num_polys(w->geom);
    VALUE polygons = rb_ary_new_capa(count);

    for (int i = 0; i < count; i++) {
        rb_ary_push(polygons, polygon_wrap_borrowed(self, tg_geom_poly_at(w->geom, i)));
    }

    RB_GC_GUARD(self);
    RB_GC_GUARD(polygons);
    return polygons;
}

#sridObject



1966
1967
1968
1969
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1966

static VALUE rb_tg_geometry_geom_srid(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return w->has_srid ? INT2NUM(w->srid) : Qnil;
}

#to_ewkb(*args) ⇒ Object



2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2180

static VALUE rb_tg_geometry_geom_to_ewkb(int argc, VALUE *argv, VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    VALUE kwargs;
    VALUE srid_value;
    VALUE out;
    tg_str_alloc_args_t str_args;
    uint8_t *plain_buf;
    uint8_t *out_buf;
    size_t required;
    size_t written;
    uint8_t byte_order;
    uint32_t type;
    int effective_srid;
    bool explicit_srid;
    int state = 0;

    rb_scan_args(argc, argv, "0:", &kwargs);
    {
        ID allowed[] = {id_srid};
        validate_keywords(kwargs, allowed, sizeof(allowed) / sizeof(allowed[0]));
    }
    explicit_srid = kwargs_has_key(kwargs, id_srid);

    if (explicit_srid) {
        srid_value = rb_hash_aref(kwargs, ID2SYM(id_srid));
        effective_srid = parse_required_srid_value(srid_value);
    } else if (w->has_srid) {
        effective_srid = w->srid;
    } else {
        rb_raise(eTGGeometryArgumentError, "to_ewkb requires srid (geom has no srid metadata)");
    }

    required = tg_geom_wkb(w->geom, NULL, 0);
    if (required < 5) {
        rb_raise(eTGGeometryError, "TG WKB writer produced an invalid header");
    }
    if (required > (size_t)LONG_MAX - 4) {
        rb_raise(rb_eNoMemError, "serialized EWKB output is too large");
    }

    plain_buf = (uint8_t *)ruby_xmalloc(required);
    written = tg_geom_wkb(w->geom, plain_buf, required);
    if (written != required) {
        ruby_xfree(plain_buf);
        rb_raise(eTGGeometryError, "TG WKB writer size changed during serialization");
    }

    byte_order = plain_buf[0];
    if (byte_order > 1) {
        ruby_xfree(plain_buf);
        rb_raise(eTGGeometryError, "TG WKB writer produced invalid byte order");
    }

    type = tg_geometry_read_u32(plain_buf + 1, byte_order);
    if ((type & 0x20000000u) != 0) {
        ruby_xfree(plain_buf);
        rb_raise(eTGGeometryError, "TG WKB writer unexpectedly produced EWKB SRID flag");
    }
    type |= 0x20000000u;

    str_args.len = (long)(required + 4);
    out = rb_protect(tg_str_new_binary_body, (VALUE)&str_args, &state);
    if (state) {
        ruby_xfree(plain_buf);
        rb_jump_tag(state);
    }

    out_buf = (uint8_t *)RSTRING_PTR(out);
    out_buf[0] = byte_order;
    tg_geometry_write_u32(out_buf + 1, type, byte_order);
    tg_geometry_write_u32(out_buf + 5, (uint32_t)effective_srid, byte_order);
    memcpy(out_buf + 9, plain_buf + 5, required - 5);
    ruby_xfree(plain_buf);

    rb_obj_freeze(out);
    RB_GC_GUARD(out);
    return out;
}

#to_geobinObject



2264
2265
2266
2267
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2264

static VALUE rb_tg_geometry_geom_to_geobin(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return binary_writer_result(tg_geom_geobin, w->geom, "GeoBIN");
}

#to_geojsonObject



2132
2133
2134
2135
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2132

static VALUE rb_tg_geometry_geom_to_geojson(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return text_writer_result(tg_geom_geojson, w->geom);
}

#to_hexObject



2259
2260
2261
2262
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2259

static VALUE rb_tg_geometry_geom_to_hex(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return text_writer_result(tg_geom_hex, w->geom);
}

#to_wkbObject



2164
2165
2166
2167
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2164

static VALUE rb_tg_geometry_geom_to_wkb(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return binary_writer_result(tg_geom_wkb, w->geom, "WKB");
}

#to_wktObject



2137
2138
2139
2140
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2137

static VALUE rb_tg_geometry_geom_to_wkt(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    return text_writer_result(tg_geom_wkt, w->geom);
}

#touches?(other) ⇒ Boolean

Returns:

  • (Boolean)


2066
2067
2068
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2066

static VALUE rb_tg_geometry_geom_touches_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_touches);
}

#typeObject



1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1971

static VALUE rb_tg_geometry_geom_type(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);

    switch (tg_geom_typeof(w->geom)) {
    case TG_POINT:
        return ID2SYM(rb_intern("point"));
    case TG_LINESTRING:
        return ID2SYM(rb_intern("linestring"));
    case TG_POLYGON:
        return ID2SYM(rb_intern("polygon"));
    case TG_MULTIPOINT:
        return ID2SYM(rb_intern("multipoint"));
    case TG_MULTILINESTRING:
        return ID2SYM(rb_intern("multilinestring"));
    case TG_MULTIPOLYGON:
        return ID2SYM(rb_intern("multipolygon"));
    case TG_GEOMETRYCOLLECTION:
        return ID2SYM(rb_intern("geometrycollection"));
    default:
        return ID2SYM(rb_intern("unknown"));
    }
}

#within?(other) ⇒ Boolean

Returns:

  • (Boolean)


2054
2055
2056
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2054

static VALUE rb_tg_geometry_geom_within_p(VALUE self, VALUE other) {
    return geom_binary_predicate(self, other, tg_geom_within);
}

#zObject



2344
2345
2346
2347
2348
2349
2350
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2344

static VALUE rb_tg_geometry_geom_z(VALUE self) {
    tg_geom_wrapper_t *w = get_geom_wrapper(self);
    if (!tg_geom_has_z(w->geom)) {
        return Qnil;
    }
    return rb_float_new(tg_geom_z(w->geom));
}