Class: GeographicItem::GeometryCollection

Inherits:
GeographicItem show all
Defined in:
app/models/geographic_item/geometry_collection.rb

Overview

Geometry collection definition…

Constant Summary collapse

SHAPE_COLUMN =
:geometry_collection

Constants inherited from GeographicItem

ANTI_MERIDIAN, DATA_TYPES, GEOGRAPHY_SQL, GEOMETRY_SQL

Instance Attribute Summary

Attributes inherited from GeographicItem

#geometry, #line_string, #multi_line_string, #multi_point, #multi_polygon, #no_cached, #point, #polygon, #shape, #type

Attributes included from Housekeeping::Users

#by

Instance Method Summary collapse

Methods inherited from GeographicItem

aliased_geographic_sql, are_contained_in_item, are_contained_in_item_by_id, are_contained_in_wkt, #area, #center_coords, #centroid, contained_by, contained_by_where_sql, contained_by_with_antimeridian_check, contained_by_wkt_shifted_sql, contained_by_wkt_sql, containing, #containing_geographic_areas, containing_point, containing_sql, containing_where_for_point_sql, containing_where_sql, containing_where_sql_geog, #contains?, crosses_anti_meridian?, crosses_anti_meridian_by_id?, default_by_geographic_area_ids, disjoint_from, distance_between, eval_for_type, #far, #geo_object, #geo_object_type, #geo_type, #geographic_name_hierarchy, geometry_for, geometry_for_collection_sql, geometry_for_sql, geometry_sql, geometry_sql2, #inferred_geographic_name_hierarchy, intersecting, #intersecting_area, intersecting_radius_of_wkt_sql, #intersects?, is_contained_by, is_contained_by_sql, lat_long_sql, #line_string_to_a, #line_string_to_hash, #multi_line_string_to_a, #multi_line_string_to_hash, #multi_point_to_a, #multi_point_to_hash, #multi_polygon_to_a, #multi_polygon_to_hash, #near, not_including, ordered_by_longest_distance_from, ordered_by_shortest_distance_from, point_inferred_geographic_name_hierarchy, #point_to_a, #point_to_hash, #polygon_to_a, #polygon_to_hash, #quick_geographic_name_hierarchy, #radius, reverse_containing_sql, #rgeo_to_geo_json, select_distance_with_geo_object, select_geography_sql, select_geometry_sql, #set_cached, #set_type_if_geography_present, single_geometry_sql, #some_data_is_provided, #st_centroid, st_collect, st_collect_sql, #st_distance, #st_distance_spheroid, #st_distance_to_geographic_item, st_multi, #st_npoints, st_union, #start_point, #to_geo_json, #to_geo_json_string, #to_wkt, #valid_geometry?, where_distance_greater_than_zero, with_area, with_collecting_event_through_georeferences, with_is_valid_geometry_column, with_latitude, with_longitude, #within?, within_radius_of_item, within_radius_of_item_sql, within_radius_of_wkt_sql

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::HasPapertrail

#attribute_updated, #attribute_updater

Methods included from Housekeeping::Timestamps

#data_breakdown_for_chartkick_recent

Methods included from Housekeeping::Users

#set_created_by_id, #set_updated_by_id

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Method Details

#rendering_hashHash

Returns:

  • (Hash)


14
15
16
# File 'app/models/geographic_item/geometry_collection.rb', line 14

def rendering_hash
  to_hash(self.geometry_collection)
end

#st_start_pointRGeo::Point

Returns first point in the collection.

Returns:

  • (RGeo::Point)

    first point in the collection



8
9
10
11
# File 'app/models/geographic_item/geometry_collection.rb', line 8

def st_start_point
  rgeo_to_geo_json =~ /(-?\d+\.?\d*),(-?\d+\.?\d*)/
  Gis::FACTORY.point($1.to_f, $2.to_f, 0.0)
end

#to_geo_json_featureGeoJSON Feature

the shape as a Feature/Feature Collection

Returns:

  • (GeoJSON Feature)


77
78
79
80
# File 'app/models/geographic_item/geometry_collection.rb', line 77

def to_geo_json_feature
  self.geometry = rgeo_to_geo_json
  super
end

#to_hash(geometry_collection) ⇒ Hash

TODO:

Seems to be deprecated for rgeo_to_geo_json?!

Returns a simple representation of the collection in points, lines, and polygons.

Parameters:

Returns:

  • (Hash)

    a simple representation of the collection in points, lines, and polygons.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/geographic_item/geometry_collection.rb', line 21

def to_hash(geometry_collection)
  data = {
    points:   [],
    lines:    [],
    polygons: []
  }
  geometry_collection.each { |it|
    case it.geometry_type.type_name
    when 'Point'
      # POINT (-88.241421 40.091565 757.0)
      point = point_to_hash(it)[:points]
      # @todo would it really be better to use object_to_hash here?  Structure-wise, perhaps, but it really is faster to do it here directly, I think...
      data[:points].push(point_to_a(it))
    when /^Line[S]*/ #when 'Line' or 'LineString'
      # LINESTRING (-32.0 21.0 0.0, -25.0 21.0 0.0, -25.0 16.0 0.0, -21.0 20.0 0.0)
      data[:lines].push(line_string_to_a(it))
    when 'Polygon'
      # POLYGON ((-14.0 23.0 0.0, -14.0 11.0 0.0, -2.0 11.0 0.0, -2.0 23.0 0.0, -8.0 21.0 0.0, -14.0 23.0 0.0), (-11.0 18.0 0.0, -8.0 17.0 0.0, -6.0 20.0 0.0, -4.0 16.0 0.0, -7.0 13.0 0.0, -11.0 14.0 0.0, -11.0 18.0 0.0))
      # note: only the exterior_ring is processed
      data[:polygons].push(polygon_to_a(it))
      # in the cases of the multi-objects, break each down to its constituent parts (i.e., remove its identity as a multi-whatever), and record those parts
    when 'MultiPoint'
      # MULTIPOINT ((3.0 -14.0 0.0), (6.0 -12.9 0.0), (5.0 -16.0 0.0), (4.0 -17.9 0.0), (7.0 -17.9 0.0))
      multi_point_to_a(it).each { |point|
        data[:points].push(point)
      }
    when 'MultiLineString'
      # MULTILINESTRING ((23.0 21.0 0.0, 16.0 21.0 0.0, 16.0 16.0 0.0, 11.0 20.0 0.0), (4.0 12.6 0.0, 16.0 12.6 0.0, 16.0 7.6 0.0), (21.0 12.6 0.0, 26.0 12.6 0.0, 22.0 17.6 0.0))
      multi_line_string_to_a(it).each { |line_string|
        data[:lines].push(line_string)
      }
    when 'MultiPolygon'
      # MULTIPOLYGON (((28.0 2.3 0.0, 23.0 -1.7 0.0, 26.0 -4.8 0.0, 28.0 2.3 0.0))
      it.each { |polygon|
        polygon_data = []
        polygon.exterior_ring.points.each { |point|
          polygon_data.push([point.x, point.y]) }
        data[:polygons].push(polygon_data)
      }
    when 'GeometryCollection'
      collection_hash = to_hash(it)
      collection_hash.each_key { |key|
        collection_hash[key].each { |item|
          data[key].push(item) }
      }
    else
      # leave everything as it is...
    end
  }
  # remove any keys with empty arrays
  data.delete_if { |key, value| value == [] }
  data
end