-
Notifications
You must be signed in to change notification settings - Fork 435
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
73edf05
Added more exceptions for fuzz testing, and added some more javadocs
peterbae a09c247
fixing merge break
peterbae 3f694ff
removing log files
peterbae 243f294
javadoc changes
peterbae 537959f
gets -> returns
peterbae 862d71d
add test
peterbae d86b237
split points into two
peterbae eac074f
move error message around
peterbae 79c7e59
check neg size for all number of sizes
peterbae 81a065f
reflect comments + make internal spatial datatype file protected
peterbae 7ec6fcc
more javadoc changes
peterbae 272a729
switch lat/long
peterbae 54c5297
refactor out duplicate code
peterbae a3eb552
add null checking + change int to long
peterbae 0de6184
handle m and z value being null case and add test
peterbae b4fca56
reuse function
peterbae 3135521
move this part to other PR
peterbae 2dfb95b
reflect comment
peterbae 6f4af3d
bit more javadoc
peterbae 8aba9e6
remove StringIndexOutOfBoundsException
peterbae 589c1c0
check wkt length
peterbae a61a58b
Merge branch 'dev' into Fuzz_And_Javadoc_fix
peterbae 1d7800d
remove catching runtime exception
peterbae 1f3e437
Merge branch 'Fuzz_And_Javadoc_fix' of https://github.com/peterbae/ms…
peterbae 35d99a8
dont need those imports
peterbae e156263
use try blocks they're the best
peterbae 5ca2a83
refactor throwing illegal WKT position into a method
peterbae 2f886a0
apparently 0 and null are different, so fix that
peterbae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,30 +9,33 @@ | |
import java.nio.ByteOrder; | ||
|
||
|
||
/** | ||
* Geography datatype represents data in a round-earth coordinate system. | ||
*/ | ||
|
||
public class Geography extends SQLServerSpatialDatatype { | ||
|
||
/** | ||
* 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 | ||
* @param wkt | ||
* Well-Known Text (WKT) provided by the user. | ||
* @param srid | ||
* Spatial Reference Identifier (SRID) provided by the user. | ||
* @throws SQLServerException | ||
* if an exception occurs | ||
*/ | ||
private Geography(String WellKnownText, int srid) throws SQLServerException { | ||
this.wkt = WellKnownText; | ||
private Geography(String wkt, int srid) throws SQLServerException { | ||
if (null == wkt || wkt.length() <= 0) { | ||
throwIllegalWKT(); | ||
} | ||
|
||
this.wkt = wkt; | ||
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); | ||
} | ||
parseWKTForSerialization(this, currentWktPos, -1, false); | ||
|
||
serializeToWkb(false); | ||
serializeToWkb(false, this); | ||
isNull = false; | ||
} | ||
|
||
|
@@ -45,11 +48,15 @@ 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(); | ||
parseWkb(this); | ||
|
||
WKTsb = new StringBuffer(); | ||
WKTsbNoZM = new StringBuffer(); | ||
|
@@ -62,8 +69,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 +85,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 +99,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 +112,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,20 +126,21 @@ 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 | ||
* @param y | ||
* y coordinate | ||
* @param lat | ||
* latitude | ||
* @param lon | ||
* 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 |
||
*/ | ||
public static Geography point(double x, double y, int srid) throws SQLServerException { | ||
return new Geography("POINT (" + x + " " + y + ")", srid); | ||
public static Geography point(double lat, double lon, int srid) throws SQLServerException { | ||
return new Geography("POINT (" + lat + " " + lon + ")", srid); | ||
} | ||
|
||
/** | ||
|
@@ -147,7 +156,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 +174,7 @@ public String STAsText() throws SQLServerException { | |
*/ | ||
public byte[] STAsBinary() { | ||
if (null == wkbNoZM) { | ||
serializeToWkb(true); | ||
serializeToWkb(true, this); | ||
} | ||
return wkbNoZM; | ||
} | ||
|
@@ -198,25 +207,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 +311,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(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
needs class description