Skip to content

Commit

Permalink
TWKB read and write implementation
Browse files Browse the repository at this point in the history
Initial work by James Hughes <jnhuva@gmail.com>, resumed by Jody Garnett <jody.garnett@gmail.com>, Gabriel Roldan <gabriel.roldan@gmail.com> and Aurélien Mino <aurelien.mino@gmail.com>
  • Loading branch information
murdos committed May 4, 2022
1 parent 2857340 commit 308391d
Show file tree
Hide file tree
Showing 24 changed files with 3,031 additions and 5 deletions.
1 change: 1 addition & 0 deletions build-tools/src/main/resources/jts/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<suppress files="Varint.java" checks="Header"/>
<suppress files="[\\/]test[\\/]" checks="[a-zA-Z0-9]*"/>
</suppressions>
4 changes: 2 additions & 2 deletions modules/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<artifactId>jts-core</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<packaging>bundle</packaging>

<properties>
<lint>unchecked</lint>
<doclint>none</doclint>
</properties>

<build>
<plugins>
<plugin>
Expand Down
5 changes: 5 additions & 0 deletions modules/io/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019 Gabriel Roldan, 2022 Aurélien Mino
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
*
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.locationtech.jts.io.twkb;

import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.CoordinateSequenceFilter;

class BoundsExtractor implements CoordinateSequenceFilter {

private final int dimensions;

double[] ordinates = new double[]{ //
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, // note, Double.MIN_VALUE is positive
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, //
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, //
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY//
};

BoundsExtractor(int dimensions) {
this.dimensions = dimensions;
}

public @Override
void filter(final CoordinateSequence seq, final int coordIndex) {
for (int ordinateIndex = 0; ordinateIndex < dimensions; ordinateIndex++) {
final double ordinate = seq.getOrdinate(coordIndex, ordinateIndex);
final int minIndex = 2 * ordinateIndex;
final int maxIndex = minIndex + 1;
ordinates[minIndex] = Math.min(ordinates[minIndex], ordinate);
ordinates[maxIndex] = Math.max(ordinates[maxIndex], ordinate);
}
}

@Override
public boolean isDone() {
return false;
}

@Override
public boolean isGeometryChanged() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 Gabriel Roldan, 2022 Aurélien Mino
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
*
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.locationtech.jts.io.twkb;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

class BufferedTKWBOutputStream extends TWKBOutputStream {

public static BufferedTKWBOutputStream create() {
BufferedDataOutput buff = BufferedDataOutput.create();
return new BufferedTKWBOutputStream(buff);
}

public int size() {
return ((BufferedDataOutput) super.out).writtenSize();
}

private BufferedTKWBOutputStream(BufferedDataOutput buff) {
super(buff);
}

public void writeTo(TWKBOutputStream out) throws IOException {
BufferedDataOutput bufferedOut = ((BufferedDataOutput) super.out);
int size = bufferedOut.writtenSize();
byte[] buff = bufferedOut.buffer();
out.write(buff, 0, size);
}

private static class BufferedDataOutput extends DataOutputStream {

static BufferedDataOutput create() {
return new BufferedDataOutput(new InternalByteArrayOutputStream());
}

public int writtenSize() {
return ((InternalByteArrayOutputStream) super.out).size();
}

public byte[] buffer() {
return ((InternalByteArrayOutputStream) super.out).buffer();
}

BufferedDataOutput(InternalByteArrayOutputStream out) {
super(out);
}

private static class InternalByteArrayOutputStream extends ByteArrayOutputStream {
public byte[] buffer() {
return super.buf;
}
}
}
}

0 comments on commit 308391d

Please sign in to comment.