Class GeoPolygon

java.lang.Object
com.azure.core.models.GeoObject
com.azure.core.models.GeoPolygon
All Implemented Interfaces:
com.azure.json.JsonSerializable<GeoObject>

public final class GeoPolygon extends GeoObject

Represents a geometric polygon in GeoJSON format.

This class encapsulates a polygon defined by a list of GeoLinearRing instances. Each ring represents a closed loop of coordinates forming the boundary of the polygon.

This class also provides a toJson(JsonWriter) method to serialize the geometric polygon to JSON, and a fromJson(JsonReader) method to deserialize a geometric polygon from JSON.

This class is useful when you want to work with a polygon in a geographic context. For example, you can use it to represent a geographic area on a map.

Note: A polygon requires at least one ring, and each ring requires at least 4 coordinates (with the first and last coordinates being the same to form a closed loop).

See Also:
  • Constructor Details

    • GeoPolygon

      public GeoPolygon(GeoLinearRing ring)
      Constructs a geometric polygon.
      Parameters:
      ring - The ring that defines the polygon.
      Throws:
      NullPointerException - If ring is null.
    • GeoPolygon

      public GeoPolygon(GeoLinearRing ring, GeoBoundingBox boundingBox, Map<String,Object> customProperties)
      Constructs a geometric polygon.
      Parameters:
      ring - The ring that defines the polygon.
      boundingBox - Bounding box for the polygon.
      customProperties - Additional properties of the polygon.
      Throws:
      NullPointerException - If ring is null.
    • GeoPolygon

      public GeoPolygon(List<GeoLinearRing> rings)
      Constructs a geometric polygon.
      Parameters:
      rings - The rings that define the polygon.
      Throws:
      NullPointerException - If rings is null.
    • GeoPolygon

      public GeoPolygon(List<GeoLinearRing> rings, GeoBoundingBox boundingBox, Map<String,Object> customProperties)
      Constructs a geometric polygon.
      Parameters:
      rings - The rings that define the polygon.
      boundingBox - Bounding box for the polygon.
      customProperties - Additional properties of the polygon.
      Throws:
      NullPointerException - If rings is null.
  • Method Details

    • getRings

      public List<GeoLinearRing> getRings()
      Unmodifiable representation of the geometric rings representing this polygon.
      Returns:
      An unmodifiable representation of the geometric rings representing this polygon.
    • getOuterRing

      public GeoLinearRing getOuterRing()
      Gets the outer ring of the polygon.
      Returns:
      Outer ring of the polygon.
    • getType

      public GeoObjectType getType()
      Description copied from class: GeoObject
      Gets the GeoJSON type for this object.
      Specified by:
      getType in class GeoObject
      Returns:
      The GeoJSON type for this object.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GeoObject
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GeoObject
    • toJson

      public com.azure.json.JsonWriter toJson(com.azure.json.JsonWriter jsonWriter) throws IOException
      Specified by:
      toJson in interface com.azure.json.JsonSerializable<GeoObject>
      Overrides:
      toJson in class GeoObject
      Throws:
      IOException
    • fromJson

      public static GeoPolygon fromJson(com.azure.json.JsonReader jsonReader) throws IOException
      Reads a JSON stream into a GeoPolygon.
      Parameters:
      jsonReader - The JsonReader being read.
      Returns:
      The GeoPolygon that the JSON stream represented, or null if it pointed to JSON null.
      Throws:
      IllegalStateException - If the type node exists and isn't equal to Polygon.
      IOException - If a GeoPolygon fails to be read from the jsonReader.