-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API and JavaDoc changes for Spatial Datatypes #752
Changes from 14 commits
73edf05
a09c247
3f694ff
243f294
537959f
862d71d
d86b237
eac074f
79c7e59
81a065f
7ec6fcc
272a729
54c5297
a3eb552
0de6184
b4fca56
3135521
2dfb95b
6f4af3d
8aba9e6
589c1c0
a61a58b
1d7800d
1f3e437
35d99a8
e156263
5ca2a83
2f886a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,19 @@ | |
|
||
package com.microsoft.sqlserver.jdbc; | ||
|
||
import java.nio.BufferUnderflowException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
|
||
/** | ||
* Geography datatype represents data in a round-earth coordinate system. | ||
*/ | ||
|
||
public class Geography extends SQLServerSpatialDatatype { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs class description |
||
|
||
/** | ||
* Private constructor used for creating a Geography object from WKT and srid. | ||
* Private constructor used for creating a Geography object from WKT and Spatial Reference Identifier. | ||
* | ||
* @param WellKnownText | ||
* Well-Known Text (WKT) provided by the user. | ||
|
@@ -22,17 +27,20 @@ public class Geography extends SQLServerSpatialDatatype { | |
* if an exception occurs | ||
*/ | ||
private Geography(String WellKnownText, int srid) throws SQLServerException { | ||
if (null == WellKnownText || WellKnownText.length() <= 0) { | ||
throwIllegalWKT(); | ||
} | ||
|
||
this.wkt = WellKnownText; | ||
this.srid = srid; | ||
|
||
try { | ||
parseWKTForSerialization(this, currentWktPos, -1, false); | ||
} catch (StringIndexOutOfBoundsException e) { | ||
String strError = SQLServerException.getErrString("R_illegalWKT"); | ||
throw new SQLServerException(strError, null, 0, null); | ||
throwIllegalWKT(); | ||
} | ||
|
||
serializeToWkb(false); | ||
serializeToWkb(false, this); | ||
isNull = false; | ||
} | ||
|
||
|
@@ -45,11 +53,19 @@ private Geography(String WellKnownText, int srid) throws SQLServerException { | |
* if an exception occurs | ||
*/ | ||
private Geography(byte[] wkb) throws SQLServerException { | ||
if (null == wkb || wkb.length <= 0) { | ||
throwIllegalWKB(); | ||
} | ||
|
||
this.wkb = wkb; | ||
buffer = ByteBuffer.wrap(wkb); | ||
buffer.order(ByteOrder.LITTLE_ENDIAN); | ||
|
||
parseWkb(); | ||
try { | ||
parseWkb(this); | ||
} catch (BufferUnderflowException e) { | ||
throwIllegalWKB(); | ||
} | ||
|
||
WKTsb = new StringBuffer(); | ||
WKTsbNoZM = new StringBuffer(); | ||
|
@@ -62,8 +78,8 @@ private Geography(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns 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. | ||
* 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. | ||
* | ||
* @param wkt | ||
* Well-Known Text (WKT) provided by the user. | ||
|
@@ -78,7 +94,8 @@ public static Geography STGeomFromText(String wkt, int srid) throws SQLServerExc | |
} | ||
|
||
/** | ||
* Returns a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation. | ||
* Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) | ||
* representation. | ||
* | ||
* @param wkb | ||
* Well-Known Binary (WKB) provided by the user. | ||
|
@@ -91,7 +108,7 @@ public static Geography STGeomFromWKB(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a constructed Geography from an internal SQL Server format for spatial data. | ||
* Constructor for a Geography instance from an internal SQL Server format for spatial data. | ||
* | ||
* @param wkb | ||
* Well-Known Binary (WKB) provided by the user. | ||
|
@@ -104,8 +121,8 @@ public static Geography deserialize(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation. SRID | ||
* is defaulted to 4326. | ||
* Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) | ||
* representation. Spatial Reference Identifier is defaulted to 4326. | ||
* | ||
* @param wkt | ||
* Well-Known Text (WKT) provided by the user. | ||
|
@@ -118,14 +135,15 @@ public static Geography parse(String wkt) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Constructs a Geography instance that represents a Point instance from its X and Y values and an SRID. | ||
* Constructor for a Geography instance that represents a Point instance from its latitude and longitude values and | ||
* a Spatial Reference Identifier. | ||
* | ||
* @param x | ||
* x coordinate | ||
* latitude | ||
* @param y | ||
* y coordinate | ||
* longitude | ||
* @param srid | ||
* SRID | ||
* Spatial Reference Identifier value | ||
* @return Geography Geography instance | ||
* @throws SQLServerException | ||
* if an exception occurs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you missed out on the method params: x and y should be changed to latitude/longitude respectively. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
@@ -147,7 +165,7 @@ public String STAsText() throws SQLServerException { | |
buffer = ByteBuffer.wrap(wkb); | ||
buffer.order(ByteOrder.LITTLE_ENDIAN); | ||
|
||
parseWkb(); | ||
parseWkb(this); | ||
|
||
WKTsb = new StringBuffer(); | ||
WKTsbNoZM = new StringBuffer(); | ||
|
@@ -165,7 +183,7 @@ public String STAsText() throws SQLServerException { | |
*/ | ||
public byte[] STAsBinary() { | ||
if (null == wkbNoZM) { | ||
serializeToWkb(true); | ||
serializeToWkb(true, this); | ||
} | ||
return wkbNoZM; | ||
} | ||
|
@@ -198,25 +216,25 @@ public boolean hasZ() { | |
} | ||
|
||
/** | ||
* Returns the X coordinate value. | ||
* Returns the latitude value. | ||
* | ||
* @return double value that represents the X coordinate. | ||
* @return double value that represents the latitude. | ||
*/ | ||
public Double getX() { | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && points.length == 2) { | ||
return points[0]; | ||
public Double getLatitude() { | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && xValues.length == 1) { | ||
return xValues[0]; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the Y coordinate value. | ||
* Returns the longitude value. | ||
* | ||
* @return double value that represents the Y coordinate. | ||
* @return double value that represents the longitude. | ||
*/ | ||
public Double getY() { | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && points.length == 2) { | ||
return points[1]; | ||
public Double getLongitude() { | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && yValues.length == 1) { | ||
return yValues[0]; | ||
} | ||
return null; | ||
} | ||
|
@@ -302,111 +320,4 @@ public String asTextZM() { | |
public String toString() { | ||
return wkt; | ||
} | ||
|
||
protected void serializeToWkb(boolean noZM) { | ||
ByteBuffer buf = ByteBuffer.allocate(determineWkbCapacity()); | ||
createSerializationProperties(); | ||
|
||
buf.order(ByteOrder.LITTLE_ENDIAN); | ||
buf.putInt(srid); | ||
buf.put(version); | ||
buf.put(serializationProperties); | ||
|
||
if (!isSinglePoint && !isSingleLineSegment) { | ||
buf.putInt(numberOfPoints); | ||
} | ||
|
||
for (int i = 0; i < numberOfPoints; i++) { | ||
buf.putDouble(points[2 * i + 1]); | ||
buf.putDouble(points[2 * i]); | ||
} | ||
|
||
if (!noZM) { | ||
if (hasZvalues) { | ||
for (int i = 0; i < numberOfPoints; i++) { | ||
buf.putDouble(zValues[i]); | ||
} | ||
} | ||
if (hasMvalues) { | ||
for (int i = 0; i < numberOfPoints; i++) { | ||
buf.putDouble(mValues[i]); | ||
} | ||
} | ||
} | ||
|
||
if (isSinglePoint || isSingleLineSegment) { | ||
wkb = buf.array(); | ||
return; | ||
} | ||
|
||
buf.putInt(numberOfFigures); | ||
for (int i = 0; i < numberOfFigures; i++) { | ||
buf.put(figures[i].getFiguresAttribute()); | ||
buf.putInt(figures[i].getPointOffset()); | ||
} | ||
|
||
buf.putInt(numberOfShapes); | ||
for (int i = 0; i < numberOfShapes; i++) { | ||
buf.putInt(shapes[i].getParentOffset()); | ||
buf.putInt(shapes[i].getFigureOffset()); | ||
buf.put(shapes[i].getOpenGISType()); | ||
} | ||
|
||
if (version == 2 && null != segments) { | ||
buf.putInt(numberOfSegments); | ||
for (int i = 0; i < numberOfSegments; i++) { | ||
buf.put(segments[i].getSegmentType()); | ||
} | ||
} | ||
|
||
if (noZM) { | ||
wkbNoZM = buf.array(); | ||
} else { | ||
wkb = buf.array(); | ||
|
||
} | ||
return; | ||
} | ||
|
||
protected void parseWkb() { | ||
srid = buffer.getInt(); | ||
version = buffer.get(); | ||
serializationProperties = buffer.get(); | ||
|
||
interpretSerializationPropBytes(); | ||
readNumberOfPoints(); | ||
readPoints(); | ||
|
||
if (hasZvalues) { | ||
readZvalues(); | ||
} | ||
|
||
if (hasMvalues) { | ||
readMvalues(); | ||
} | ||
|
||
if (!(isSinglePoint || isSingleLineSegment)) { | ||
readNumberOfFigures(); | ||
readFigures(); | ||
readNumberOfShapes(); | ||
readShapes(); | ||
} | ||
|
||
determineInternalType(); | ||
|
||
if (buffer.hasRemaining()) { | ||
if (version == 2 && internalType.getTypeCode() != 8 && internalType.getTypeCode() != 11) { | ||
readNumberOfSegments(); | ||
readSegments(); | ||
} | ||
} | ||
} | ||
|
||
private void readPoints() { | ||
points = new double[2 * numberOfPoints]; | ||
for (int i = 0; i < numberOfPoints; i++) { | ||
points[2 * i + 1] = buffer.getDouble(); | ||
points[2 * i] = buffer.getDouble(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to import this?