com.esri.core.geometry.GeometryEngine Java Examples

The following examples show how to use com.esri.core.geometry.GeometryEngine. 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: spatial-framework-for-hadoop   Author: Esri   File: TestStGeomFromShape.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromPolygonShape() throws UDFArgumentException {
	Polygon polygon = createPolygon();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(polygon);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryAsWritable);
	assertNotNull("The OGC geometry must not be null!", ogcGeometry);

	Geometry esriGeometry = ogcGeometry.getEsriGeometry();
	assertNotNull("The Esri geometry must not be null!", esriGeometry);
	assertTrue("The geometries are different!",
			GeometryEngine.equals(polygon, esriGeometry, SpatialReference.create(wkid)));
}
 
Example #2
Source Project: spatial-framework-for-hadoop   Author: Esri   File: TestStGeomFromShape.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromPolylineShape() throws UDFArgumentException {
	Polyline line = createPolyline();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(line);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryAsWritable);
	assertNotNull("The OGC geometry must not be null!", ogcGeometry);

	Geometry esriGeometry = ogcGeometry.getEsriGeometry();
	assertNotNull("The Esri geometry must not be null!", esriGeometry);
	assertTrue("The geometries are different!",
			GeometryEngine.equals(line, esriGeometry, SpatialReference.create(wkid)));
}
 
