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

Java DataSource类代码示例

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

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



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

示例1: createDataSource

import org.gdal.ogr.DataSource; //导入依赖的package包/类
public static DataSource createDataSource(final List<Node>       nodes,
                                          final List<Edge>       edges,
                                          final SpatialReference sourceSpatialReference)
{
   final DataSource dataSource = ogr.GetDriverByName("Memory")
                                     .CreateDataSource("vector data");

    try
    {
        final Layer edgeLayer = createEdgeLayer(dataSource,
                                                nodes,
                                                edges,
                                                sourceSpatialReference);
    }
    catch(final Throwable th)
    {
        dataSource.delete();
        throw th;
    }

    return dataSource;
}
 
开发者ID:GitHubRGI,项目名称:swagd,代码行数:23,代码来源:Utility.java


示例2: calculateAndWriteTerrainFactors

import org.gdal.ogr.DataSource; //导入依赖的package包/类
public static void calculateAndWriteTerrainFactors(final File                      terrainFactors,
                                                   final File                      output,
                                                   final List<Node>                nodes,
                                                   final List<Edge>                edges,
                                                   final CoordinateReferenceSystem coordinateReferenceSystem)
{
    final SpatialReference sourceSpatialReference = GdalUtility.createSpatialReference(coordinateReferenceSystem);

    final DataSource dataSource = Utility.createDataSource(nodes,
                                                           edges,
                                                           sourceSpatialReference);
    try
    {

    }
    finally
    {
        dataSource.delete();    // Also destroys edgeLayer
    }
}
 
开发者ID:GitHubRGI,项目名称:swagd,代码行数:21,代码来源:RoutingNetworkTerrainFactors.java


示例3: reprojectShapeFile

