Search in sources :

Example 6 with Polygon

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;
}
Also used : OGCPoint(com.esri.core.geometry.ogc.OGCPoint) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) Polygon(com.esri.core.geometry.Polygon) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) HashSet(java.util.HashSet)

Example 7 with Polygon

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());
}
Also used : Line(com.esri.core.geometry.Line) DataBag(org.apache.pig.data.DataBag) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) Point(com.esri.core.geometry.Point) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) Polygon(com.esri.core.geometry.Polygon) DataByteArray(org.apache.pig.data.DataByteArray) Point(com.esri.core.geometry.Point) Tuple(org.apache.pig.data.Tuple) Segment(com.esri.core.geometry.Segment)

Example 8 with Polygon

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);
}
Also used : MultiPoint(com.esri.core.geometry.MultiPoint) MultiPath(com.esri.core.geometry.MultiPath) GeometryWrapper(org.apache.sis.internal.feature.GeometryWrapper) MultiPoint(com.esri.core.geometry.MultiPoint) Point(com.esri.core.geometry.Point) Geometry(com.esri.core.geometry.Geometry) Line(com.esri.core.geometry.Line) Polyline(com.esri.core.geometry.Polyline) Collection(java.util.Collection) Polygon(com.esri.core.geometry.Polygon)

Example 9 with Polygon

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"));
}
Also used : Point(com.esri.core.geometry.Point) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Polygon(com.esri.core.geometry.Polygon)

Aggregations

Polygon (com.esri.core.geometry.Polygon)9 Point (com.esri.core.geometry.Point)8 Line (com.esri.core.geometry.Line)3 Polyline (com.esri.core.geometry.Polyline)3 OGCPolygon (com.esri.core.geometry.ogc.OGCPolygon)3 MultiPath (com.esri.core.geometry.MultiPath)2 MultiPoint (com.esri.core.geometry.MultiPoint)2 Segment (com.esri.core.geometry.Segment)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)2 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)2 DataBag (org.apache.pig.data.DataBag)2 DataByteArray (org.apache.pig.data.DataByteArray)2 Tuple (org.apache.pig.data.Tuple)2 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)2 Point (android.graphics.Point)1 Geometry (com.esri.core.geometry.Geometry)1 OGCConcreteGeometryCollection (com.esri.core.geometry.ogc.OGCConcreteGeometryCollection)1 OGCGeometryCollection (com.esri.core.geometry.ogc.OGCGeometryCollection)1 OGCLineString (com.esri.core.geometry.ogc.OGCLineString)1 CartesianPoint (com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint)1