librasterlite2库示例demo笔记(自用)

librasterlite2示例demo笔记.txt



【RL2】 sql_reference_list
https://www.gaia-gis.it/fossil/librasterlite2/wiki?name=sql_reference_list

【与GeoTIFF相关的函数】
RL2_GeoTIFF_Version () : String
Will return the version of libgeotiff currently in use.

RL2_GetMapImageFromRaster 
Will attempt to create a digital image representing a Styled Map from a Coverage of the Raster type.
Will return a BLOB containing the Styled Map: or NULL on invalid arguments or if any error occurs.
'image/geotiff': TIFF image format (RGB uncompressed) with internal georeferencing
'image/geotiff8': TIFF image format (uncompressed, based on a Palette of max. 256 colors) with internal georeferencing
'application/pdf' or 'application/x-pdf': PDF document format
default is 'image/png'.
Note: png8, gif, tiff8 and geotiff8 images are usually noticeably smaller because are based on a restricted palette of colors, but sometimes at the cost of a possibly disturbing color degradation.



【SQL functions importing raster data from external datasources】
RL2_LoadRaster
RL2_LoadRastersFromDir
【SQL functions exporting raw raster data to external files】
RL2_WriteGeoTiff
RL2_WriteTripleBandGeoTiff
RL2_WriteMonoBandGeoTiff
【SQL functions exporting raw raster data to external files (Section oriented)】
RL2_WriteSectionGeoTiff
RL2_WriteSectionTripleBandGeoTiff
RL2_WriteSectionMonoBandGeoTiff





【RL2_LoadRaster】
RL2_LoadRaster ( coverageName String , sourcePath String ) : Integer
RL2_LoadRaster ( coverageName String , sourcePath String , withWorldFile Integer ) : Integer
RL2_LoadRaster ( coverageName String , sourcePath String , withWorldFile Integer , forceSRID Integer ) : Integer
RL2_LoadRaster ( coverageName String , sourcePath String , withWorldFile Integer , forceSRID Integer , pyramidize Integer ) : Integer
RL2_LoadRaster ( coverageName String , sourcePath String , withWorldFile Integer , forceSRID Integer , pyramidize Integer, transaction Integer ) : Integer

Will attempt to create and populate a new Section within a Coverage by importing an external file-based raster datasource (of the JPEG, TIFF, GeoTiff or ASCII Grid type).
Will return 1 (TRUE/SUCCESS) or 0 (FALSE/FAILURE): or -1 on invalid arguments.
Please note:
if the optional argument withWorldFile (expected to be of the Boolean type) is set to TRUE, then a corresponding WorldFile is expected to be found and will be used to goerefence the raster.
if the optional argument forceSRID is explicit set, than its value will be assumed to represent the SRID declared by the external datasource.
Please note: declaring some forceSRID value is absolutely required for any JPEG, TIFF and ASCII Grid file, because only GeoTIFF could eventually declare some SRID.
if the optional argument pyramidize (expected to be of the Boolean type) is set to TRUE, then any Pyramid level directly supporting the current Section will be immediately built; otherwise Pyramid levels will be ignored.
if the last optional argument (expected to be of the Boolean type) isn't declared an internal SQL Transaction will be implicitly handled.
Please note very well: this SQL function is only available when the environment variable SPATIALITE_SECURITY=relaxed is set.
将尝试通过导入外部基于文件的栅格数据源(JPEG、TIFF、GeoTiff或ASCII网格类型)来创建和填充复盖范围内的新部分。
将返回1(TRUE/SUCCESS)或0(FALSE/FAILURE):或在无效参数上返回-1。
请注意:
如果可选参数withWorldFile(预期为布尔类型)设置为TRUE,则预计将找到相应的WorldFile,并将用于从栅格中读取。
如果显式设置了可选参数forceSRID,则将假定其值表示外部数据源声明的SRID。
请注意:任何JPEG,TIFF和ASCII网格文件都绝对需要声明一些srid值,因为只有GeoTIFF最终可以声明一些SRID。
如果可选参数pyramidize(预期为布尔类型)设置为TRUE,则直接支持当前部分的任何金字塔级别将立即构建;否则金字塔级别将被忽略。
如果未声明最后一个可选参数(预期为布尔类型),则将隐式处理内部SQL事务。
请非常注意:此SQL函数仅在设置环境变量SPATIALITE_SECURITY=relaxed时可用。


