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>"));
}
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;
}
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));
}
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);
}
Aggregations