Hi,To be honest I am new with rasterlite2, and I want to use its c++ api. I have seen rasterliteGetRasterByRect function which returns raster based on rectangular but I dont know if there is any relevant function in rasterlite2. In fact there is not any api documents for rasterlite2 which I can use them, How can I find a api relevant to RL2_GetMapImageFromRaster() in C++?
SELECTRL2_GetMapImageFromRaster
(
-- coverage_name
'1890.berlin_postgrenzen',
-- Rectangle to extract
BuildMBR(20800.0,22000.0,24000.0,19600.0),
-- Image size[together with Rectangle = Resolution]
1200,1920,
-- style to use (if any)
'default',
-- Image format to return result
'image/png',
-- background color
'#ffffff',
0,0,1);
Hi,
Well You mean I must just query the results and convert them into png for example. The hard part is its conversion from BloB to png.
-- QT:
QByteArray imageData = sqlite3_column_blob(stmt,0);
QImage result_image=QImage::fromData( imageData );
-- wxWindows:
const unsigned char *p_blob = (const unsigned char *) sqlite3_column_blob(stmt, 0);wxImage result_image = wxImage(FrameWidth, FrameHeight);result_image.SetData(p_blob, false);
rl2CoveragePtr coverage= rl2_create_coverage_from_dbms(db_,cov);
const char *a2= rl2_get_coverage_name(coverage);
rl2_get_coverage_resolution(coverage,&hres,&vres);
// rl2_get_raw_raster_data(db_,20,coverage,200,300,49.47,34.472,54.147,37.687,72.0,72.0,buffer,
// buffer_s,pallet,RL2_PIXEL_GRAYSCALE);
// rl2_export_raw_pixels_from_dbms(db_,20,coverage,72,72,49.47,34.472,54.147,37.687,300,300,1,&buffer,
// &buffer_s);
double minx=0,miny=0,maxx=0,maxy=0;
double ex_minx=49.47,ex_miny=34.47,ex_maxx=54.147,ex_maxy=37.67;
int hight=(int)((ex_maxy-ex_miny)/hres);
int width=(int)((ex_maxx-ex_minx)/vres);
if (rl2_get_raw_raster_data
(db_, 20, coverage, width, hight,49.47,34.472,54.147,37.687, hres, vres,&buffer,
&buffer_s, NULL,RL2_PIXEL_RGB) != RL2_OK){
rl2RasterPtr rst= rl2_create_raster (width,hight, RL2_SAMPLE_UINT8, RL2_PIXEL_RGB, 3.0,
buffer, buffer_s, NULL, NULL, 0.0, NULL);
rl2_export_jpeg_from_dbms(db_, 20,"test.jpg",
coverage, hres, vres,49.47,34.472,54.147,37.687,width, hight,72.0,1);
rl2_get_raster_extent(rst,&minx,&miny,&maxx,&maxy);
}
Hi,
Thanks very much. If I want to use Rasterlite2 api is there any procedures for it? I have to then convert images to mapnik::image
frombuffer( (object)arg1)
What if we want to get images directly using C++ api?
-- Rectangle to extract
BuildMBR(20800.0,22000.0,24000.0,19600.0),
-- Image size[together with Rectangle = Resolution]
1200,1920,
Hican you give me a hint about the use of-- Rectangle to extract
BuildMBR(20800.0,22000.0,24000.0,19600.0),
-- Image size[together with Rectangle = Resolution]
1200,1920,My first question is about MBR. Does the coordinates have to be based on SRID of input data? for example here MBR is coordinates based on UTM?
Also what about image size? does it must be based on resolution? I mean I have to calculate it based on this equation? (minx-maxx/resolution)=mage width?
SELECT 'Adlerstraßen' AS name, RL2_GetMapImageFromRaster ( -- The dbPrefix argument is intended to specify the ATTACHED-DB where the Coverage is expected to be found 'main', -- chosen name of raster_coverage lower('1910.alt_berlin_coelln_friedrichsweder'), -- area to extract, BuildMbr ( 24500.0,21030.0, 24900.0,20630.0, 3068 ), -- image-size width,height (calculate) -- 1181 CAST(round((24900.0-24500.0)/0.338695578413350) AS INTEGER), -- 1181 CAST(round((21030.0-20630.0)/0.338695578413350) AS INTEGER), -- style-name 'default', -- image/mime-type jpeg 'image/png', -- background '#ffffff', -- transparent 0, -- jpeg quality 80, -- 1 = adapt image width,height if needed 1 ) AS image;
<ChannelSelection>
<RedChannel>
<SourceChannelName>3</SourceChannelName>
</RedChannel>
<GreenChannel>
<SourceChannelName>2</SourceChannelName>
</GreenChannel>
<BlueChannel>
<SourceChannelName>1</SourceChannelName>
</BlueChannel>
</ChannelSelection>
<ContrastEnhancement>
<Histogram/>
</ContrastEnhancement>
int img_size=0;
int state=0;
const char * img_buff = sqlite_utils::get_png(dataset_,cov_info,40,38,55,45,1200,600,state,img_size);
// int img_size = strlen(img_buff);
if(state==0) {
rl2RasterPtr rst = rl2_raster_from_png (img_buff,img_size,0);
unsigned char* RGBA_buff;
int RGBA_size;
int state_rgba = rl2_raster_data_to_RGBA (rst,&RGBA_buff, &RGBA_size);
} else {
cout<<"\r\nERROR";
}
double x0, y0, x1, y1;//This is defined to get coverage extents in 4326
x0=coverage.geo_minx;
y0=coverage.geo_miny;
x1=coverage.geo_maxx;
y1=coverage.geo_maxy;
box2d<double> raster_extent(x0, y0, x1, y1);
box2d<double> intersect = raster_extent.intersect(q.get_bbox());//we have a query object in mapnik which requests a bbox and also has a resolution.
const int width = static_cast<int>(std::get<0>(q.resolution()) * intersect.width() + 0.5);
const int height = static_cast<int>(std::get<0>(q.resolution()) * intersect.height() + 0.5);
const double pixel_size = (intersect.width() >= intersect.height()) ?
(intersect.width() / (double) width) : (intersect.height() / (double) height);
Mapnik LOG> 2017-09-25 14:23:57: rasterlite_featureset: Coverage extent=box2d(44.9995836965389984,29.9990570224555348,55.0011049965362488,40.0004167635142949)
Mapnik LOG> 2017-09-25 14:23:57: rasterlite_featureset: View extent=box2d(44.9995836965389984,29.9990570224555348,55.0011049965362488,40.0004167635142949)
Mapnik LOG> 2017-09-25 14:23:57: rasterlite_featureset: Intersect extent=box2d(44.9995836965389984,29.9990570224555348,55.0011049965362488,40.0004167635142949)
Mapnik LOG> 2017-09-25 14:23:57: rasterlite_featureset: Query resolution=59.9918,59.9918
Mapnik LOG> 2017-09-25 14:23:57: rasterlite_featureset: Size=600 600
Mapnik LOG> 2017-09-25 14:23:57: rasterlite_featureset: Pixel Size=0.0166692
Mapnik LOG> 2017-09-25 14:23:57: get_image sql : SELECT RL2_GetMapImageFromRaster ('srtmdem',ST_Transform(BuildMbr(44.9996,29.9991,55.0011,40.0004,4326),3857),600,600,'srtm_plus','image/png','#ffffff',1,80,1) as image
I'm sorry, but it seems a messy nonsense.
- the SRTM dataset is natively based on SRID=4326, but you've
reprojected it on SRID=3857 (how ? may be using gdalwarp ?)
- then you are asking RasterLite2 to reproject back again to
SRID=4326
- if your specific goal is the one to display on the screen
poor quality raster maps imposing at the same time a very
high CPU workload you are pointing in the right direction
in any case you are never expected to directly face any
BBOX related question when applying a reprojection
between two different SRIDs; just pass the appropriate
image BBOX (in the output "map" SRID), and RasterLite2
will take care to automatically adapt such BBOX to the
native BBOX of the underlaying Coverage.
I have checked different versions of rl2 and find out that the latest version has some kind of different bahaviours than others.I have a database with srtm coverage (4326),This query works fine with this version :librasterlite2-1.0.0-develSELECT RL2_GetMapImageFromRaster ('srtmdem',ST_Transform(BuildMbr(44.9996,29.9996,55.0004,40.0004,4326),4326),600,600,'srtm_plus','image/png','#ffffff',1,80,1) as imagebut with this one :librasterlite2-c19226c1a6It returns Null, I have tried different Mbrs and this is true for all of them,well wmslite with librasterlite2-1.0.0-devel recognizes database as a valid database but this one :librasterlite2-c19226c1a6 returns an error,Gdal driver works with librasterlite2-c19226c1a6 but with librasterlite2-1.0.0-devel it does not work.I think sth is changed which I am not noticed.I also tried to change coverages SRID to 3857, I reprojected images and then imported into another database, none of my queries worked as I have to use ST_Transform(BuildMbr(44.9996,29.9996,55.0004,40.0004,4326),3857) to create mbr and it seems I am miscalculating width and hightThanks very muchMajid
Dear Sandro,
well at first I thought there is something wrong with my reprojected images, so I opened them in qgis