use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SLDUtils method readSLDFile.
/**
* Creates a StyledLayerDescriptor object containing a SLD by reading the contents of a file.
*
* @param file the file
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor readSLDFile(File file) {
StyledLayerDescriptor sld = null;
if (file != null) {
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
try {
// By using URL here allows external graphics to loaded properly
URL url = file.toURI().toURL();
SLDParser styleReader = new SLDParser(styleFactory, url);
setResourcelocator(styleReader, file.toURI().toURL());
sld = styleReader.parseSLD();
} catch (MalformedURLException e) {
ConsoleManager.getInstance().exception(SLDUtils.class, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(SLDUtils.class, e);
}
}
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class DefaultSymbols method createNewLine.
/**
* Creates a new line symbol.
*
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createNewLine() {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
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);
LineSymbolizer line = createDefaultLineSymbolizer();
rule.symbolizers().add(line);
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class DefaultSymbols method createNewPoint.
/**
* Creates a new point symbol.
*
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createNewPoint() {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
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);
PointSymbolizer point = createDefaultPointSymbolizer();
rule.symbolizers().add(point);
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class DefaultSymbols method createNewRaster.
/**
* Creates the new raster symbol.
*
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createNewRaster() {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
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);
RasterSymbolizer raster = createDefaultRasterSymbolizer();
rule.symbolizers().add(raster);
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class CreateInternalDataSource method connect.
/**
* Creates the.
*
* @param typeName the type name
* @param geometryFieldName the geometry field name
* @param editorFile the editor file
* @return the list of datastores
*/
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
List<DataSourceInfo> dataSourceInfoList = new ArrayList<DataSourceInfo>();
dataSourceInfoList.add(dsInfo);
dsInfo.reset();
if (editorFile != null) {
StyledLayerDescriptor sld = editorFile.getSLD();
determineGeometryType(sld);
ExtendedSimpleFeatureTypeBuilder b = new ExtendedSimpleFeatureTypeBuilder();
// set the name
typeName = INTERNAL_SCHEMA_NAME;
dsInfo.setTypeName(typeName);
b.setName(typeName);
String namespace = null;
b.setNamespaceURI(namespace);
// add a geometry property
// set crs first
b.setCRS(DefaultGeographicCRS.WGS84);
SLDDataInterface sldData = editorFile.getSLDData();
List<DataSourceAttributeData> fieldList = sldData.getFieldList();
// Set the geometry field by default
geometryField.reset();
if (geometryFieldName != null) {
geometryField.setGeometryFieldName(geometryFieldName);
}
List<AttributeDescriptor> attrDescList = new ArrayList<AttributeDescriptor>();
if ((fieldList == null) || fieldList.isEmpty()) {
// Read the fields from the SLD
ExtractAttributes extract = new ExtractAttributes();
extract.extractDefaultFields(sld);
fieldList = extract.getFields();
// Add non-geometry fields to the feature type builder
for (DataSourceAttributeData dsAttribute : fieldList) {
if (dsAttribute.getName() != null) {
b.add(dsAttribute.getName(), dsAttribute.getType());
}
}
List<String> geometryFields = extract.getGeometryFields();
for (String localGeometryFieldName : geometryFields) {
geometryField.setGeometryFieldName(localGeometryFieldName);
}
} else {
addFields(attrDescList, b, fieldList);
}
attrDescList.add(addGeometryField(b, geometryField.getGeometryFieldName()));
b.addAll(attrDescList);
// Store the fields
sldData.setFieldList(fieldList);
// Build the feature type
SimpleFeatureType schema = b.buildFeatureType();
dsInfo.setSchema(schema);
CreateSampleData sampleData = new CreateSampleData();
sampleData.create(schema, fieldList);
MemoryDataStore dataStore = sampleData.getDataStore();
dsInfo.setDataStore(dataStore);
dsInfo.populateFieldMap();
}
return dataSourceInfoList;
}
Aggregations