Skip to content

Commit

Permalink
support EMPTY geometries (claeis/ili2db#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
claeis committed Mar 20, 2020
1 parent 592a6c8 commit 347777f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ideas/open issues
LATEST
-----------------------------
- Validator: ArrayIndexOutOfBoundsException with n-ary association (ilivalidator#232)
- Wkb2iox: support EMPTY geometries (ili2db#338)

iox-ili 1.20.17 (2020-03-01)
-----------------------------
Expand Down
47 changes: 40 additions & 7 deletions src/main/java/ch/interlis/iox_j/wkb/Wkb2iox.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ private IomObject setSRID(IomObject g)
private IomObject readPoint() throws IOException
{
readCoordinate();
if(Double.isNaN(ordValues[0]) && Double.isNaN(ordValues[1])) {
// POINT EMPTY
return null;
}
IomObject ret=new ch.interlis.iom_j.Iom_jObject("COORD",null);
ret.setattrvalue("C1", Double.toString(ordValues[0]));
ret.setattrvalue("C2", Double.toString(ordValues[1]));
Expand All @@ -220,8 +224,12 @@ private IomObject readPoint() throws IOException
}
private IomObject readMultiPoint() throws IOException
{
int coordc = dis.readInt();
if(coordc==0) {
// MULTIPOINT EMPTY
return null;
}
IomObject ret=new ch.interlis.iom_j.Iom_jObject(OBJ_MULTICOORD,null);
int coordc = dis.readInt();
for(int coordi=0;coordi<coordc;coordi++){
byte byteOrder = dis.readByte();
int typeInt = dis.readInt();
Expand All @@ -244,10 +252,14 @@ private IomObject readLineString() throws IOException
// <byte order> <wkblinestring> [ <num> <wkbpoint binary>... ]
// <wkblinearring> ::= <num> <wkbpoint binary>...

int coordc = dis.readInt();
if(coordc==0) {
// LINESTRING EMPTY
return null;
}
IomObject ret=new ch.interlis.iom_j.Iom_jObject("POLYLINE",null);
IomObject sequence=new ch.interlis.iom_j.Iom_jObject("SEGMENTS",null);
ret.addattrobj("sequence",sequence);
int coordc = dis.readInt();
for(int coordi=0;coordi<coordc;coordi++){
sequence.addattrobj("segment", readPoint());
}
Expand All @@ -256,6 +268,10 @@ private IomObject readLineString() throws IOException
private IomObject readCompoundCurve() throws IOException
{
int compc = dis.readInt();
if(compc==0) {
// EMPTY
return null;
}
IomObject ret=new ch.interlis.iom_j.Iom_jObject("POLYLINE",null);
IomObject sequence=new ch.interlis.iom_j.Iom_jObject("SEGMENTS",null);
ret.addattrobj("sequence",sequence);
Expand Down Expand Up @@ -318,7 +334,10 @@ private IomObject readPolygon() throws IOException
// <byte order> <wkbpolygon> [ <num> <wkblinearring binary>... ]
// | <triangle binary representation>
int holec = dis.readInt();

if(holec==0) {
// POLYGON EMPTY
return null;
}
IomObject ret=new ch.interlis.iom_j.Iom_jObject("MULTISURFACE",null);
IomObject surface=new ch.interlis.iom_j.Iom_jObject("SURFACE",null);
ret.addattrobj("surface",surface);
Expand Down Expand Up @@ -346,7 +365,10 @@ private IomObject readCurvePolygon() throws IOException, ParseException


int ringc = dis.readInt();

if(ringc==0) {
// EMPTY
return null;
}
IomObject ret=new ch.interlis.iom_j.Iom_jObject("MULTISURFACE",null);
IomObject surface=new ch.interlis.iom_j.Iom_jObject("SURFACE",null);
ret.addattrobj("surface",surface);
Expand All @@ -373,8 +395,12 @@ private IomObject readMultiPolygon() throws IOException, ParseException
| <triangle binary representation>
*/
IomObject ret=null;
int polygonc = dis.readInt();
if(polygonc==0) {
// MULTIPOLYGON EMPTY
return null;
}
IomObject ret=null;
for(int polygoni=0;polygoni<polygonc;polygoni++){
byte byteOrder = dis.readByte();
int typeInt = dis.readInt();
Expand Down Expand Up @@ -409,8 +435,12 @@ private IomObject readMultiSurface() throws IOException, ParseException
<curvepolygon binary representation>
| <polyhedralsurface binary representation>
*/
IomObject ret=null;
int surfacec = dis.readInt();
if(surfacec==0) {
// EMPTY
return null;
}
IomObject ret=null;
for(int surfacei=0;surfacei<surfacec;surfacei++){
byte byteOrder = dis.readByte();
int typeInt = dis.readInt();
Expand Down Expand Up @@ -442,8 +472,11 @@ private IomObject readMultiCurve(boolean allowCurve) throws IOException, ParseEx
[ <num> <linestring binary representation>... ]
*/
int curvec = dis.readInt();
if(curvec==0) {
return null;
}
IomObject ret=new ch.interlis.iom_j.Iom_jObject(OBJ_MULTIPOLYLINE,null);
int curvec = dis.readInt();
for(int curvei=0;curvei<curvec;curvei++){
byte byteOrder = dis.readByte();
int typeInt = dis.readInt();
Expand Down

0 comments on commit 347777f

Please sign in to comment.