• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JFileDataStoreChooser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.geotools.swing.data.JFileDataStoreChooser的典型用法代码示例。如果您正苦于以下问题:Java JFileDataStoreChooser类的具体用法?Java JFileDataStoreChooser怎么用?Java JFileDataStoreChooser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JFileDataStoreChooser类属于org.geotools.swing.data包,在下文中一共展示了JFileDataStoreChooser类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getNewShapeFile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
private static File getNewShapeFile(File oldFile) {
    String path = oldFile.getAbsolutePath();
    String newPath = path.substring(0, path.length() - 4) + ".shp";

    JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
    chooser.setDialogTitle("Save shapefile");
    chooser.setSelectedFile(new File(newPath));

    int returnVal = chooser.showSaveDialog(null);

    if (returnVal != JFileDataStoreChooser.APPROVE_OPTION) {
        // the user canceled the dialog
        System.exit(0);
    }

    File newFile = chooser.getSelectedFile();
    if (newFile.equals(oldFile)) {
        System.out.println("Error: cannot replace " + oldFile);
        System.exit(0);
    }

    return newFile;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:24,代码来源:GeoToolsVisualization.java


示例2: getNewShapeFile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
/**
 * Requests a file location from the user via a dialog box, it will then return the file object. 
 *
 * @return File A File object of the file chosen by the user.
 */
private static File getNewShapeFile() {

	//Prompt user for a location and filename to save the shape file(s) at.
       JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
       chooser.setDialogTitle("Save shapefile");

       //Store the user choice.
       int returnVal = chooser.showSaveDialog(null);

       //If user cancelled the dialog, exit application entirely.
       if(returnVal != JFileDataStoreChooser.APPROVE_OPTION){
           System.exit(0);
       }

       //Set new file.
       File file = chooser.getSelectedFile();

       //Return the new file.
       return file;
   }
 
开发者ID:Stefangemfind,项目名称:MapMatching,代码行数:26,代码来源:App.java


示例3: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的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);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:30,代码来源:QuickstartCache.java


示例4: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的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);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:26,代码来源:Quickstart.java


示例5: getNewShapeFile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
/**
 * Prompt the user for the name and path to use for the output shapefile
 * 
 * @param csvFile
 *            the input csv file used to create a default shapefile name
 * 
 * @return name and path for the shapefile as a new File object
 */
private static File getNewShapeFile(File csvFile) {
    String path = csvFile.getAbsolutePath();
    String newPath = path.substring(0, path.length() - 4) + ".shp";

    JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
    chooser.setDialogTitle("Save shapefile");
    chooser.setSelectedFile(new File(newPath));

    int returnVal = chooser.showSaveDialog(null);

    if (returnVal != JFileDataStoreChooser.APPROVE_OPTION) {
        // the user cancelled the dialog
        System.exit(0);
    }

    File newFile = chooser.getSelectedFile();
    if (newFile.equals(csvFile)) {
        System.out.println("Error: cannot replace " + csvFile);
        System.exit(0);
    }

    return newFile;
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:32,代码来源:Csv2Shape.java


示例6: displayShapefile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的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);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:30,代码来源:StyleLab.java


示例7: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	File file = null;
	if (args.length == 0) {
		// display a data store file chooser dialog for shapefiles
		file = JFileDataStoreChooser.showOpenFile("shp", null);
		if (file == null) {
			return;
		}
	} else {
		file = new File(args[0]);
		if (!file.exists()) {
			System.err.println(file + " doesn't exist");
			return;
		}
	}
	new Tissot(file);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:18,代码来源:Tissot.java


示例8: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	File file = null;
	if (args.length == 0) {
		// display a data store file chooser dialog for shapefiles
		file = JFileDataStoreChooser.showOpenFile("shp", null);
		if (file == null) {
			return;
		}
	} else {
		file = new File(args[0]);
		if (!file.exists()) {
			System.err.println(file + " doesn't exist");
			return;
		}
	}
	new SaveMapAsImage(file);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:18,代码来源:SaveMapAsImage.java


示例9: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	File file = null;
	if (args.length == 0) {
		// display a data store file chooser dialog for shapefiles
		file = JFileDataStoreChooser.showOpenFile("shp", null);
		if (file == null) {
			return;
		}
	} else {
		file = new File(args[0]);
		if (!file.exists()) {
			System.err.println(file + " doesn't exist");
			return;
		}
	}
	new MapWithGrid(file);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:18,代码来源:MapWithGrid.java


