How to set multiple conditions in definition expression of a feature layer

774
2
10-28-2013 04:15 AM
NiranjanBorawake
New Contributor
When I set definition expression of a county layer to
countyLayer.setDefinitionExpression("STATE_FIPS = '" + fips + "'");
only the counties in state with FIPS as
fips
are rendered.

Now, what I need to do is render all the blocks inside a county of a state. Block group layer has STATE_FIPS (length 2 ) and CNTY_FIPS (length 3). If I set definition expression to
blockLayer.setDefinitionExpression("CNTY_FIPS = '" + countyFips + "'");
, this will render blocks inside county with CNTY_FIPS = countyFips. But, since CNTY_FIPS is of length 3 and this expression matches for county in every state and blocks inside all the counties of the states are rendered.

I am trying or rather what I need to do is
blockLayer.setDefinitionExpression("CNTY_FIPS = '" + countyFips + "' AND STATE_FIPS = '" + fips + "'");


This way only blocks inside a state with STATE_FIPS = fips will be renedered. But combining expression with AND does not work.

Any help would be apreciated. Thanks in advance.
0 Kudos
2 Replies
ManojrajTeli
Occasional Contributor II
Hi Niranjan Borawake,

could you run the definition expression string you get after merging the string in rest endpoint and find out what exactly error.Actually all the expression from SQL works for the service there may be string format error.


Thanks
Manojraj Teli
0 Kudos
NiranjanBorawake
New Contributor
Thanks Manojraj.

This time it did work. May be there was some issue with the expression string that was getting created. Now when I do
blockLayer.getDefinitionExpression()
it gives me "STATE_FIPS = '01' AND CNTY_FIPS='001'".

Thanks.
0 Kudos