Class Geography


  • public class Geography
    extends java.lang.Object
    Geography datatype represents data in a round-earth coordinate system.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void appendToWKTBuffers​(java.lang.Object o)
      Append the data to both stringbuffers.
      java.lang.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()  
      java.lang.Double getLatitude()
      Returns the latitude value.
      java.lang.Double getLongitude()
      Returns the longitude value.
      java.lang.Double getM()
      Returns the M (measure) value of the object.
      protected java.lang.String getNextStringToken()
      Reads the next string token (usually POINT, LINESTRING, etc.).
      int getSrid()
      Returns the Spatial Reference Identifier (SRID) value.
      java.lang.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​(java.lang.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, java.lang.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, java.lang.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.
      java.lang.String STAsText()
      Returns the Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation of a Geography instance.
      java.lang.String STGeographyType()
      Returns the Open Geospatial Consortium (OGC) type name represented by a Geography instance.
      static Geography STGeomFromText​(java.lang.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()  
      java.lang.String toString()
      Returns the String representation of the Geography object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • buffer

        protected java.nio.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)
      • wkt

        protected java.lang.String wkt
      • wktNoZM

        protected java.lang.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 java.lang.StringBuffer WKTsb
      • WKTsbNoZM

        protected java.lang.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
      • currentWktPos

        protected int currentWktPos
      • pointList

        protected java.util.List<com.microsoft.sqlserver.jdbc.Point> pointList
      • figureList

        protected java.util.List<com.microsoft.sqlserver.jdbc.Figure> figureList
      • shapeList

        protected java.util.List<com.microsoft.sqlserver.jdbc.Shape> shapeList
      • segmentList

        protected java.util.List<com.microsoft.sqlserver.jdbc.Segment> segmentList
      • serializationProperties

        protected byte serializationProperties
    • Method Detail

      • STGeomFromText

        public static Geography STGeomFromText​(java.lang.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​(java.lang.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 - latitude
        lon - longitude
        srid - Spatial Reference Identifier value
        Returns:
        Geography Geography instance
        Throws:
        SQLServerException - if an exception occurs
      • STAsText

        public java.lang.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 java.lang.Double getLatitude()
        Returns the latitude value.
        Returns:
        double value that represents the latitude.
      • getLongitude

        public java.lang.Double getLongitude()
        Returns the longitude value.
        Returns:
        double value that represents the longitude.
      • getM

        public java.lang.Double getM()
        Returns the M (measure) value of the object.
        Returns:
        double value that represents the M value.
      • getZ

        public java.lang.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 java.lang.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 java.lang.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 java.lang.String toString()
        Returns the String representation of the Geography object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String that contains the WKT 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 included
        type - 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 object
        pointIndexEnd - upper bound for reading points
        figureIndexEnd - upper bound for reading figures
        segmentIndexEnd - upper bound for reading segments
        shapeIndexEnd - 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
      • readShapeWkt

        protected void readShapeWkt​(int parentShapeIndex,
                                    java.lang.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 method
        nextToken - next string token
        Throws:
        SQLServerException - if an exception occurs
      • readMultiPolygonWkt

        protected void readMultiPolygonWkt​(int thisShapeIndex,
                                           java.lang.String nextToken)
                                    throws SQLServerException
        Reads a MultiPolygon WKT.
        Parameters:
        thisShapeIndex - shape index of current shape
        nextToken - 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 type
        isFirstIteration - 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 java.lang.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.
      • hasMoreToken

        protected boolean hasMoreToken()
      • createSerializationProperties

        protected void createSerializationProperties()
      • determineWkbCapacity

        protected int determineWkbCapacity()
      • appendToWKTBuffers

        protected void appendToWKTBuffers​(java.lang.Object o)
        Append the data to both stringbuffers.
        Parameters:
        o - data to append to the stringbuffers.
      • interpretSerializationPropBytes

        protected void interpretSerializationPropBytes()
      • determineInternalType

        protected void determineInternalType()