use of com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface in project sldeditor by robward-scisys.
the class DetermineRasterFormatTest method testChoose.
/**
* Test method for
* {@link com.sldeditor.datasource.chooseraster.DetermineRasterFormat#choose(java.io.File, com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface)}.
*/
@Test
public void testChoose() {
AbstractGridFormat gridFormat = DetermineRasterFormat.choose(null, null);
assertTrue(UnknownFormat.class == gridFormat.getClass());
URL url = SLDTreeTest.class.getResource("/raster/sld/sld_cookbook_raster.tif");
File f = new File(url.getFile());
gridFormat = DetermineRasterFormat.choose(f, null);
assertTrue(gridFormat != null);
// Force to WorldImageFormat
gridFormat = DetermineRasterFormat.choose(f, new ChooseRasterFormatInterface() {
@Override
public AbstractGridFormat showPanel(Set<AbstractGridFormat> formatList) {
WorldImageFormat wif = new WorldImageFormat();
return wif;
}
});
assertTrue(WorldImageFormat.class == gridFormat.getClass());
}
use of com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface in project sldeditor by robward-scisys.
the class CreateExternalDataSource method connect.
/**
* Connect.
*
* @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) {
SLDDataInterface sldData = editorFile.getSLDData();
DataSourcePropertiesInterface dataSourceProperties = sldData.getDataSourceProperties();
Map<String, Object> map = dataSourceProperties.getConnectionProperties();
if (dataSourceProperties.hasPassword()) {
String password = dataSourceProperties.getPassword();
if (password == null) {
password = "dummy password";
dataSourceProperties.setPassword(password);
map = dataSourceProperties.getConnectionProperties();
}
}
DataStore dataStore = null;
try {
dataStore = DataStoreFinder.getDataStore(map);
if (dataStore != null) {
// Try connecting to a vector data source
dsInfo.setTypeName(typeName);
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
SimpleFeatureType schema = source.getSchema();
if (schema.getCoordinateReferenceSystem() == null) {
// No crs found to set a default and reload
if (dataStore instanceof ShapefileDataStore) {
ShapefileDataStore shapeFileDatastore = (ShapefileDataStore) dataStore;
CoordinateReferenceSystem crs = JCRSChooser.showDialog(Localisation.getString(CreateExternalDataSource.class, "CRSPanel.title"), defaultCRS.getIdentifiers().iterator().next().toString());
if (crs != null) {
shapeFileDatastore.forceSchemaCRS(crs);
}
source = dataStore.getFeatureSource(typeName);
schema = source.getSchema();
}
}
dsInfo.setSchema(schema);
determineGeometryType(schema.getGeometryDescriptor().getType());
} else {
// Try connecting to a raster data source
Object rasterFilename = map.get(DataSourceConnectorInterface.FILE_MAP_KEY);
if (rasterFilename != null) {
File rasterFile = new File(ExternalFilenames.convertURLToFile((String) rasterFilename));
ChooseRasterFormatInterface panel = new ChooseRasterFormatPanel(Controller.getInstance().getFrame());
AbstractGridFormat format = DetermineRasterFormat.choose(rasterFile, panel);
AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
dsInfo.setGridCoverageReader(reader);
} else {
logger.error("No matching datastore");
}
}
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
dsInfo.setDataStore(dataStore);
if (!dsInfo.hasData()) {
ConsoleManager.getInstance().error(this, Localisation.getField(CreateExternalDataSource.class, "CreateExternalDataSource.failedToConnect") + dataSourceProperties.getDebugConnectionString());
}
}
return dataSourceInfoList;
}
Aggregations