Java Code Examples for com.nextgis.maplib.datasource.Feature#setFieldValue()

The following examples show how to use com.nextgis.maplib.datasource.Feature#setFieldValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void readNGWDate(Feature feature, JsonReader reader, String fieldName)
        throws IOException
{
    reader.beginObject();
    int nYear = 1900;
    int nMonth = 1;
    int nDay = 1;
    int nHour = 0;
    int nMinute = 0;
    int nSecond = 0;
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(NGWUtil.NGWKEY_YEAR)) {
            nYear = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_MONTH)) {
            nMonth = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_DAY)) {
            nDay = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_HOUR)) {
            nHour = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_MINUTE)) {
            nMinute = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_SECOND)) {
            nSecond = reader.nextInt();
        } else {
            reader.skipValue();
        }
    }

    TimeZone timeZone = TimeZone.getDefault();
    timeZone.setRawOffset(0); // set to UTC
    Calendar calendar = new GregorianCalendar(timeZone);
    calendar.set(nYear, nMonth - 1, nDay, nHour, nMinute, nSecond);
    calendar.set(Calendar.MILLISECOND, 0); // we must to reset millis
    feature.setFieldValue(fieldName, calendar.getTimeInMillis());

    reader.endObject();
}
 
Example 2
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void readNGWFeatureFields(Feature feature, JsonReader reader, List<Field> fields)
        throws IOException, IllegalStateException, NumberFormatException
{
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (reader.peek() == JsonToken.NULL) {
            reader.skipValue();
        } else {
            boolean bAdded = false;
            for (Field field : fields) {
                if (field.getName().equals(name) || field.getName().equals(LayerUtil.normalizeFieldName(name))) {
                    switch (field.getType()) {
                        case GeoConstants.FTReal:
                            feature.setFieldValue(field.getName(), reader.nextDouble());
                            bAdded = true;
                            break;
                        case GeoConstants.FTInteger:
                            feature.setFieldValue(field.getName(), reader.nextInt());
                            bAdded = true;
                            break;
                        case GeoConstants.FTString:
                            feature.setFieldValue(field.getName(), reader.nextString());
                            bAdded = true;
                            break;
                        case GeoConstants.FTDate:
                        case GeoConstants.FTTime:
                        case GeoConstants.FTDateTime:
                            readNGWDate(feature, reader, field.getName());
                            bAdded = true;
                            break;
                        default:
                            break;
                    }
                    break;
                }
            }
            if (!bAdded) {
                reader.skipValue();
            }
        }
    }
    reader.endObject();
}