Select to view content in your preferred language

GeometryEngine doesn't project correct point

2415
9
Jump to solution
07-18-2017 02:16 AM
spkiwijohnson
Deactivated User

Hello everyone.

The thing is, when I project the point, the getX() and getY() methods of the resulting point (mMapPoint) sometimes throw a GeometryException, because its X and Y values are NaN.

Here is the piece of code with the issue I am currently facing.

double locy = mLocationToShow.getLatitude();
double locx = mLocationToShow.getLongitude();

Point wgsPoint = new Point(locx, locy);
SpatialReference spatialNew = SpatialReference.create(4326);
SpatialReference spatialMapView = mMapView.getSpatialReference(); // its value is 102100

mMapPoint = (Point) GeometryEngine.project(wgsPoint,
 spatialNew,
 spatialMapView);
mMapViewEnvelope = new Envelope(mMapPoint, Constants.kMapMiniMapStandardZoom,
Constants.kMapMiniMapStandardZoom);

Maybe the issue has something to do with normalization (normalizeCentralMeridian), but I can't figure out how to implement it in this case.

Any help is appreciated.

0 Kudos
1 Solution

Accepted Solutions
AlexanderNohe1
Honored Contributor

I believe your X and Y are mixed up.

The Y value cannot be outside of the range of -90 to 90 in projection 4326 since this is decimal degrees.

This image should help:

 Decimal degrees

View solution in original post

9 Replies
AlexanderNohe1
Honored Contributor

Which version of the runtime are you using?

0 Kudos
spkiwijohnson
Deactivated User

It is 10.2.9.

0 Kudos
AlexanderNohe1
Honored Contributor

What are these values:

Constants.kMapMiniMapStandardZoom
0 Kudos
AlexanderNohe1
Honored Contributor

Also, can you give us an idea of the coordinates before projecting?

0 Kudos
spkiwijohnson
Deactivated User

Sure! But I assume that the problem arises earlier (when projecting the point with GeometryEngine.project).

Constants.kMapMiniMapStandardZoom = 350.0

For example, the flow is the following:

0. We call this whole method.

1. At the beginning the mMapPoint is not initialized. The mMapView SpatialReference is null.

2. Then we assign wgsPoint the following values: 46.73234939575195 and -117.00054168701172.

3. After this mMapPoint is successfully assigned.

4. Then in another method mMapView is assigned SpatialReference value of 102100.

5. We call this whole method once more.

6. Again, the coordinates of wgsPoint are the same: 46.73234939575195 and -117.000541687011726.

7. And NOW after we once again project the Point, when we try to call getX() or getY() on mMapPoint the exception is thrown.

So the only difference is in the following: during the first call of this method the SpatialReference of mMapView  is null and during the second call it is 102100.

0 Kudos
AlexanderNohe1
Honored Contributor

What happens when you assign the point a spatial reference rather than specifying it in the project method?

0 Kudos
AlexanderNohe1
Honored Contributor

So I just tried reproducing and was unsuccessful in getting any errors or exceptions thrown.  Could you be a bit more specific on the exception?  What exactly did it say?  Below is the code I used trying to repro.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        double locX = -117.000541687011726;
        double locY = 46.73234939575195;

        Point point = new Point(locX, locY);
        Point z = projectPoint(point, null);
        Log.e("NOHE", "" + z.getX());
        Point point1 = projectPoint(z, SpatialReference.create(102100));
        Log.e("NOHE", "" + point1.getX());
    }

    private Point projectPoint(Point pointToProject, SpatialReference projectTo) {
        double locX = pointToProject.getX();
        double locY = pointToProject.getY();

        Point point = new Point(locX, locY);
        return (Point) GeometryEngine.project(point, SpatialReference.create(4326), projectTo);

    }
spkiwijohnson
Deactivated User

Yes, that is definitely the same case! However, we should swap around the initial coordinates in your example (it's location of Moskow, Idaho) and so we can now reproduce my issue.

double locX = 46.73234939575195;
double locY = -117.00054168701172;

After this, I get the same error in your example, as I got in my own code: 

Caused by: com.esri.core.geometry.GeometryException: This operation should not be performed on an empty geometry.
at com.esri.core.geometry.Point.getX(SourceFile:143)

0 Kudos
AlexanderNohe1
Honored Contributor

I believe your X and Y are mixed up.

The Y value cannot be outside of the range of -90 to 90 in projection 4326 since this is decimal degrees.

This image should help:

 Decimal degrees