Search in sources :

Example 1 with Polygon

use of com.esri.core.geometry.Polygon in project android-gps-test-tool by Esri.

the class DrawCircle method createMercatorCircle.

public void createMercatorCircle(double radius, Point center) {
    double lon1 = degToRad(center.x);
    double lat1 = degToRad(center.y);
    //radius km
    double R_KM = 6371;
    //radius mi
    double R_MI = 3963;
    //double d = radius/R_KM; //angular distance on earth's surface
    double d = radius / R_MI;
    Polygon circle = new Polygon();
    //number of nodes in circle
    int nodes = 100;
    int step = Math.round(360 / nodes);
    int n = 0;
    double[] pointArray;
    for (int x = 0; x <= 360; x++) {
        int z = Math.round(n += step);
        double bearing = degToRad(x);
        double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d) + Math.cos(lat1) * Math.sin(d) * Math.cos(bearing));
        double lon2 = lon1 + Math.atan2(Math.sin(bearing) * Math.sin(d) * Math.cos(lat1), Math.cos(d) - Math.sin(lat1) * Math.sin(lat2));
    //pointArray[x] = GeometryEngine.project(x, y, sr)
    }
}
Also used : Polygon(com.esri.core.geometry.Polygon) Point(android.graphics.Point)

Example 2 with Polygon

use of com.esri.core.geometry.Polygon in project sis by apache.

the class EnvelopeOperationTest method run.