Example #3
Source Project: spatial-framework-for-hadoop   Author: Esri   File: ST_AsText.java    License: Apache License 2.0 6 votes vote down vote up
public Text evaluate(BytesWritable geomref){
	if (geomref == null || geomref.getLength() == 0){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
	if (ogcGeometry == null){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}
	
	int wktExportFlag = getWktExportFlag(GeometryUtils.getType(geomref));
	
	try {
		// mind: GeometryType with ST_AsText(ST_GeomFromText('MultiLineString((0 80, 0.03 80.04))'))
		// return new Text(ogcGeometry.asText());
		return new Text(GeometryEngine.geometryToWkt(ogcGeometry.getEsriGeometry(), wktExportFlag));
	} catch (Exception e){
		LOG.error(e.getMessage());
		return null;
	}
}
 
Example #4
Source Project: spatial-framework-for-hadoop   Author: Esri   File: ST_AsJson.java    License: Apache License 2.0 6 votes vote down vote up
public Text evaluate(BytesWritable geomref){
	if (geomref == null || geomref.getLength() == 0){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
	if (ogcGeometry == null){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	Geometry esriGeom = ogcGeometry.getEsriGeometry();
	int wkid = GeometryUtils.getWKID(geomref);
	return new Text(GeometryEngine.geometryToJson(wkid, esriGeom));
}
 
Example #5
Source Project: barefoot   Author: bmwcarit   File: PostGISReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExclusion() throws IOException, JSONException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("config/oberbayern.properties"));
    RoadReader reader = Loader.reader(properties);
    Polygon polygon = (Polygon) GeometryEngine.geometryFromWkt(
            "POLYGON ((11.40848 47.93157, 11.45109 47.93157,11.45109 47.89296,11.40848 47.89296,11.40848 47.93157))",
            WktImportFlags.wktImportDefaults, Type.Polygon);
    HashSet<Short> exclusion = new HashSet<>(Arrays.asList((short) 117));
    BaseRoad road = null;

    reader.open(polygon, exclusion);
    int count = 0;

    while ((road = reader.next()) != null) {
        assertTrue(
                GeometryEngine.overlaps(polygon, road.geometry(), SpatialReference.create(4326))
                        || GeometryEngine.contains(polygon, road.geometry(),
                                SpatialReference.create(4326)));
        assertTrue(!exclusion.contains(road.type()));
        count += 1;
    }

    reader.close();
    assertTrue(count > 0);
}
 
Example #6
Source Project: arcgis-runtime-demos-android   Author: Esri   File: LocalGeofence.java    License: Apache License 2.0 6 votes vote down vote up
public static void setFence(Polygon newFence, SpatialReference fenceSpatialReference) {

    // Keep the original geometries.
    mFenceSr = fenceSpatialReference;
    mFence = newFence;

    // Work with the fence in WGS84, as that's what the location updates will be in.
    // Note that transformations could be used here to increase accuracy.
    if ( mFenceSr.getID() != mWgs84Sr.getID() ) {
      Geometry densified = GeometryEngine.geodesicDensifyGeometry(mFence,
          mFenceSr, 20, null);
      mFenceWgs84 = (Polygon)GeometryEngine.project(densified, mFenceSr, mWgs84Sr);
    }
    else {
      mFenceWgs84 = mFence;
    }
  }
 
Example #7
Source Project: arcgis-runtime-demo-java   Author: Esri   File: DemoTheatreApp.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process result from geoprocessing execution.
 * 
 * @param result output of geoprocessing execution.
 */
private void processResult(GPParameter[] result) {
  for (GPParameter outputParameter : result) {
    if (outputParameter instanceof GPFeatureRecordSetLayer) {
      GPFeatureRecordSetLayer gpLayer = (GPFeatureRecordSetLayer) outputParameter;
      int zone = 0;
      // get all the graphics and add them to the graphics layer.
      // there will be one graphic per zone.
      for (Graphic graphic : gpLayer.getGraphics()) {
        SpatialReference fromSR = SpatialReference.create(4326);
        Geometry g = graphic.getGeometry();
        Geometry pg = GeometryEngine.project(g, fromSR, jMap.getSpatialReference());
        Graphic theGraphic = new Graphic(pg, zoneFillSymbols[zone++]);
        // add to the graphics layer
        graphicsLayer.addGraphic(theGraphic);
      }
    }
  }
}
 
Example #8
Source Project: barefoot   Author: bmwcarit   File: RoadTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJSON() throws JSONException {
    String wkt = "LINESTRING(11.3136273 48.0972002,11.3138846 48.0972999)";
    BaseRoad osm = new BaseRoad(0L, 1L, 2L, 4L, true, (short) 5, 5.1F, 6.1F, 6.2F, 7.1F,
            (Polyline) GeometryEngine.geometryFromWkt(wkt, WktImportFlags.wktImportDefaults,
                    Geometry.Type.Polyline));

    Road road = new Road(osm, Heading.forward);
    RoadMap map = new RoadMap();
    map.add(road);

    String json = road.toJSON().toString();
    Road road2 = Road.fromJSON(new JSONObject(json), map);

    assertEquals(road, road2);
}
 
Example #9
Source Project: spatial-framework-for-hadoop   Author: Esri   File: TestStGeomFromShape.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromPointShape() throws UDFArgumentException {
	Point point = createFirstLocation();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(point);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	validatePoint(point, wkid, geometryAsWritable);
}
 
Example #10
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: BufferProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private com.esri.ges.spatial.Geometry constructBuffer(double x, double y, double radius, String units, int wkidin, int wkidbuffer, int wkidout) throws GeometryException
{
	Point center = new Point();
	center.setX(x);
	center.setY(y);
	SpatialReference srIn = SpatialReference.create(wkidin);
	SpatialReference srBuffer = SpatialReference.create(wkidbuffer);
	SpatialReference srOut = SpatialReference.create(wkidout);
	UnitConverter uc = new UnitConverter();
	String c_name = uc.findConnonicalName(units);
	int unitout = uc.findWkid(c_name);
	Unit  u = new LinearUnit(unitout);
	Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer);
	Geometry buffer = GeometryEngine.buffer(centerProj, srBuffer, radius, u);
	Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	String json = GeometryEngine.geometryToJson(srOut, bufferout);
	return spatial.fromJson(json);
	
}
 
Example #11
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: EllipseProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private MapGeometry constructEllipse(double x, double y, double majorAxis, double minorAxis, double rotation, int wkidin, int wkidbuffer, int wkidout)
{
	Point center = new Point();
	center.setX(x);
	center.setY(y);
	SpatialReference srIn = SpatialReference.create(wkidin);
	SpatialReference srBuffer = SpatialReference.create(wkidbuffer);
	SpatialReference srOut = SpatialReference.create(wkidout);
	UnitConverter uc = new UnitConverter();
	majorAxis = uc.Convert(majorAxis, units, srBuffer);
	minorAxis = uc.Convert(minorAxis, units, srBuffer);
	Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer);
	GeometryUtility geoutil = new GeometryUtility();
	Polygon ellipse = geoutil.GenerateEllipse(centerProj, majorAxis, minorAxis, rotation);
	Geometry ellipseOut = GeometryEngine.project(ellipse, srBuffer, srOut);
	MapGeometry mapGeo = new MapGeometry(ellipseOut, srOut);
	return mapGeo;
}
 
