Package com.microsoft.sqlserver.jdbc

# Class Geometry

java.lang.Object
com.microsoft.sqlserver.jdbc.Geometry

public class Geometry extends Object
Geometry datatype represents data in a Euclidean (flat) coordinate system. This class will stay in this current package for backwards compatibility.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Geometry()`
Creates a Geometry object
`protected`
`Geometry(byte[] clr)`
Private constructor used for creating a Geometry object from internal SQL Server format.
`protected`
`Geometry(String wkt, int srid)`
Private constructor used for creating a Geometry object from WKT and Spatial Reference Identifier.

## Method Summary

Modifier and Type
Method
Description
`String`
`asTextZM()`
Returns the Well-Known Text (WKT) representation of the Geometry object.
`static Geometry`
`deserialize(byte[] clr)`
Constructor for a Geometry instance from an internal SQL Server format for spatial data.
`List<Figure>`
`getFigureList()`
Get figure list
`Double`
`getM()`
Returns the M (measure) value of the object.
`List<Point>`
`getPointList()`
Get point list
`List<Segment>`
`getSegmentList()`
Get segment list
`List<Shape>`
`getShapeList()`
Get shape list
`int`
`getSrid()`
Returns the Spatial Reference Identifier (SRID) value.
`Double`
`getX()`
Returns the X coordinate value.
`Double`
`getY()`
Returns the Y coordinate value.
`Double`
`getZ()`
Returns the Z (elevation) value of the object.
`boolean`
`hasM()`
Returns if the object contains a M (measure) value.
`boolean`
`hasZ()`
Returns if the object contains a Z (elevation) value.
`boolean`
`isNull()`
Returns if the Geometry object is null.
`static Geometry`
`parse(String wkt)`
Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.
`static Geometry`
`point(double x, double y, int srid)`
Constructor for a Geometry instance that represents a Point instance from its X and Y values and an Spatial Reference Identifier.
`byte[]`
`serialize()`
Returns the bytes that represent an internal SQL Server format of Geometry type.
`byte[]`
`STAsBinary()`
Returns the Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation of a Geometry instance.
`String`
`STAsText()`
Returns the Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation of a Geometry instance.
`String`
`STGeometryType()`
Returns the Open Geospatial Consortium (OGC) type name represented by a geometry instance.
`static Geometry`
`STGeomFromText(String wkt, int srid)`
Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation augmented with any Z (elevation) and M (measure) values carried by the instance.
`static Geometry`
`STGeomFromWKB(byte[] wkb)`
Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.
`int`
`STNumPoints()`
Returns the number of points in the Geometry object.
`String`
`toString()`
Returns the String representation of the Geometry object.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### Geometry

protected Geometry()
Creates a Geometry object

### Geometry

protected Geometry(String wkt, int srid) throws SQLServerException
Private constructor used for creating a Geometry object from WKT and Spatial Reference Identifier.

Parameters:
  `wkt` - Well-Known Text (WKT) provided by the user.
  `srid` - Spatial Reference Identifier (SRID) provided by the user.
Throws:
  `SQLServerException` - if an exception occurs

### Geometry

protected Geometry(byte[] clr) throws SQLServerException
Private constructor used for creating a Geometry object from internal SQL Server format.

Parameters:
  `clr` - Internal SQL Server format provided by the user.
Throws:
  `SQLServerException` - if an exception occurs

## Method Details

### STGeomFromText

public static Geometry STGeomFromText(String wkt, int srid) throws SQLServerException
Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation augmented with any Z (elevation) and M (measure) values carried by the instance.

Parameters:
  `wkt` - Well-Known Text (WKT) provided by the user.
  `srid` - Spatial Reference Identifier (SRID) provided by the user.
Returns:
  Geometry Geometry instance created from WKT and SRID
Throws:
  `SQLServerException` - if an exception occurs

### STGeomFromWKB

public static Geometry STGeomFromWKB(byte[] wkb) throws SQLServerException
Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation. Note: This method currently uses internal SQL Server format (CLR) to create a Geometry instance, but in the future this will be changed to accept WKB data instead, as the SQL Server counterpart of this method (STGeomFromWKB) uses WKB. For existing users who are already using this method, consider switching to deserialize(byte) instead.

Parameters:
  `wkb` - Well-Known Binary (WKB) provided by the user.
Returns:
  Geometry Geometry instance created from WKB
Throws:
  `SQLServerException` - if an exception occurs

### deserialize

public static Geometry deserialize(byte[] clr) throws SQLServerException
Constructor for a Geometry instance from an internal SQL Server format for spatial data.

Parameters:
  `clr` - Internal SQL Server format provided by the user.
Returns:
  Geometry Geometry instance created from clr
Throws:
  `SQLServerException` - if an exception occurs

### parse

public static Geometry parse(String wkt) throws SQLServerException
Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation. Spatial Reference Identifier is defaulted to 0.

Parameters:
  `wkt` - Well-Known Text (WKT) provided by the user.
Returns:
  Geometry Geometry instance created from WKT
Throws:
  `SQLServerException` - if an exception occurs

### point

public static Geometry point(double x, double y, int srid) throws SQLServerException
Constructor for a Geometry instance that represents a Point instance from its X and Y values and an Spatial Reference Identifier.

Parameters:
  `x` - x coordinate
  `y` - y coordinate
  `srid` - Spatial Reference Identifier value
Returns:
  Geometry Geography instance
Throws:
  `SQLServerException` - if an exception occurs

### STAsText

public String STAsText() throws SQLServerException
Returns the Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation of a Geometry instance. This text will not contain any Z (elevation) or M (measure) values carried by the instance.

Returns:
  the WKT representation without the Z and M values.
Throws:
  `SQLServerException` - if an exception occurs

### STAsBinary

public byte[] STAsBinary()
Returns the Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation of a Geometry instance. This value will not contain any Z or M values carried by the instance.

Returns:
  byte array representation of the Geometry object.

### serialize

public byte[] serialize()
Returns the bytes that represent an internal SQL Server format of Geometry type.

Returns:
  byte array representation of the Geometry object.

### hasM

public boolean hasM()
Returns if the object contains a M (measure) value.

Returns:
  boolean that indicates if the object contains M value.

### hasZ

public boolean hasZ()
Returns if the object contains a Z (elevation) value.

Returns:
  boolean that indicates if the object contains Z value.

### getX

public Double getX()
Returns the X coordinate value.

Returns:
  double value that represents the X coordinate.

### getY

public Double getY()
Returns the Y coordinate value.

Returns:
  double value that represents the Y coordinate.

### getM

public Double getM()
Returns the M (measure) value of the object.

Returns:
  double value that represents the M value.

### getZ

public Double getZ()
Returns the Z (elevation) value of the object.

Returns:
  double value that represents the Z value.

### getSrid

public int getSrid()
Returns the Spatial Reference Identifier (SRID) value.

Returns:
  int value of SRID.

### isNull

public boolean isNull()
Returns if the Geometry object is null.

Returns:
  boolean that indicates if the object is null.

### STNumPoints

public int STNumPoints()
Returns the number of points in the Geometry object.

Returns:
  int that indicates the number of points in the Geometry object.

### STGeometryType

public String STGeometryType()
Returns the Open Geospatial Consortium (OGC) type name represented by a geometry instance.

Returns:
  String that contains the Geometry object's type name

### asTextZM

public String asTextZM()
Returns the Well-Known Text (WKT) representation of the Geometry object.

Returns:
  String that contains the WKT representation of the Geometry object.

### toString

public String toString()
Returns the String representation of the Geometry object.

Overrides:
  `toString` in class `Object`
Returns:
  String that contains the WKT representation of the Geometry object.

### getPointList

public List<Point> getPointList()
Get point list

Returns:
  point list

### getFigureList

public List<Figure> getFigureList()
Get figure list

Returns:
  figure list

### getShapeList

public List<Shape> getShapeList()
Get shape list

Returns:
  shape list

### getSegmentList

public List<Segment> getSegmentList()
Get segment list

Returns:
  segment list