作者windsheep (....)
看板C_Sharp
标题[问题] GDAL/OGR 读 S-57 格式档案的问题
时间Tue Jun 15 16:16:04 2010
最近在尝试用C#读S-57格式的档案
用的是由
http://download.osgeo.org/gdal/
下载的gdal source code
也有试过搭用FW Tools 2.4.7
http://fwtools.maptools.org/
我试着把里面的ogrinfo.cs make 起来
但是执行的结果不如预期..
我用的环境是VS 2005
ogr相关的dll, 我试过拿gdal source make出来的 gdal_csharp.dll 等九个dll
或是把FW Tools里的直接拿来用, 都有一样问题..
不知有没有先进有遇过一样的问题
我执行的source code如下:
using System;
using System.Collections.Generic;
using System.Text;
using OSGeo.OGR;
using OSGeo.OSR;
namespace ogrinfo
{
class OGRInfo
{
public static void usage()
{
Console.WriteLine("usage: ogrinfo {data source name}");
System.Environment.Exit(-1);
}
public static void Main(string[] args)
{
if (args.Length != 1) usage();
// Using early initialization of System.Console
Console.WriteLine("");
/*
-------------------------------------------------------------------- */
/* Register format(s).
*/
/*
-------------------------------------------------------------------- */
Ogr.RegisterAll();
/*
-------------------------------------------------------------------- */
/* Open data source.
*/
/*
-------------------------------------------------------------------- */
DataSource ds = Ogr.Open(args[0], 0);
if (ds == null)
{
Console.WriteLine("Can't open " + args[0]);
System.Environment.Exit(-1);
}
/*
-------------------------------------------------------------------- */
/* Get driver
*/
/*
-------------------------------------------------------------------- */
Driver drv = ds.GetDriver();
if (drv == null)
{
Console.WriteLine("Can't get driver.");
System.Environment.Exit(-1);
}
// TODO: drv.name is still unsafe with lazy initialization (Bug
1339)
Console.WriteLine("Using driver " + drv.name);
/*
-------------------------------------------------------------------- */
/* Iterating through the layers
*/
/*
-------------------------------------------------------------------- */
for (int iLayer = 0; iLayer < ds.GetLayerCount(); iLayer++)
{
Layer layer = ds.GetLayerByIndex(iLayer);
if (layer == null)
{
Console.WriteLine("FAILURE: Couldn't fetch advertised
layer " + iLayer);
System.Environment.Exit(-1);
}
Console.WriteLine(layer.GetName());
//ReportLayer(layer);
}
}
}
主要会执行到的code我标了一下颜色了..
执行结果是
Using driver S57
DSID
Point
Line
Area
Meta
ds.GetLayerCount() 只传回 5, 只有5个layer
layer的Name印出来就只有 DSID/Point/Line/Area/Meta 这五个
但是如果是用FW_Tools里或是gdal自己make出来的
就可以读到如下比较完整的layer
using driver `S57' successful.
1: DSID (None)
2: ACHARE
3: BCNSPP (Point)
4: BRIDGE
5: BUISGL
6: BUAARE
7: BOYSPP (Point)
8: CBLSUB (Line String)
9: COALNE (Line String)
10: DEPARE
11: DEPCNT (Line String)
12: DOCARE (Polygon)
13: DRYDOC (Polygon)
14: FSHFAC
15: HRBARE (Polygon)
16: HRBFAC
17: LAKARE (Polygon)
18: LNDARE
19: LNDELV
20: LNDMRK
21: LIGHTS (Point)
22: MORFAC
23: OBSTRN
24: PILBOP
25: RTPBCN (Point)
26: RDOSTA (Point)
27: RAILWY (Line String)
28: RESARE (Polygon)
29: RIVERS
30: ROADWY
31: SBDARE
32: SLCONS
33: SISTAT (Point)
34: SISTAW (Point)
35: SOUNDG (3D Multi Point)
36: TOPMAR (Point)
37: TSSBND (Line String)
38: TSSLPT (Polygon)
39: TSEZNE (Polygon)
40: TUNNEL
41: UWTROC (Point)
42: WATTUR
43: WRECKS
44: TS_FEB
45: M_COVR (Polygon)
46: M_NSYS (Polygon)
47: M_QUAL (Polygon)
48: C_AGGR (None)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.124.122.57