Class: TG::Geometry::Geom

Inherits:
Object
  • Object
show all
Defined in:
ext/tg_geometry/tg_geometry_ext.c

Instance Method Summary collapse

Instance Method Details

#bboxObject



1309
1310
1311
1312
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1309

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)


1357
1358
1359
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1357

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)


1377
1378
1379
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1377

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)


1373
1374
1375
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1373

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)


1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1314

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



1554
1555
1556
1557
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1554

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)


1365
1366
1367
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1365

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)


1549
1550
1551
1552
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1549

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)


1353
1354
1355
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1353

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

#extra_coordsObject



1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1585

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



1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1494

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)


1539
1540
1541
1542
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1539

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)


1544
1545
1546
1547
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1544

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



1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1687

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



1680
1681
1682
1683
1684
1685
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1680

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)


1564
1565
1566
1567
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1564

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)


1559
1560
1561
1562
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1559

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)


1361
1362
1363
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1361

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)


1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1396

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)


1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1385

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



1519
1520
1521
1522
1523
1524
1525
1526
1527
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1519

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



1630
1631
1632
1633
1634
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1630

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



1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1636

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



1577
1578
1579
1580
1581
1582
1583
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1577

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



1675
1676
1677
1678
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1675

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



1625
1626
1627
1628
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1625

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



1600
1601
1602
1603
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1600

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



1650
1651
1652
1653
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1650

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



1509
1510
1511
1512
1513
1514
1515
1516
1517
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1509

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



1605
1606
1607
1608
1609
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1605

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



1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1611

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



1529
1530
1531
1532
1533
1534
1535
1536
1537
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1529

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



1655
1656
1657
1658
1659
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1655

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



1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1661

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;
}

#to_geobinObject



1489
1490
1491
1492
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1489

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



1447
1448
1449
1450
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1447

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



1484
1485
1486
1487
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1484

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



1479
1480
1481
1482
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1479

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



1452
1453
1454
1455
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1452

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)


1381
1382
1383
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1381

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

#typeObject



1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1286

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)


1369
1370
1371
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1369

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

#zObject



1569
1570
1571
1572
1573
1574
1575
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1569

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));
}