『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

使用ArcGIS读取 SQLite 中的空间数据

使用ArcGIS读取 SQLite 中的空间数据
对于 SQLite 里面原生的空间数据,spatialite.dll(需要几个依赖库)这个库读取,这样的话,我们将创建好的数据在脱离 ArcGIS 软件后也可以方便读取,比如在 WP 中,读取出来的数据,我们可以解析成 ArcGIS Runtime for WP 中的数据,以便使用。

       对于 SQLite 里面原生的空间数据,spatialite.dll(需要几个依赖库)这个库读取,这样的话,我们将创建好的数据在脱离 ArcGIS 软件后也可以方便读取,比如在 WP 中,读取出来的数据,我们可以解析成 ArcGIS Runtime for WP 中的数据,以便使用。 下面给出代码示例和截图,在示例用已经将空间数据读取出来了

 

string          conn = @"Data

Source=D:\2013\SQLite\spatialtest.sqlite;Pooling=true;FailIfMissing=false" ;

SQLiteCommand       cmd;

SQLiteConnection    pConn = new SQLiteConnection( conn );

 

if ( pConn.State != ConnectionState.Open )

{

    pConn.Open();

}

 

cmd     = new SQLiteCommand( String.Format( "SELECT load_extension('{0}');", "spatialite.dll" ) );

cmd.Connection  = pConn;

cmd.ExecuteNonQuery(); /* 加载类库后必须执行这句,不然会出问题 */

 

/* 可以查看表名称 */

DataTable dt = pConn.GetSchema( "Tables" );

Console.WriteLine( "打印表名称......" );

foreach ( DataRow dataRow in dt.Rows )

{

    string tableName = dataRow["TABLE_NAME"].ToString();

    Console.WriteLine( tableName );

}

cmd.CommandType = CommandType.Text;

string commandText = "Select AsBinary(Shape),* from POI";

cmd.CommandText = commandText;

DataSet ds = new DataSet();

;

SQLiteDataAdapter da = new SQLiteDataAdapter( cmd );

da.Fill( ds ); 6

pConn.Close();

Console.WriteLine( "空间数据......" );

 

foreach ( DataRow dataRow in ds.Tables[0].Rows )

{

    string tableName = dataRow["AsText(Shape)"].ToString();

    Console.WriteLine( tableName );

}

Console.ReadLine();

 

 

 

 

       从 SQLite 中读取了空间数据,那么可以根据需要迚行转换,下面是我写的一个 AO 中的点对象和 SQLite 中点对象的转换(在 ArcGIS 中这个已经不用做了,Esri 已经帮我们实现)。

 

public static String IGeometryToWKT( IGeometry pGeometry )

{

    if ( pGeometry == null )

    {

        return(null);

    }

    String sGeoStr = "";

    if ( pGeometry is IPoint )

    {

        Point pt = (Point) pGeometry;

        sGeoStr = "POINT" + "(" + pt.X + " " + pt.Y + ")";

    }else{ /* 其余格式,省略 */

        sGeoStr = null; 9

    }

    return(sGeoStr);

}

 

 

public static IGeometry WKTToIGeometry( String sWkt )

{

    IGeometry pGeo = null;

    if ( sWkt == null || sWkt == "" )

    {

        return(null);

    }

    String  headStr = sWkt.Substring( 0, sWkt.IndexOf( "(" ) );

    String  temp    = sWkt.Substring( sWkt.IndexOf( "(" ) + 1, sWkt.LastIndexOf( ")" ) );

    if ( headStr.Equals( "Point", StringComparison.InvariantCultureIgnoreCase ) )

    {

        String[] values = temp.Split( ' ' );

        pGeo = new PointClass

        {

            X   = Convert.ToDouble( values[0] ),

            Y   = Convert.ToDouble( values[1] )

        };

    }else{

        /* 其余的省略 */

    }

    return(pGeo);

}

      京ICP备2025132830号-1 京公网安备 号