com.esri.core.geometry.Point Java Examples

The following examples show how to use com.esri.core.geometry.Point. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Bats   Author: lealone   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
/** Returns the OGC type of a geometry. */
private static Type type(Geometry g) {
  switch (g.getType()) {
  case Point:
    return Type.POINT;
  case Polyline:
    return Type.LINESTRING;
  case Polygon:
    return Type.POLYGON;
  case MultiPoint:
    return Type.MULTIPOINT;
  case Envelope:
    return Type.POLYGON;
  case Line:
    return Type.LINESTRING;
  case Unknown:
    return Type.Geometry;
  default:
    throw new AssertionError(g);
  }
}
 
Example #2
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(Geometry.Type t)
{
	String type = null;
	if(t == Geometry.Type.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==Geometry.Type.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==Geometry.Type.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==Geometry.Type.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #3
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(Geometry.Type t)
{
	String type = null;
	if(t == Geometry.Type.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==Geometry.Type.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==Geometry.Type.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==Geometry.Type.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #4
Source Project: sis   Author: apache   File: EnvelopeOperationTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a feature type with a bounds operation.
 * The feature contains the following properties:
 *
 * <ul>
 *   <li>{@code name} as a {@link String}</li>
 *   <li>{@code classes} as a {@link Polygon}</li>
 *   <li>{@code climbing wall} as a {@link Point}</li>
 *   <li>{@code gymnasium} as a {@link Polygon}</li>
 *   <li>{@code sis:geometry} as a link to the default geometry</li>
 *   <li>{@code bounds} as the feature envelope attribute.</li>
 * </ul>
 *
 * @param  defaultGeometry  1 for using "classes" as the default geometry, or 3 for "gymnasium".
 * @return the feature for a school.
 */
private static DefaultFeatureType school(final int defaultGeometry) throws FactoryException {
    final DefaultAttributeType<?> standardCRS = new DefaultAttributeType<>(
            name(AttributeConvention.CRS_CHARACTERISTIC), CoordinateReferenceSystem.class, 1, 1, HardCodedCRS.WGS84_φλ);

    final DefaultAttributeType<?> normalizedCRS = new DefaultAttributeType<>(
            name(AttributeConvention.CRS_CHARACTERISTIC), CoordinateReferenceSystem.class, 1, 1, HardCodedCRS.WGS84);

    final AbstractIdentifiedType[] attributes = {
        new DefaultAttributeType<>(name("name"),          String.class,  1, 1, null),
        new DefaultAttributeType<>(name("classes"),       Polygon.class, 1, 1, null, standardCRS),
        new DefaultAttributeType<>(name("climbing wall"), Point.class,   1, 1, null, standardCRS),
        new DefaultAttributeType<>(name("gymnasium"),     Polygon.class, 1, 1, null, normalizedCRS),
        null,
        null
    };
    attributes[4] = FeatureOperations.link(name(AttributeConvention.GEOMETRY_PROPERTY), attributes[defaultGeometry]);
    attributes[5] = FeatureOperations.envelope(name("bounds"), null, attributes);
    return new DefaultFeatureType(name("school"), false, null, attributes);
}
 
Example #5
Source Project: arcgis-runtime-demos-android   Author: Esri   File: GeofenceServiceNormal.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This action is handled in the provided background thread. It is called
 * when this service receives a location update from Google fusion API;
 * therefore no connection to the Google API client is required.
 */
private void handleActionCheckLocation(Location newLocation) {

  if(newLocation !=null) {
    // The incoming location is the current device location, in geographic coordinates.
    Point locationPoint = new Point(newLocation.getLongitude(), newLocation.getLatitude());
    LocalGeofence.FenceInformation info = LocalGeofence.latestLocation(locationPoint);
    Log.i(TAG, String.format("GeofenceServiceNormal Status: %s, UpdateChange: %s, Change: %s", info.status, info.updateChange, info.change));

    if (info.change == LocalGeofence.Change.ENTERED) {
      sendNotification(String.format("Alert! Entered %s", LocalGeofence.getFeatureName()));
    }
    else if (info.change == LocalGeofence.Change.EXITED) {
      sendNotification(String.format("Exited %s", LocalGeofence.getFeatureName()));
    }

    if (LocalGeofence.UpdateChange.FASTER == info.updateChange) {
      // Ensure we are receiving updates frequently.
      handleActionChangeToFastUpdates();
    }
    else if (LocalGeofence.UpdateChange.SLOWER == info.updateChange) {
      // Ensure we are receiving updates less frequently.
      handleActionStartNormalUpdates();
    }
  }
}
 
Example #6
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
@SqlNullable
@Description("Returns the lower left and upper right corners of bounding rectangular polygon of a Geometry")
@ScalarFunction("ST_EnvelopeAsPts")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stEnvelopeAsPts(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2);
    Point lowerLeftCorner = new Point(envelope.getXMin(), envelope.getYMin());
    Point upperRightCorner = new Point(envelope.getXMax(), envelope.getYMax());
    GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(lowerLeftCorner, null, false)));
    GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(upperRightCorner, null, false)));
    return blockBuilder.build();
}
 