Example #12
Source Project: barefoot   Author: bmwcarit   File: MatcherKState.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets {@link JSONArray} of {@link MatcherKState} with map matched positions, represented by
 * road id and fraction, and the geometry of the routes.
 *
 * @return {@link JSONArray} of {@link MatcherKState} with map matched positions, represented by
 *         road id and fraction, and the geometry of the routes.
 * @throws JSONException thrown on JSON extraction or parsing error.
 */
public JSONArray toSlimJSON() throws JSONException {
    JSONArray json = new JSONArray();
    if (this.sequence() != null) {
        for (MatcherCandidate candidate : this.sequence()) {
            JSONObject jsoncandidate = candidate.point().toJSON();
            if (candidate.transition() != null) {
                jsoncandidate.put("route",
                        GeometryEngine.geometryToWkt(candidate.transition().route().geometry(),
                                WktExportFlags.wktExportLineString));
            }
            json.put(jsoncandidate);
        }
    }
    return json;
}
 
Example #13
Source Project: arcgis-runtime-demo-java   Author: Esri   File: GeoJsonParser.java    License: Apache License 2.0 6 votes vote down vote up
private List<Feature> parseFeatures(ArrayNode jsonFeatures) {
  List<Feature> features = new LinkedList<Feature>();
  for (JsonNode jsonFeature : jsonFeatures) {
    String type = jsonFeature.path(FIELD_TYPE).getTextValue();
    if (!FIELD_FEATURE.equals(type)) {
      continue;
    }
    Geometry g = parseGeometry(jsonFeature.path(FIELD_GEOMETRY));
    if (outSR != null && outSR.getID() != 4326) {
      g = GeometryEngine.project(g, inSR, outSR);
    }
    Map<String, Object> attributes = parseProperties(jsonFeature.path(FIELD_PROPERTIES));
    Feature f = new Graphic(g, symbol, attributes);
    features.add(f);
  } 
  return features; 
}
 
Example #14
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 #15
Source Project: arcgis-runtime-demo-java   Author: Esri   File: DemoTheatreAppImproved.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process result from geoprocessing execution.
 * 
 * @param result output of geoprocessing execution.
 */
private void processResult(GPParameter[] result) {
  for (GPParameter outputParameter : result) {
    if (outputParameter instanceof GPFeatureRecordSetLayer) {
      GPFeatureRecordSetLayer gpLayer = (GPFeatureRecordSetLayer) outputParameter;
      int zone = 0;
      // get all the graphics and add them to the graphics layer.
      // there will be one graphic per zone.
      for (Graphic graphic : gpLayer.getGraphics()) {
        SpatialReference fromSR = SpatialReference.create(4326);
        Geometry g = graphic.getGeometry();
        Geometry pg = GeometryEngine.project(g, fromSR, jMap.getSpatialReference());
        Graphic theGraphic = new Graphic(pg, zoneFillSymbols[zone++]);
        // add to the graphics layer
        graphicsLayer.addGraphic(theGraphic);
      }
    }
  }
}
 
Example #16
@Override
protected Integer displaySpotReport(double x, double y, final int wkid, Integer graphicId, Geomessage geomessage) {
    try {
        Geometry pt = new Point(x, y);
        if (null != mapController.getSpatialReference() && wkid != mapController.getSpatialReference().getID()) {
            pt = GeometryEngine.project(pt, SpatialReference.create(wkid), mapController.getSpatialReference());
        }
        if (null != graphicId) {
            spotReportLayer.updateGraphic(graphicId, pt);
            spotReportLayer.updateGraphic(graphicId, geomessage.getProperties());
        } else {
            Graphic graphic = new Graphic(pt, spotReportSymbol, geomessage.getProperties());
            graphicId = spotReportLayer.addGraphic(graphic);
            
        }
        return graphicId;
    } catch (NumberFormatException nfe) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Could not parse spot report", nfe);
        return null;
    }
}
 