示例10: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	File file = null;
	File raster = null;
	if (args.length == 0) {
		raster = JFileImageChooser.showOpenFile(null);
		// display a data store file chooser dialog for shapefiles
		file = JFileDataStoreChooser.showOpenFile("shp", null);
		if (file == null) {
			return;
		}
	} else {
		file = new File(args[0]);
		if (!file.exists()) {
			System.err.println(file + " doesn't exist");
			return;
		}
		raster = new File(args[1]);
		if (!raster.exists()) {
			System.err.println(raster + " doesn't exist");
			return;
		}
	}
	new SaveMapAsImage(file, raster);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:25,代码来源:SaveMapAsImage.java


示例11: getNewShapeFile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
/**
 * Prompt the user for the name and path to use for the output shapefile
 * 
 * @param csvFile the input csv file used to create a default shapefile name
 * 			
 * @return name and path for the shapefile as a new File object
 */
private static File getNewShapeFile(File csvFile) {
	
	String path = csvFile.getAbsolutePath();
	String newPath = path.substring(0, path.length() - 4) + ".shp";
	
	JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
	chooser.setDialogTitle("Save shapefile");
	chooser.setSelectedFile(new File(newPath));
	
	int returnVal = chooser.showSaveDialog(null);
	
	if (returnVal != JFileDataStoreChooser.APPROVE_OPTION)
	{
		// the user cancelled the dialog
		System.exit(0);
	}
	
	File newFile = chooser.getSelectedFile();
	if (newFile.equals(csvFile))
	{
		System.out.println("Error: cannot replace " + csvFile);
		System.exit(0);
	}
	
	return newFile;
}
 
开发者ID:petebrew,项目名称:fhaes,代码行数:34,代码来源:Csv2Shape2.java


示例12: getFeatureSourceFromFile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
/**
 * This function is really just a simplification of the process to create a
 * SimpleFeatureSource object. It will prompt the user for a file via a dialog
 * and then proceed to process it into a feature source.
 *
 * @return SimpleFeatureSource The processed feature source.
 * @throws IOException 
 */
private static SimpleFeatureSource getFeatureSourceFromFile() throws IOException{

	//Open a file and process it into a FeatureSource.
	File file = JFileDataStoreChooser.showOpenFile("shp", null);
       FileDataStore store = FileDataStoreFinder.getDataStore(file);
       
       return store.getFeatureSource();
}
 
开发者ID:Stefangemfind,项目名称:MapMatching,代码行数:17,代码来源:App.java


示例13: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的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);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:31,代码来源:Quickstart.java