【RL2_LoadRastersFromDir】
RL2_LoadRastersFromDir ( coverageName String , dirPath String , extension String ) : Integer
RL2_LoadRastersFromDir ( coverageName String , dirPath String , extension String , withWorldFile Integer ) : Integer
RL2_LoadRastersFromDir ( coverageName String , dirPath String , extension String , withWorldFile Integer , forceSRID Integer ) : Integer
RL2_LoadRastersFromDir ( coverageName String , dirPath String , extension String , withWorldFile Integer , forceSRID Integer , pyramidize Integer ) : Integer
RL2_LoadRastersFromDir ( coverageName String , dirPath String , extension String , withWorldFile Integer , forceSRID Integer , pyramidize Integer, transaction Integer ) : Integer

Will attempt to import all external file-based raster datasources (of the JPEG, TIFF, GeoTiff or ASCII Grid type) found within an external directory.
For each datasource being imported a corresponding Section will be created and populated.
Will return 1 (TRUE/SUCCESS) or 0 (FALSE/FAILURE): or -1 on invalid arguments.
Please note:
the mandatory extension argument is expected to specify the filename extension identifying the files to be imported (e.g. .tif, .jpg or .asc).
if the optional argument withWorldFile (expected to be of the Boolean type) is set to TRUE, then a corresponding WorldFile is expected to be found and will be used to goerefence the raster.
if the optional argument forceSRID is explicit set, than its value will be assumed to represent the SRID declared by the external datasource.
Please note: declaring some forceSRID value is absolutely required for any JPEG, TIFF and ASCII Grid file, because only GeoTIFF could eventually declare some SRID.
if the optional argument pyramidize (expected to be of the Boolean type) is set to TRUE, then any Pyramid level directly supporting the current Section will be immediately built; otherwise Pyramid levels will be ignored.
if the last optional argument (expected to be of the Boolean type) isn't declared an internal SQL Transaction will be implicitly handled.
Please note very well: this SQL function is only available when the environment variable SPATIALITE_SECURITY=relaxed is set.
将尝试导入【外部目录】中找到的所有基于外部文件的栅格数据源(JPEG,TIFF,GeoTiff或ASCII网格类型)。
对于导入的每个数据源,将创建并填充相应的部分。
将返回1(TRUE/SUCCESS)或0(FALSE/FAILURE):或在无效参数上返回-1。
请注意:
强制扩展名参数预期指定文件扩展名标识要导入的文件(例如。tif,。jpg或。asc)。
如果可选参数withWorldFile(预期为布尔类型)设置为TRUE,则预计将找到相应的WorldFile,并将用于从栅格中读取。
如果显式设置了可选参数forceSRID,则将假定其值表示外部数据源声明的SRID。
请注意:任何JPEG,TIFF和ASCII网格文件都绝对需要声明一些srid值,因为只有GeoTIFF最终可以声明一些SRID。
如果可选参数pyramidize(预期为布尔类型)设置为TRUE,则直接支持当前部分的任何金字塔级别将立即构建;否则金字塔级别将被忽略。
如果未声明最后一个可选参数(预期为布尔类型),则将隐式处理内部SQL事务。
请非常注意:此SQL函数仅在设置环境变量SPATIALITE_SECURITY=relaxed时可用。