Example #17
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: MgrsLayerController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tells the controller to display the given point.
 * @param pt the point to display.
 * @param sr the spatial reference of the point to display.
 */
public void showPoint(Point pt, SpatialReference sr) {
    synchronized (graphicUpdateLock) {
        lastPointShownLatLon = (Point) GeometryEngine.project(pt, sr, Utilities.WGS84);
        if (-1 == pointGraphicId) {
            createPointGraphic(pt);
            createTextGraphics(pt);
        } else {
            updateGraphic(pointGraphicId, pt);
            updateTextGraphics(pt);
            updateTextGraphics(getDistanceBearingString(currentGpsPointLatLon, lastPointShownLatLon));
        }
    }
    
    setLayerVisibility(true);
    moveLayerToTop();
}
 
Example #18
Source Project: arcgis-runtime-demo-java   Author: Esri   File: ParticleGraphicsEllipseApp.java    License: Apache License 2.0 5 votes vote down vote up
private void addEllipses(int numberOfEllipses) {
  SimpleMarkerSymbol[] symbols = {symbol4, symbol3, symbol2, symbol1};
  // some values that works well
  int majorAxisLength = 4612483;
  int minorAxisLength = 1843676;

  centerPoint = new Point(500000-5000000, 500000 + 3000000);
  centerGraphicsLayer.addGraphic(new Graphic(centerPoint, null));

  for (int i = 0; i < numberOfEllipses; i++) {
    Point center = new Point(random.nextInt(500000)-5000000, random.nextInt(500000) + 3000000);
    int majorAxisDirection = random.nextInt(60);
    LinearUnit unit = new LinearUnit(LinearUnit.Code.METER);

    Geometry ellipse = GeometryEngine.geodesicEllipse(center, map.getSpatialReference(), majorAxisLength, minorAxisLength,
        majorAxisDirection, pointCount, unit, Geometry.Type.MULTIPOINT);

    if (ellipse instanceof MultiPoint) {
      SimpleMarkerSymbol symbol = symbols[i%4];
      MultiPoint mp = (MultiPoint) ellipse;
      Ellipse currentEllipse = new Ellipse(mp); 
      ellipses.add(currentEllipse);
      int j = 0;
      while (j < mp.getPointCount()) {
        if (j%8==0) {
          Point point = mp.getPoint(j);
          int id = ellipseGraphicsLayer.addGraphic(new Graphic(point, symbol));
          currentEllipse.addPoint(id, j);
        }
        j++;
      }
    }
  }
}
 
Example #19
Source Project: barefoot   Author: bmwcarit   File: MatcherKState.java    License: Apache License 2.0 5 votes vote down vote up
public JSONObject toMonitorJSON() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("time", sample().time());
    json.put("point", GeometryEngine.geometryToWkt(estimate().point().geometry(),
            WktExportFlags.wktExportPoint));
    Polyline routes = monitorRoute(estimate());
    if (routes.getPathCount() > 0) {
        json.put("route",
                GeometryEngine.geometryToWkt(routes, WktExportFlags.wktExportMultiLineString));
    }

    JSONArray candidates = new JSONArray();
    for (MatcherCandidate candidate : vector()) {
        JSONObject jsoncandidate = new JSONObject();
        jsoncandidate.put("point", GeometryEngine.geometryToWkt(candidate.point().geometry(),
                WktExportFlags.wktExportPoint));
        jsoncandidate.put("prob",
                Double.isInfinite(candidate.filtprob()) ? "Infinity" : candidate.filtprob());

        routes = monitorRoute(candidate);
        if (routes.getPathCount() > 0) {
            jsoncandidate.put("route", GeometryEngine.geometryToWkt(routes,
                    WktExportFlags.wktExportMultiLineString));
        }
        candidates.put(jsoncandidate);
    }
    json.put("candidates", candidates);
    return json;
}
 
Example #20
Source Project: Bats   Author: lealone   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
/** Computes the union of {@code geom1} and {@code geom2}. */
public static Geom ST_Union(Geom geom1, Geom geom2) {
  SpatialReference sr = geom1.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[]{geom1.g(), geom2.g()}, sr);
  return bind(g, sr);
}
 
