-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
24 changed files
with
3,031 additions
and
5 deletions.
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
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
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
52 changes: 52 additions & 0 deletions
52
modules/io/common/src/main/java/org/locationtech/jts/io/twkb/BoundsExtractor.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
modules/io/common/src/main/java/org/locationtech/jts/io/twkb/BufferedTKWBOutputStream.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.