【RL2_WriteGeoTiff】
RL2_WriteGeoTiff ( dbPrefix String , coverageName String , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , pixelResolution Double ) : Integer
RL2_WriteGeoTiff ( dbPrefix String , coverageName String , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double ) : Integer
RL2_WriteGeoTiff ( dbPrefix String , coverageName String , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double , withWoldFile Integer ) : Integer
RL2_WriteGeoTiff ( dbPrefix String , coverageName String , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double , withWoldFile Integer , tiffCompression String ) : Integer
RL2_WriteGeoTiff ( dbPrefix String , coverageName String , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double , withWoldFile Integer , tiffCompression String , tiffTileSize Integer ) : Integer
Will attempt to export raw raster data from a Coverage into an external GeoTIFF file.
Will return 1 (TRUE/SUCCESS) or 0 (FALSE/FAILURE): or -1 on invalid arguments.
Please note:
The dbPrefix argument is intended to specify the ATTACHED-DB where the Coverage is expected to be found; it could be eventually NULL, and in this case the MAIN DB will implicitly be assumed.
the boundingBox is expected to represent the overall extent of the exported GeoTIFF; you could eventually pass any arbitrary kind of Geometry, and the Bounding Box aka MBR will be automatically determined.
the horzPixelResolution and vertPixelResolution must exactly match the Coverage's base resolution or one of the resolutions made available by the corresponding Pyramid levels.
and the BoundingBox must exactly match the TIFF width and height dimensions at that resolution.
if the optional argument withWorldFile is set to TRUE then an auxiliary WorldFile will be exported as well.
the optional argument tiffCompression could be one of 'NONE', 'DEFLATE', 'LZW', 'JPEG', 'FAX3' or 'FAX4'; default is 'NONE'.
the last optional argument can be used so to specify the preferred TIFF tile size (only square tiles are supported); default is 256.
Please note very well: this SQL function is only available when the environment variable SPATIALITE_SECURITY=relaxed is set.
将尝试将原始栅格数据从Coverage导出到外部GeoTIFF文件中。
将返回1(TRUE/SUCCESS)或0(FALSE/FAILURE):或在无效参数上返回-1。
请注意:
DbPrefix参数旨在指定期望找到Coverage的ATTACHED-DB;它最终可能为NULL,在这种情况下,将隐式假定主DB。
boundingBox预计表示导出的GeoTIFF的整体范围;您最终可以传递任何任意类型的几何体,并且边界框又名MBR将被自动确定。
horzPixelResolution和vertPixelResolution必须完全匹配复盖的基本分辨率或相应金字塔级别提供的分辨率之一。
并且BoundingBox必须与该分辨率下的TIFF宽度和高度尺寸完全匹配。
如果可选参数withWorldFile设置为TRUE,那么也将导出辅助WorldFile。
可选参数tiffCompression可以是'NONE','DEFLATE','LZW','JPEG','FAX3'或'FAX4'之一;默认为'NONE'。
最后一个可选参数可用于指定首选TIFF瓷砖大小(仅支持方形瓷砖);默认值为256。
请非常注意:此SQL函数仅在设置环境变量SPATIALITE_SECURITY=relaxed时可用。


【RL2_WriteSectionGeoTiff】
RL2_WriteSectionGeoTiff ( dbPrefix String , coverageName String , sectionID Integer , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , pixelResolution Double ) : Integer
RL2_WriteSectionGeoTiff ( dbPrefix String , coverageName String , sectionID Integer , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double ) : Integer
RL2_WriteSectionGeoTiff ( dbPrefix String , coverageName String , sectionID Integer , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double , withWoldFile Integer ) : Integer
RL2_WriteSectionGeoTiff ( dbPrefix String , coverageName String , sectionID Integer , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double , withWoldFile Integer , tiffCompression String ) : Integer
RL2_WriteSectionGeoTiff ( dbPrefix String , coverageName String , sectionID Integer , filePath String , width Integer , height Integer , boundingBox BLOB-Geometry , horzPixelResolution Double , vertPixelResolution Double , withWoldFile Integer , tiffCompression String , tiffTileSize Integer ) : Integer
Will attempt to export raw raster data from a Coverage into an external GeoTIFF file; only the Tiles directly belonging to the selected Section will be considered.
Will return 1 (TRUE/SUCCESS) or 0 (FALSE/FAILURE): or -1 on invalid arguments.
Please note:
The dbPrefix argument is intended to specify the ATTACHED-DB where the Coverage is expected to be found; it could be eventually NULL, and in this case the MAIN DB will implicitly be assumed.
the boundingBox is expected to represent the overall extent of the exported GeoTIFF; you could eventually pass any arbitrary kind of Geometry, and the Bounding Box aka MBR will be automatically determined.
the horzPixelResolution and vertPixelResolution must exactly match the Coverage's base resolution or one of the resolutions made available by the corresponding Pyramid levels.
and the BoundingBox must exactly match the TIFF width and height dimensions at that resolution.
if the optional argument withWorldFile is set to TRUE then an auxiliary WorldFile will be exported as well.
the optional argument tiffCompression could be one of 'NONE', 'DEFLATE', 'LZW', 'JPEG', 'FAX3' or 'FAX4'; default is 'NONE'.
the last optional argument can be used so to specify the preferred TIFF tile size (only square tiles are supported); default is 256.
Please note very well: this SQL function is only available when the environment variable SPATIALITE_SECURITY=relaxed is set.
将尝试将原始栅格数据从Coverage导出到外部GeoTIFF文件中;只考虑直接属于所选部分的切片。
将返回1(TRUE/SUCCESS)或0(FALSE/FAILURE):或在无效参数上返回-1。
请注意:
DbPrefix参数旨在指定期望找到Coverage的ATTACHED-DB;它最终可能为NULL,在这种情况下,将隐式假定主DB。
boundingBox预计表示导出的GeoTIFF的整体范围;您最终可以传递任何任意类型的几何体,并且边界框又名MBR将被自动确定。
horzPixelResolution和vertPixelResolution必须完全匹配复盖的基本分辨率或相应金字塔级别提供的分辨率之一。
并且BoundingBox必须与该分辨率下的TIFF宽度和高度尺寸完全匹配。
如果可选参数withWorldFile设置为TRUE,那么也将导出辅助WorldFile。
可选参数tiffCompression可以是'NONE','DEFLATE','LZW','JPEG','FAX3'或'FAX4'之一;默认为'NONE'。
最后一个可选参数可用于指定首选TIFF瓷砖大小(仅支持方形瓷砖);默认值为256。
请非常注意:此SQL函数仅在设置环境变量SPATIALITE_SECURITY=relaxed时可用。




