use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class MapBoxTool method exportToSLD.
/**
* Export to SLD.
*/
private void exportToSLD() {
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
for (SLDDataInterface sldData : sldDataList) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
String layerName = sldData.getLayerNameWithOutSuffix();
if (sld != null) {
String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
String destinationFolder = sldData.getSLDFile().getParent();
File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, SLDEditorFile.getSLDFileExtension());
String sldFilename = fileToSave.getName();
if (fileToSave.exists()) {
ConsoleManager.getInstance().error(this, Localisation.getField(MapBoxTool.class, "MapBoxTool.destinationAlreadyExists") + " " + sldFilename);
} else {
ConsoleManager.getInstance().information(this, Localisation.getField(MapBoxTool.class, "MapBoxTool.exportToSLDMsg") + " " + sldFilename);
try (BufferedWriter out = new BufferedWriter(new FileWriter(fileToSave))) {
out.write(sldString);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
}
}
use of org.geotools.styling.StyledLayerDescriptor 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.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SymbolizerDetailsPanel method getMinimumVersion.
/**
* Gets the minimum version vendor option present in the SLD.
*
* @param parentObj the parent obj
* @param sldObj the sld obj
* @param vendorOptionsPresentList the vendor options present list
*/
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
Class<?> parentClass = null;
Class<?> classSelected = sldObj.getClass();
if (sldObj instanceof StyledLayerDescriptor) {
// No parent
} else if (sldObj instanceof StyledLayer) {
parentClass = StyledLayerDescriptor.class;
} else if (sldObj instanceof Style) {
parentClass = StyledLayer.class;
} else if (sldObj instanceof FeatureTypeStyle) {
parentClass = Style.class;
} else if (sldObj instanceof Rule) {
parentClass = FeatureTypeStyle.class;
} else if (sldObj instanceof Symbolizer) {
parentClass = Rule.class;
}
internalGetMinimumVersion(parentObj, sldObj, vendorOptionsPresentList, parentClass, classSelected);
if (sldObj instanceof PointSymbolizerImpl) {
PointSymbolizerImpl pointSymbolizer = (PointSymbolizerImpl) sldObj;
parentClass = PointSymbolizerImpl.class;
classSelected = FillImpl.class;
internalGetMinimumVersion(pointSymbolizer, pointSymbolizer.getGraphic(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof LineSymbolizerImpl) {
LineSymbolizerImpl lineSymbolizer = (LineSymbolizerImpl) sldObj;
parentClass = LineSymbolizerImpl.class;
classSelected = StrokeImpl.class;
internalGetMinimumVersion(lineSymbolizer, lineSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof PolygonSymbolizerImpl) {
PolygonSymbolizerImpl polygonSymbolizer = (PolygonSymbolizerImpl) sldObj;
parentClass = PolygonSymbolizerImpl.class;
classSelected = FillImpl.class;
internalGetMinimumVersion(polygonSymbolizer, polygonSymbolizer.getFill(), vendorOptionsPresentList, parentClass, classSelected);
classSelected = StrokeImpl.class;
internalGetMinimumVersion(polygonSymbolizer, polygonSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof TextSymbolizerImpl) {
TextSymbolizerImpl textSymbolizer = (TextSymbolizerImpl) sldObj;
parentClass = Rule.class;
classSelected = TextSymbolizerImpl.class;
internalGetMinimumVersion(parentObj, textSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof RasterSymbolizerImpl) {
RasterSymbolizerImpl rasterSymbolizer = (RasterSymbolizerImpl) sldObj;
parentClass = Rule.class;
classSelected = RasterSymbolizerImpl.class;
internalGetMinimumVersion(parentObj, rasterSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
}
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class ScalePanelUtils method containsScales.
/**
* Extracts all the rule scales.
*
* @param sldData the sld data
* @return the scale sld data
*/
public static List<ScaleSLDData> containsScales(SLDDataInterface sldData) {
List<ScaleSLDData> dataList = null;
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
for (StyledLayer styledLayer : styledLayerList) {
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
for (Style style : namedLayerImpl.styles()) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule rule : fts.rules()) {
double minScale = rule.getMinScaleDenominator();
double maxScale = rule.getMaxScaleDenominator();
if (isMinScaleSet(minScale) || isMaxScaleSet(maxScale)) {
if (dataList == null) {
dataList = new ArrayList<>();
}
ScaleSLDData scaleSLDData = new ScaleSLDData(sld, sldData);
scaleSLDData.setNamedLayer(namedLayerImpl.getName());
scaleSLDData.setFeatureTypeStyle(fts.getName());
scaleSLDData.setStyle(style.getName());
scaleSLDData.setRule(rule);
if (isMinScaleSet(minScale)) {
scaleSLDData.setMinScale(minScale);
}
if (isMaxScaleSet(maxScale)) {
scaleSLDData.setMaxScale(maxScale);
}
dataList.add(scaleSLDData);
}
}
}
}
}
}
}
return dataList;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class VectorReader method createSLDData.
/**
* Creates the SLD data.
*
* @param map the map
* @return the styled layer descriptor
*/
private StyledLayerDescriptor createSLDData(Map<String, Object> map, String featureClass) {
StyledLayerDescriptor sld = null;
DataStore dataStore = null;
try {
dataStore = DataStoreFinder.getDataStore(map);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
return null;
}
if (dataStore != null) {
// Try connecting to a vector data source
String typeName;
GeometryTypeEnum geometryTypeEnum = GeometryTypeEnum.UNKNOWN;
try {
if (featureClass == null) {
typeName = dataStore.getTypeNames()[0];
} else {
typeName = featureClass;
}
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
SimpleFeatureType schema = source.getSchema();
GeometryType geometryType = schema.getGeometryDescriptor().getType();
Class<?> bindingType = geometryType.getBinding();
geometryTypeEnum = GeometryTypeMapping.getGeometryType(bindingType);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
return null;
} finally {
dataStore.dispose();
}
switch(geometryTypeEnum) {
case POINT:
sld = DefaultSymbols.createNewPoint();
break;
case LINE:
sld = DefaultSymbols.createNewLine();
break;
case POLYGON:
sld = DefaultSymbols.createNewPolygon();
break;
default:
break;
}
}
return sld;
}
Aggregations