Search in sources :

Example 11 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class ExtractAttributes method extractAttribute.

/**
 * Extract attribute.
 *
 * @param attributeType the attribute type
 * @param expression the expression
 * @param foundList the found list
 * @return the class
 */
protected Class<?> extractAttribute(Class<?> attributeType, Expression expression, List<String> foundList) {
    Class<?> returnType = String.class;
    if (expression instanceof AttributeExpressionImpl) {
        AttributeExpressionImpl attribute = (AttributeExpressionImpl) expression;
        // Determine if attribute is a geometry
        if ((GeometryTypeMapping.getGeometryType(attributeType) != GeometryTypeEnum.UNKNOWN) || (attributeType == Geometry.class)) {
            if (!geometryFieldList.contains(attribute.getPropertyName())) {
                geometryFieldList.add(attribute.getPropertyName());
            }
        } else {
            if (!fieldList.containsKey(attribute.getPropertyName()) && (attribute.getPropertyName() != null)) {
                DataSourceAttributeData field = new DataSourceAttributeData(attribute.getPropertyName(), attributeType, null);
                processedFieldList.add(field);
                fieldList.put(attribute.getPropertyName(), field);
                foundList.add(attribute.getPropertyName());
            }
        }
    } else if (expression instanceof FunctionExpression) {
        FunctionExpression function = (FunctionExpression) expression;
        FunctionName functionName = function.getFunctionName();
        List<Parameter<?>> argumentList = functionName.getArguments();
        int index = 0;
        for (Expression parameterExpression : function.getParameters()) {
            Parameter<?> parameter = argumentList.get(index);
            extractAttribute(parameter.getType(), parameterExpression, foundList);
            index++;
        }
        returnType = functionName.getReturn().getType();
    } else if (expression instanceof LiteralExpressionImpl) {
        LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
        try {
            Geometry geometry = reader.read(literal.toString());
            if (geometry != null) {
                returnType = Geometry.class;
            }
        } catch (ParseException e1) {
        // Ignore
        }
        if (returnType == String.class) {
            try {
                @SuppressWarnings("unused") int integer = Integer.valueOf(literal.toString());
                returnType = Integer.class;
            } catch (NumberFormatException e) {
            // Ignore
            }
        }
        if (returnType == String.class) {
            try {
                @SuppressWarnings("unused") double doubleValue = Double.valueOf(literal.toString());
                returnType = Double.class;
            } catch (NumberFormatException e) {
            // Ignore
            }
        }
    }
    return returnType;
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpression(org.geotools.filter.FunctionExpression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) FunctionExpression(org.geotools.filter.FunctionExpression) Expression(org.opengis.filter.expression.Expression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Parameter(org.opengis.parameter.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(com.vividsolutions.jts.io.ParseException)

Example 12 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class ExtractAttributes method extractDefaultFields.

/**
 * Extract default fields.
 *
 * @param sld the sld
 */
public void extractDefaultFields(StyledLayerDescriptor sld) {
    if (sld != null) {
        visit(sld);
        // Check to see if any geometry fields have been added to processedFieldList
        List<DataSourceAttributeData> fieldsToMoveToGeometryList = new ArrayList<DataSourceAttributeData>();
        for (DataSourceAttributeData dsAttribute : processedFieldList) {
            if (dsAttribute.getType() == Geometry.class) {
                fieldsToMoveToGeometryList.add(dsAttribute);
            }
        }
        // Move geometry fields to the correct list
        for (DataSourceAttributeData ds : fieldsToMoveToGeometryList) {
            geometryFieldList.add(ds.getName());
            processedFieldList.remove(ds);
        }
    }
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) ArrayList(java.util.ArrayList)

Example 13 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class WindBarbDetails method populateExpression.

/**
 * Populate expression.
 *
 * @param wellKnownName the well known name
 */
public void populateExpression(String wellKnownName) {
    if (wellKnownName != null) {
        int startSpeedOpenBracket = wellKnownName.indexOf("(");
        int endSpeedCloseBracket = wellKnownName.indexOf(")");
        if ((startSpeedOpenBracket < 0) || (endSpeedCloseBracket < 0)) {
            // Invalid
            return;
        }
        String windSpeed = wellKnownName.substring(startSpeedOpenBracket + 1, endSpeedCloseBracket);
        int startUnitsOpenBracket = wellKnownName.indexOf("[");
        int endUnitsOpenBracket = wellKnownName.indexOf("]");
        if ((startUnitsOpenBracket < 0) || (endUnitsOpenBracket < 0)) {
            // Invalid
            return;
        }
        Expression windSpeedExpression = null;
        if (AttributeUtils.isAttribute(windSpeed)) {
            String propertyName = AttributeUtils.extract(windSpeed);
            windSpeedExpression = getFilterFactory().property(propertyName);
            DataSourceInterface dataSource = DataSourceFactory.getDataSource();
            dataSource.addField(new DataSourceAttributeData(propertyName, Double.class, null));
        } else {
            windSpeedExpression = getFilterFactory().literal(windSpeed);
        }
        boolean isNorthernHemisphere = !wellKnownName.endsWith(HEMISPHERE_S);
        fieldConfigVisitor.populateField(FieldIdEnum.WINDBARB_WINDSPEED, windSpeedExpression);
        fieldConfigVisitor.populateBooleanField(FieldIdEnum.WINDBARB_NORTHERN_HEMISPHERE, isNorthernHemisphere);
        String windSpeedUnits = wellKnownName.substring(startUnitsOpenBracket + 1, endUnitsOpenBracket);
        fieldConfigVisitor.populateComboBoxField(FieldIdEnum.WINDBARB_WINDSPEED_UNITS, windSpeedUnits);
    }
}
Also used : DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) ConstantExpression(org.geotools.filter.ConstantExpression) Expression(org.opengis.filter.expression.Expression)

Example 14 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceAttributeDataTest method testEquals.

@Test
public void testEquals() {
    String expectedName1 = "test name";
    Class<?> expectedType1 = Integer.class;
    Object expectedValue1 = Integer.valueOf(42);
    DataSourceAttributeData dsa1 = new DataSourceAttributeData(expectedName1, expectedType1, expectedValue1);
    DataSourceAttributeData dsa3 = new DataSourceAttributeData(expectedName1, expectedType1, expectedValue1);
    assertEquals(dsa1, dsa1);
    assertEquals(dsa1, dsa3);
    assertEquals(dsa1.hashCode(), dsa1.hashCode());
    assertFalse(dsa1.equals(null));
    String expectedName2 = "test name2";
    Class<?> expectedType2 = Double.class;
    Object expectedValue2 = Integer.valueOf(24);
    DataSourceAttributeData dsa2 = new DataSourceAttributeData(expectedName2, expectedType2, expectedValue2);
    assertFalse(dsa1.equals(dsa2));
    DataSourceAttributeData obj1 = new DataSourceAttributeData(expectedName1, expectedType2, expectedValue1);
    assertFalse(dsa1.equals(obj1));
    assertFalse(dsa1.equals(new DataSourceAttributeData(expectedName1, null, expectedValue1)));
    assertFalse(dsa1.equals(new DataSourceAttributeData(null, expectedType1, expectedValue1)));
    DataSourceAttributeData obj2 = new DataSourceAttributeData(expectedName1, expectedType1, expectedValue2);
    assertTrue(dsa1.equals(obj2));
    assertFalse(new DataSourceAttributeData(null, expectedType1, expectedValue1).equals(dsa1));
    assertFalse(new DataSourceAttributeData(expectedName1, null, expectedValue1).equals(dsa1));
    assertTrue(new DataSourceAttributeData(expectedName1, expectedType1, null).equals(dsa1));
    DataSourceAttributeData obj3 = new DataSourceAttributeData(null, expectedType1, expectedValue1);
    assertFalse(obj3.equals("wrong class"));
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) Test(org.junit.Test)

Example 15 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceAttributeDataTest method testSetType.

/**
 * Test method for {@link com.sldeditor.datasource.attribute.DataSourceAttributeData#setType(java.lang.Class)}.
 */
@Test
public void testSetType() {
    String expectedName = "test name";
    Class<?> expectedType1 = Integer.class;
    Object expectedValue = Integer.valueOf(42);
    DataSourceAttributeData dsa = new DataSourceAttributeData(expectedName, expectedType1, expectedValue);
    Class<?> expectedType2 = Float.class;
    dsa.setType(expectedType2);
    assertEquals(expectedType2, dsa.getType());
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) Test(org.junit.Test)

Aggregations

DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)40 Test (org.junit.Test)23 ExtractAttributes (com.sldeditor.datasource.impl.ExtractAttributes)12 ArrayList (java.util.ArrayList)11 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)10 Rule (org.geotools.styling.Rule)8 Filter (org.opengis.filter.Filter)8 LineString (com.vividsolutions.jts.geom.LineString)5 SLDDataInterface (com.sldeditor.common.SLDDataInterface)4 DataSourceAttributeList (com.sldeditor.datasource.attribute.DataSourceAttributeList)4 Point (com.vividsolutions.jts.geom.Point)4 IOException (java.io.IOException)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)4 DataSourceImpl (com.sldeditor.datasource.impl.DataSourceImpl)3 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)3 SLDData (com.sldeditor.common.data.SLDData)2 CreateDataSourceInterface (com.sldeditor.datasource.impl.CreateDataSourceInterface)2