I want to obtain a new Point (geodetic) by adding x and y offset (in meters) to another Point. Is there any class or function to do that like in the case of GeodeticDistanceResult?
Solved! Go to Solution.
// Define initial point.
Point initialPoint(7.65851, 45.97661, SpatialReference::wgs84());
// Apply 1000m offset in the y-direction (i.e. azimuth = 0 deg).
QList<Point> initialPointList{initialPoint};
QList<Point> yOffsetPoint = GeometryEngine::moveGeodetic(initialPointList, 1000, LinearUnit::meters(), 0.0f, AngularUnit::degrees(), GeodeticCurveType::GreatElliptic);
// Apply 500m offset in the x-direction (i.e. azimuth = 90 deg).
QList<Point> offsetPointList = GeometryEngine::moveGeodetic(yOffsetPoint, 500, LinearUnit::meters(), 90.0f, AngularUnit::degrees(), GeodeticCurveType::GreatElliptic);
// Convert offsetPointList from QList<Point> to Point.
Point offsetPoint = offsetPointList.at(0);
// Define initial point.
Point initialPoint(7.65851, 45.97661, SpatialReference::wgs84());
// Apply 1000m offset in the y-direction (i.e. azimuth = 0 deg).
QList<Point> initialPointList{initialPoint};
QList<Point> yOffsetPoint = GeometryEngine::moveGeodetic(initialPointList, 1000, LinearUnit::meters(), 0.0f, AngularUnit::degrees(), GeodeticCurveType::GreatElliptic);
// Apply 500m offset in the x-direction (i.e. azimuth = 90 deg).
QList<Point> offsetPointList = GeometryEngine::moveGeodetic(yOffsetPoint, 500, LinearUnit::meters(), 90.0f, AngularUnit::degrees(), GeodeticCurveType::GreatElliptic);
// Convert offsetPointList from QList<Point> to Point.
Point offsetPoint = offsetPointList.at(0);
Thank you very much @AndrewBladon ! I guess I have overlooked this method of GeometryEngine.
Could you give me an example using this method with Qml? I want to define a function that enables a point to be shifted 2km to the north. But the return value of the function is a empty list.
function addNewPoint() {
var refPointList = [];
var refPoint = ArcGISRuntimeEnvironment.createObject("Point", {
x: centerX,
y: centerY,
spatialReference: viewPointCenter.spatialReference});
refPointList.push(refPoint);
console.log(refPointList);
var newPointList = GeometryEngine.moveGeodetic(refPointList, 2, linearUnitKm,
0, angularUnit, Enums.GeodeticCurveTypeGeodesic);
console.log("newPointList=",newPointList);
polylineBuilderAddNewPoint.addPoint(newPointList[0]);
var graphic = ArcGISRuntimeEnvironment.createObject("Graphic", {
geometry: polylineBuilderAddNewPoint.geometry,
});
graphicsOverlayAddNewPoint.graphics.append(graphic);
}
Here is some sample code I put together that moves the point and displays a graphic at the new point
ApplicationWindow {
id: appWindow
width: 800
height: 600
title: "Untitled172"
// add a mapView component
MapView {
id: mv
anchors.fill: parent
// set focus to enable keyboard navigation
focus: true
// add a map to the mapview
Map {
// add the ArcGISStreets basemap to the map
initBasemapStyle: Enums.BasemapStyleArcGISStreets
initialViewpoint: ViewpointExtent {
extent: Envelope {
id: env
json: {"spatialReference":{"latestWkid":3857,"wkid":102100},"xmax":-13013797.089479687,"xmin":-13034963.75614633,"ymax":4036739.5261344,"ymin":4020864.5261344174}
}
}
}
GraphicsOverlay {
id: graphicsOverlayAddNewPoint
Graphic {
geometry: Point {
x: -117
y: 34
spatialReference: SpatialReference {wkid: 4326}
}
symbol: SimpleMarkerSymbol {
color: "red"
}
}
}
Component.onCompleted: {
movePoint()
}
function movePoint() {
var refPointList = [];
var refPoint = ArcGISRuntimeEnvironment.createObject("Point", {
x: -117,
y: 34,
spatialReference: Factory.SpatialReference.createWgs84()});
refPointList.push(refPoint);
var linearUnit = ArcGISRuntimeEnvironment.createObject("LinearUnit", {linearUnitId: Enums.LinearUnitIdKilometers});
var angularUnit = ArcGISRuntimeEnvironment.createObject("AngularUnit", {angularUnitId: Enums.AngularUnitIdDegrees});
var movedPoints = GeometryEngine.moveGeodetic(refPointList, 2, linearUnit,
0, angularUnit, Enums.GeodeticCurveTypeGeodesic);
var graphic = ArcGISRuntimeEnvironment.createObject("Graphic", {
geometry: movedPoints[0],
symbol: ArcGISRuntimeEnvironment.createObject("SimpleMarkerSymbol", {color: "purple"})
});
graphicsOverlayAddNewPoint.graphics.append(graphic);
}
}
}
Thank you very much!