use of com.vividsolutions.jts.geom.LinearRing in project incubator-rya by apache.
the class MongoGeoIndexerIT method testDcSearchWithSubjectAndContext.
@Test
public void testDcSearchWithSubjectAndContext() throws Exception {
// test a ring around dc
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
f.setConf(conf);
f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
final URI predicate = GeoConstants.GEO_AS_WKT;
final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
final Resource context = vf.createURI("foo:context");
final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
f.storeStatement(convertStatement(statement));
f.flush();
final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
// query with correct context subject
assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
// query with wrong context
assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
// query with wrong subject
assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
}
}
use of com.vividsolutions.jts.geom.LinearRing in project incubator-rya by apache.
the class MongoGeoIndexerIT method testPrimeMeridianSearch.
@Test
public void testPrimeMeridianSearch() throws Exception {
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
f.setConf(conf);
f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
final URI predicate = GeoConstants.GEO_AS_WKT;
final Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
final Resource context = vf.createURI("foo:context");
final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
f.storeStatement(convertStatement(statement));
f.flush();
final double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 };
final double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 };
final double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 };
final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
final LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2));
final LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2));
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
final Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
final Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
// Test a ring with a hole in it
final Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
// test a ring outside the point
final double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
}
}
use of com.vividsolutions.jts.geom.LinearRing in project alliance by codice.
the class NitfImageTransformer method getPolygonForSegment.
private Polygon getPolygonForSegment(ImageSegment segment, GeometryFactory geomFactory) {
Coordinate[] coords = new Coordinate[5];
ImageCoordinates imageCoordinates = segment.getImageCoordinates();
coords[0] = new Coordinate(imageCoordinates.getCoordinate00().getLongitude(), imageCoordinates.getCoordinate00().getLatitude());
coords[4] = new Coordinate(coords[0]);
coords[1] = new Coordinate(imageCoordinates.getCoordinate0MaxCol().getLongitude(), imageCoordinates.getCoordinate0MaxCol().getLatitude());
coords[2] = new Coordinate(imageCoordinates.getCoordinateMaxRowMaxCol().getLongitude(), imageCoordinates.getCoordinateMaxRowMaxCol().getLatitude());
coords[3] = new Coordinate(imageCoordinates.getCoordinateMaxRow0().getLongitude(), imageCoordinates.getCoordinateMaxRow0().getLatitude());
LinearRing externalRing = geomFactory.createLinearRing(coords);
return geomFactory.createPolygon(externalRing, null);
}
use of com.vividsolutions.jts.geom.LinearRing 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.LinearRing 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);
}
}
Aggregations