import org.gdal.ogr.DataSource; //导入依赖的package包/类
public static void reprojectShapeFile(String pathFile, String outPathFile) {
	ogr.RegisterAll();

	DataSource vector = ogr.Open(pathFile);

	SpatialReference src = new SpatialReference(WKTString.WKT3995);
	SpatialReference dst = new SpatialReference(WKTString.WKTWGS84);
	CoordinateTransformation tr = new CoordinateTransformation(src, dst);

	Driver drv = ogr.GetDriverByName("ESRI Shapefile");
	File file = new File(outPathFile);
	if (file.exists())
		drv.DeleteDataSource(outPathFile);

	DataSource outputDs = drv.CreateDataSource(outPathFile);
	Layer outLayer = outputDs.CreateLayer(outPathFile, dst);
	
	FieldDefn field_def = new FieldDefn("DN",ogr.OFTInteger);
	outLayer.CreateField(field_def);
	 
	Layer ll = vector.GetLayer(0);
	// Get the Layer's Feature Definition
	FeatureDefn featureDefn = ll.GetLayerDefn();
	
	int n = ll.GetFeatureCount();

	// outLayer.StartTransaction();
	for (int i = 0; i < n; i++) {
		Feature feat = ll.GetNextFeature();
		Geometry gg = feat.GetGeometryRef();
		Geometry newgg = new Geometry(ogr.wkbPolygon);

		int srcType = gg.GetGeometryType() ;//& (ogrConstants.wkb25DBit);
		if (srcType == ogr.wkbPolygon) {
			//int resg = gg.Transform(tr);
			newgg.AddGeometry(gg);
		} else if (srcType == ogr.wkbMultiPolygon) {
			int geomCount = gg.GetGeometryCount();
			for (int geomIndex = 0; geomIndex < geomCount; geomIndex++) {
				Geometry g=gg.GetGeometryRef(geomIndex);
				int resg = g.Transform(tr);
				newgg.AddGeometry(g);
			}
		}

		// create a new feature
		Feature f = new Feature(featureDefn);
		f.SetGeometry(newgg);
		// f.SetFID(i);
		for (int j = 0; j < feat.GetFieldCount(); j++) {
			String type = feat.GetFieldDefnRef(j).GetFieldTypeName(feat.GetFieldType(j));
			if (type.equals("String")) {
				f.SetField(feat.GetFieldDefnRef(j).GetName(), feat.GetFieldAsString(j));
			} else if (type.equals("StringList")) {

			} else if (type.equals("Integer")) {
				f.SetField(feat.GetFieldDefnRef(j).GetName(), feat.GetFieldAsInteger(j));
			} else if (type.equals("IntegerList")) {
			} else if (type.equals("Real")) {
				f.SetField(feat.GetFieldDefnRef(j).GetName(), feat.GetFieldAsDouble(j));
			} else if (type.equals("RealList")) {
			}
		}

		// Add new feature to output Layer
		int res = outLayer.CreateFeature(f);

		System.out.println("create feature:" + res);

		gg.delete();
		feat.delete();
	}
	// outLayer.CommitTransaction();

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:76,代码来源:GDALWarpReprojection.java


示例4: createEdgeLayer

import org.gdal.ogr.DataSource; //导入依赖的package包/类
private static Layer createEdgeLayer(final DataSource       dataSource,
                                     final Collection<Node> nodes,
                                     final Iterable<Edge>   edges,
                                     final SpatialReference spatialReference)
{
     final Map<Integer, Node> nodeMap = new HashMap<>(nodes.size());

    for(final Node node : nodes)
    {
        nodeMap.put(node.getIdentifier(), node);
    }

    final Layer edgeLayer = dataSource.CreateLayer("edges",
                                                   spatialReference,
                                                   ogrConstants.wkbLineString);

    try
    {
        for(final Edge edge : edges)
        {
            final Feature edgeFeature = new Feature(edgeLayer.GetLayerDefn());

            final Geometry line = new Geometry(ogrConstants.wkbLineString);

            final Node node0 = nodeMap.get(edge.getFrom());
            final Node node1 = nodeMap.get(edge.getTo());

            line.AddPoint(node0.getX(), node0.getY());
            line.AddPoint(node1.getX(), node1.getY());

            if(edgeFeature.SetGeometry(line) != gdalconstConstants.CE_None)
            {
                throw new RuntimeException(new GdalError().getMessage());
            }

            if(edgeLayer.CreateFeature(edgeFeature) != gdalconstConstants.CE_None)
            {
                throw new RuntimeException(new GdalError().getMessage());
            }
        }
    }
    catch(final Throwable th)
    {
        edgeLayer.delete();
        throw th;
    }

    return edgeLayer;
}
 
开发者ID:GitHubRGI,项目名称:swagd,代码行数:50,代码来源:Utility.java


示例5: write

import org.gdal.ogr.DataSource; //导入依赖的package包/类
@Override
public void write(final List<Node>                nodes,
                  final List<Edge>                edges,
                  final NodeDimensionality        nodeDimensionality,        // not used
                  final List<Pair<String, Type>>  nodeAttributeDescriptions, // not used
                  final List<Pair<String, Type>>  edgeAttributeDescriptions, // not used
                  final CoordinateReferenceSystem coordinateReferenceSystem) throws RoutingNetworkStoreException
{
    final SpatialReference sourceSpatialReference;

    try
    {
        sourceSpatialReference = GdalUtility.createSpatialReference(coordinateReferenceSystem);
    }
    catch(final RuntimeException ex)
    {
        throw new RoutingNetworkStoreException(ex);
    }

    final Dataset rasterDataset = this.createRaster(sourceSpatialReference);

    try
    {
        final DataSource dataSource = Utility.createDataSource(nodes,
                                                               edges,
                                                               sourceSpatialReference);
        try
        {
            final int rasterizeError = gdal.RasterizeLayer(rasterDataset,
                                                           new int[]{1, 2, 3, 4},
                                                           dataSource.GetLayer(0),
                                                           new double[]{ this.foreground.getRed(),
                                                                         this.foreground.getGreen(),
                                                                         this.foreground.getBlue(),
                                                                         this.foreground.getAlpha()
                                                                       },
                                                           null,                    // "options" vector. valid choices are described here: http://gdal.org/gdal__alg_8h.html#adfe5e5d287d6c184aab03acbfa567cb1
                                                           this.progressCallback);

            if(rasterizeError != gdalconstConstants.CE_None)
            {
                throw new RuntimeException(new GdalError().getMessage());
            }
        }
        finally
        {
            dataSource.delete();    // Also destroys edgeLayer
        }
    }
    finally
    {
        rasterDataset.delete();
    }
}
 
开发者ID:GitHubRGI,项目名称:swagd,代码行数:55,代码来源:ImageRoutingNetworkStoreWriter.java


示例6: checkValid

import org.gdal.ogr.DataSource; //导入依赖的package包/类
/**
    * Process a file 
    * @param pFile file to process
    * @return true if opened ok, false if not
    */
   @SuppressWarnings("unused")
public static boolean checkValid(File pFile) {

   	if(!pFile.exists()) return false;
   	
   	final String pszWHERE = null;
   	final Geometry poSpatialFilter = null;
   	Driver poDriver = null;
   	final String pszDataSource = pFile.getAbsolutePath();

   	/* -------------------------------------------------------------------- */
   	/*      Open data source.                                               */
   	/* -------------------------------------------------------------------- */

   	DataSource poDS = ogr.Open(pszDataSource, !bReadOnly);
   	if (poDS == null && !bReadOnly)	{
   		poDS = ogr.Open(pszDataSource, false);
   		if (poDS == null && bVerbose) {
   			if(bVerbose) System.out.println( "Had to open data source read-only.");
   		}
   	}

   	/* -------------------------------------------------------------------- */
   	/*      Report failure                                                  */
   	/* -------------------------------------------------------------------- */
   	if( poDS == null ) {
   		if(bVerbose) {
   			System.out.print("FAILURE: Unable to open datasource `"+pszDataSource+"' with the following drivers.\n");
   			for( int iDriver = 0; iDriver < ogr.GetDriverCount(); iDriver++ ) {
   				System.out.println( "  -> " + ogr.GetDriver(iDriver).GetName() );
   			}
   		}
   		return false;
   	}

   	poDriver = poDS.GetDriver();
   	
   	if(!poDriver.GetName().equalsIgnoreCase(OGR_NTF_DRIVER_NAME)) {
   		// i.e. this is not an NTF file
   		return false;
   	}

   	/* -------------------------------------------------------------------- */
   	/*      Some information messages.                                      */
   	/* -------------------------------------------------------------------- */
   	if( bVerbose ) {
   		System.out.println( "INFO: Open of `" + pszDataSource + "'\n" +
   				"      using driver `" + poDriver.GetName() + "' successful." );
   	}

   	/* -------------------------------------------------------------------- */
   	/*      Process each data source layer.                                 */
   	/* -------------------------------------------------------------------- */

   	for(int iLayer = 0; iLayer < poDS.GetLayerCount(); iLayer++) {
   		Layer poLayer = poDS.GetLayer(iLayer);

   		if(poLayer==null) {
   			if(bVerbose) System.out.println( "FAILURE: Couldn't fetch advertised layer " + iLayer + "!");
   			return false;
   		}

   		boolean layerOk = reportOnLayer( poLayer, pszWHERE, poSpatialFilter );
   		if(!layerOk) return false;
   		
   	}

   	// if we get this far then the file must be valid(ish)
   	return true;
   }
 
开发者ID:bl-dpt,项目名称:geolint,代码行数:76,代码来源:GDALWrapper.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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