本文整理汇总了Java中org.geotools.map.Layer类的典型用法代码示例。如果您正苦于以下问题:Java Layer类的具体用法?Java Layer怎么用?Java Layer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Layer类属于org.geotools.map包,在下文中一共展示了Layer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSearchEnv
import org.geotools.map.Layer; //导入依赖的package包/类
private ReferencedEnvelope createSearchEnv(final DirectPosition2D pos, final double radius) {
final CoordinateReferenceSystem contextCRS = getMapContent().getCoordinateReferenceSystem();
ReferencedEnvelope env = new ReferencedEnvelope(pos.x - radius, pos.x + radius, pos.y - radius, pos.y + radius,
contextCRS);
if (isTransformRequired()) {
final Layer layer = layerRef.get();
if (layer != null) {
final CoordinateReferenceSystem layerCRS = layer.getFeatureSource().getSchema()
.getCoordinateReferenceSystem();
try {
env = env.transform(layerCRS, true);
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}
}
return env;
}
示例2: renderVectorMap
import org.geotools.map.Layer; //导入依赖的package包/类
/**
* Render vector map.
*
* @param features the results
* @param imageSize the image size
* @param style the style
* @param dpi the dpi
*/
private void renderVectorMap(FeatureSource<SimpleFeatureType, SimpleFeature> features,
Rectangle imageSize, Style style, int dpi) {
List<Layer> layerList = new ArrayList<Layer>();
if (style != null) {
FeatureLayer featureLayer = new FeatureLayer(features, style);
layerList.add(featureLayer);
}
boolean hasGeometry = false;
ReferencedEnvelope bounds = null;
if (features != null) {
bounds = calculateBounds();
wmsEnvVarValues.setMapBounds(bounds);
EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);
if (features.getSchema() != null) {
hasGeometry = (features.getSchema().getGeometryDescriptor() != null);
}
}
internal_renderMap(layerList, bounds, imageSize, hasGeometry, dpi);
}
示例3: getHelper
import org.geotools.map.Layer; //导入依赖的package包/类
/**
* gets the helper for the given layer.
* @param layer the layer
* @return the helper
*/
public static InfoToolHelper getHelper(Layer layer) {
loadProviders();
for (InfoToolHelper helper : cachedInstances) {
try {
if (helper.isSupportedLayer(layer)) {
return helper.getClass().newInstance();
}
} catch (Exception ex) {
throw new InfoToolHelperException(ex);
}
}
return null;
}
示例4: createFeatureLayerFromMapObject
import org.geotools.map.Layer; //导入依赖的package包/类
/**
* Creates a feature layer based on a map object.
*/
public static Layer createFeatureLayerFromMapObject( InternalMapObject mapObject )
{
Style style = mapObject.getStyle();
SimpleFeatureType featureType = mapObject.getFeatureType();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( featureType );
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
featureBuilder.add( mapObject.getGeometry() );
SimpleFeature feature = featureBuilder.buildFeature( null );
featureCollection.add( feature );
return new FeatureLayer( featureCollection, style );
}
示例5: layerAdded
import org.geotools.map.Layer; //导入依赖的package包/类
/**
* Called when a new map layer has been added. Sets the layer as selected
* (for queries) and, if the layer table is being used, adds the new layer
* to the table.
*/
@Override
public void layerAdded(final MapLayerListEvent event) {
final Layer layer = event.getElement();
if (layerTable != null) {
layerTable.onAddLayer(layer);
}
layer.setSelected(true);
redrawBaseImage = true;
final boolean atFullExtent = equalsFullExtent(getDisplayArea());
final boolean firstLayer = content.layers().size() == 1;
if (firstLayer || atFullExtent) {
reset();
if (firstLayer) {
setCrs(layer.getBounds().getCoordinateReferenceSystem());
return;
}
}
if (!isDisposed())
redraw();
}
示例6: layerRemoved
import org.geotools.map.Layer; //导入依赖的package包/类
/**
* Called when a map layer has been removed
*/
@Override
public void layerRemoved(final MapLayerListEvent event) {
final Layer layer = event.getElement();
if (layerTable != null) {
layerTable.onRemoveLayer(layer);
}
redrawBaseImage = true;
if (content.layers().size() == 0) {
clearFields();
} else {
setFullExtent();
}
if (!isDisposed())
redraw();
}
示例7: run
import org.geotools.map.Layer; //导入依赖的package包/类
@Override
public void run() {
final Display display = WorkbenchHelper.getDisplay();
final Shell shell = new Shell(display);
final File openFile = JFileImageChooser.showOpenFile(shell);
if (openFile != null && openFile.exists()) {
final AbstractGridFormat format = GridFormatFinder.findFormat(openFile);
final AbstractGridCoverage2DReader tiffReader = format.getReader(openFile);
final StyleFactoryImpl sf = new StyleFactoryImpl();
final RasterSymbolizer symbolizer = sf.getDefaultRasterSymbolizer();
final Style defaultStyle = SLD.wrapSymbolizers(symbolizer);
final MapContent mapContent = mapPane.getMapContent();
final Layer layer = new GridReaderLayer(tiffReader, defaultStyle);
layer.setTitle(openFile.getName());
mapContent.addLayer(layer);
mapPane.redraw();
}
}
示例8: saveAsCSV
import org.geotools.map.Layer; //导入依赖的package包/类
@Override
public void saveAsCSV() {
final Layer layer = mapLayerTable.getMapLayerTableViewer().getSelectedMapLayer();
if (layer == null)
return;
final HashSet<String> atts = new HashSet<String>();
final String layerName = layer.getFeatureSource().getName().toString();
for (final String at : attributes.keySet()) {
final String[] dec = at.split(";");
if (layerName.equals(dec[0])) {
atts.add(dec[1]);
}
}
final List<IShape> geoms = osmfile.getLayers().get(layerName);
final List<String> attsOrd = new ArrayList<String>(atts);
Collections.sort(attsOrd);
saveAsCSV(attsOrd, geoms, layerName);
}
示例9: createCoastlineLayer
import org.geotools.map.Layer; //导入依赖的package包/类
private static Layer createCoastlineLayer() {
try {
// File file = new File(
// "/home/dxm/Downloads/shapefile-australia-coastline-polygon/cstauscd_r.shp");
File file = new File("src/main/resources/shapes/countries.shp");
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Style style = SLD.createSimpleStyle(featureSource.getSchema());
Style style = SLD.createPolygonStyle(Color.black, new Color(242, 237, 206), 1);
Layer layer = new FeatureLayer(featureSource, style);
return layer;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: createExtraFeatures
import org.geotools.map.Layer; //导入依赖的package包/类
private static Layer createExtraFeatures() {
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("Location");
b.setCRS(DefaultGeographicCRS.WGS84);
// picture location
b.add("geom", Point.class);
final SimpleFeatureType TYPE = b.buildFeatureType();
GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
Point point = gf.createPoint(new Coordinate(CANBERRA_LONG, CANBERRA_LAT));
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(TYPE);
builder.add(point);
SimpleFeature feature = builder.buildFeature("Canberra");
DefaultFeatureCollection features = new DefaultFeatureCollection(null, null);
features.add(feature);
Style style = SLD.createPointStyle("Star", Color.BLUE, Color.BLUE, 0.3f, 10);
return new FeatureLayer(features, style);
}
示例11: main
import org.geotools.map.Layer; //导入依赖的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);
}
示例12: main
import org.geotools.map.Layer; //导入依赖的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);
}
示例13: displayShapefile
import org.geotools.map.Layer; //导入依赖的package包/类
/**
* Prompts the user for a shapefile (unless a filename is provided
* on the command line; then creates a simple Style and displays
* the shapefile on screen
*/
private void displayShapefile() throws Exception {
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
FeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("StyleLab");
// Create a basic Style to render the features
Style style = createStyle(file, featureSource);
// Add the features and the associated Style object to
// the MapContent as a new Layer
Layer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}
示例14: TwoAttributes
import org.geotools.map.Layer; //导入依赖的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);
}
示例15: SaveMapAsImage
import org.geotools.map.Layer; //导入依赖的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);
}