Class: TG::Geometry::Geom
- Inherits:
-
Object
- Object
- TG::Geometry::Geom
- Defined in:
- ext/tg_geometry/tg_geometry_ext.c
Instance Method Summary collapse
- #bbox ⇒ Object
- #contains?(other) ⇒ Boolean
- #covered_by?(other) ⇒ Boolean
- #covers?(other) ⇒ Boolean
- #covers_xy?(x_value, y_value) ⇒ Boolean
- #dims ⇒ Object
- #disjoint?(other) ⇒ Boolean
- #empty? ⇒ Boolean
- #equals?(other) ⇒ Boolean
- #extra_coords ⇒ Object
- #extra_json ⇒ Object
- #feature? ⇒ Boolean
- #feature_collection? ⇒ Boolean
- #geometries ⇒ Object
- #geometry_at(index_value) ⇒ Object
- #has_m? ⇒ Boolean
- #has_z? ⇒ Boolean
- #intersects?(other) ⇒ Boolean
- #intersects_rect?(*args) ⇒ Boolean
- #intersects_xy?(x_value, y_value) ⇒ Boolean
- #line ⇒ Object
- #line_at(index_value) ⇒ Object
- #lines ⇒ Object
- #m ⇒ Object
- #num_geometries ⇒ Object
- #num_lines ⇒ Object
- #num_points ⇒ Object
- #num_polygons ⇒ Object
- #point ⇒ Object
- #point_at(index_value) ⇒ Object
- #points ⇒ Object
- #polygon ⇒ Object
- #polygon_at(index_value) ⇒ Object
- #polygons ⇒ Object
- #to_geobin ⇒ Object
- #to_geojson ⇒ Object
- #to_hex ⇒ Object
- #to_wkb ⇒ Object
- #to_wkt ⇒ Object
- #touches?(other) ⇒ Boolean
- #type ⇒ Object
- #within?(other) ⇒ Boolean
- #z ⇒ Object
Instance Method Details
#bbox ⇒ Object
1339 1340 1341 1342 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1339
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
1387 1388 1389 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1387
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
1407 1408 1409 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1407
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
1403 1404 1405 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1403
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
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1344
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;
}
|
#dims ⇒ Object
1584 1585 1586 1587 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1584
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
1395 1396 1397 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1395
static VALUE rb_tg_geometry_geom_disjoint_p(VALUE self, VALUE other) {
return geom_binary_predicate(self, other, tg_geom_disjoint);
}
|
#empty? ⇒ Boolean
1579 1580 1581 1582 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1579
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
1383 1384 1385 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1383
static VALUE rb_tg_geometry_geom_equals_p(VALUE self, VALUE other) {
return geom_binary_predicate(self, other, tg_geom_equals);
}
|
#extra_coords ⇒ Object
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1615
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_json ⇒ Object
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1524
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
1569 1570 1571 1572 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1569
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
1574 1575 1576 1577 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1574
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;
}
|
#geometries ⇒ Object
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1717
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
1710 1711 1712 1713 1714 1715 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1710
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
1594 1595 1596 1597 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1594
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
1589 1590 1591 1592 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1589
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
1391 1392 1393 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1391
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
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1426
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
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1415
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;
}
|
#line ⇒ Object
1549 1550 1551 1552 1553 1554 1555 1556 1557 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1549
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
1660 1661 1662 1663 1664 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1660
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));
}
|
#lines ⇒ Object
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1666
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;
}
|
#m ⇒ Object
1607 1608 1609 1610 1611 1612 1613 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1607
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_geometries ⇒ Object
1705 1706 1707 1708 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1705
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_lines ⇒ Object
1655 1656 1657 1658 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1655
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_points ⇒ Object
1630 1631 1632 1633 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1630
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_polygons ⇒ Object
1680 1681 1682 1683 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1680
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));
}
|
#point ⇒ Object
1539 1540 1541 1542 1543 1544 1545 1546 1547 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1539
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
1635 1636 1637 1638 1639 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1635
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));
}
|
#points ⇒ Object
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1641
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;
}
|
#polygon ⇒ Object
1559 1560 1561 1562 1563 1564 1565 1566 1567 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1559
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
1685 1686 1687 1688 1689 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1685
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));
}
|
#polygons ⇒ Object
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1691
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_geobin ⇒ Object
1519 1520 1521 1522 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1519
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_geojson ⇒ Object
1477 1478 1479 1480 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1477
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_hex ⇒ Object
1514 1515 1516 1517 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1514
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_wkb ⇒ Object
1509 1510 1511 1512 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1509
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_wkt ⇒ Object
1482 1483 1484 1485 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1482
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
1411 1412 1413 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1411
static VALUE rb_tg_geometry_geom_touches_p(VALUE self, VALUE other) {
return geom_binary_predicate(self, other, tg_geom_touches);
}
|
#type ⇒ Object
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1316
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
1399 1400 1401 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1399
static VALUE rb_tg_geometry_geom_within_p(VALUE self, VALUE other) {
return geom_binary_predicate(self, other, tg_geom_within);
}
|
#z ⇒ Object
1599 1600 1601 1602 1603 1604 1605 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1599
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));
}
|