本文整理汇总了Java中org.geotools.styling.SLD.createSimpleStyle方法的典型用法代码示例。如果您正苦于以下问题:Java SLD.createSimpleStyle方法的具体用法?Java SLD.createSimpleStyle怎么用?Java SLD.createSimpleStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.styling.SLD
的用法示例。
在下文中一共展示了SLD.createSimpleStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStyle
import org.geotools.styling.SLD; //导入方法依赖的package包/类
public Style getStyle()
{
Style style = null;
if ( geometry instanceof Point )
{
style = SLD.createPointStyle( CIRCLE, strokeColor, fillColor,
fillOpacity, radius );
}
else if ( geometry instanceof Polygon || geometry instanceof MultiPolygon )
{
if ( MapLayerType.BOUNDARY.equals( mapLayerType ) )
{
style = SLD.createLineStyle( strokeColor, LINE_STROKE_WIDTH );
}
else
{
style = SLD.createPolygonStyle( strokeColor, fillColor, fillOpacity );
}
}
else
{
style = SLD.createSimpleStyle( getFeatureType() );
}
return style;
}
示例2: getRenderer
import org.geotools.styling.SLD; //导入方法依赖的package包/类
private static GTRenderer getRenderer(File shapeFilesFolder) {
File[] shpFiles = shapeFilesFolder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".shp");
}
});
MapContent mapContent = new MapContent();
for (File shpFile : shpFiles) {
try {
SimpleFeatureCollection readFC = NwwUtilities.readAndReproject(shpFile.getAbsolutePath());
ReferencedEnvelope tmpBounds = readFC.getBounds();
if (tmpBounds.getWidth() == 0 || tmpBounds.getHeight() == 0) {
System.err.println("Ignoring: " + shpFile);
continue;
}
// if (bounds == null) {
// bounds = new ReferencedEnvelope(tmpBounds);
// } else {
// bounds.expandToInclude(tmpBounds);
// }
Style style = SldUtilities.getStyleFromFile(shpFile);
if (style == null)
style = SLD.createSimpleStyle(readFC.getSchema());
FeatureLayer layer = new FeatureLayer(readFC, style);
mapContent.addLayer(layer);
} catch (Exception e) {
e.printStackTrace();
}
}
GTRenderer renderer = new StreamingRenderer();
renderer.setMapContent(mapContent);
return renderer;
}
示例3: main
import org.geotools.styling.SLD; //导入方法依赖的package包/类
/**
* This method demonstrates using a memory-based cache to speed up the display (e.g. when
* zooming in and out).
*
* There is just one line extra compared to the main method, where we create an instance of
* CachingFeatureStore.
*/
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
CachingFeatureSource cache = new CachingFeatureSource(featureSource);
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("Using cached features");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(cache, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}
示例4: main
import org.geotools.styling.SLD; //导入方法依赖的package包/类
/**
* GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its
* contents on the screen in a map frame
*/
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("Quickstart");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}
示例5: TwoAttributes
import org.geotools.styling.SLD; //导入方法依赖的package包/类
public TwoAttributes(String[] args) throws IOException {
File file = new File(args[0]);
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
SimpleFeatureType schema = featureSource.getSchema();
System.out.println(schema);
// Create a map content and add our shapefile to it
MapContent mapContent = new MapContent();
mapContent.setTitle("GeoTools Mapping");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
mapContent.addLayer(layer);
frame = new JMapFrame(mapContent);
frame.enableStatusBar(true);
frame.enableToolBar(true);
JToolBar toolBar = frame.getToolBar();
toolBar.addSeparator();
SaveAction save = new SaveAction("Save");
toolBar.add(save);
frame.initComponents();
frame.setSize(1000, 500);
frame.setVisible(true);
}
示例6: SaveMapAsImage
import org.geotools.styling.SLD; //导入方法依赖的package包/类
public SaveMapAsImage(File file) throws IOException {
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
mapContent = new MapContent();
mapContent.setTitle("GeoTools Mapping");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
mapContent.addLayer(layer);
frame = new JMapFrame(mapContent);
frame.enableStatusBar(true);
frame.enableToolBar(true);
JToolBar toolBar = frame.getToolBar();
toolBar.addSeparator();
SaveAction save = new SaveAction("Save");
toolBar.add(save);
frame.initComponents();
frame.setSize(1000, 500);
frame.setVisible(true);
}
示例7: withTestModels
import org.geotools.styling.SLD; //导入方法依赖的package包/类
private static void withTestModels(String folder) throws Exception {
URL schemaURL = new File("/Users/markus/Documents/Projects/EMFFrag/02_workspace/citygml.git/de.hub.citygml.models/schemas/"+folder+"/TestFeature.xsd").toURL();
URL modelURL = new File("/Users/markus/Documents/Projects/EMFFrag/02_workspace/citygml.git/de.hub.citygml.models/schemas/"+folder+"/TestFeature.xml").toURL();
GML gml = new GML(Version.WFS1_1);
gml.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
NameImpl typeName = new NameImpl("http://www.geotools.org/test", "TestFeature");
//
SimpleFeatureType featureType = gml.decodeSimpleFeatureType(schemaURL, typeName);
System.out.println("#1: " + (featureType == null ? "NULL" : featureType.toString()));
SimpleFeatureCollection featureCollection = gml.decodeFeatureCollection(modelURL.openStream());
System.out.println("#2: " + featureCollection.size());
MapContent map = new MapContent();
map.setTitle("Quickstart");
Style style = SLD.createSimpleStyle(featureCollection.getSchema());
Layer layer = new FeatureLayer(featureCollection, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}
示例8: getLinesStyle
import org.geotools.styling.SLD; //导入方法依赖的package包/类
/**
* Create style for a lines layer.
*
* @param schema
* @return a line style.
*/
public static Style getLinesStyle( SimpleFeatureType schema ) {
Style style = SLD.createSimpleStyle(schema);
Rule origRule = style.featureTypeStyles().get(0).rules().get(0);
Symbolizer symbolizer = origRule.symbolizers().get(0);
LineSymbolizer lineSymbolizer = (LineSymbolizer) symbolizer;
Stroke stroke = lineSymbolizer.getStroke();
if (stroke == null) {
stroke = sf.createStroke(ff.literal("#0000FF"), ff.literal("2"), ff.literal("1"));
} else {
stroke.setColor(ff.literal("#0000FF"));
stroke.setWidth(ff.literal("2"));
stroke.setOpacity(ff.literal("1"));
}
lineSymbolizer.setStroke(stroke);
return style;
}
示例9: initMap
import org.geotools.styling.SLD; //导入方法依赖的package包/类
private void initMap() {
try {
FileDataStore store = FileDataStoreFinder
.getDataStore(this.getClass().getClassLoader().getResource("maps/countries.shp"));
SimpleFeatureSource featureSource = store.getFeatureSource();
map = new MapContent();
map.setTitle("Quickstart");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
FeatureLayer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
map.getViewport().setScreenArea(new Rectangle((int) canvas.getWidth(), (int) canvas.getHeight()));
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: getRenderer
import org.geotools.styling.SLD; //导入方法依赖的package包/类
private static GTRenderer getRenderer( ASpatialDb db, String tableName, int featureLimit, Style style ) {
MapContent mapContent = new MapContent();
// read data and convert it to featurecollection
try {
long t1 = System.currentTimeMillis();
System.out.println("STARTED READING: " + tableName);
String databasePath = db.getDatabasePath();
File dbFile = new File(databasePath);
File parentFolder = dbFile.getParentFile();
if (style == null) {
File sldFile = new File(parentFolder, tableName + ".sld");
if (sldFile.exists()) {
style = SldUtilities.getStyleFromFile(sldFile);
}
}
DefaultFeatureCollection fc = SpatialDbsImportUtils.tableToFeatureFCollection(db, tableName, featureLimit,
NwwUtilities.GPS_CRS_SRID);
long t2 = System.currentTimeMillis();
System.out.println("FINISHED READING: " + tableName + " -> " + ((t2 - t1) / 1000) + "sec");
if (style == null) {
style = SLD.createSimpleStyle(fc.getSchema());
}
FeatureLayer layer = new FeatureLayer(fc, style);
long t3 = System.currentTimeMillis();
System.out.println("FINISHED BUILDING: " + tableName + " -> " + ((t3 - t2) / 1000) + "sec");
mapContent.addLayer(layer);
} catch (Exception e) {
e.printStackTrace();
}
GTRenderer renderer = new StreamingRenderer();
renderer.setMapContent(mapContent);
return renderer;
}
示例11: main
import org.geotools.styling.SLD; //导入方法依赖的package包/类
/**
* GeoTools Quickstart demo application. Prompts the user for a shapefile
* and displays its contents on the screen in a map frame
*/
public static void main(String[] args) throws Exception {
File file = null;
if (args.length >= 1) {
file = new File(args[0]);
}
if (file == null) {
// display a data store file chooser dialog for shapefiles
file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("Quickstart");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}
示例12: displayShapefile
import org.geotools.styling.SLD; //导入方法依赖的package包/类
/**
* This method:
* <ol type="1">
* <li>Prompts the user for a shapefile to display
* <li>Creates a JMapFrame with custom toolbar buttons
* <li>Displays the shapefile
* </ol>
*/
// docs start display
private void displayShapefile() throws Exception {
sourceFile = JFileDataStoreChooser.showOpenFile("shp", null);
if (sourceFile == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile);
featureSource = store.getFeatureSource();
// Create a map context and add our shapefile to it
map = new MapContent();
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
map.layers().add(layer);
// Create a JMapFrame with custom toolbar buttons
JMapFrame mapFrame = new JMapFrame(map);
mapFrame.enableToolBar(true);
mapFrame.enableStatusBar(true);
JToolBar toolbar = mapFrame.getToolBar();
toolbar.addSeparator();
toolbar.add(new JButton(new ValidateGeometryAction()));
toolbar.add(new JButton(new ExportShapefileAction()));
// Display the map frame. When it is closed the application will exit
mapFrame.setSize(800, 600);
mapFrame.setVisible(true);
}
示例13: Tissot
import org.geotools.styling.SLD; //导入方法依赖的package包/类
public Tissot(File file) throws IOException {
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
mapContent = new MapContent();
mapContent.setTitle("GeoTools Mapping");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
mapContent.addLayer(layer);
ReferencedEnvelope gridBounds = layer.getBounds();
Layer gridLayer = createGridLayer(style, gridBounds);
mapContent.addLayer(gridLayer);
Style pstyle = SLD.createPointStyle("circle", Color.red, Color.red, 1.0f,
5.0f);
Layer tissotLayer = createTissotLayer(pstyle, gridBounds);
mapContent.addLayer(tissotLayer);
frame = new JMapFrame(mapContent);
frame.enableStatusBar(true);
frame.enableToolBar(true);
JToolBar toolBar = frame.getToolBar();
toolBar.addSeparator();
SaveAction save = new SaveAction("Save");
toolBar.add(save);
frame.initComponents();
frame.setSize(1000, 500);
frame.setVisible(true);
}
示例14: MapWithGrid
import org.geotools.styling.SLD; //导入方法依赖的package包/类
public MapWithGrid(File file) throws IOException {
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
mapContent = new MapContent();
mapContent.setTitle("GeoTools Mapping");
style = SLD.createSimpleStyle(featureSource.getSchema());
layer = new FeatureLayer(featureSource, style);
ReferencedEnvelope gridBounds = layer.getBounds();
gridLayer = createGridLayer(style, gridBounds);
mapContent.addLayer(layer);
mapContent.addLayer(gridLayer);
mapContent.addMapBoundsListener(this);
frame = new JMapFrame(mapContent);
frame.enableStatusBar(true);
frame.enableToolBar(true);
JToolBar toolBar = frame.getToolBar();
toolBar.addSeparator();
SaveAction save = new SaveAction("Save");
toolBar.add(save);
frame.initComponents();
frame.setSize(1000, 500);
frame.setVisible(true);
}
示例15: SaveMapAsImage
import org.geotools.styling.SLD; //导入方法依赖的package包/类
public SaveMapAsImage(File file, File raster) throws IOException {
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
mapContent = new MapContent();
mapContent.setTitle("GeoTools Mapping");
AbstractGridFormat format = GridFormatFinder.findFormat(raster);
AbstractGridCoverage2DReader reader = format.getReader(raster);
GridCoverage2D cov;
try {
cov = reader.read(null);
} catch (IOException giveUp) {
throw new RuntimeException(giveUp);
}
Style rasterStyle = createRGBStyle(cov);
Layer rasterLayer = new GridReaderLayer(reader, rasterStyle);
mapContent.addLayer(rasterLayer);
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
mapContent.addLayer(layer);
mapContent.getViewport().setCoordinateReferenceSystem(
DefaultGeographicCRS.WGS84);
frame = new JMapFrame(mapContent);
frame.enableStatusBar(true);
frame.enableToolBar(true);
JToolBar toolBar = frame.getToolBar();
toolBar.addSeparator();
SaveAction save = new SaveAction("Save");
toolBar.add(save);
frame.initComponents();
frame.setSize(1000, 500);
frame.setVisible(true);
}