Search in sources :

Example 26 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class Styles method ttfPoint2.

public static MutableStyle ttfPoint2() throws URISyntaxException {
    // general informations
    final String name = "mySymbol";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    // the visual element
    final Expression size = FF.literal(12);
    final Expression opacity = LITERAL_ONE_FLOAT;
    final Expression rotation = LITERAL_ONE_FLOAT;
    final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
    final Displacement disp = DEFAULT_DISPLACEMENT;
    final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    final Stroke stroke = SF.stroke(Color.BLACK, 1);
    final Fill fill = SF.fill(Color.RED);
    final Expression external = FF.literal("ttf:Dialog?char=0x2A");
    final Mark mark = SF.mark(external, fill, stroke);
    symbols.add(mark);
    final Graphic graphic = SF.graphic(symbols, opacity, size, rotation, anchor, disp);
    final PointSymbolizer symbolizer = SF.pointSymbolizer(name, geometry, desc, unit, graphic);
    final MutableStyle style = SF.style(symbolizer);
    return style;
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Stroke(org.opengis.style.Stroke) GraphicStroke(org.opengis.style.GraphicStroke) Fill(org.opengis.style.Fill) GraphicFill(org.opengis.style.GraphicFill) Description(org.opengis.style.Description) Graphic(org.opengis.style.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) ExternalMark(org.opengis.style.ExternalMark) Mark(org.opengis.style.Mark) Unit(javax.measure.Unit) Displacement(org.opengis.style.Displacement) AnchorPoint(org.opengis.style.AnchorPoint) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression)

Example 27 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class SE100toGTTransformer method visitUserStyle.

// Style, FTS and Rule-------------------------------------------------------
/**
 * Transform a SLD v1.0 userstyle in GT style.
 */
public MutableStyle visitUserStyle(final org.geotoolkit.sld.xml.v100.UserStyle us) {
    if (us == null) {
        return null;
    } else {
        final MutableStyle mls = styleFactory.style();
        mls.setName(us.getName());
        final InternationalString title = (us.getTitle() == null) ? null : new SimpleInternationalString(us.getTitle());
        final InternationalString abs = (us.getAbstract() == null) ? null : new SimpleInternationalString(us.getAbstract());
        mls.setDescription(styleFactory.description(title, abs));
        final Boolean def = us.isIsDefault();
        mls.setDefault((def != null) ? def : false);
        final List<org.geotoolkit.sld.xml.v100.FeatureTypeStyle> ftss = us.getFeatureTypeStyle();
        for (final org.geotoolkit.sld.xml.v100.FeatureTypeStyle obj : ftss) {
            final MutableFeatureTypeStyle fts = visitFTS(obj);
            mls.featureTypeStyles().add(fts);
        }
        return mls;
    }
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle)

Example 28 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class SE110toGTTransformer method visitUserStyle.

// Style, FTS and Rule-------------------------------------------------------
/**
 * Transform a SLD v1.1 userstyle in GT style.
 */
public MutableStyle visitUserStyle(final org.geotoolkit.sld.xml.v110.UserStyle us) throws FactoryException {
    if (us == null) {
        return null;
    } else {
        final MutableStyle mls = styleFactory.style();
        mls.setName(us.getName());
        mls.setDescription(visitDescription(us.getDescription()));
        final Boolean def = us.isIsDefault();
        mls.setDefault((def != null) ? def : false);
        final List<Object> ftss = us.getFeatureTypeStyleOrCoverageStyleOrOnlineResource();
        for (final Object obj : ftss) {
            MutableFeatureTypeStyle fts = visitFTS(obj);
            mls.featureTypeStyles().add(fts);
        }
        return mls;
    }
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle)

Example 29 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class MapBuilder method createFeatureLayer.

/**
 * Create a default feature map layer with a feature collection and a style.
 * @param collection layer data collection
 * @return FeatureMapLayer
 * @deprecated use createLayer method instead
 */
@Deprecated
public static MapLayer createFeatureLayer(final FeatureSet collection) {
    MutableStyle style;
    String name = "";
    String title = null;
    String abstrat = null;
    try {
        final FeatureType type = collection.getType();
        name = type.getName().tip().toString();
        title = name;
        abstrat = type.getName().toString();
        style = RandomStyleBuilder.createDefaultVectorStyle(type);
    } catch (DataStoreException ex) {
        style = ((MutableStyleFactory) DefaultFactories.forBuildin(StyleFactory.class)).style(RandomStyleBuilder.createRandomPointSymbolizer());
    }
    final MapLayer maplayer = new MapLayer();
    maplayer.setData(collection);
    maplayer.setStyle(style);
    maplayer.setIdentifier(name);
    maplayer.setTitle(title);
    maplayer.setAbstract(abstrat);
    maplayer.setOpacity(1.0);
    return maplayer;
}
Also used : MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) StyleFactory(org.opengis.style.StyleFactory) FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) MutableStyle(org.geotoolkit.style.MutableStyle) MapLayer(org.apache.sis.portrayal.MapLayer) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory)

Example 30 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class WMCUtilities method getMapContext.

