use of com.vividsolutions.jts.geom.Polygon in project hibernate-orm by hibernate.
the class HANAExpectationsFactory method getTestPolygon.
@Override
public Polygon getTestPolygon() {
WKTReader reader = new WKTReader();
try {
Polygon polygon = (Polygon) reader.read("POLYGON((0 0, 50 0, 90 90, 100 0, 0 0))");
polygon.setSRID(getTestSrid());
return polygon;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
use of com.vividsolutions.jts.geom.Polygon in project hibernate-orm by hibernate.
the class AbstractExpectationsFactory method getTestPolygon.
/**
* Return a testsuite-suite polygon (filter, ...)
*
* @return a testsuite-suite polygon
*/
public Polygon getTestPolygon() {
WKTReader reader = new WKTReader();
try {
Polygon polygon = (Polygon) reader.read(TEST_POLYGON_WKT);
polygon.setSRID(getTestSrid());
return polygon;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
use of com.vividsolutions.jts.geom.Polygon in project alliance by codice.
the class DAGConverter method convertShape.
private String convertShape(Any any, boolean swapCoordinates) {
org.codice.alliance.nsili.common.UCO.Rectangle rectangle = RectangleHelper.extract(any);
org.codice.alliance.nsili.common.UCO.Coordinate2d upperLeft = rectangle.upper_left;
org.codice.alliance.nsili.common.UCO.Coordinate2d lowerRight = rectangle.lower_right;
Geometry geom;
final WKTWriter wktWriter = new WKTWriter();
if (upperLeft.x == lowerRight.x && upperLeft.y == lowerRight.y) {
// Build a Point vs Polygon
Coordinate pointCoord;
if (swapCoordinates) {
pointCoord = new Coordinate(upperLeft.y, upperLeft.x);
} else {
pointCoord = new Coordinate(upperLeft.x, upperLeft.y);
}
geom = GEOMETRY_FACTORY.createPoint(pointCoord);
} else {
Coordinate[] coordinates = new Coordinate[5];
Coordinate lowerLeftCoord;
Coordinate upperLeftCoord;
Coordinate upperRightCoord;
Coordinate lowerRightCoord;
if (swapCoordinates) {
lowerLeftCoord = new Coordinate(upperLeft.y, lowerRight.x);
upperLeftCoord = new Coordinate(upperLeft.y, upperLeft.x);
upperRightCoord = new Coordinate(lowerRight.y, upperLeft.x);
lowerRightCoord = new Coordinate(lowerRight.y, lowerRight.x);
} else {
lowerLeftCoord = new Coordinate(upperLeft.x, lowerRight.y);
upperLeftCoord = new Coordinate(upperLeft.x, upperLeft.y);
upperRightCoord = new Coordinate(lowerRight.x, upperLeft.y);
lowerRightCoord = new Coordinate(lowerRight.x, lowerRight.y);
}
coordinates[0] = lowerLeftCoord;
coordinates[1] = upperLeftCoord;
coordinates[2] = upperRightCoord;
coordinates[3] = lowerRightCoord;
coordinates[4] = lowerLeftCoord;
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
geom = new Polygon(shell, null, GEOMETRY_FACTORY);
}
return wktWriter.write(geom);
}
use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.
the class Fgdb2iox method readGeometry.
private IomObject readGeometry() throws IOException, ParseException, IoxException {
dis.setOrder(ByteOrderValues.LITTLE_ENDIAN);
int typeInt = dis.readInt();
int geometryType = typeInt & EsriShpConstants.shapeBasicTypeMask;
if (geometryType == EsriShpConstants.ShapeNull) {
return null;
}
// determine if Z values are present
hasZ = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasZs) != 0);
boolean hasM = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointM || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointM || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineM || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonM || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasMs) != 0);
boolean hasCurves = (geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon) && (typeInt & EsriShpConstants.shapeNonBasicModifierMask) != 0 || (typeInt & EsriShpConstants.shapeHasCurves) != 0;
inputDimension = hasZ ? 3 : 2;
// only allocate ordValues buffer if necessary
if (ordValues == null || ordValues.length < inputDimension)
ordValues = new double[inputDimension];
if (geometryType == EsriShpConstants.ShapePoint || geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeGeneralPoint) {
double x = dis.readDouble();
double y = dis.readDouble();
IomObject ret = new ch.interlis.iom_j.Iom_jObject("COORD", null);
ret.setattrvalue("C1", Double.toString(x));
ret.setattrvalue("C2", Double.toString(y));
if (hasZ) {
double z = dis.readDouble();
ret.setattrvalue("C3", Double.toString(z));
}
return ret;
}
if (geometryType == EsriShpConstants.ShapeGeneralMultiPatch) {
throw new IoxException("unexpected geometryType " + geometryType);
}
// boundingBox
double min_x = dis.readDouble();
double min_y = dis.readDouble();
double max_x = dis.readDouble();
double max_y = dis.readDouble();
// cParts
int cParts = 0;
int[] partStart = null;
if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
} else {
cParts = dis.readInt();
partStart = new int[cParts];
}
// cPoints
int cPoints = dis.readInt();
// parts[cParts]
if (cParts > 0) {
for (int i = 0; i < cParts; i++) {
partStart[i] = dis.readInt();
}
}
// points[cPoints]
Coordinate[] points = new Coordinate[cPoints];
for (int i = 0; i < cPoints; i++) {
points[i] = new Coordinate();
points[i].x = dis.readDouble();
points[i].y = dis.readDouble();
}
if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
throw new IoxException("unexpected geometryType " + geometryType);
} else if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
} else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
} else {
throw new IoxException("unexpected geometryType " + geometryType);
}
if (hasZ) {
double min_z = dis.readDouble();
double max_z = dis.readDouble();
// Zs[cPoints]
for (int i = 0; i < cPoints; i++) {
points[i].z = dis.readDouble();
}
}
if (hasM) {
double min_m = dis.readDouble();
double max_m = dis.readDouble();
// Ms[cPoints]
for (int i = 0; i < cPoints; i++) {
// ignore
dis.readDouble();
}
}
java.util.Map<Integer, Arc> arcs = null;
if (hasCurves) {
int cSegmentModifiers = dis.readInt();
arcs = new java.util.HashMap<Integer, Arc>();
for (int i = 0; i < cSegmentModifiers; i++) {
int startPointIndex = dis.readInt();
int segmentType = dis.readInt();
if (segmentType == EsriShpConstants.segmentArc) {
double v1 = dis.readDouble();
double v2 = dis.readDouble();
int bits = dis.readInt();
// int skip1=dis.readInt();
if ((bits & EsriShpConstants.arcIsEmpty) != 0) {
// skip it
} else if ((bits & EsriShpConstants.arcIsLine) != 0) {
// straight line, skip it
} else if ((bits & EsriShpConstants.arcIsPoint) != 0) {
throw new IoxException("not supported SegmentArc.Bits " + bits);
} else if ((bits & EsriShpConstants.arcDefinedIP) != 0) {
// throw new IoxException("not supported SegmentArc.Bits "+bits);
} else {
if ((bits & EsriShpConstants.arcIsCCW) != 0) {
// counterclockwise
} else {
// clockwise
}
}
// double skip1=dis.readDouble();
// double skip2=dis.readDouble();
// double skip3=dis.readDouble();
arcs.put(startPointIndex, new Arc(startPointIndex, v1, v2, bits));
} else if (segmentType == EsriShpConstants.segmentLine) {
// will never appear; should be ignored
} else if (segmentType == EsriShpConstants.segmentSpiral) {
} else if (segmentType == EsriShpConstants.segmentBezier3Curve) {
// two middle control points
double skip1 = dis.readDouble();
double skip2 = dis.readDouble();
double skip3 = dis.readDouble();
double skip4 = dis.readDouble();
} else if (segmentType == EsriShpConstants.segmentEllipticArc) {
// center
double skip1 = dis.readDouble();
double skip2 = dis.readDouble();
// rotation or fromV
double skip3 = dis.readDouble();
// semiMajor
double skip4 = dis.readDouble();
// minorMajorRatio or deltaV
double skip5 = dis.readDouble();
// bits
int skip6 = dis.readInt();
} else if (segmentType == 0) {
break;
} else {
throw new IoxException("unexpected segmentType " + segmentType);
// EhiLogger.traceState(("unexpected segmentType "+segmentType));
// continue;
}
}
}
JtsextGeometryFactory fact = new JtsextGeometryFactory();
if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
if (cParts == 1) {
LineString line = getPolyline(fact, 0, points, partStart, arcs, false);
IomObject ret;
try {
ret = Jtsext2iox.JTS2polyline(line);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
return ret;
}
IomObject ret = new Iom_jObject(Wkb2iox.OBJ_MULTIPOLYLINE, null);
for (int i = 0; i < cParts; i++) {
LineString line = getPolyline(fact, i, points, partStart, arcs, false);
try {
IomObject lineObj = Jtsext2iox.JTS2polyline(line);
ret.addattrobj(Wkb2iox.ATTR_POLYLINE, lineObj);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
}
return ret;
} else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
if (cParts == 1) {
LineString line = getPolyline(fact, 0, points, partStart, arcs, true);
if (line.getCoordinateSequence().size() <= 3) {
throw new IoxException("Not a Ring");
}
Polygon polygon = fact.createCurvePolygon(fact.createRing(line));
IomObject ret;
try {
ret = Jtsext2iox.JTS2surface(polygon);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
return ret;
}
ArrayList<LineString> shells = new ArrayList<LineString>();
ArrayList<LineString> holes = new ArrayList<LineString>();
for (int i = 0; i < cParts; i++) {
LineString line = getPolyline(fact, i, points, partStart, arcs, true);
if (line.getCoordinateSequence().size() <= 3) {
throw new IoxException("Not a Ring");
}
if (CGAlgorithms.isCCW(line.getCoordinates())) {
holes.add(line);
} else {
shells.add(line);
}
}
if (shells.size() == 0) {
throw new IoxException("polygon without shell");
} else if (shells.size() == 1) {
LinearRing shell = fact.createRing(shells.get(0));
Polygon polygon = null;
if (holes.size() == 0) {
polygon = fact.createPolygon(shell);
} else {
LinearRing[] hole = new LinearRing[holes.size()];
int i = 0;
for (LineString line : holes) {
hole[i] = fact.createRing(line);
i++;
}
polygon = fact.createPolygon(shell, hole);
}
IomObject ret = null;
try {
ret = Jtsext2iox.JTS2surface(polygon);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
return ret;
} else {
// TODO MultiSurface
}
return null;
} else {
throw new IoxException("unexpected geometryType " + geometryType);
}
}
use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.
the class Iox2fgdb method surface2wkb.
/**
* Converts a SURFACE to a JTS Polygon.
* @param obj INTERLIS SURFACE structure
* @param strokeP maximum stroke to use when removing ARCs
* @return JTS Polygon
* @throws Iox2wkbException
*/
public byte[] surface2wkb(// SurfaceOrAreaType type)
IomObject polygonObj, // SurfaceOrAreaType type)
boolean asCurvePolygon, // SurfaceOrAreaType type)
double strokeP, // SurfaceOrAreaType type)
int srsId) throws IoxException {
if (polygonObj == null) {
return null;
}
byte[] ret = null;
Polygon polygon = Iox2jtsext.surface2JTS(polygonObj, strokeP);
os.reset();
if (asCurvePolygon) {
int shapeType = EsriShpConstants.ShapeGeneralPolygon;
shapeType |= EsriShpConstants.shapeHasCurves;
shapeType |= (outputDimension == 3 ? EsriShpConstants.shapeHasZs : 0);
os.writeInt(shapeType);
} else {
if (outputDimension == 3) {
os.writeInt(EsriShpConstants.ShapePolygonZ);
} else {
os.writeInt(EsriShpConstants.ShapePolygon);
}
}
// boundingBox
Envelope env = polygon.getEnvelopeInternal();
os.writeDouble(env.getMinX());
os.writeDouble(env.getMinY());
os.writeDouble(env.getMaxX());
os.writeDouble(env.getMaxY());
// cParts The number of rings in the polygon.
// cPoints The total number of points for all parts.
int cPart = 1;
int cPoints = getNumPoints(polygon.getExteriorRing());
int holec = polygon.getNumInteriorRing();
cPart += holec;
for (int holei = 0; holei < holec; holei++) {
cPoints += getNumPoints(polygon.getInteriorRingN(holei));
}
os.writeInt(cPart);
os.writeInt(cPoints);
// parts[cParts] An array of length NumParts. Stores, for each Ring, the index of its
// first point in the points array. Array indexes are with respect to 0.
int partStart = 0;
os.writeInt(partStart);
partStart += getNumPoints(polygon.getExteriorRing());
for (int holei = 0; holei < holec; holei++) {
os.writeInt(partStart);
partStart += getNumPoints(polygon.getInteriorRingN(holei));
}
java.util.ArrayList<Arc> arcs = null;
if (asCurvePolygon) {
arcs = new java.util.ArrayList<Arc>();
}
java.util.ArrayList<Double> zv = null;
if (outputDimension == 3) {
zv = new java.util.ArrayList<Double>();
}
double[] zMin = new double[1];
double[] zMax = new double[1];
{
Coordinate coord = polygon.getExteriorRing().getStartPoint().getCoordinate();
if (outputDimension == 3) {
zMin[0] = coord.z;
zMax[0] = coord.z;
}
}
// shell is always in clockwise order
// holes are in a counterclockwise direction
LineString polyline = polygon.getExteriorRing();
int startPtIdx = 0;
polyline = asOneLine(polyline);
if (CGAlgorithms.isCCW(polyline.getCoordinates())) {
polyline = (LineString) polyline.reverse();
}
writePoints(polyline, false, zv, zMin, zMax, startPtIdx, arcs);
startPtIdx += getNumPoints(polyline);
for (int holei = 0; holei < holec; holei++) {
polyline = polygon.getInteriorRingN(holei);
polyline = asOneLine(polyline);
if (!CGAlgorithms.isCCW(polyline.getCoordinates())) {
polyline = (LineString) polyline.reverse();
}
writePoints(polyline, true, zv, zMin, zMax, startPtIdx, arcs);
startPtIdx += getNumPoints(polyline);
}
if (outputDimension == 3) {
// zMin
os.writeDouble(zMin[0]);
// zMax
os.writeDouble(zMax[0]);
// Zs[cPoints]
for (Double z : zv) {
os.writeDouble(z);
}
}
if (asCurvePolygon) {
writeArcs(arcs);
}
ret = os.toByteArray();
return ret;
}
Aggregations