Class: Parse::GeoJSON::MultiPolygon

Inherits:
Geometry show all
Defined in:
lib/parse/model/geojson.rb

Overview

‘MultiPolygon` — an Array of Polygons, each Polygon an Array of linear rings, each ring an Array of `[lng, lat]` pairs. The canonical use case is administrative or territorial regions made up of disjoint pieces (Hawaii, Indonesia, multi-island service areas, postal-code clusters).

GeoJSON nesting depth is 4: ‘coordinates[ring][lng_or_lat]`. Each ring must contain ≥ 4 points and be explicitly closed.

Examples:

Parse::GeoJSON::MultiPolygon.new [
  [[[ 0, 0], [ 1, 0], [ 1, 1], [ 0, 1], [ 0, 0]]],
  [[[ 5, 5], [ 6, 5], [ 6, 6], [ 5, 6], [ 5, 5]]],
]

Constant Summary collapse

TYPE =
"MultiPolygon"
MIN_RING_POINTS =
4

Constants inherited from Geometry

Geometry::TYPE_REGISTRY

Constants inherited from Model

Model::CLASS_AUDIENCE, Model::CLASS_INSTALLATION, Model::CLASS_JOB_SCHEDULE, Model::CLASS_JOB_STATUS, Model::CLASS_PRODUCT, Model::CLASS_PUSH_STATUS, Model::CLASS_ROLE, Model::CLASS_SCHEMA, Model::CLASS_SESSION, Model::CLASS_USER, Model::ID, Model::KEY_CLASS_NAME, Model::KEY_CREATED_AT, Model::KEY_OBJECT_ID, Model::KEY_UPDATED_AT, Model::OBJECT_ID, Model::TYPE_ACL, Model::TYPE_BYTES, Model::TYPE_DATE, Model::TYPE_FIELD, Model::TYPE_FILE, Model::TYPE_GEOPOINT, Model::TYPE_NUMBER, Model::TYPE_OBJECT, Model::TYPE_POINTER, Model::TYPE_POLYGON, Model::TYPE_RELATION

Instance Attribute Summary

Attributes inherited from Geometry

#coordinates

Instance Method Summary collapse

Methods inherited from Geometry

#==, from_geojson, geojson_type, #geojson_type, #initialize, #inspect, #to_geojson, #to_json

Methods inherited from Model

#dirty?, find_class

Methods included from Client::Connectable

#client

Constructor Details

This class inherits a constructor from Parse::GeoJSON::Geometry

Instance Method Details

#polygonsArray<Parse::Polygon>

Returns each member polygon as a Polygon (with axis swap back to Parse’s ‘[lat, lng]`). Inner rings (holes) are dropped because Polygon does not support them.

Returns:

  • (Array<Parse::Polygon>)

    each member polygon as a Polygon (with axis swap back to Parse’s ‘[lat, lng]`). Inner rings (holes) are dropped because Polygon does not support them.



211
212
213
214
215
216
# File 'lib/parse/model/geojson.rb', line 211

def polygons
  @coordinates.map do |rings|
    outer = rings.first
    Parse::Polygon.new(outer.map { |(lng, lat)| [lat.to_f, lng.to_f] })
  end
end