Java Code Examples for org.geotools.styling.UserLayer#setLayerFeatureConstraints()

The following examples show how to use org.geotools.styling.UserLayer#setLayerFeatureConstraints() . 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: InlineDatastoreVisitor.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 *
 * @see
 *     org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.UserLayer)
 */
@Override
public void visit(UserLayer layer) {

    Style[] style = layer.getUserStyles();
    int length = style.length;
    Style[] styleCopy = new Style[length];
    for (int i = 0; i < length; i++) {
        if (style[i] != null) {
            style[i].accept(this);
            styleCopy[i] = (Style) pages.pop();
        }
    }

    FeatureTypeConstraint[] lfc = layer.getLayerFeatureConstraints();
    FeatureTypeConstraint[] lfcCopy = new FeatureTypeConstraint[lfc.length];

    length = lfc.length;
    for (int i = 0; i < length; i++) {
        if (lfc[i] != null) {
            lfc[i].accept(this);
            lfcCopy[i] = (FeatureTypeConstraint) pages.pop();
        }
    }

    UserLayer copy = sf.createUserLayer();
    copy.setName(layer.getName());
    copy.setUserStyles(styleCopy);
    copy.setLayerFeatureConstraints(lfcCopy);

    // Reuse the existing inline feature data store
    copy.setInlineFeatureDatastore(layer.getInlineFeatureDatastore());
    copy.setInlineFeatureType(layer.getInlineFeatureType());

    if (STRICT && !copy.equals(layer)) {
        throw new IllegalStateException("Was unable to duplicate provided UserLayer:" + layer);
    }
    pages.push(copy);
}
 
Example 2
Source File: SldUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a style to its string representation to be written to file.
 * 
 * @param style the style to convert.
 * @return the style string.
 * @throws Exception
 */
public static String styleToString( Style style ) throws Exception {
    StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
    UserLayer layer = sf.createUserLayer();
    layer.setLayerFeatureConstraints(new FeatureTypeConstraint[]{null});
    sld.addStyledLayer(layer);
    layer.addUserStyle(style);

    SLDTransformer aTransformer = new SLDTransformer();
    aTransformer.setIndentation(4);
    String xml = aTransformer.transform(sld);
    return xml;
}
 
Example 3
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a style to its string representation to be written to file.
 * 
 * @param style the style to convert.
 * @return the style string.
 * @throws Exception
 */
public static String styleToString( Style style ) throws Exception {
    StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
    UserLayer layer = sf.createUserLayer();
    layer.setLayerFeatureConstraints(new FeatureTypeConstraint[]{null});
    sld.addStyledLayer(layer);
    layer.addUserStyle(style);

    SLDTransformer aTransformer = new SLDTransformer();
    aTransformer.setIndentation(4);
    String xml = aTransformer.transform(sld);
    return xml;
}
 
Example 4
Source File: StyleWrapper.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a style to its string representation to be written to file.
 * 
 * @param style the style to convert.
 * @return the style string.
 * @throws Exception
 */
public String toXml() throws Exception {
    StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
    UserLayer layer = sf.createUserLayer();
    layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] { null });
    sld.addStyledLayer(layer);
    layer.addUserStyle(style);

    SLDTransformer aTransformer = new SLDTransformer();
    aTransformer.setIndentation(4);
    String xml = aTransformer.transform(sld);
    return xml;
}
 
Example 5
Source File: UserLayerDetails.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update symbol.
 *
 * @param changedField the changed field
 */
private void updateSymbol(FieldIdEnum changedField) {
    if (!Controller.getInstance().isPopulating()) {
        UserLayer userLayer = getStyleFactory().createUserLayer();
        String name = fieldConfigVisitor.getText(FieldIdEnum.NAME);
        userLayer.setName(name);

        // Feature type constraints
        List<FeatureTypeConstraint> ftcList =
                fieldConfigVisitor.getFeatureTypeConstraint(
                        FieldIdEnum.LAYER_FEATURE_CONSTRAINTS);
        if ((ftcList != null) && !ftcList.isEmpty()) {
            FeatureTypeConstraint[] ftcArray = new FeatureTypeConstraint[ftcList.size()];
            userLayer.setLayerFeatureConstraints(ftcList.toArray(ftcArray));
        }

        // Source
        GroupConfigInterface group = getGroup(GroupIdEnum.USER_LAYER_SOURCE);
        if (group != null) {
            MultiOptionGroup userLayerSourceGroup = (MultiOptionGroup) group;

            OptionGroup selectedOption = userLayerSourceGroup.getSelectedOptionGroup();
            switch (selectedOption.getId()) {
                case REMOTE_OWS_OPTION:
                    updateRemoteOWS(userLayer);
                    break;
                case INLINE_FEATURE_OPTION:
                    updateInlineFeatureOption(userLayer);
                    break;
                default:
                    break;
            }
        }

        StyledLayer existingStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        if (existingStyledLayer instanceof UserLayerImpl) {
            UserLayerImpl existingUserLayer = (UserLayerImpl) existingStyledLayer;

            for (Style style : existingUserLayer.userStyles()) {
                userLayer.addUserStyle(style);
            }
        }
        SelectedSymbol.getInstance().replaceStyledLayer(userLayer);

        // Update inline data sources if the inline data changed,
        // reduces creation of datasources
        updateInLineFeature(changedField);

        this.fireUpdateSymbol();
    }
}