use of com.esri.core.geometry.Polygon in project presto by prestodb.
the class GeometryUtils method isPointOrRectangle.
public static boolean isPointOrRectangle(OGCGeometry ogcGeometry, Envelope envelope) {
if (ogcGeometry instanceof OGCPoint) {
return true;
}
if (!(ogcGeometry instanceof OGCPolygon)) {
return false;
}
Polygon polygon = (Polygon) ogcGeometry.getEsriGeometry();
if (polygon.getPathCount() > 1) {
return false;
}
if (polygon.getPointCount() != 4) {
return false;
}
Set<Point> corners = new HashSet<>();
corners.add(new Point(envelope.getXMin(), envelope.getYMin()));
corners.add(new Point(envelope.getXMin(), envelope.getYMax()));
corners.add(new Point(envelope.getXMax(), envelope.getYMin()));
corners.add(new Point(envelope.getXMax(), envelope.getYMax()));
for (int i = 0; i < 4; i++) {
Point point = polygon.getPoint(i);
if (!corners.contains(point)) {
return false;
}
}
return true;
}
use of com.esri.core.geometry.Polygon in project pigeon by aseldawy.
the class MakePolygon method exec.
@Override
public DataByteArray exec(Tuple b) throws IOException {
DataBag points = (DataBag) b.get(0);
Point[] coordinates = new Point[(int) points.size()];
int i = 0;
for (Tuple t : points) {
coordinates[i++] = (Point) (geometryParser.parseGeom(t.get(0))).getEsriGeometry();
}
Polygon multi_path = new Polygon();
for (i = 1; i < coordinates.length; i++) {
Segment segment = new Line();
segment.setStart(coordinates[i - 1]);
segment.setEnd(coordinates[i]);
multi_path.addSegment(segment, false);
}
OGCPolygon linestring = new OGCPolygon(multi_path, 0, SpatialReference.create(4326));
return new DataByteArray(linestring.asBinary().array());
}
use of com.esri.core.geometry.Polygon in project sis by apache.
the class Factory method createFromComponents.
/**
* Creates a geometry from components.
* The expected {@code components} type depend on the target geometry type:
* <ul>
* <li>If {@code type} is a multi-geometry, then the components shall be an array of {@link Point},
* {@link Geometry}, {@link Polyline} or {@link Polygon} elements, depending on the desired target type.</li>
* <li>Otherwise the components shall be an array or collection of {@link Point} instances.</li>
* </ul>
*
* @param type type of geometry to create.
* @param components the components. Valid classes depend on the type of geometry to create.
* @return geometry built from the given components.
* @throws ClassCastException if the given object is not an array or a collection of supported geometry components.
*/
@Override
public GeometryWrapper<Geometry> createFromComponents(final GeometryType type, final Object components) {
/*
* No exhaustive `if (x instanceof y)` checks in this method.
* `ClassCastException` shall be handled by the caller.
*/
final Collection<?> data = (components instanceof Collection<?>) ? (Collection<?>) components : Arrays.asList((Object[]) components);
/*
* ESRI API does not distinguish between single geometry and geometry collection, except MultiPoint.
* So if the number of components is 1, there is no reason to create a new geometry object.
*/
Geometry geometry = (Geometry) CollectionsExt.singletonOrNull(data);
if (geometry == null) {
boolean isPolygon = false;
switch(type) {
case MULTI_LINESTRING:
case LINESTRING:
break;
case MULTI_POLYGON:
case POLYGON:
isPolygon = true;
break;
case GEOMETRY_COLLECTION:
{
for (final Object component : data) {
isPolygon = (((Geometry) component).getType() == Geometry.Type.Polygon);
if (!isPolygon)
break;
}
break;
}
// Default to multi-points for now.
case GEOMETRY:
case POINT:
case MULTI_POINT:
{
final MultiPoint points = new MultiPoint();
for (final Object p : data) {
points.add((Point) p);
}
geometry = points;
if (type == GeometryType.POINT) {
geometry = new Point(OperatorCentroid2D.local().execute(geometry, null));
}
break;
}
default:
throw new AssertionError(type);
}
if (geometry == null) {
final MultiPath path = isPolygon ? new Polygon() : new Polyline();
if (type.isCollection()) {
for (final Object component : data) {
path.add((MultiPath) component, false);
}
} else {
final Iterator<?> it = data.iterator();
if (it.hasNext()) {
final Line segment = new Line();
segment.setEnd((Point) it.next());
while (it.hasNext()) {
segment.setStartXY(segment.getEndX(), segment.getEndY());
segment.setEnd((Point) it.next());
path.addSegment(segment, false);
}
}
}
geometry = path;
}
}
return new Wrapper(geometry);
}
use of com.esri.core.geometry.Polygon in project sis by apache.
the class FeatureOperationsTest method run.
/**
* Implementation of {@link #testDenseFeature()} and {@link #testSparseFeature()} methods.
*/
private static void run(final AbstractFeature feature) {
assertNull("Before a geometry is set", feature.getPropertyValue("bounds"));
GeneralEnvelope expected;
// Set one geometry
Polygon classes = new Polygon();
classes.startPath(10, 20);
classes.lineTo(10, 30);
classes.lineTo(15, 30);
classes.lineTo(15, 20);
feature.setPropertyValue("classes", classes);
expected = new GeneralEnvelope(HardCodedCRS.WGS84_LATITUDE_FIRST);
expected.setRange(0, 10, 15);
expected.setRange(1, 20, 30);
assertEnvelopeEquals(expected, (Envelope) feature.getPropertyValue("bounds"));
// Set second geometry
Point wall = new Point(18, 40);
feature.setPropertyValue("climbing wall", wall);
expected = new GeneralEnvelope(HardCodedCRS.WGS84_LATITUDE_FIRST);
expected.setRange(0, 10, 18);
expected.setRange(1, 20, 40);
assertEnvelopeEquals(expected, (Envelope) feature.getPropertyValue("bounds"));
// Set third geometry. This geometry has CRS axis order reversed.
Polygon gymnasium = new Polygon();
gymnasium.startPath(-5, -30);
gymnasium.lineTo(-6, -30);
gymnasium.lineTo(-6, -31);
gymnasium.lineTo(-5, -31);
feature.setPropertyValue("gymnasium", gymnasium);
expected = new GeneralEnvelope(HardCodedCRS.WGS84_LATITUDE_FIRST);
expected.setRange(0, -31, 18);
expected.setRange(1, -6, 40);
assertEnvelopeEquals(expected, (Envelope) feature.getPropertyValue("bounds"));
}
Aggregations