https://gis.stackexchange.com/questions/416863/sqlite-spatialite-error-no-such-function-importgeojson
SPATIALITE_SECURITY=relaxed sqlite3 'db.sqlite' "SELECT load_extension('mod_spatialite')" "SELECT ImportGeoJSON('file.geojson', 'osmgeojson')"





[示例]
/** \example test_xl.c

test_xl.c is a simple demonstration and diagnostic tool for the Excel (.xls) file format.

This sample code provides an example of:
 - opening the .xls file  打开EXCEL
 - querying general information  查询一般信息
 - querying Workbooks, SST entries and FAT entries  查询工作簿,SST条目和FAT条目
 - error handling  错误处理
 - closing the .xls file when no further operations are required  关闭EXCEL


 /** \example xl2sql.c

xl2sql a simple tool that takes an .xls file as input, and generates a SQL script as output. 
xls2sql一个简单的工具,输入xls文件,生成SQL脚本。
You can then use the SQL script to load the extracted data info a SQLite / SpatiaLite database.
您可以使用SQL脚本加载提取的数据到SQLite/SpatiaLite数据库中。

//和DB建立链接
sqlite3_open_v2()
#和sqlite3_close_v2()对应

//spatialite库初始化,清除缓存
void *cache = spatialite_alloc_connection();
spatialite_init_ex(handle, cache, 0)

//rasterlite2库初始化,清除缓存
void *priv_data;
priv_data = rl2_alloc_private();
rl2_init(handle, priv_data, 0);
【rl2函数原型】
RL2_DECLARE void *rl2_alloc_private (void);//初始化支持每个RL2连接的内部私有内存块
RL2_DECLARE void rl2_init (sqlite3 * db_handle, const void *ptr, int verbose);\\注意在尝试调用任何RasterLite2自己的函数之前,总是希望显式调用rl2_init函数。
参数db_handle   处理当前SQLite连接
参数ptr         rl2_alloc_private()返回的内存指针
参数verbose     如果为TRUE,则在stderr上显示短启动消息

//显示库的版本
printf("SQLite version: %s\n", sqlite3_libversion());
printf("RasterLite2 version: %s\n", rl2_version());
printf("\n\n");

//初始化数据库(DB)的元表(MetaTable)
//执行SQL:SELECT InitSpatialMetadata(1) 1-作为单事务处理,速度快
const char *sql;
sql = "SELECT InitSpatialMetadata(1)";
ret = sqlite3_exec(handle, sql, NULL, NULL, &err_msg);
if (ret != SQLITE_OK)
{
    fprintf(stderr, "InitSpatialMetadata() error: %s\n", err_msg);
    sqlite3_free(err_msg);
    err = 1;
    goto stop;//!!不建议用goto!!
}
【SQL原型】
InitSpatialMetaData( transaction Integer , mode String ) : Integer//初始化空间数据库
创建geometry_columns和spatial_ref_sys元数据表格,返回1-true 0-false
可选参数 transaction=TRUE 整个操作将作为单个事务处理(速度更快,安全性低)
可选参数 mode=未指定,所有可能的ESPG SRID定义都被插入spatial_ref_sys表
        mode='WGS84' 只会插入与WGS84相关的EPSG SRIDs
        mode='NONE' 根本不会插入EPSG SRID

//执行SQL:SELECT CreateRasterCoveragesTable()
sql = "SELECT CreateRasterCoveragesTable()";
ret = sqlite3_exec(handle, sql, NULL, NULL, &err_msg);
if (ret != SQLITE_OK)
{
    fprintf(stderr, "CreateRasterCoveragesTable() error: %s\n", err_msg);
    sqlite3_free(err_msg);
    err = 1;
    //goto stop;
    return stop(no_data, handle, err, cache, priv_data);
}
【SQL原型】
CreateRasterCoveragesTable( void ) : Integer
创建Rasterlite-2所需要的raster_coverages表,返回1-true 0-false

//执行SQL:SELECT CreateStylingTables()
    sql = "SELECT CreateStylingTables()";
    ret = sqlite3_exec(handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
    {
        fprintf(stderr, "CreateStylingTables() error: %s\n", err_msg);
        sqlite3_free(err_msg);
        err = 1;
        //goto stop;
        return stop(no_data, handle, err, cache, priv_data);
    }
【SQL原型】
CreateStylingTables( relaxed Integer , transaction Integer ) : Integer
创建一组支持SLD/SE Styled Layers的表,返回1-true 0-false -1-无效参数
可选参数 relaxed=TRUE 安装验证触发器validating Triggers的relaxed版本(不检查严格的XSD架构验证)
可选参数 transaction=TRUE 整个操作将作为单个事务处理(a monolithic SQL transaction)
注意:如果尚未定义,将隐式调用Create Raster Coverage Table()和CreateVectorCoveragesTables()以创建相应的表。

//创建一个黑色(RGB:0,0,0)像素(无数据NO-DATA/透明色Transparent color)
no_data = rl2_create_pixel(RL2_SAMPLE_UINT8,    /* unsigned 8bit sample */
        RL2_PIXEL_RGB,  /* RGB pixel */
        3   /* number of bands */
        );
