Search in sources :

Example 26 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class InlineFeatureUtilsTest method testGetInlineFeaturesText.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#getInlineFeaturesText(org.geotools.styling.UserLayer)}.
 */
@Test
public void testGetInlineFeaturesText() {
    String actualResult = InlineFeatureUtils.getInlineFeaturesText(null);
    assertTrue(actualResult.compareTo("") == 0);
    // Test 1
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    UserLayer userLayer1 = (UserLayer) sld.layers().get(0);
    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer1);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));
    // Test 2
    sldData = new SLDData(null, testInline1b);
    sld = SLDUtils.createSLDFromString(sldData);
    UserLayer userLayer2 = (UserLayer) sld.layers().get(0);
    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer2);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) UserLayer(org.geotools.styling.UserLayer) Test(org.junit.Test)

Example 27 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class CreateInlineDataSource method connect.

/**
 * Creates the data source.
 *
 * @param typeName the type name
 * @param geometryFieldName the geometry field name
 * @param editorFile the editor file
 * @return the list of data stores
 */
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
    for (DataSourceInfo dsInfo : dataSourceInfoList) {
        dsInfo.reset();
    }
    dataSourceInfoList.clear();
    if (editorFile != null) {
        StyledLayerDescriptor sld = editorFile.getSLD();
        List<UserLayer> userLayerList = InlineFeatureUtils.extractUserLayers(sld);
        for (UserLayer userLayer : userLayerList) {
            DataSourceInfo dsInfo = new DataSourceInfo();
            dsInfo.setUserLayer(userLayer);
            dataSourceInfoList.add(dsInfo);
            DataStore dataStore = userLayer.getInlineFeatureDatastore();
            if (dataStore == null) {
                continue;
            }
            try {
                List<Name> nameList = dataStore.getNames();
                if (!nameList.isEmpty()) {
                    typeName = nameList.get(0).getLocalPart();
                }
                // Set the type name
                dsInfo.setTypeName(typeName);
                SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
                SimpleFeatureType schema = source.getSchema();
                dsInfo.setSchema(schema);
                dsInfo.setDataStore(dataStore);
                GeometryTypeEnum geometryType = InlineFeatureUtils.determineGeometryType(schema.getGeometryDescriptor(), source.getFeatures());
                dsInfo.setGeometryType(geometryType);
            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
                dsInfo.reset();
            }
        }
    }
    return dataSourceInfoList;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) IOException(java.io.IOException) UserLayer(org.geotools.styling.UserLayer) Name(org.opengis.feature.type.Name)

Example 28 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class CreateInternalDataSourceTest method testDetermineGeometryType.

/**
 * Test method for
 * {@link com.sldeditor.datasource.impl.CreateInternalDataSource#determineGeometryType(StyledLayerDescriptor)}.
 */
@Test
public void testDetermineGeometryType() {
    TestCreateInternalDataSource ds = new TestCreateInternalDataSource();
    assertEquals(GeometryTypeEnum.UNKNOWN, ds.callDetermineGeometryType(null));
    // Create StyledLayerDescriptor
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    UserLayer userLayer = styleFactory.createUserLayer();
    sld.addStyledLayer(userLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    // Raster
    RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
    rule.symbolizers().add(raster);
    assertEquals(GeometryTypeEnum.RASTER, ds.callDetermineGeometryType(sld));
    // Polygon
    rule.symbolizers().clear();
    PolygonSymbolizer polygon = DefaultSymbols.createDefaultPolygonSymbolizer();
    rule.symbolizers().add(polygon);
    assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
    // Line
    rule.symbolizers().clear();
    LineSymbolizer line = DefaultSymbols.createDefaultLineSymbolizer();
    rule.symbolizers().add(line);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Point
    rule.symbolizers().clear();
    PointSymbolizer point = DefaultSymbols.createDefaultPointSymbolizer();
    rule.symbolizers().add(point);
    assertEquals(GeometryTypeEnum.POINT, ds.callDetermineGeometryType(sld));
    // Add line to point
    rule.symbolizers().add(line);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Add point, line
    rule.symbolizers().clear();
    rule.symbolizers().add(line);
    rule.symbolizers().add(point);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Add polygon, line
    rule.symbolizers().clear();
    rule.symbolizers().add(point);
    rule.symbolizers().add(polygon);
    assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 29 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class DataSourceImplTest method testConnectToInlineDataSource.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}.
 */
@Test
public void testConnectToInlineDataSource() {
    DataSourceImpl ds = new DataSourceImpl();
    DummyInlineSLDFile editorFile = new DummyInlineSLDFile();
    DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate();
    ds.addListener(dataSourceUpdateListener);
    CreateDataSourceInterface internalDataSource = new DummyCreateDataSource();
    CreateDataSourceInterface externalDataSource = new DummyCreateDataSource();
    CreateDataSourceInterface inlineDataSource = new CreateInlineDataSource();
    ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource);
    ds.connect("typeName", editorFile, null);
    assertTrue(dataSourceUpdateListener.hasBeenCalled());
    assertEquals(GeometryTypeEnum.UNKNOWN, dataSourceUpdateListener.geometryType);
    assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
    Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList();
    assertNull(fieldList);
    FeatureSource<SimpleFeatureType, SimpleFeature> exampleLayer = ds.getExampleFeatureSource();
    assertNull(exampleLayer);
    Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> userLayerMap = ds.getUserLayerFeatureSource();
    assertEquals(1, userLayerMap.size());
    assertFalse(dataSourceUpdateListener.hasBeenCalled());
    ds.updateUserLayers();
    assertTrue(dataSourceUpdateListener.hasBeenCalled());
    DataSourcePropertiesInterface dsi = ds.getDataConnectorProperties();
    assertNotNull(dsi);
}
Also used : FeatureSource(org.geotools.data.FeatureSource) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) DataSourceImpl(com.sldeditor.datasource.impl.DataSourceImpl) CreateDataSourceInterface(com.sldeditor.datasource.impl.CreateDataSourceInterface) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CreateInlineDataSource(com.sldeditor.datasource.impl.CreateInlineDataSource) UserLayer(org.geotools.styling.UserLayer) Test(org.junit.Test)

Aggregations

UserLayer (org.geotools.styling.UserLayer)29 Test (org.junit.Test)17 DummyInlineSLDFile (com.sldeditor.test.unit.datasource.impl.DummyInlineSLDFile)10 InLineFeatureModel (com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel)8 Style (org.geotools.styling.Style)6 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)4 NamedLayer (org.geotools.styling.NamedLayer)4 Rule (org.geotools.styling.Rule)4 StyledLayer (org.geotools.styling.StyledLayer)4 UndoEvent (com.sldeditor.common.undo.UndoEvent)3 IOException (java.io.IOException)3 FeatureSource (org.geotools.data.FeatureSource)3 LineSymbolizer (org.geotools.styling.LineSymbolizer)3 PointSymbolizer (org.geotools.styling.PointSymbolizer)3 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)3 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)3 SLDData (com.sldeditor.common.data.SLDData)2 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)2 FieldConfigInlineFeature (com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature)2