/**
 * Implementation of the test 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_φλ);
    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_φλ);
    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_φλ);
    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)

Example 3 with Polygon

use of com.esri.core.geometry.Polygon in project pigeon by aseldawy.

the class Connect method exec.

@Override
public DataByteArray exec(Tuple b) throws IOException {
    try {
        // Read information from input
        Iterator<Tuple> firstPointIdIter = ((DataBag) b.get(0)).iterator();
        Iterator<Tuple> lastPointIdIter = ((DataBag) b.get(1)).iterator();
        Iterator<Tuple> shapesIter = ((DataBag) b.get(2)).iterator();
        // Shapes that are created after connected line segments
        Vector<OGCGeometry> createdShapes = new Vector<OGCGeometry>();
        Vector<OGCLineString> linestrings = new Vector<OGCLineString>();
        Vector<Long> firstPointId = new Vector<Long>();
        Vector<Long> lastPointId = new Vector<Long>();
        while (firstPointIdIter.hasNext() && lastPointIdIter.hasNext() && shapesIter.hasNext()) {
            OGCGeometry geom = geometryParser.parseGeom(shapesIter.next().get(0));
            long first_point_id = (Long) firstPointIdIter.next().get(0);
            long last_point_id = (Long) lastPointIdIter.next().get(0);
            if (geom.isEmpty()) {
            // Skip empty geometries
            } else if (geom instanceof OGCPolygon) {
                // Copy to output directly. Polygons cannot be connected to other shapes.
                createdShapes.add(geom);
            } else if (geom instanceof OGCLineString) {
                linestrings.add((OGCLineString) geom);
                firstPointId.add(first_point_id);
                lastPointId.add(last_point_id);
            } else {
                throw new GeoException("Cannot connect shapes of type " + geom.getClass());
            }
        }
        if (firstPointIdIter.hasNext() || lastPointIdIter.hasNext() || shapesIter.hasNext()) {
            throw new ExecException("All parameters should be of the same size (" + firstPointId.size() + "," + lastPointId.size() + "," + linestrings.size() + ")");
        }
        // Stores an ordered list of line segments in current connected block
        Vector<OGCLineString> connected_lines = new Vector<OGCLineString>();
        // Total number of points in all visited linestrings
        int sumPoints = 0;
        // Which linestrings to reverse upon connection
        Vector<Boolean> reverse = new Vector<Boolean>();
        long first_point_id = -1;
        long last_point_id = -1;
        // Reorder linestrings to form a contiguous list of connected linestrings
        while (!linestrings.isEmpty()) {
            // Loop invariant:
            // At the beginning of each iteration, the lines in connected_lines are connected.
            // In each iteration, we move one linestring from linestrings to connected_lines
            // while keeping them connected
            int size_before = connected_lines.size();
            for (int i = 0; i < linestrings.size(); ) {
                if (connected_lines.isEmpty()) {
                    // First linestring
                    first_point_id = firstPointId.remove(i);
                    last_point_id = lastPointId.remove(i);
                    reverse.add(false);
                    sumPoints += linestrings.get(i).numPoints();
                    connected_lines.add(linestrings.remove(i));
                } else if (lastPointId.get(i) == first_point_id) {
                    // This linestring goes to the beginning of the list as-is
                    lastPointId.remove(i);
                    first_point_id = firstPointId.remove(i);
                    sumPoints += linestrings.get(i).numPoints();
                    connected_lines.add(0, linestrings.remove(i));
                    reverse.add(0, false);
                } else if (firstPointId.get(i) == first_point_id) {
                    // Should go to the beginning after being reversed
                    firstPointId.remove(i);
                    first_point_id = lastPointId.remove(i);
                    sumPoints += linestrings.get(i).numPoints();
                    connected_lines.add(0, linestrings.remove(i));
                    reverse.add(0, true);
                } else if (firstPointId.get(i) == last_point_id) {
                    // This linestring goes to the end of the list as-is
                    firstPointId.remove(i);
                    last_point_id = lastPointId.remove(i);
                    sumPoints += linestrings.get(i).numPoints();
                    connected_lines.add(linestrings.remove(i));
                    reverse.add(false);
                } else if (lastPointId.get(i) == last_point_id) {
                    // Should go to the end after being reversed
                    lastPointId.remove(i);
                    last_point_id = firstPointId.remove(i);
                    sumPoints += linestrings.get(i).numPoints();
                    connected_lines.add(linestrings.remove(i));
                    reverse.add(true);
                } else {
                    i++;
                }
            }
            if (connected_lines.size() == size_before || linestrings.isEmpty()) {
                // Cannot connect any more lines to the current block. Emit as a shape
                boolean isPolygon = first_point_id == last_point_id;
                Point[] points = new Point[sumPoints - connected_lines.size() + (isPolygon ? 0 : 1)];
                int n = 0;
                for (int i = 0; i < connected_lines.size(); i++) {
                    OGCLineString linestring = connected_lines.get(i);
                    boolean isReverse = reverse.get(i);
                    int last_i = (isPolygon || i < connected_lines.size() - 1) ? linestring.numPoints() - 1 : linestring.numPoints();
                    for (int i_point = 0; i_point < last_i; i_point++) {
                        points[n++] = (Point) linestring.pointN(isReverse ? linestring.numPoints() - 1 - i_point : i_point).getEsriGeometry();
                    }
                }
                MultiPath multi_path = isPolygon ? new Polygon() : new Polyline();
                for (int i = 1; i < points.length; i++) {
                    Segment segment = new Line();
                    segment.setStart(points[i - 1]);
                    segment.setEnd(points[i]);
                    multi_path.addSegment(segment, false);
                }
                createdShapes.add(isPolygon ? new OGCPolygon((Polygon) multi_path, 0, SpatialReference.create(4326)) : new OGCLineString((Polyline) multi_path, 0, SpatialReference.create(4326)));
                // Re-initialize all data structures to connect remaining lines
                if (!linestrings.isEmpty()) {
                    connected_lines.clear();
                    reverse.clear();
                    sumPoints = 0;
                }
            }
        }
        if (createdShapes.size() == 1) {
            return new DataByteArray(createdShapes.get(0).asBinary().array());
        } else if (createdShapes.size() > 1) {
            OGCGeometryCollection collection = new OGCConcreteGeometryCollection(createdShapes, createdShapes.get(0).getEsriSpatialReference());
            return new DataByteArray(collection.asBinary().array());
        } else {
            throw new GeoException("No shapes to connect");
        }
    } catch (Exception e) {
        throw new GeoException(e);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCLineString(com.esri.core.geometry.ogc.OGCLineString) Segment(com.esri.core.geometry.Segment) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) OGCGeometryCollection(com.esri.core.geometry.ogc.OGCGeometryCollection) OGCConcreteGeometryCollection(com.esri.core.geometry.ogc.OGCConcreteGeometryCollection) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) Polygon(com.esri.core.geometry.Polygon) Vector(java.util.Vector) DataByteArray(org.apache.pig.data.DataByteArray) MultiPath(com.esri.core.geometry.MultiPath) DataBag(org.apache.pig.data.DataBag) ExecException(org.apache.pig.backend.executionengine.ExecException) Point(com.esri.core.geometry.Point) Point(com.esri.core.geometry.Point) IOException(java.io.IOException) ExecException(org.apache.pig.backend.executionengine.ExecException) Line(com.esri.core.geometry.Line) Polyline(com.esri.core.geometry.Polyline) Tuple(org.apache.pig.data.Tuple)

Example 4 with Polygon

use of com.esri.core.geometry.Polygon in project presto by prestodb.

the class SphericalGeoFunctions method stSphericalArea.

@SqlNullable
@Description("Returns the area of a geometry on the Earth's surface using spherical model")
@ScalarFunction("ST_Area")
@SqlType(DOUBLE)
public static Double stSphericalArea(@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    validateSphericalType("ST_Area", geometry, EnumSet.of(POLYGON, MULTI_POLYGON));
    Polygon polygon = (Polygon) geometry.getEsriGeometry();
    // See https://www.movable-type.co.uk/scripts/latlong.html
    // and http://osgeo-org.1560.x6.nabble.com/Area-of-a-spherical-polygon-td3841625.html
    // and https://www.element84.com/blog/determining-if-a-spherical-polygon-contains-a-pole
    // for the underlying Maths
    double sphericalExcess = 0.0;
    int numPaths = polygon.getPathCount();
    for (int i = 0; i < numPaths; i++) {
        double sign = polygon.isExteriorRing(i) ? 1.0 : -1.0;
        sphericalExcess += sign * Math.abs(computeSphericalExcess(polygon, polygon.getPathStart(i), polygon.getPathEnd(i)));
    }
    // isExteriorRing returns false for the exterior ring
    return Math.abs(sphericalExcess * EARTH_RADIUS_M * EARTH_RADIUS_M);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Polygon(com.esri.core.geometry.Polygon) CartesianPoint(com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 5 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)

Aggregations

Polygon (com.esri.core.geometry.Polygon)6 Point (com.esri.core.geometry.Point)5 OGCPolygon (com.esri.core.geometry.ogc.OGCPolygon)3 Line (com.esri.core.geometry.Line)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 Point (android.graphics.Point)1 MultiPath (com.esri.core.geometry.MultiPath)1 Polyline (com.esri.core.geometry.Polyline)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 Description (com.facebook.presto.spi.function.Description)1 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)1 SqlNullable (com.facebook.presto.spi.function.SqlNullable)1