arcgis sdk android,ArcGIS Runtime SDK for Android

【解决办法】:

ArcGIS for Android 10.2.7的API提供了setOrderByFields方法实现对要素服务生成的.geodatabase进行排序,使用该方法的前提需要要素服务本身支持supportedadvancedquery。但是这种... 显示全部 »

【解决办法】:

ArcGIS for Android 10.2.7的API提供了setOrderByFields方法实现对要素服务生成的.geodatabase进行排序,使用该方法的前提需要要素服务本身支持supportedadvancedquery。但是这种方式经过测试无效。可以通过以下示例代码实现在客户端对要素进行排序,但是如果要排序的要素过多,会影响性能:

[code]

private void queryTable() {

String[] outFields = {sortField};

QueryParameters queryParams = new QueryParameters();

queryParams.setOutFields(outFields);

queryParams.setWhere(objectid > 0);

featureTable.queryFeatures(queryParams, new CallbackListener(){

@Override

public void onCallback(FeatureResult objs) {

Feature[] arrayToSort = new Feature[(int) objs.featureCount()];

int i = 0;

for(Object object : objs) {

Feature feature = (Feature) object;

arrayToSort[i] = feature;

i++;

}

Feature[] sortedArray = prepareSort(arrayToSort, sortField, true);

for(Feature feature : sortedArray) {

System.out.println(feature.getAttributeValue(sortField));

}

}

@Override

public void onError(Throwable e) {

e.printStackTrace();

}

});

}

private Feature[] prepareSort(Feature[] arrayToSort, String fieldName, boolean ascending) {

try {

Integer.valueOf((String) arrayToSort[0].getAttributeValue(fieldName).toString());

return sortNumberArray(arrayToSort, fieldName, ascending);

}

catch (Exception e){

return sortStringArray(arrayToSort, fieldName, ascending);

}

}

private Feature[] sortStringArray(Feature[] arrayToSort, String fieldName, boolean ascending) {

System.out.println(stringSort);

Feature temp;

for(int i = 0; i 

for(int j = 1; j < (arrayToSort.length-i); j++) {

if(ascending) {

if(arrayToSort[j-1].getAttributeValue(fieldName).toString().compareToIgnoreCase(arrayToSort[j].getAttributeValue(fieldName).toString()) > 0) {

temp = arrayToSort[j-1];

arrayToSort[j-1] = arrayToSort[j];

arrayToSort[j] = temp;

}

}

else {

if(arrayToSort[j-1].getAttributeValue(fieldName).toString().compareToIgnoreCase(arrayToSort[j].getAttributeValue(fieldName).toString()) < 0) {

temp = arrayToSort[j-1];

arrayToSort[j-1] = arrayToSort[j];

arrayToSort[j] = temp;

}

}

}

}

return arrayToSort;

}

private Feature[] sortNumberArray(Feature[] arrayToSort, String fieldName, boolean ascending) {

Feature temp;

for(int i = 0; i 

for(int j = 1; j < (arrayToSort.length-i); j++) {

if(ascending) {

if(Double.parseDouble(arrayToSort[j-1].getAttributeValue(fieldName).toString()) > Double.parseDouble(arrayToSort[j].getAttributeValue(fieldName).toString())) {

temp = arrayToSort[j-1];

arrayToSort[j-1] = arrayToSort[j];

arrayToSort[j] = temp;

}

}

else {

if(Double.parseDouble(arrayToSort[j-1].getAttributeValue(fieldName).toString()) < Double.parseDouble(arrayToSort[j].getAttributeValue(fieldName).toString())) {

temp = arrayToSort[j-1];

arrayToSort[j-1] = arrayToSort[j];

arrayToSort = temp;

}

}

}

}

return arrayToSort;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值