Example #21
Source Project: presto   Author: prestosql   File: GeometryUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean contains(OGCGeometry ogcGeometry, Envelope envelope)
{
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    while (true) {
        Geometry geometry = cursor.next();
        if (geometry == null) {
            return false;
        }

        if (GeometryEngine.contains(geometry, envelope, null)) {
            return true;
        }
    }
}
 
Example #22
Source Project: arcgis-runtime-demo-java   Author: Esri   File: GeoJsonParser.java    License: Apache License 2.0 5 votes vote down vote up
private List<Geometry> parseGeometries(ArrayNode jsonGeometries) {
  List<Geometry> geometries = new LinkedList<Geometry>();
  for (JsonNode jsonGeometry : jsonGeometries) {
    Geometry g = parseGeometry(jsonGeometry);
    if (outSR != null && outSR.getID() != 4326) {
      g = GeometryEngine.project(g, inSR, outSR);
    }
    geometries.add(g);
  } 
  return geometries; 
}
 
Example #23
Source Project: geometry-api-java   Author: Esri   File: OGCGeometry.java    License: Apache License 2.0 5 votes vote down vote up
public OGCGeometry difference(OGCGeometry another) {
	if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
		return (new OGCConcreteGeometryCollection(this, esriSR)).difference(another);
	}
	
	com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
	com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
	return createFromEsriGeometry(
			com.esri.core.geometry.GeometryEngine.difference(geom1, geom2,
					getEsriSpatialReference()), esriSR);
}
 
Example #24
Source Project: geometry-api-java   Author: Esri   File: OGCGeometry.java    License: Apache License 2.0 5 votes vote down vote up
public boolean crosses(OGCGeometry another) {
	if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
		//TODO
		throw new UnsupportedOperationException();
	}
	
	com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
	com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
	return com.esri.core.geometry.GeometryEngine.crosses(geom1, geom2,
			getEsriSpatialReference());
}
 
Example #25
Source Project: barefoot   Author: bmwcarit   File: GeographyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPathInterception1() {
    String point = "POINT(11.410624 48.144161)";
    String line =
            "LINESTRING(11.4047013 48.1402147,11.4047038 48.1402718,11.4047661 48.1403687,11.4053519 48.141055,11.4054617 48.1411901,11.4062664 48.1421968,11.4064586 48.1424479,11.4066449 48.1427372,11.4067254 48.1429028,11.4067864 48.1430673,11.4068647 48.1433303,11.4069456 48.1436822,11.4070524 48.1440368,11.4071569 48.1443314,11.4072635 48.1445915,11.4073887 48.1448641,11.4075228 48.1450729,11.407806 48.1454843,11.4080135 48.1458112,11.4083012 48.1463167,11.4086211 48.1469061,11.4087461 48.1471386,11.4088719 48.1474078,11.4089422 48.1476014,11.409028 48.1478353,11.409096 48.1480701,11.4091568 48.1483459,11.4094282 48.1498536)";

    Point c = (Point) GeometryEngine.geometryFromWkt(point, WktImportFlags.wktImportDefaults,
            Type.Point);
    Polyline ab = (Polyline) GeometryEngine.geometryFromWkt(line,
            WktImportFlags.wktImportDefaults, Type.Polyline);

    sw1.start();
    double f = spatial.intercept(ab, c);
    sw1.stop();

    double l = spatial.length(ab);

    sw2.start();
    Point p = spatial.interpolate(ab, l, f);
    sw2.stop();

    double d = spatial.distance(p, c);

    assertEquals(p.getX(), 11.407547966254612, 10E-6);
    assertEquals(p.getY(), 48.14510945890138, 10E-6);
    assertEquals(f, 0.5175157549609246, 10E-6);
    assertEquals(l, 1138.85464239099, 10E-6);
    assertEquals(d, 252.03375312704165, 10E-6);

    if (benchmark) {
        System.out.println("[Geography] path interception " + sw1.us()
                + " us (gnomonic), path interpolation " + sw2.us() + " us (geodesic)");
    }
}
 