Example #7
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example #8
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
private static Point getPolygonSansHolesCentroid(Polygon polygon)
{
    int pointCount = polygon.getPointCount();
    double xSum = 0;
    double ySum = 0;
    double signedArea = 0;
    for (int i = 0; i < pointCount; i++) {
        Point current = polygon.getPoint(i);
        Point next = polygon.getPoint((i + 1) % polygon.getPointCount());
        double ladder = current.getX() * next.getY() - next.getX() * current.getY();
        xSum += (current.getX() + next.getX()) * ladder;
        ySum += (current.getY() + next.getY()) * ladder;
        signedArea += ladder / 2;
    }
    return new Point(xSum / (signedArea * 6), ySum / (signedArea * 6));
}
 
Example #9
Source Project: arcgis-runtime-demos-android   Author: Esri   File: GeofenceServiceFast.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This action is handled in the provided background thread. It is called
 * when this service receives a location update from Google fusion API;
 * therefore no connection to the Google API client is required.
 */
private void handleActionCheckLocation(Location newLocation) {

  if(newLocation !=null) {
    // The incoming location is the current device location, in geographic coordinates.
    Point locationPoint = new Point(newLocation.getLongitude(), newLocation.getLatitude());
    LocalGeofence.FenceInformation info = LocalGeofence.latestLocation(locationPoint);
    Log.i(TAG, String.format("GeofenceServiceFast Status: %s, UpdateChange: %s, Change: %s", info.status, info.updateChange, info.change));

    if (info.change == LocalGeofence.Change.ENTERED) {
      sendNotification(String.format("Alert! Entered %s", LocalGeofence.getFeatureName()));
    }
    else if (info.change == LocalGeofence.Change.EXITED) {
      sendNotification(String.format("Exited %s", LocalGeofence.getFeatureName()));
    }

    if (LocalGeofence.UpdateChange.FASTER == info.updateChange) {
      // Ensure we are receiving updates frequently.
      handleActionStartFastUpdates();
    }
    else if (LocalGeofence.UpdateChange.SLOWER == info.updateChange) {
      // Ensure we are receiving updates less frequently.
      handleActionChangeToNormalUpdates();
    }
  }
}
 
Example #10
Source Project: barefoot   Author: bmwcarit   File: DijkstraBenchmark.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNoRouteBound() {
    Set<RoadPoint> sources = map.spatial().nearest(new Point(11.58424, 48.17635));
    Set<RoadPoint> targets = map.spatial().nearest(new Point(11.59151, 48.15231));

    assertTrue(!sources.isEmpty());
    assertTrue(!targets.isEmpty());

    RoadPoint source = sources.iterator().next();
    RoadPoint target = targets.iterator().next();

    Router<Road, RoadPoint> algo = new Dijkstra<>();

    Stopwatch sw = new Stopwatch();
    sw.start();
    List<Road> edges = algo.route(source, target, new Distance(), new Distance(), 10000d);
    sw.stop();

    assertTrue(edges == null);

    logger.info("no route bound example (fastest, priority): {} ms", sw.ms());
}
 
