Package com.microsoft.sqlserver.jdbc
Class Geography
- java.lang.Object
-
- com.microsoft.sqlserver.jdbc.Geography
-
public class Geography extends Object
Geography datatype represents data in a round-earth coordinate system.
-
-
Field Summary
Fields Modifier and Type Field Description protected ByteBuffer
buffer
As a general rule, the ~IndexEnd variables are non-inclusive (i.e.protected int
currentFigureIndex
protected int
currentPointIndex
protected int
currentSegmentIndex
protected int
currentShapeIndex
protected int
currentWktPos
protected byte
FA_ARC
protected byte
FA_COMPOSITE_CURVE
protected byte
FA_EXTERIOR_RING
protected byte
FA_INTERIOR_RING
protected byte
FA_LINE
protected byte
FA_POINT
protected byte
FA_STROKE
protected List<com.microsoft.sqlserver.jdbc.Figure>
figureList
protected com.microsoft.sqlserver.jdbc.Figure[]
figures
protected boolean
hasMvalues
protected boolean
hasZvalues
protected InternalSpatialDatatype
internalType
protected boolean
isLargerThanHemisphere
protected boolean
isNull
protected boolean
isSingleLineSegment
protected boolean
isSinglePoint
protected boolean
isValid
protected double[]
mValues
protected int
numberOfFigures
protected int
numberOfPoints
protected int
numberOfSegments
protected int
numberOfShapes
protected List<com.microsoft.sqlserver.jdbc.Point>
pointList
protected List<com.microsoft.sqlserver.jdbc.Segment>
segmentList
protected com.microsoft.sqlserver.jdbc.Segment[]
segments
protected byte
serializationProperties
protected List<com.microsoft.sqlserver.jdbc.Shape>
shapeList
protected com.microsoft.sqlserver.jdbc.Shape[]
shapes
protected int
srid
protected byte
version
protected byte[]
wkb
protected byte[]
wkbNoZM
protected String
wkt
protected String
wktNoZM
protected StringBuffer
WKTsb
protected StringBuffer
WKTsbNoZM
protected double[]
xValues
protected double[]
yValues
protected double[]
zValues
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendToWKTBuffers(Object o)
Append the data to both stringbuffers.String
asTextZM()
Returns the Well-Known Text (WKT) representation of the Geography object.protected boolean
checkEmptyKeyword(int parentShapeIndex, InternalSpatialDatatype isd, boolean isInsideAnotherShape)
protected void
constructCompoundcurveWKT(int segmentStartIndex, int segmentEndIndex, int pointEndIndex)
Constructs a CompoundCurve in WKT form.protected void
constructCurvepolygonWKT(int figureStartIndex, int figureEndIndex, int segmentStartIndex, int segmentEndIndex)
Constructs a CurvePolygon in WKT form.protected void
constructGeometryCollectionWKT(int shapeEndIndex)
The starting point for constructing a GeometryCollection type in WKT form.protected void
constructLineWKT(int pointStartIndex, int pointEndIndex)
Constructs a line in WKT form.protected void
constructMultipolygonWKT(int shapeStartIndex, int shapeEndIndex)
Constructs a MultiPolygon in WKT form.protected void
constructMultiShapeWKT(int shapeStartIndex, int shapeEndIndex)
Constructs a mutli-shape (MultiPoint / MultiLineString) in WKT form.protected void
constructPointWKT(int pointIndex)
Constructs and appends a Point type in WKT form to the stringbuffer.protected void
constructSegmentWKT(int currentSegment, byte segment, int pointEndIndex)
Constructs a Segment in WKT form.protected void
constructShapeWKT(int figureStartIndex, int figureEndIndex)
Constructs a shape (simple Geometry/Geography entities that are contained within a single bracket) in WKT form.protected void
constructWKT(com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype sd, InternalSpatialDatatype isd, int pointIndexEnd, int figureIndexEnd, int segmentIndexEnd, int shapeIndexEnd)
Constructs the WKT representation of Geometry/Geography from the deserialized data.protected void
createSerializationProperties()
static Geography
deserialize(byte[] wkb)
Constructor for a Geography instance from an internal SQL Server format for spatial data.protected void
determineInternalType()
protected int
determineWkbCapacity()
Double
getLatitude()
Returns the latitude value.Double
getLongitude()
Returns the longitude value.Double
getM()
Returns the M (measure) value of the object.protected String
getNextStringToken()
Reads the next string token (usually POINT, LINESTRING, etc.).int
getSrid()
Returns the Spatial Reference Identifier (SRID) value.Double
getZ()
Returns the Z (elevation) value of the object.boolean
hasM()
Returns if the object contains a M (measure) value.protected boolean
hasMoreToken()
boolean
hasZ()
Returns if the object contains a Z (elevation) value.protected void
interpretSerializationPropBytes()
boolean
isNull()
Returns if the Geography object is null.static Geography
parse(String wkt)
Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.protected void
parseWkb(com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype type)
Deserializes the buffer (that contains WKB representation of Geometry/Geography data), and stores it into multiple corresponding data structures.protected void
parseWKTForSerialization(com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype sd, int startPos, int parentShapeIndex, boolean isGeoCollection)
Parses WKT and populates the data structures of the Geometry/Geography instance.static Geography
point(double lat, double lon, int srid)
Constructor for a Geography instance that represents a Point instance from its latitude and longitude values and a Spatial Reference Identifier.protected void
populateStructures()
Populates the various data structures contained within the Geometry/Geography instance.protected byte
readByte()
protected void
readCloseBracket()
protected void
readCompoundCurveWkt(boolean isFirstIteration)
Reads a CompoundCurve WKT.protected void
readCurvePolygon()
Reads a CurvePolygon WKT.protected double
readDouble()
protected void
readFigures()
protected int
readInt()
protected void
readLineWkt()
Reads a series of Point types.protected void
readMultiPolygonWkt(int thisShapeIndex, String nextToken)
Reads a MultiPolygon WKT.protected void
readMvalues()
protected void
readNumberOfFigures()
protected void
readNumberOfPoints()
protected void
readNumberOfSegments()
protected void
readNumberOfShapes()
protected void
readOpenBracket()
protected void
readPointWkt()
Reads Point WKT and adds it to the list of points.protected void
readSegments()
protected void
readSegmentWkt(int segmentType, boolean isFirstIteration)
Reads a Segment WKT.protected void
readShapes()
protected void
readShapeWkt(int parentShapeIndex, String nextToken)
Reads a shape (simple Geometry/Geography entities that are contained within a single bracket) WKT.protected void
readZvalues()
byte[]
serialize()
Returns the bytes that represent an internal SQL Server format of Geography type.protected void
serializeToWkb(boolean noZM, com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype type)
Serializes the Geogemetry/Geography instance to WKB.byte[]
STAsBinary()
Returns the Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation of a Geography instance.String
STAsText()
Returns the Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation of a Geography instance.String
STGeographyType()
Returns the Open Geospatial Consortium (OGC) type name represented by a Geography instance.static Geography
STGeomFromText(String wkt, int srid)
Constructor for a Geography 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 Geography
STGeomFromWKB(byte[] wkb)
Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.int
STNumPoints()
Returns the number of points in the Geography object.protected void
throwIllegalWKB()
protected void
throwIllegalWKT()
String
toString()
Returns the String representation of the Geography object.
-
-
-
Field Detail
-
buffer
protected ByteBuffer buffer
As a general rule, the ~IndexEnd variables are non-inclusive (i.e. pointIndexEnd = 8 means the shape using it will only go up to the 7th index of the array)
-
internalType
protected InternalSpatialDatatype internalType
-
wkt
protected String wkt
-
wktNoZM
protected String wktNoZM
-
wkb
protected byte[] wkb
-
wkbNoZM
protected byte[] wkbNoZM
-
srid
protected int srid
-
version
protected byte version
-
numberOfPoints
protected int numberOfPoints
-
numberOfFigures
protected int numberOfFigures
-
numberOfShapes
protected int numberOfShapes
-
numberOfSegments
protected int numberOfSegments
-
WKTsb
protected StringBuffer WKTsb
-
WKTsbNoZM
protected StringBuffer WKTsbNoZM
-
currentPointIndex
protected int currentPointIndex
-
currentFigureIndex
protected int currentFigureIndex
-
currentSegmentIndex
protected int currentSegmentIndex
-
currentShapeIndex
protected int currentShapeIndex
-
xValues
protected double[] xValues
-
yValues
protected double[] yValues
-
zValues
protected double[] zValues
-
mValues
protected double[] mValues
-
figures
protected com.microsoft.sqlserver.jdbc.Figure[] figures
-
shapes
protected com.microsoft.sqlserver.jdbc.Shape[] shapes
-
segments
protected com.microsoft.sqlserver.jdbc.Segment[] segments
-
hasZvalues
protected boolean hasZvalues
-
hasMvalues
protected boolean hasMvalues
-
isValid
protected boolean isValid
-
isSinglePoint
protected boolean isSinglePoint
-
isSingleLineSegment
protected boolean isSingleLineSegment
-
isLargerThanHemisphere
protected boolean isLargerThanHemisphere
-
isNull
protected boolean isNull
-
FA_INTERIOR_RING
protected final byte FA_INTERIOR_RING
- See Also:
- Constant Field Values
-
FA_STROKE
protected final byte FA_STROKE
- See Also:
- Constant Field Values
-
FA_EXTERIOR_RING
protected final byte FA_EXTERIOR_RING
- See Also:
- Constant Field Values
-
FA_POINT
protected final byte FA_POINT
- See Also:
- Constant Field Values
-
FA_LINE
protected final byte FA_LINE
- See Also:
- Constant Field Values
-
FA_ARC
protected final byte FA_ARC
- See Also:
- Constant Field Values
-
FA_COMPOSITE_CURVE
protected final byte FA_COMPOSITE_CURVE
- See Also:
- Constant Field Values
-
currentWktPos
protected int currentWktPos
-
pointList
protected List<com.microsoft.sqlserver.jdbc.Point> pointList
-
figureList
protected List<com.microsoft.sqlserver.jdbc.Figure> figureList
-
shapeList
protected List<com.microsoft.sqlserver.jdbc.Shape> shapeList
-
segmentList
protected List<com.microsoft.sqlserver.jdbc.Segment> segmentList
-
serializationProperties
protected byte serializationProperties
-
-
Method Detail
-
STGeomFromText
public static Geography STGeomFromText(String wkt, int srid) throws SQLServerException
Constructor for a Geography 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:
- Geography Geography instance created from WKT and SRID
- Throws:
SQLServerException
- if an exception occurs
-
STGeomFromWKB
public static Geography STGeomFromWKB(byte[] wkb) throws SQLServerException
Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation.- Parameters:
wkb
- Well-Known Binary (WKB) provided by the user.- Returns:
- Geography Geography instance created from WKB
- Throws:
SQLServerException
- if an exception occurs
-
deserialize
public static Geography deserialize(byte[] wkb) throws SQLServerException
Constructor for a Geography instance from an internal SQL Server format for spatial data.- Parameters:
wkb
- Well-Known Binary (WKB) provided by the user.- Returns:
- Geography Geography instance created from WKB
- Throws:
SQLServerException
- if an exception occurs
-
parse
public static Geography parse(String wkt) throws SQLServerException
Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation. Spatial Reference Identifier is defaulted to 4326.- Parameters:
wkt
- Well-Known Text (WKT) provided by the user.- Returns:
- Geography Geography instance created from WKT
- Throws:
SQLServerException
- if an exception occurs
-
point
public static Geography point(double lat, double lon, int srid) throws SQLServerException
Constructor for a Geography instance that represents a Point instance from its latitude and longitude values and a Spatial Reference Identifier.- Parameters:
lat
- latitudelon
- longitudesrid
- Spatial Reference Identifier value- Returns:
- Geography 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 Geography 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 Geography instance. This value will not contain any Z or M values carried by the instance.- Returns:
- byte array representation of the Geography object.
-
serialize
public byte[] serialize()
Returns the bytes that represent an internal SQL Server format of Geography type.- Returns:
- byte array representation of the Geography 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.
-
getLatitude
public Double getLatitude()
Returns the latitude value.- Returns:
- double value that represents the latitude.
-
getLongitude
public Double getLongitude()
Returns the longitude value.- Returns:
- double value that represents the longitude.
-
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 Geography object is null.- Returns:
- boolean that indicates if the object is null.
-
STNumPoints
public int STNumPoints()
Returns the number of points in the Geography object.- Returns:
- int that indicates the number of points in the Geography object.
-
STGeographyType
public String STGeographyType()
Returns the Open Geospatial Consortium (OGC) type name represented by a Geography instance.- Returns:
- String that contains the Geography object's type name
-
asTextZM
public String asTextZM()
Returns the Well-Known Text (WKT) representation of the Geography object.- Returns:
- String that contains the WKT representation of the Geography object.
-
toString
public String toString()
Returns the String representation of the Geography object.
-
serializeToWkb
protected void serializeToWkb(boolean noZM, com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype type)
Serializes the Geogemetry/Geography instance to WKB.- Parameters:
noZM
- flag to indicate if Z and M coordinates should be includedtype
- Type of Spatial Datatype (Geometry/Geography)
-
parseWkb
protected void parseWkb(com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype type) throws SQLServerException
Deserializes the buffer (that contains WKB representation of Geometry/Geography data), and stores it into multiple corresponding data structures.- Parameters:
type
- Type of Spatial Datatype (Geography/Geometry)- Throws:
SQLServerException
- if an Exception occurs
-
constructWKT
protected void constructWKT(com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype sd, InternalSpatialDatatype isd, int pointIndexEnd, int figureIndexEnd, int segmentIndexEnd, int shapeIndexEnd) throws SQLServerException
Constructs the WKT representation of Geometry/Geography from the deserialized data.- Parameters:
sd
- the Geometry/Geography instance.isd
- internal spatial datatype objectpointIndexEnd
- upper bound for reading pointsfigureIndexEnd
- upper bound for reading figuressegmentIndexEnd
- upper bound for reading segmentsshapeIndexEnd
- upper bound for reading shapes- Throws:
SQLServerException
- if an exception occurs
-
parseWKTForSerialization
protected void parseWKTForSerialization(com.microsoft.sqlserver.jdbc.SQLServerSpatialDatatype sd, int startPos, int parentShapeIndex, boolean isGeoCollection) throws SQLServerException
Parses WKT and populates the data structures of the Geometry/Geography instance.- Parameters:
sd
- the Geometry/Geography instance.startPos
- The index to start from from the WKT.parentShapeIndex
- The index of the parent's Shape in the shapes array. Used to determine this shape's parent.isGeoCollection
- flag to indicate if this is part of a GeometryCollection.- Throws:
SQLServerException
- if an exception occurs
-
constructPointWKT
protected void constructPointWKT(int pointIndex)
Constructs and appends a Point type in WKT form to the stringbuffer. There are two stringbuffers - WKTsb and WKTsbNoZM. WKTsb contains the X, Y, Z and M coordinates, whereas WKTsbNoZM contains only X and Y coordinates.- Parameters:
pointIndex
- indicates which point to append to the stringbuffer.
-
constructLineWKT
protected void constructLineWKT(int pointStartIndex, int pointEndIndex)
Constructs a line in WKT form.- Parameters:
pointStartIndex
- .pointEndIndex
- .
-
constructShapeWKT
protected void constructShapeWKT(int figureStartIndex, int figureEndIndex)
Constructs a shape (simple Geometry/Geography entities that are contained within a single bracket) in WKT form.- Parameters:
figureStartIndex
- .figureEndIndex
- .
-
constructMultiShapeWKT
protected void constructMultiShapeWKT(int shapeStartIndex, int shapeEndIndex)
Constructs a mutli-shape (MultiPoint / MultiLineString) in WKT form.- Parameters:
shapeStartIndex
- .shapeEndIndex
- .
-
constructCompoundcurveWKT
protected void constructCompoundcurveWKT(int segmentStartIndex, int segmentEndIndex, int pointEndIndex)
Constructs a CompoundCurve in WKT form.- Parameters:
segmentStartIndex
- .segmentEndIndex
- .pointEndIndex
- .
-
constructMultipolygonWKT
protected void constructMultipolygonWKT(int shapeStartIndex, int shapeEndIndex)
Constructs a MultiPolygon in WKT form.- Parameters:
shapeStartIndex
- .shapeEndIndex
- .
-
constructCurvepolygonWKT
protected void constructCurvepolygonWKT(int figureStartIndex, int figureEndIndex, int segmentStartIndex, int segmentEndIndex)
Constructs a CurvePolygon in WKT form.- Parameters:
figureStartIndex
- .figureEndIndex
- .segmentStartIndex
- .segmentEndIndex
- .
-
constructSegmentWKT
protected void constructSegmentWKT(int currentSegment, byte segment, int pointEndIndex)
Constructs a Segment in WKT form. SQL Server re-uses the last point of a segment if the following segment is of type 3 (first arc) or type 2 (first line). This makes sense because the last point of a segment and the first point of the next segment have to match for a valid curve. This means that the code has to look ahead and decide to decrement the currentPointIndex depending on what segment comes next, since it may have been reused (and it's reflected in the array of points)- Parameters:
currentSegment
- .segment
- .pointEndIndex
- .
-
constructGeometryCollectionWKT
protected void constructGeometryCollectionWKT(int shapeEndIndex) throws SQLServerException
The starting point for constructing a GeometryCollection type in WKT form.- Parameters:
shapeEndIndex
- .- Throws:
SQLServerException
- if an exception occurs
-
readPointWkt
protected void readPointWkt() throws SQLServerException
Reads Point WKT and adds it to the list of points. This method will read up until and including the comma that may come at the end of the Point WKT.- Throws:
SQLServerException
- if an exception occurs
-
readLineWkt
protected void readLineWkt() throws SQLServerException
Reads a series of Point types.- Throws:
SQLServerException
- if an exception occurs
-
readShapeWkt
protected void readShapeWkt(int parentShapeIndex, String nextToken) throws SQLServerException
Reads a shape (simple Geometry/Geography entities that are contained within a single bracket) WKT.- Parameters:
parentShapeIndex
- shape index of the parent shape that called this methodnextToken
- next string token- Throws:
SQLServerException
- if an exception occurs
-
readCurvePolygon
protected void readCurvePolygon() throws SQLServerException
Reads a CurvePolygon WKT.- Throws:
SQLServerException
- if an exception occurs
-
readMultiPolygonWkt
protected void readMultiPolygonWkt(int thisShapeIndex, String nextToken) throws SQLServerException
Reads a MultiPolygon WKT.- Parameters:
thisShapeIndex
- shape index of current shapenextToken
- next string token- Throws:
SQLServerException
- if an exception occurs
-
readSegmentWkt
protected void readSegmentWkt(int segmentType, boolean isFirstIteration) throws SQLServerException
Reads a Segment WKT.- Parameters:
segmentType
- segment typeisFirstIteration
- flag that indicates if this is the first iteration from the loop outside- Throws:
SQLServerException
- if an exception occurs
-
readCompoundCurveWkt
protected void readCompoundCurveWkt(boolean isFirstIteration) throws SQLServerException
Reads a CompoundCurve WKT.- Parameters:
isFirstIteration
- flag that indicates if this is the first iteration from the loop outside- Throws:
SQLServerException
- if an exception occurs
-
getNextStringToken
protected String getNextStringToken()
Reads the next string token (usually POINT, LINESTRING, etc.). Then increments currentWktPos to the end of the string token.- Returns:
- the next string token
-
populateStructures
protected void populateStructures()
Populates the various data structures contained within the Geometry/Geography instance.
-
readOpenBracket
protected void readOpenBracket() throws SQLServerException
- Throws:
SQLServerException
-
readCloseBracket
protected void readCloseBracket() throws SQLServerException
- Throws:
SQLServerException
-
hasMoreToken
protected boolean hasMoreToken()
-
createSerializationProperties
protected void createSerializationProperties()
-
determineWkbCapacity
protected int determineWkbCapacity()
-
appendToWKTBuffers
protected void appendToWKTBuffers(Object o)
Append the data to both stringbuffers.- Parameters:
o
- data to append to the stringbuffers.
-
interpretSerializationPropBytes
protected void interpretSerializationPropBytes()
-
readNumberOfPoints
protected void readNumberOfPoints() throws SQLServerException
- Throws:
SQLServerException
-
readZvalues
protected void readZvalues() throws SQLServerException
- Throws:
SQLServerException
-
readMvalues
protected void readMvalues() throws SQLServerException
- Throws:
SQLServerException
-
readNumberOfFigures
protected void readNumberOfFigures() throws SQLServerException
- Throws:
SQLServerException
-
readFigures
protected void readFigures() throws SQLServerException
- Throws:
SQLServerException
-
readNumberOfShapes
protected void readNumberOfShapes() throws SQLServerException
- Throws:
SQLServerException
-
readShapes
protected void readShapes() throws SQLServerException
- Throws:
SQLServerException
-
readNumberOfSegments
protected void readNumberOfSegments() throws SQLServerException
- Throws:
SQLServerException
-
readSegments
protected void readSegments() throws SQLServerException
- Throws:
SQLServerException
-
determineInternalType
protected void determineInternalType()
-
checkEmptyKeyword
protected boolean checkEmptyKeyword(int parentShapeIndex, InternalSpatialDatatype isd, boolean isInsideAnotherShape) throws SQLServerException
- Throws:
SQLServerException
-
throwIllegalWKT
protected void throwIllegalWKT() throws SQLServerException
- Throws:
SQLServerException
-
throwIllegalWKB
protected void throwIllegalWKB() throws SQLServerException
- Throws:
SQLServerException
-
readByte
protected byte readByte() throws SQLServerException
- Throws:
SQLServerException
-
readInt
protected int readInt() throws SQLServerException
- Throws:
SQLServerException
-
readDouble
protected double readDouble() throws SQLServerException
- Throws:
SQLServerException
-
-