if (no_data == NULL)
{
    fprintf(stderr, "unable to create a Black NoData pixel\n");
    err = 1;
    goto stop;
}
rl2_set_pixel_sample_uint8(no_data, 0, 0);
rl2_set_pixel_sample_uint8(no_data, 1, 0);
rl2_set_pixel_sample_uint8(no_data, 2, 0);
【rl2函数原型】
RL2_DECLARE rl2PixelPtr rl2_create_pixel (unsigned char sample_type, unsigned char pixel_type, unsigned char num_samples);
分配和初始化一个新的像素对象,返回指向新创建的像素对象的指针,失败NULL
参数 sample_type 可选:RL2_SAMPLE_1_BIT, RL2_SAMPLE_2_BIT, RL2_SAMPLE_4_BIT,
        RL2_SAMPLE_INT8, RL2_SAMPLE_UINT8, RL2_SAMPLE_INT16, RL2_SAMPLE_UINT16,
        RL2_SAMPLE_INT32, RL2_SAMPLE_UINT32, RL2_SAMPLE_FLOAT or RL2_SAMPLE_DOUBLE.
    /** RasterLite2 constant: Sample Type 1-bit */
    #define RL2_SAMPLE_1_BIT        0xa1
    /** RasterLite2 constant: Sample Type 2-bit */
    #define RL2_SAMPLE_2_BIT        0xa2
    /** RasterLite2 constant: Sample Type 4-bit */
    #define RL2_SAMPLE_4_BIT        0xa3
    /** RasterLite2 constant: Sample Type 8 bit Integer */
    #define RL2_SAMPLE_INT8         0xa4
    /** RasterLite2 constant: Sample Type 8 bit Unsigned Integer */
    #define RL2_SAMPLE_UINT8        0xa5
    /** RasterLite2 constant: Sample Type 16 bit Integer */
    #define RL2_SAMPLE_INT16        0xa6
    /** RasterLite2 constant: Sample Type 16 bit Unsigned Integer */
    #define RL2_SAMPLE_UINT16       0xa7
    /** RasterLite2 constant: Sample Type 32 bit Integer */
    #define RL2_SAMPLE_INT32        0xa8
    /** RasterLite2 constant: Sample Type 32 bit Unsigned Integer */
    #define RL2_SAMPLE_UINT32       0xa9
    /** RasterLite2 constant: Sample Type Floating Point Single Precision */
    #define RL2_SAMPLE_FLOAT        0xaa
    /** RasterLite2 constant: Sample Type Floating Point Double Precision */
    #define RL2_SAMPLE_DOUBLE       0xab
参数 pixel_type 可选:RL2_PIXEL_MONOCHROME, RL2_PIXEL_PALETTE, RL2_PIXEL_GRAYSCALE,
        RL2_PIXEL_RGB, RL2_PIXEL_MULTIBAND, RL2_PIXEL_DATAGRID.
    /** RasterLite2 constant: Pixel Type Monochrome - Bilevel */
    #define RL2_PIXEL_MONOCHROME        0x11
    /** RasterLite2 constant: Pixel Type Palette based */
    #define RL2_PIXEL_PALETTE       0x12
    /** RasterLite2 constant: Pixel Type Grayscale */
    #define RL2_PIXEL_GRAYSCALE     0x13
    /** RasterLite2 constant: Pixel Type Red-Green-Blue */
    #define RL2_PIXEL_RGB           0x14
    /** RasterLite2 constant: Pixel Type Multiband (arbitrary) */
    #define RL2_PIXEL_MULTIBAND     0x15
    /** RasterLite2 constant: Pixel Type Data-Grid */
    #define RL2_PIXEL_DATAGRID      0x16
    /** RasterLite2 constant: Pixel Type NONE */
参数 num_samples:每个像素的样本数/波段数
注意:有责任销毁(之前或之后)任何分配的像素对象

RL2_DECLARE int rl2_set_pixel_sample_uint8 (rl2PixelPtr pxl, int band, unsigned char sample);
将像素/样本值分配给uint8像素对象,成功返回RL2_OK,错误返回RL2_ERROR(包括引用不匹配PixelType的像素)
参数 pxl 指向像素对象的指针
参数 band 样本/波段索引(从0开始)
参数 sample 要设置的像素/样本值

//创建一个虚拟的RGB coverage
if (rl2_create_dbms_coverage(handle,    /* DB handle */
        "euro_flags",   /* Coverage name */
        RL2_SAMPLE_UINT8,   /* unsigned 8bit sample */
        RL2_PIXEL_RGB,  /* RGB pixel */
        3,  /* number of bands */
        RL2_COMPRESSION_PNG,    /* PNG compressed tiles */
        100,    /* compression quality */
        256,    /* tile Width */
        256,    /* tile Height */
        4326,   /* pseudo-SRID (this is simply to define a cartesian space) */ //伪SRID(这只是定义一个笛卡尔空间) *
        h_res,  /* horizontal pixel resolution */
        v_res,  /* vertical pixel resolution */
        no_data,    /* transparent Color = BLACK */ //相当于背景值?
        NULL,   /* palette (not required by RGB) */ //调色板
        1,  /* enabling StrictResolution mode */
        0,  /* disabling MixedResolutions mode */
        1,  /* enabling Section Paths recording */
        1,  /* enabling Section MD5 checksum */
        1,  /* enabling Section Summary */
        1   /* enabling IsQueryable */
    ) != RL2_OK)
