【解决办法】:
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;
}