Spatialite 入门一

SQLite号称全世界最小的数据库,在几乎绝大多数数据库都具有空间数据的存储和查询功能后,SQLite目前也有了空间数据支持的扩展,利用这个扩展,可以按照OGC的Simple Feature Access标准存取空间数据。这个项目名叫SpatiaLite,与其一同分发的还有一个VirtualShape。前者为SQLite增加空间数据支持,后者可以把一个Shapefile作为SQLite的数据库

SpatiaLite编译(Windows)

下载地址:https://www.gaia-gis.it/fossil/libspatialite/index

Windows编译参考地址:http://www.gaia-gis.it/gaia-sins/msvc_how_to.html

依赖第三方库 libproj、libgeos、libfreexl、libiconv、libsqlite3、libz、libxml2、librttopp、libexpatd、liblzma、libreadosm

SpatiaLite空间数据表结构

 

 

(基于BLOB类型的)Geometry: 将空间数据以WKB(Well-Known Binary Representation)形式存储在名为WKB_Geometry的BLOB类型的字段中, 不会出现折行存储Geometry的情况 一行存储一个Geometry对象 每行GID是该Geometry对象的唯一标识 YMIN, YMAX, XMIN, XMAX用于存储该对象的四至 该表的主码是GID

 

SpatiaLite 简单示例

GAIA_POINT类型:

int geoType = gaiaGeometryType(geo);

if (geoType == GAIA_POINT) // 读取pointz

{

gaiaPointPtr p = geo->FirstPoint;

while (p != nullptr)

{ PointD pt; pt.x = p->X; pt.y = p->Y; p = p->Next; }

}

GAIA_LINESTRING类型:

int geoType = gaiaGeometryType(geo);

if (geoType == GAIA_LINESTRING) // 读取linestring

{ gaiaLinestringPtr lp = geo->FirstLinestring;

while (lp != nullptr)

{     for (int i = 0; i < lp->Points; i++)     

        {         PointD pt;         pt.x = (lp->Coords)[i * 2];         pt.y = (lp->Coords)[i * 2 + 1];         pt.z = 0;         points.emplace_back(pt);     

}     

lp = lp->Next;

}

}

GAIA_POLYGON类型:

int geoType = gaiaGeometryType(geo);

if (geoType == GAIA_POLYGON) // 读取polygon

{ gaiaPolygonPtr poly = geo->FirstPolygon;

while (poly != nullptr)

{     

gaiaRingPtr pRing = poly->Exterior;     //外环

for (int i = 0; i < pRing->Points; i++)     

{         PointD pt;         pt.x = (pRing->Coords)[i * 2];  

       pt.y = (pRing->Coords)[i * 2 + 1];     

   points.emplace_back(pt);   

 }   

pRing = poly->Interiors;     //内环

while(pRing != nullptr)

{

for (int i = 0; i < pRing->Points; i++)     

{         PointD pt;         pt.x = (pRing->Coords)[i * 2];  

       pt.y = (pRing->Coords)[i * 2 + 1];     

   points.emplace_back(pt);   

 }   

pRing->Next;

}

 poly = poly->Next;

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值