示例14: snipetDataStoreFinder

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
public void snipetDataStoreFinder() throws Exception {
    // start datastore
    File file = JFileDataStoreChooser.showOpenFile("shp", null);
    
    Map<String,Object> params = new HashMap<String,Object>();
    params.put( "url", file.toURI().toURL() );
    params.put( "create spatial index", false );
    params.put( "memory mapped buffer", false );
    params.put( "charset", "ISO-8859-1" );
    
    DataStore store = DataStoreFinder.getDataStore( params );
    SimpleFeatureSource featureSource = store.getFeatureSource( store.getTypeNames()[0] );
    // end datastore
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:15,代码来源:QuickstartNotes.java


示例15: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
/**
 * 
 * @param args
 *            shapefile to use, if not provided the user will be prompted
 */
public static void main(String[] args) throws Exception {
    System.out.println("Welcome to GeoTools:" + GeoTools.getVersion());
    
    File file, file2;
    if (args.length == 0) {
        file = JFileDataStoreChooser.showOpenFile("shp", null);
    } else {
        file = new File(args[0]);
    }
    if (args.length <= 1) {
        file2 = JFileDataStoreChooser.showOpenFile("shp", null);
    } else {
        file2 = new File(args[1]);
    }
    if (file == null || !file.exists() || file2 == null || !file2.exists()) {
        System.exit(1);
    }
    Map<String, Object> connect = new HashMap<String, Object>();
    connect.put("url", file.toURI().toURL());
    DataStore shapefile = DataStoreFinder.getDataStore(connect);
    String typeName = shapefile.getTypeNames()[0];
    SimpleFeatureSource shapes = shapefile.getFeatureSource(typeName);
    
    Map<String, Object> connect2 = new HashMap<String, Object>();
    connect.put("url", file2.toURI().toURL());
    DataStore shapefile2 = DataStoreFinder.getDataStore(connect);
    String typeName2 = shapefile2.getTypeNames()[0];
    SimpleFeatureSource shapes2 = shapefile2.getFeatureSource(typeName2);
    
    joinExample(shapes, shapes2);
    System.exit(0);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:38,代码来源:JoinExample.java


示例16: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    SelectionLab me = new SelectionLab();

    File file = JFileDataStoreChooser.showOpenFile("shp", null);
    if (file == null) {
        return;
    }

    me.displayShapefile(file);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:11,代码来源:SelectionLab.java


示例17: displayShapefile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的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);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:38,代码来源:CRSLab.java


示例18: main

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	File file = null;
	if (args.length == 0) {
		// display a data store file chooser dialog for shapefiles
		file = JFileDataStoreChooser.showOpenFile("shp", null);
		if (file == null) {
			return;
		}
	} else {
		file = new File(args[0]);
		if (!file.exists()) {
			System.err.println(file + " doesn't exist");
			return;
		}
	}
	PointInPolygon tester = new PointInPolygon();
	FileDataStore store = FileDataStoreFinder.getDataStore(file);
	SimpleFeatureSource featureSource = store.getFeatureSource();
	tester.setFeatures(featureSource.getFeatures());
	GeometryFactory fac = new GeometryFactory();
	for (int i = 0; i < 1000; i++) {

		double lat = (Math.random() * 180.0) - 90.0;
		double lon = (Math.random() * 360.0) - 180.0;
		Point p = fac.createPoint(new Coordinate(lat, lon));
		boolean flag = tester.isInShape(p);
		if (flag) {
			System.out.println(p + " is in States ");
		}
	}
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:32,代码来源:PointInPolygon.java


示例19: exportToShapefile

import org.geotools.swing.data.JFileDataStoreChooser; //导入依赖的package包/类
/**
 * Export features to a new shapefile using the map projection in which they are currently
 * displayed
 */
// docs start export
private void exportToShapefile() throws Exception {
    SimpleFeatureType schema = featureSource.getSchema();
    JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
    chooser.setDialogTitle("Save reprojected shapefile");
    chooser.setSaveFile(sourceFile);
    int returnVal = chooser.showSaveDialog(null);
    if (returnVal != JFileDataStoreChooser.APPROVE_OPTION) {
        return;
    }
    File file = chooser.getSelectedFile();
    if (file.equals(sourceFile)) {
        JOptionPane.showMessageDialog(null, "Cannot replace " + file);
        return;
    }

    // set up the math transform used to process the data
    CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
    CoordinateReferenceSystem worldCRS = map.getCoordinateReferenceSystem();
    boolean lenient = true; // allow for some error due to different datums
    MathTransform transform = CRS.findMathTransform(dataCRS, worldCRS, lenient);

    // grab all features
    SimpleFeatureCollection featureCollection = featureSource.getFeatures();

    // And create a new Shapefile with a slight modified schema
    DataStoreFactorySpi factory = new ShapefileDataStoreFactory();
    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    create.put("create spatial index", Boolean.TRUE);
    DataStore dataStore = factory.createNewDataStore(create);
    SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype(schema, worldCRS);
    dataStore.createSchema(featureType);

    // carefully open an iterator and writer to process the results
    Transaction transaction = new DefaultTransaction("Reproject");
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
                    dataStore.getFeatureWriterAppend(featureType.getTypeName(), transaction);
    SimpleFeatureIterator iterator = featureCollection.features();
    try {
        while (iterator.hasNext()) {
            // copy the contents of each feature and transform the geometry
            SimpleFeature feature = iterator.next();
            SimpleFeature copy = writer.next();
            copy.setAttributes(feature.getAttributes());

            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            Geometry geometry2 = JTS.transform(geometry, transform);

            copy.setDefaultGeometry(geometry2);
            writer.write();
        }
        transaction.commit();
        JOptionPane.showMessageDialog(null, "Export to shapefile complete");
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        JOptionPane.showMessageDialog(null, "Export to shapefile failed");
    } finally {
        writer.close();
        iterator.close();
        transaction.close();
    }
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:69,代码来源:CRSLab.java



注:本文中的org.geotools.swing.data.JFileDataStoreChooser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CodeSizeEvaluator类代码示例发布时间:2022-05-23
下一篇:
Java DurabilityData类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap