Adding x and y offset to a Point

989
5
Jump to solution
11-14-2021 11:07 PM
FatmaAkdemir
Occasional Contributor II

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?

0 Kudos
1 Solution

Accepted Solutions
AndrewBladon
Esri Contributor
Hi Fatma - thank you for your message.

 

Yes, you can create a new point by applying an offset to an existing point using the GeometryEngine::moveGeodetic method (or GeometryEngine.moveGeodetic method using Qml). This allows you to offset a point/points by a specified distance and azimuth.

 

If you would like to apply an offset in the x and y directions, you could use the moveGeodetic method twice, once in the x-direction and then again in the y-direction. Please find an example of this using the C++ api below, where:
  • An initial point initialPoint is created.
  • initialPoint is converted from a Point object into a QList<Point> called initialPointList for compatability with the GeometryEngine::moveGeodetic method arguments.
  • initialPointList is offset by 1000m in the y-direction to create a new QList<Point> called yOffsetPoint.
  • yOffsetPoint is offset by 500m in the x-direction to create a new QList<Point> called offsetPointList.
  • The offset point is converted from the QList<Point> into a Point called offsetPoint.

 

// 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);

 

I hope this helps you achieve your desired result. Let us know if we can provide you with any further information.

View solution in original post

5 Replies
AndrewBladon
Esri Contributor
Hi Fatma - thank you for your message.

 

Yes, you can create a new point by applying an offset to an existing point using the GeometryEngine::moveGeodetic method (or GeometryEngine.moveGeodetic method using Qml). This allows you to offset a point/points by a specified distance and azimuth.

 

If you would like to apply an offset in the x and y directions, you could use the moveGeodetic method twice, once in the x-direction and then again in the y-direction. Please find an example of this using the C++ api below, where:
  • An initial point initialPoint is created.
  • initialPoint is converted from a Point object into a QList<Point> called initialPointList for compatability with the GeometryEngine::moveGeodetic method arguments.
  • initialPointList is offset by 1000m in the y-direction to create a new QList<Point> called yOffsetPoint.
  • yOffsetPoint is offset by 500m in the x-direction to create a new QList<Point> called offsetPointList.
  • The offset point is converted from the QList<Point> into a Point called offsetPoint.

 

// 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);

 

I hope this helps you achieve your desired result. Let us know if we can provide you with any further information.
FatmaAkdemir
Occasional Contributor II

Thank you very much @AndrewBladon !  I guess I have overlooked this method of GeometryEngine.

0 Kudos
lsc
by
New Contributor II

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);
}

0 Kudos
LucasDanzinger
Esri Frequent Contributor

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);
        }
    }
}
lsc
by
New Contributor II

Thank you very much!

0 Kudos