use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class RobustLineIntersectionTest method checkIntersectionNone.
void checkIntersectionNone(final String wkt1, final String wkt2) throws ParseException {
final LineString l1 = (LineString) this.geometryFactory.geometry(wkt1);
final LineString l2 = (LineString) this.geometryFactory.geometry(wkt2);
final Point[] pt = new Point[] { l1.getPoint(0), l1.getPoint(1), l2.getPoint(0), l2.getPoint(1) };
checkIntersection(pt, 0, 0, null);
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class LineStringGenerator method newGeometry.
/**
* As the user increases the number of points, the probability of creating a random valid linestring decreases.
* Please take not of this when selecting the generation style, and the number of points.
*
* May return null if a geometry could not be created.
*
* @see #getNumberPoints()
* @see #setNumberPoints(int)
* @see #getGenerationAlgorithm()
* @see #setGenerationAlgorithm(int)
*
* @see #VERT
* @see #HORZ
* @see #ARC
*
* @see com.revolsys.geometry.testold.generator.GeometryGenerator#newIterator()
*
* @throws IllegalStateException When the alg is not valid or the number of points is invalid
* @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
*/
@Override
public Geometry newGeometry() {
if (this.geometryFactory == null) {
throw new NullPointerException("GeometryFactoryI is not declared");
}
if (this.boundingBox == null || this.boundingBox.isEmpty()) {
throw new NullPointerException("Bounding Box is not declared");
}
if (this.numberPoints < 2) {
throw new IllegalStateException("Too few points");
}
final Point[] coords = new Point[this.numberPoints];
// base x
final double x = this.boundingBox.getMinX();
final double dx = this.boundingBox.getMaxX() - x;
// base y
final double y = this.boundingBox.getMinY();
final double dy = this.boundingBox.getMaxY() - y;
for (int i = 0; i < RUNS; i++) {
switch(getGenerationAlgorithm()) {
case VERT:
fillVert(x, dx, y, dy, coords, this.geometryFactory);
break;
case HORZ:
fillHorz(x, dx, y, dy, coords, this.geometryFactory);
break;
case ARC:
fillArc(x, dx, y, dy, coords, this.geometryFactory);
break;
default:
throw new IllegalStateException("Invalid Alg. Specified");
}
final LineString ls = this.geometryFactory.lineString(coords);
final IsValidOp valid = new IsValidOp(ls);
if (valid.isValid()) {
return ls;
}
}
return null;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class ArcSdeStGeometryFieldDefinition method getParts.
public static List<List<Geometry>> getParts(final Geometry geometry) {
final List<List<Geometry>> partsList = new ArrayList<>();
if (geometry != null) {
final ClockDirection expectedRingOrientation = ClockDirection.COUNTER_CLOCKWISE;
for (final Geometry part : geometry.geometries()) {
if (!part.isEmpty()) {
if (part instanceof Point) {
final Point point = (Point) part;
partsList.add(Collections.<Geometry>singletonList(point));
} else if (part instanceof LineString) {
final LineString line = (LineString) part;
partsList.add(Collections.<Geometry>singletonList(line));
} else if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
final List<Geometry> ringList = new ArrayList<>();
ClockDirection partExpectedRingOrientation = expectedRingOrientation;
for (LinearRing ring : polygon.rings()) {
final ClockDirection ringOrientation = ring.getClockDirection();
if (ringOrientation != partExpectedRingOrientation) {
ring = ring.reverse();
}
ringList.add(ring);
if (partExpectedRingOrientation == expectedRingOrientation) {
partExpectedRingOrientation = expectedRingOrientation.opposite();
}
}
partsList.add(ringList);
}
}
}
}
return partsList;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class PackedCoordinateUtil method getPointsMultiPart.
@SuppressWarnings("unused")
private static List<LineString> getPointsMultiPart(final int vertexCount, final Double xOffset, final Double yOffset, final Double xyScale, final Double zOffset, final Double zScale, final Double mOffset, final Double mScale, final InputStream inputStream) {
try (final PackedIntegerInputStream in = new PackedIntegerInputStream(inputStream)) {
final List<double[]> pointsList = new ArrayList<>();
final long packedByteLength = in.readLong5();
final long dimensionFlag = in.readLong();
final int annotationDimension = in.read();
final int shapeFlags = in.read();
final boolean hasZ = (dimensionFlag & 0x01) == 0x01;
final boolean hasM = (dimensionFlag & 0x02) == 0x02;
int axisCount;
if (hasM) {
axisCount = 4;
} else if (hasZ) {
axisCount = 3;
} else {
axisCount = 2;
}
final double[] coordinates = new double[vertexCount * axisCount];
long previousX = Math.round(xOffset * xyScale);
long previousY = Math.round(yOffset * xyScale);
int j = 0;
for (int i = 0; i < vertexCount; i++) {
final long deltaX = in.readLong();
final long deltaY = in.readLong();
previousX = previousX + deltaX;
previousY = previousY + deltaY;
final double x = previousX / xyScale;
final double y = previousY / xyScale;
if (previousX == -1 && previousY == 0) {
final double[] subCoordinates = new double[j * axisCount];
System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
pointsList.add(subCoordinates);
j = 0;
} else {
final int xIndex = j * axisCount;
coordinates[xIndex] = x;
coordinates[xIndex + 1] = y;
j++;
}
}
if (coordinates.length == axisCount * j) {
pointsList.add(coordinates);
} else {
final double[] subCoordinates = new double[j * axisCount];
System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
pointsList.add(subCoordinates);
}
if (hasZ) {
getPointsMultiPartZorM(in, pointsList, axisCount, 2, zOffset, zScale);
}
if (hasM) {
getPointsMultiPartZorM(in, pointsList, axisCount, 3, mOffset, mScale);
}
final List<LineString> lists = new ArrayList<>();
for (final double[] partCoordinates : pointsList) {
lists.add(new LineStringDouble(axisCount, partCoordinates));
}
return lists;
} catch (final IOException e) {
throw new RuntimeException("Error reading coordinates", e);
} finally {
FileUtil.closeSilent(inputStream);
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class PackedCoordinateUtil method getMultiPolygonPoints.
@SuppressWarnings("unused")
private static List<List<LineString>> getMultiPolygonPoints(final int vertexCount, final Double xOffset, final Double yOffset, final Double xyScale, final Double zOffset, final Double zScale, final Double mOffset, final Double mScale, final InputStream inputStream) {
try (final PackedIntegerInputStream in = new PackedIntegerInputStream(inputStream)) {
final List<List<double[]>> parts = new ArrayList<>();
final long packedByteLength = in.readLong5();
final long dimensionFlag = in.readLong();
final int annotationDimension = in.read();
final int shapeFlags = in.read();
final boolean hasZ = (dimensionFlag & 0x01) == 0x01;
final boolean hasM = (dimensionFlag & 0x02) == 0x02;
int axisCount;
if (hasM) {
axisCount = 4;
} else if (hasZ) {
axisCount = 3;
} else {
axisCount = 2;
}
List<double[]> pointsList = new ArrayList<>();
final double[] coordinates = new double[vertexCount * axisCount];
long previousX = Math.round(xOffset * xyScale);
long previousY = Math.round(yOffset * xyScale);
int j = 0;
for (int i = 0; i < vertexCount; i++) {
final long deltaX = in.readLong();
final long deltaY = in.readLong();
previousX = previousX + deltaX;
previousY = previousY + deltaY;
final double x = previousX / xyScale;
final double y = previousY / xyScale;
if (previousX == -1 && previousY == 0 || x == -1 && y == 0) {
if (!pointsList.isEmpty()) {
parts.add(pointsList);
}
pointsList = new ArrayList<>();
} else {
coordinates[j * axisCount] = x;
coordinates[j * axisCount + 1] = y;
if (j > 0 && i < vertexCount - 1) {
if (coordinates[0] == x && coordinates[1] == y) {
if (j > 2) {
final double[] subCoordinates = new double[j * axisCount + axisCount];
System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
pointsList.add(subCoordinates);
}
j = 0;
} else {
j++;
}
} else {
j++;
}
}
}
if (j > 2) {
if (coordinates.length == axisCount * j) {
pointsList.add(coordinates);
} else {
final double[] subCoordinates = new double[j * axisCount];
System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
pointsList.add(subCoordinates);
}
}
if (!pointsList.isEmpty()) {
parts.add(pointsList);
}
if (hasZ) {
getMultiPolygonPointsZorM(in, parts, axisCount, 2, zOffset, zScale);
}
if (hasM) {
getMultiPolygonPointsZorM(in, parts, axisCount, 3, mOffset, mScale);
}
final List<List<LineString>> lists = new ArrayList<>();
for (final List<double[]> part : parts) {
final List<LineString> list = new ArrayList<>();
lists.add(list);
for (final double[] partCoordinates : part) {
list.add(new LineStringDouble(axisCount, partCoordinates));
}
}
return lists;
} catch (final IOException e) {
throw new RuntimeException("Error reading coordinates", e);
} finally {
FileUtil.closeSilent(inputStream);
}
}
Aggregations