本文整理汇总了Java中org.geotools.map.FeatureLayer类的典型用法代码示例。如果您正苦于以下问题:Java FeatureLayer类的具体用法?Java FeatureLayer怎么用?Java FeatureLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FeatureLayer类属于org.geotools.map包,在下文中一共展示了FeatureLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderVectorMap
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例2: highlightSelectedPolygon
import org.geotools.map.FeatureLayer; //导入依赖的package包/类
/**
* hightlight the selected Polygon.
* @param polygonID the selected Polygon
*/
public void highlightSelectedPolygon(String polygonID) {
for (SimpleFeature simpleFeature : polygonFeatureCollection) {
String featureID = (String) simpleFeature.getAttribute("id");
if (featureID.equals(polygonID)) {
Style style =
createSelectedStyle(simpleFeature.getIdentifier());
org.geotools.map.Layer layer = null;
for (org.geotools.map.Layer layers : mapPane.getMapContent()
.layers()) {
String t = layers.getTitle();
if (t != null && t.equals(POLYGON_LAYER_TITLE)) {
layer = layers;
}
}
if (layer instanceof FeatureLayer) {
((FeatureLayer) layer).setStyle(style);
}
}
}
}
示例3: createFeatureLayerFromMapObject
import org.geotools.map.FeatureLayer; //导入依赖的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 );
}
示例4: run
import org.geotools.map.FeatureLayer; //导入依赖的package包/类
@Override
public void run() {
final Display display = WorkbenchHelper.getDisplay();
final Shell shell = new Shell(display);
final File openFile = JFileDataStoreChooser.showOpenFile(new String[] { "*.shp" }, shell); //$NON-NLS-1$
try {
if (openFile != null && openFile.exists()) {
final MapContent mapContent = mapPane.getMapContent();
final FileDataStore store = FileDataStoreFinder.getDataStore(openFile);
final SimpleFeatureSource featureSource = store.getFeatureSource();
final Style style = Utils.createStyle(openFile, featureSource);
final FeatureLayer featureLayer = new FeatureLayer(featureSource, style);
mapContent.addLayer(featureLayer);
mapPane.redraw();
}
} catch (final IOException e) {
e.printStackTrace();
}
}
示例5: createCoastlineLayer
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
}
示例6: createExtraFeatures
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例7: getRenderer
import org.geotools.map.FeatureLayer; //导入依赖的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;
}
示例8: main
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例9: main
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例10: displayShapefile
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例11: TwoAttributes
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例12: SaveMapAsImage
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例13: withTestModels
import org.geotools.map.FeatureLayer; //导入依赖的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);
}
示例14: initMap
import org.geotools.map.FeatureLayer; //导入依赖的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();
}
}
示例15: update
import org.geotools.map.FeatureLayer; //导入依赖的package包/类
private void update(final int row) {
Thread t = new Thread() {
public void run() {
int attr = row;
if (attr < 0) {
return;
}
String name = (String) varTable.getValueAt(attr, 0);
selAttr = schema.getDescriptor(name);
if (selAttr == null || map.layers().isEmpty()) {
return;
}
FeatureLayer layer = (FeatureLayer) map.layers().get(0);
Style style = null;
try {
style = legend.getStyle((SimpleFeatureCollection) layer
.getFeatureSource().getFeatures(), selAttr
.getLocalName());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
layer.setStyle(style);
}
};
SwingUtilities.invokeLater(t);
}