Example #26
Source Project: arcgis-runtime-demo-java   Author: Esri   File: OverlayApp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent e) {
  Point pt = map.toMapPoint(e.getX(), e.getY());

  Geometry buffer = GeometryEngine.buffer(pt, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());

  Graphic g = new Graphic(buffer, bufferSymbol);
  graphicsLayer.addGraphic(g);
}
 
Example #27
Source Project: arcgis-runtime-demo-java   Author: Esri   File: GeometryOnlineApp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent event) {
  graphicsLayer.removeAll();

  // add buffer as a graphic
  Point mapPoint = map.toMapPoint(event.getX(), event.getY());
  final Geometry buffer = GeometryEngine.buffer(
      mapPoint, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());
  graphicsLayer.addGraphic(new Graphic(buffer, new SimpleFillSymbol(new Color(255, 0, 0, 255))));

  // get states at the buffered area
  QueryTask queryTask = new QueryTask(featureLayer.getUrl());
  QueryParameters queryParams = new QueryParameters();
  queryParams.setInSpatialReference(map.getSpatialReference());
  queryParams.setOutSpatialReference(map.getSpatialReference());
  queryParams.setGeometry(buffer);
  queryParams.setReturnGeometry(true);
  queryParams.setOutFields(new String[] {"STATE_NAME"});

  queryTask.execute(queryParams, new CallbackListener<FeatureResult>() {

    @Override
    public void onError(Throwable arg0) {
      // deal with any exception
    }

    @Override
    public void onCallback(FeatureResult result) {
      for (Object objFeature : result) {
        Feature feature = (Feature) objFeature;
        graphicsLayer.addGraphic(new Graphic(feature.getGeometry(), stateSymbol));
        graphicsLayer.addGraphic(new Graphic(buffer, new SimpleFillSymbol(new Color(255, 0, 0, 255))));


      }
    }
  });
}
 
Example #28
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: QueryReportProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private com.esri.ges.spatial.Geometry constructGeometryFromString(String geoString) throws GeometryException
{
	String[] pairs = geoString.split(" ");
	
	Polygon polygon = new Polygon();
	Boolean firstit = true;
	for(String coords: pairs)
	{
		
		String[] tuple = coords.split(",");
		Double x = Double.parseDouble(tuple[0]);
		Double y = Double.parseDouble(tuple[1]);
		Point p = new Point(x,y);
		Double z = Double.NaN;
		if (tuple.length>2)
		{
			z = Double.parseDouble(tuple[2]);
			p.setZ(z);
		}
		if(firstit)
		{
			polygon.startPath(p);
			firstit=false;
		}
		else
		{
			polygon.lineTo(p);
		}
	}
	polygon.closeAllPaths();
	String json = GeometryEngine.geometryToJson(srIn, polygon);
	return spatial.fromJson(json);
}
 
Example #29
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: QueryReportProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private com.esri.ges.spatial.Geometry constructBuffer(Geometry geo, double radius, Unit u) throws GeometryException, JsonParseException, IOException
{
	
	com.esri.core.geometry.Geometry buffer = GeometryEngine.buffer(inGeometry, srBuffer, radius, u);
	com.esri.core.geometry.Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	String json = GeometryEngine.geometryToJson(srOut, bufferout);
	return spatial.fromJson(json);
	
}
 
Example #30
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: QueryReportProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private String GetDistAsString(Graphic g, SpatialReference inputSr, String units)
{
	com.esri.core.geometry.Geometry geo = g.getGeometry();
	com.esri.core.geometry.Geometry curGeo;
	
	if(!inputSr.equals(srBuffer))
	{
		curGeo = GeometryEngine.project(geo, inputSr, srBuffer);
	}
	else
	{
		curGeo=geo;
	}
	double tmpDist = GeometryEngine.distance(inGeometry, curGeo, srBuffer);
	UnitConverter uc = new UnitConverter();
	int inUnitWkid = uc.findWkid(srBuffer.getUnit().getName());
	String cn = uc.findConnonicalName(units);
	int outUnitWkid = uc.findWkid(cn);
	double dist;
	if(inUnitWkid!=outUnitWkid)
	{
		dist = uc.Convert(tmpDist, inUnitWkid, outUnitWkid);
	}
	else
	{
		dist=tmpDist;
	}
	
	DecimalFormat df = new DecimalFormat("#.00");
	return df.format(dist);
}