return 0;
【rl2函数原型】
RL2_DECLARE int rl2_create_dbms_coverage (sqlite3 * handle, const char *coverage,
                  unsigned char sample, unsigned char pixel,
                  unsigned char num_bands,
                  unsigned char compression, int quality,
                  unsigned int tile_width,
                  unsigned int tile_height, int srid,
                  double x_res, double y_res,
                  rl2PixelPtr no_data, rl2PalettePtr palette,
                  int strict_resolution, int mixed_resolutions,
                  int section_paths, int section_md5,
                  int section_summary, int is_queryable);
成功执行返回0,否则返回-1
/** RasterLite2 ret-value: OK (success) */
#define RL2_OK              0
/** RasterLite2 ret-value: ERROR (failure) */
#define RL2_ERROR           -1
压缩方式 compression
    /** RasterLite2 constant: Compression UNKNOWN */
    #define RL2_COMPRESSION_UNKNOWN     0x20
    /** RasterLite2 constant: Compression None */
    #define RL2_COMPRESSION_NONE        0x21
    /** RasterLite2 constant: Compression Deflate Delta (zip) */
    #define RL2_COMPRESSION_DEFLATE     0x22
    /** RasterLite2 constant: Compression Deflate noDelta (zip) */
    #define RL2_COMPRESSION_DEFLATE_NO  0xd2
    /** RasterLite2 constant: Compression LZMA Delta */
    #define RL2_COMPRESSION_LZMA        0x23
    /** RasterLite2 constant: Compression LZMA noDelta */
    #define RL2_COMPRESSION_LZMA_NO 0xd3
    /** RasterLite2 constant: Compression GIF */
    #define RL2_COMPRESSION_GIF     0x24
    /** RasterLite2 constant: Compression PNG */
    #define RL2_COMPRESSION_PNG     0x25
    /** RasterLite2 constant: Compression JPEG */
    #define RL2_COMPRESSION_JPEG        0x26
    /** RasterLite2 constant: Compression WEBP (lossy mode) */
    #define RL2_COMPRESSION_LOSSY_WEBP  0x27
    /** RasterLite2 constant: Compression WEBP (lossless mode) */
    #define RL2_COMPRESSION_LOSSLESS_WEBP   0x28
    /** RasterLite2 constant: Compression CCITTFAX3 */
    #define RL2_COMPRESSION_CCITTFAX3   0x29
    /** RasterLite2 constant: Compression CCITTFAX4 */
    #define RL2_COMPRESSION_CCITTFAX4   0x30
    /** RasterLite2 constant: Compression LZW */
    #define RL2_COMPRESSION_LZW     0x31
    /** RasterLite2 constant: Compression JPEG2000 (lossy mode) */
    #define RL2_COMPRESSION_LOSSY_JP2   0x33
    /** RasterLite2 constant: Compression JPEG2000 (lossless mode) */
    #define RL2_COMPRESSION_LOSSLESS_JP2    0x34
    /** RasterLite2 constant: Compression LZ4 Delta */
    #define RL2_COMPRESSION_LZ4     0x35
    /** RasterLite2 constant: Compression LZ4 noDelta */
    #define RL2_COMPRESSION_LZ4_NO      0xd4
    /** RasterLite2 constant: Compression ZSTD Delta */
    #define RL2_COMPRESSION_ZSTD        0x36
    /** RasterLite2 constant: Compression ZSTD noDelta */
    #define RL2_COMPRESSION_ZSTD_NO 0xd5

//插入第一个Section: belgian flag(比利时国旗?)
unsigned int flag_base = 1234;//基本块宽度(国旗长3倍,宽2倍)
double h_res = 1.5 / ((double)flag_base * 3.0); //水平像素分辨率
double v_res = 1.0 / ((double)flag_base * 2.0); //垂向像素分辨率
unsigned char *pixels;
int pixels_sz;
调用create_belgium(flag_base, &pixels, &pixels_sz)函数
    width = flag_base * 3;
    height = flag_base * 2;
    sz = width * height * 3;
    unsigned char *pix = (unsigned char *)malloc(sz);//分配所需的内存空间,并返回一个指向它的指针
    调用fill_vert函数(垂向:黑/黄/红条)
        static void fill_vert(unsigned char r, unsigned char g, unsigned char b, unsigned char *pix, int strip从左往右第几列条纹(0开始), unsigned int width, unsigned int height)
    fill_vert(1, 1, 1, pix, 0, width, height);  /* black */
    fill_vert(255, 233, 54, pix, 1, width, height); /* yellow */
    fill_vert(255, 15, 33, pix, 2, width, height);  /* red */
    调用add_border(pix, width, height)函数 //窄的灰边
        RGB=(192,192,192)
        width = 8
    *pixels = pix;//赋值的RGB国旗
    *pixels_sz = sz;//像元数?
//执行SQL:在‘euro_flags’的coverage中,创建‘belgium’的Section,大小未知,BuildMBR(0, 0, 1.5, 1, 4326),生成金字塔,单事件处理,默认低位编址
sql = "SELECT RL2_ImportSectionRawPixels('euro_flags', 'belgium', "
    "?, ?, ?, BuildMBR(0, 0, 1.5, 1, 4326), 1, 1, 0)";
//调用insert_section函数
    插入一个 RAW pixel buffer
    sqlite3_stmt *stmt = NULL;
    调用sqlite3_prepare_v2(handle, sql, strlen(sql), &stmt, NULL)函数
***【函数原型】
***sqlite3_exec函数执行SQL语句方便,但是效率低;其内部执行可以分为解析、编译、执行三步。
***用sqlite3_prepare_v2(解析编译)+sqlite3_stmt(准备语句)+sqlite3_bind_*(赋值)+sqlite3_step(执行)替代。
***#一次解析编译,多次执行,整体效率高
    sqlite3_reset(stmt);//重置一个准备语句对象stmt到它的初始状态
    sqlite3_clear_bindings(stmt);//重设绑定数值
    sqlite3_bind_int(stmt, 1, width);//绑定变量width
    sqlite3_bind_int(stmt, 2, height);//绑定变量height
    sqlite3_bind_blob(stmt, 3, pixels, pixels_sz, free);//绑定变量pixelBuf
    //循环执行赋值
    while (1)
    {
        ret = sqlite3_step(stmt);//执行 返回SQLITE_DONE丨SQLITE_ROW丨SQLITE_MISUSE
        if (ret == SQLITE_DONE)//sql语句执行完成且成功
            break;
        if (ret == SQLITE_ROW)//每次只返回一行
            ok = sqlite3_column_int(stmt, 0);//查询(query)结果的筛选,返回当前结果的某1列
        else
        {
            fprintf(stderr,
                "SELECT RL2_ImportSectionRawPixels; sqlite3_step() error: %s\n",
                sqlite3_errmsg(handle));
            goto error;
        }
    }
    sqlite3_finalize(stmt);//销毁sqlite3_stmt对象


if (!insert_section
(handle, sql, flag_base * 3, flag_base * 2, pixels, pixels_sz))
{
    err = 1;
    //goto stop;
    return stop(no_data, handle, err, cache, priv_data);
}
【SQL原型】
RL2_ImportSectionRawPixels ( coverageName String , sectionName String , width Integer , height Integer , pixelBuf BLOB , boundingBox BLOB-Geometry , pyramidize Integer, transaction Integer , bigEndian Boolean ) : Integer
尝试通过从BLOB像素缓冲区(pixel buffer)导入栅格数据来填充复盖范围内的部分(Section within a Coverage),成功返回1,失败0,无效参数-1
注意:
The target Coverage在主DB中找到
参数 pixelBuf BLOB格式,对应pixel buffer(矩形数组:height*width)
参数 boundingBox 预计表示BLOB像素缓冲区的整体范围;您可以传递任何任意类型的几何体,并且边界框又名MBR将被自动确定。
可选参数 pyramidize=TRUE(默认) 直接构建支持当前Section的任何金字塔层Pyramid level
可选参数 transaction 未赋值 将隐式处理内部SQL事务
可选参数 bigEndian=False(默认) 确定多字节像素/带值是否期望以其大端或小端编码表示(多字节存储顺序)
    1)Little-endian:将低序字节存储在起始地址(低位编址)
    2)Big-endian:将高序字节存储在起始地址(高位编址)
BuildMbr( x1 Double precision , y1 Double precision , x2 Double precision , y2 Double precision [ , SRID Integer] ) : Geometry
Point[x1 y1]和Point[x2 y2],用于识别Line segment。返回表示这个线段的Geometry
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值