AnsweredAssumed Answered

GeometryEngine.within() - must have equivalent geometries

Question asked by cloftis_RTI_GST on Jul 30, 2018
Latest reply on Jul 31, 2018 by sgill-esristaff

Using ArcGIS andorid 100x API I'm trying to determine if points returned onLocationChanged are within a queried feature. When I use the GeometryEngine.within() method I'm getting runtime errors stating that "geometry1 and geometry2 must have equivalent spatial references." Adding a breakpoint to my code I see that my Point (i.e., geometry 1) has spatial reference SR: 4326, but the spatial reference (feature.getGeometry()) associated with the feature returned from my queryFeatureAsync (i.e., geometry 2) is null. Assuming this is the source of the problem, how can I get my feature to have the correct spatial reference? 

 

Code snippet:

       // get the MapView's LocationDisplay
      this.mLocationDisplay = this.mMapView.getLocationDisplay();
      this.mLocationDisplay.addLocationChangedListener(new LocationDisplay.LocationChangedListener() {
         @Override
         public void onLocationChanged(LocationDisplay.LocationChangedEvent locationChangedEvent) {
            final LocationDataSource.Location l = locationChangedEvent.getLocation();
            // segments == layer containing geometries of interest
           
if (MainActivity.this.segments != null) {
               final FeatureTable featureTable = MainActivity.this.segments.getFeatureTable();
               featureTable.addDoneLoadingListener(new Runnable() {
                  @Override
                  public void run() {
                     featureTable.removeDoneLoadingListener(null);
                     QueryParameters queryParameters = new QueryParameters();
                     queryParameters.setWhereClause(String.format("feature_identifier='%1$s'", "myFeature"));
                     final ListenableFuture<FeatureQueryResult> listenableFuture = featureTable.queryFeaturesAsync(queryParameters);
                     listenableFuture.addDoneListener(new Runnable() {
                        @Override
                        public void run() {
                           try {
                              FeatureQueryResult featureQueryResult = listenableFuture.get();
                              if (featureQueryResult.iterator().hasNext()) {
                                 try {
                                    Iterator<Feature> iterator = featureQueryResult.iterator(); // create an Iterator
                                    Feature feature;
                                    while (iterator.hasNext()) { // cycle through results
                                       feature = iterator.next();
                                       if (l.getPosition() != null) {
                                          //****next line: geometry1 and geometry2 must have equivalent spatial references *****
                                          if (GeometryEngine.within(l.getPosition(), feature.getGeometry())) {
                                             Log.d(TAG, "inside feature");
                                          } else {
                                             Log.d(TAG, "outside feature");
                                          }
                                       }
                                    }
                                 } catch (Exception e) {
                                    Log.e(TAG, e.getMessage());
                                 }
                              }
                           } catch (Exception e) {
                              Log.e(TAG, e.getMessage());
                           }
                        }
                     });
                  }
               });
            }
         }
      });

Outcomes