Example #11
Source Project: presto   Author: prestosql   File: BingTileFunctions.java    License: Apache License 2.0 6 votes vote down vote up
private static BingTile getTileCoveringLowerRightCorner(Envelope envelope, int zoomLevel)
{
    BingTile tile = latitudeLongitudeToTile(envelope.getYMin(), envelope.getXMax(), zoomLevel);

    // If the tile covering the lower right corner of the envelope overlaps the envelope only
    // at the border then return a tile shifted to the left and/or top
    int deltaX = 0;
    int deltaY = 0;
    Point upperLeftCorner = tileXYToLatitudeLongitude(tile.getX(), tile.getY(), tile.getZoomLevel());
    if (upperLeftCorner.getX() == envelope.getXMax()) {
        deltaX = -1;
    }
    if (upperLeftCorner.getY() == envelope.getYMin()) {
        deltaY = -1;
    }

    if (deltaX != 0 || deltaY != 0) {
        return BingTile.fromCoordinates(tile.getX() + deltaX, tile.getY() + deltaY, tile.getZoomLevel());
    }

    return tile;
}
 
Example #12
Source Project: calcite   Author: apache   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
/** Returns the OGC type of a geometry. */
private static Type type(Geometry g) {
  switch (g.getType()) {
  case Point:
    return Type.POINT;
  case Polyline:
    return Type.LINESTRING;
  case Polygon:
    return Type.POLYGON;
  case MultiPoint:
    return Type.MULTIPOINT;
  case Envelope:
    return Type.POLYGON;
  case Line:
    return Type.LINESTRING;
  case Unknown:
    return Type.Geometry;
  default:
    throw new AssertionError(g);
  }
}
 
Example #13
Source Project: presto   Author: prestosql   File: GeometryUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static int getPointCount(OGCGeometry ogcGeometry)
{
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    int points = 0;
    while (true) {
        com.esri.core.geometry.Geometry geometry = cursor.next();
        if (geometry == null) {
            return points;
        }

        if (geometry.isEmpty()) {
            continue;
        }

        if (geometry instanceof Point) {
            points++;
        }
        else {
            points += ((MultiVertexGeometry) geometry).getPointCount();
        }
    }
}
 
Example #14
Source Project: spatial-framework-for-hadoop   Author: Esri   File: TestEsriJsonSerDe.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void TestIntPoint() throws Exception {
       ArrayList<Object> stuff = new ArrayList<Object>();
	Properties proptab = new Properties();
	proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num,shape");
	proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "bigint,binary");
	AbstractSerDe jserde = mkSerDe(proptab);
       StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();

       //value.set("{\"attributes\":{\"num\":7},\"geometry\":{\"x\":15.0,\"y\":5.0}}");
       addWritable(stuff, 7L);
       addWritable(stuff, new Point(15.0, 5.0));
	Object row = runSerDe(stuff, jserde, rowOI);
	Object fieldData = getField("num", row, rowOI);
	Assert.assertEquals(7, ((LongWritable)fieldData).get());

       //value.set("{\"attributes\":{\"num\":4},\"geometry\":{\"x\":7.0,\"y\":2.0}}");
	stuff.clear();
       addWritable(stuff, 4L);
       addWritable(stuff, new Point(7.0, 2.0));
	row = runSerDe(stuff, jserde, rowOI);
	fieldData = getField("num", row, rowOI);
	Assert.assertEquals(4, ((LongWritable)fieldData).get());
	fieldData = getField("shape", row, rowOI);
	ckPoint(new Point(7.0, 2.0), (BytesWritable)fieldData);
}
 
Example #15
Source Project: arcgis-runtime-demo-java   Author: Esri   File: DemoTheatreApp.java    License: Apache License 2.0 6 votes vote down vote up
private void highlightGeometry(Point point) {
  if (point == null) {
    return;
  }

  graphicsLayer.removeAll();
  graphicsLayer.addGraphic(
    new Graphic(point, new SimpleMarkerSymbol(Color.CYAN, 20, SimpleMarkerSymbol.Style.CIRCLE)));
  
  // -----------------------------------------------------------------------------------------
  // Zoom to the highlighted graphic
  // -----------------------------------------------------------------------------------------
  Geometry geometryForZoom = GeometryEngine.buffer(
    point, 
    map.getSpatialReference(), 
    map.getFullExtent().getWidth() * 0.10, 
    map.getSpatialReference().getUnit());
  map.zoomTo(geometryForZoom);
}
 
