Select to view content in your preferred language

Is it possible to apply a spatial filter AND a where clause against a Feature Layer?

475
3
06-22-2022 11:27 AM
LeeTaEthni
Emerging Contributor

I get type errors if I put in anything other than '1=1' in the where clause when using geometry input on a query.  Is it supported to do both a SQL filter and spatial filter on a Feature Layer query?

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

Can you post your code?

0 Kudos
LeeTaEthni
Emerging Contributor

public query(value: string, point?: { latitude: number; longitude: number }): Observable<PeopleInCountry[]> {
value = value.toLowerCase();
const query = {
outFields: ['PEID', 'NmDisp', 'GENC0'],
orderByFields: ['NmDisp'],
where: `status=1`,
geometry: {
type: 'point',
latitude: point!.latitude,
longitude: point!.longitude,
} as any,
} as any;
if (value) {
query.where = `LOWER(NmDisp) LIKE '%${value}%' OR LOWER(PEID) LIKE '%${value}%' AND status = 1`;
}
return new Observable((observer) => {
this.featureLayer
.queryFeatures(query)
.then((result) => {
observer.next(result);
observer.complete();
})
.catch((e) => {
observer.error(e);
observer.complete();
});
});
}

0 Kudos
KenBuja
MVP Esteemed Contributor

When you're working with TypeScript, you can't use autocasting.

Due to limitations in TypeScript, autocasting works best in non-TypeScript applications. Autocasting casts JavaScript objects as ArcGIS API for JavaScript class types without the need for these classes to be explicitly imported. No changes are required if you are already using the API without any TypeScript build errors.

You won't be able to use

geometry: {
  type: 'point',
  latitude: point!.latitude,
  longitude: point!.longitude,
} as any,

 but have to create a new Point and use that in the geometry property

geometry: new Point({
  latitude: point!.latitude,
  longitude: point!.longitude
});
0 Kudos