/**
 * Create a Geotk {@link MapContext} embeding layers described by given wmc.
 *
 * @param root The {@link ViewContextType}, root markup of the wmc.
 * @return a {@link MapContext} containing layers extracted from wmc.
 */
public static MapLayers getMapContext(ViewContextType root) {
    ArgumentChecks.ensureNonNull("ViewContextType", root);
    CoordinateReferenceSystem srs = CommonCRS.WGS84.normalizedGeographic();
    final MapLayers context = MapBuilder.createContext();
    // Get needed markups
    GeneralType general = root.getGeneral();
    LayerListType layers = root.getLayerList();
    if (general != null) {
        // Retrieve enveloppe for the map context.
        BoundingBoxType bbox = general.getBoundingBox();
        try {
            srs = AbstractCRS.castOrCopy(CRS.forCode(bbox.getSRS())).forConvention(AxesConvention.RIGHT_HANDED);
        } catch (FactoryException ex) {
            Logger.getLogger("org.geotoolkit.wmc").log(Level.SEVERE, null, ex);
        }
        final double width = bbox.getMaxx().subtract(bbox.getMinx()).doubleValue();
        final double height = bbox.getMaxy().subtract(bbox.getMiny()).doubleValue();
        Envelope aoi = new Envelope2D(srs, bbox.getMinx().doubleValue(), bbox.getMiny().doubleValue(), width, height);
        SimpleInternationalString title = new SimpleInternationalString(general.getTitle());
        SimpleInternationalString description = new SimpleInternationalString((general.getAbstract() == null) ? "No description" : general.getAbstract());
        context.setTitle(title);
        context.setAbstract(description);
        context.setAreaOfInterest(aoi);
    }
    // set context general values
    context.setIdentifier(root.getId());
    // fill context with layers
    for (final LayerType layerType : layers.getLayer()) {
        // build server from parameters.
        final ServerType serverType = layerType.getServer();
        final DataStore server;
        final String serviceId = getServiceId(serverType.getService().value());
        final GenericName layerName = NamesExt.valueOf(layerType.getName());
        try {
            final URL serviceURL = new URL(serverType.getOnlineResource().getHref());
            final DataStoreProvider factory = DataStores.getProviderById(serviceId);
            final ParameterValueGroup parameters = factory.getOpenParameters().createValue();
            parameters.parameter("identifier").setValue(serviceId);
            parameters.parameter("version").setValue(serverType.getVersion());
            parameters.parameter("url").setValue(serviceURL);
            server = factory.open(parameters);
        } catch (Exception ex) {
            Logger.getLogger("org.geotoolkit.wmc").log(Level.SEVERE, null, ex);
            continue;
        }
        try {
            Resource resource = server.findResource(layerName.toString());
            if (resource instanceof FeatureSet) {
                final FeatureSet featureSet = (FeatureSet) resource;
                final MutableStyle style = RandomStyleBuilder.createRandomVectorStyle(featureSet.getType());
                final MapLayer layer = MapBuilder.createLayer(featureSet);
                layer.setStyle(style);
                context.getComponents().add(layer);
            } else if (resource instanceof GridCoverageResource) {
                final MapLayer mapLayer = MapBuilder.createCoverageLayer((GridCoverageResource) resource);
                context.getComponents().add(mapLayer);
            }
        } catch (DataStoreException ex) {
            Logger.getLogger("org.geotoolkit.wmc").log(Level.SEVERE, null, ex);
            continue;
        }
    }
    return context;
}
Also used : FactoryException(org.opengis.util.FactoryException) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) MapLayer(org.apache.sis.portrayal.MapLayer) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) Envelope(org.opengis.geometry.Envelope) URL(java.net.URL) GenericName(org.opengis.util.GenericName) MutableStyle(org.geotoolkit.style.MutableStyle) DataStore(org.apache.sis.storage.DataStore) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DataStoreException(org.apache.sis.storage.DataStoreException) DataStoreProvider(org.apache.sis.storage.DataStoreProvider) Resource(org.apache.sis.storage.Resource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) Envelope2D(org.apache.sis.geometry.Envelope2D) DataStoreException(org.apache.sis.storage.DataStoreException) JAXBException(javax.xml.bind.JAXBException) FactoryException(org.opengis.util.FactoryException) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) FeatureSet(org.apache.sis.storage.FeatureSet) MapLayers(org.apache.sis.portrayal.MapLayers)

Aggregations

MutableStyle (org.geotoolkit.style.MutableStyle)55 Expression (org.opengis.filter.Expression)20 MapLayer (org.apache.sis.portrayal.MapLayer)19 Unit (javax.measure.Unit)16 MapLayers (org.apache.sis.portrayal.MapLayers)15 Description (org.opengis.style.Description)15 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 Feature (org.opengis.feature.Feature)11 FeatureType (org.opengis.feature.FeatureType)11 Fill (org.opengis.style.Fill)11 GraphicalSymbol (org.opengis.style.GraphicalSymbol)11 Stroke (org.opengis.style.Stroke)11 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)10 FeatureSet (org.apache.sis.storage.FeatureSet)10 GraphicStroke (org.opengis.style.GraphicStroke)10 PointSymbolizer (org.opengis.style.PointSymbolizer)10 BufferedImage (java.awt.image.BufferedImage)9 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)9 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)9