Example #16
Source Project: Quicksql   Author: Qihoo360   File: GeoFunctions.java    License: MIT License 6 votes vote down vote up
/** Returns the OGC type of a geometry. */
private static Type type(Geometry g) {
  switch (g.getType()) {
  case Point:
    return Type.POINT;
  case Polyline:
    return Type.LINESTRING;
  case Polygon:
    return Type.POLYGON;
  case MultiPoint:
    return Type.MULTIPOINT;
  case Envelope:
    return Type.POLYGON;
  case Line:
    return Type.LINESTRING;
  case Unknown:
    return Type.Geometry;
  default:
    throw new AssertionError(g);
  }
}
 
Example #17
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example #18
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(GeometryType t)
{
	String type = null;
	if(t == GeometryType.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==GeometryType.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==GeometryType.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==GeometryType.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #19
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(Geometry.Type t)
{
	String type = null;
	if(t == Geometry.Type.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==Geometry.Type.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==Geometry.Type.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==Geometry.Type.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #20
Source Project: spatial-framework-for-hadoop   Author: Esri   File: TestEsriJsonSerDe.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void TestNullGeom() throws Exception {
       ArrayList<Object> stuff = new ArrayList<Object>();
	Properties proptab = new Properties();
	proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "shape");
	proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "binary");
	AbstractSerDe jserde = mkSerDe(proptab);
       StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();

       //value.set("{\"attributes\":{},\"geometry\":{\"x\":15.0,\"y\":5.0}}");
       addWritable(stuff, new Point(15.0, 5.0));
	Object row = runSerDe(stuff, jserde, rowOI);
	Object fieldData = getField("shape", row, rowOI);
	ckPoint(new Point(15.0, 5.0), (BytesWritable)fieldData);

       //value.set("{\"attributes\":{},\"geometry\":null}");
	stuff.set(0, null);
	row = runSerDe(stuff, jserde, rowOI);
	fieldData = getField("shape", row, rowOI);
	Assert.assertNull(fieldData);
}
 
Example #21
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(Geometry.Type t)
{
	String type = null;
	if(t == Geometry.Type.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==Geometry.Type.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==Geometry.Type.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==Geometry.Type.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #22
Source Project: arcgis-runtime-demo-java   Author: Esri   File: GeoJsonParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Example:
 * [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
 * @param parser
 * @return a polygon
 * @throws JsonParseException
 * @throws IOException
 */
private Polygon parseSimplePolygonCoordinates(JsonNode node) {
  Polygon g = new Polygon();
  boolean first = true;
  ArrayNode points = (ArrayNode) node;
  for (JsonNode point : points) {
    Point p = parsePointCoordinates(point);
    if (first) {
      g.startPath(p);
      first = false;
    } else {
      g.lineTo(p);
    }  
  }
  g.closeAllPaths();
  return g;
}
 
Example #23
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example #24
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: GeometryUtility.java    License: Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example #25
private void processVertices(GeoEvent ge, Polyline polyln, double distTotal, long start, long end, LinearUnit lu, Boolean projected) throws MessagingException, FieldException
{
	int count = polyln.getPointCount();
	double currentDist = 0;
	long currentTime = start;
	long totalTime = end - start;
	Geometry outGeo = null;
	Point projGeo = null;
	Point lastPoint = null;
	for(int i = 0; i < count; ++i)
	{
		projGeo = polyln.getPoint(i);
		
		if(i!=0)
		{
			Polyline seg = new Polyline();
			seg.startPath(lastPoint);
			seg.lineTo(projGeo);
			double segDist = GeometryEngine.geodesicLength(seg, processSr, lu);
			currentDist += segDist;
			double percent = currentDist/distTotal;
			currentTime = (long) Math.floor((start + (totalTime*percent)));
			
		}
		if(projected)
		{
			outGeo = GeometryEngine.project(projGeo, processSr, outSr);
		}
		else
		{
			outGeo=projGeo;
		}
		MapGeometry outMapGeo = new MapGeometry(outGeo, outSr);
		double minutesFromStart = (currentTime - start)/60000;
		GeoEvent msg = createVertexGeoevent(ge, outMapGeo, currentDist, currentTime, minutesFromStart, i);
		send(msg);
		lastPoint = projGeo;
	}
}
 
Example #26
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Description("Returns the Point value that is the mathematical centroid of a Geometry")
@ScalarFunction("ST_Centroid")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stCentroid(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    OGCGeometry geometry = deserialize(input);
    validateType("ST_Centroid", geometry, EnumSet.of(POINT, MULTI_POINT, LINE_STRING, MULTI_LINE_STRING, POLYGON, MULTI_POLYGON));
    GeometryType geometryType = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (geometryType == GeometryType.POINT) {
        return input;
    }

    int pointCount = ((MultiVertexGeometry) geometry.getEsriGeometry()).getPointCount();
    if (pointCount == 0) {
        return serialize(createFromEsriGeometry(new Point(), geometry.getEsriSpatialReference()));
    }

    Point centroid;
    switch (geometryType) {
        case MULTI_POINT:
            centroid = computePointsCentroid((MultiVertexGeometry) geometry.getEsriGeometry());
            break;
        case LINE_STRING:
        case MULTI_LINE_STRING:
            centroid = computeLineCentroid((Polyline) geometry.getEsriGeometry());
            break;
        case POLYGON:
            centroid = computePolygonCentroid((Polygon) geometry.getEsriGeometry());
            break;
        case MULTI_POLYGON:
            centroid = computeMultiPolygonCentroid((OGCMultiPolygon) geometry);
            break;
        default:
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Unexpected geometry type: " + geometryType);
    }
    return serialize(createFromEsriGeometry(centroid, geometry.getEsriSpatialReference()));
}
 
Example #27
Source Project: barefoot   Author: bmwcarit   File: SpatialExample.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws SourceException, IOException {
    // Load and construct road map
    RoadMap map = Loader.roadmap("oberbayern.properties", true).construct();

    Point c = new Point(11.550474464893341, 48.034123185269095);
    double r = 50; // radius search within 50 meters
    Set<RoadPoint> points = map.spatial().radius(c, r);

    for (RoadPoint point : points) {
        GeometryEngine.geometryToGeoJson(point.geometry());
        GeometryEngine.geometryToGeoJson(point.edge().geometry());
    }
}
 
Example #28
Source Project: arcgis-runtime-demo-java   Author: Esri   File: GeoJsonParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses a multipoint
 * Example:
 * [ [100.0, 0.0], [101.0, 1.0] ].
 * @param parser
 * @return a multipoint.
 * @throws Exception
 */
private MultiPoint parseMultiPointCoordinates(JsonNode node) {
  MultiPoint p = new MultiPoint();
  ArrayNode jsonPoints = (ArrayNode) node;
  for (JsonNode jsonPoint : jsonPoints) {
    Point point = parsePointCoordinates(jsonPoint);
    p.add(point);
  }
  return p;
}
 
Example #29
Source Project: barefoot   Author: bmwcarit   File: GeographyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLineAzimuth() {
    Point reyk = new Point(-21.933333, 64.15);
    Point berl = new Point(13.408056, 52.518611);
    Point mosk = new Point(37.616667, 55.75);

    assertEquals(azimuth(berl, mosk, true), spatial.azimuth(berl, mosk, 0f), 1E-9);
    assertEquals(azimuth(berl, mosk, false), spatial.azimuth(berl, mosk, 1f), 1E-9);
    assertEquals(azimuth(berl, reyk, true), spatial.azimuth(berl, reyk, 0f), 1E-9);
    assertTrue(spatial.azimuth(berl, mosk, 0f) < spatial.azimuth(berl, mosk, 0.5)
            && spatial.azimuth(berl, mosk, 0.5) < spatial.azimuth(berl, mosk, 1f));
}
 
Example #30
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: MapController.java    License: Apache License 2.0 5 votes vote down vote up
private void fireIdentifyComplete(Point mapPoint) {
    identifyListener.identifyComplete(
            mapPoint,
            allResults.toArray(new IdentifiedItem[allResults.size()]),
            resultToLayer
            );
}