45
45
feature_ptr feature(new Feature(1));
46
47
GDALRasterBand * red = 0;
47
48
GDALRasterBand * green = 0;
48
49
GDALRasterBand * blue = 0;
49
50
GDALRasterBand * alpha = 0;
50
51
GDALRasterBand * grey = 0;
51
for (int i = 0; i < dataset_.GetRasterCount() ;++i)
53
GDALRasterBand * band = dataset_.GetRasterBand(i+1);
54
//if (band->GetOverviewCount() > 0)
56
// band = band->GetOverview(0);
61
band->GetBlockSize(&bsx,&bsy);
62
std::cout << boost::format("Block=%dx%d Type=%s Color=%s \n") % bsx % bsy
63
% GDALGetDataTypeName(band->GetRasterDataType())
64
% GDALGetColorInterpretationName(band->GetColorInterpretation());
66
GDALColorInterp color_interp = band->GetColorInterpretation();
84
case GCI_PaletteIndex:
87
GDALColorTable *color_table = band->GetColorTable();
91
int count = color_table->GetColorEntryCount();
93
std::cout << "Color Table count = " << count << "\n";
95
for ( int i = 0; i < count; i++ )
97
const GDALColorEntry *ce = color_table->GetColorEntry ( i );
100
std::cout << "color entry RGB (" << ce->c1 <<"," <<ce->c2 << "," << ce->c3 << ")\n";
115
53
unsigned raster_xsize = dataset_.GetRasterXSize();
116
54
unsigned raster_ysize = dataset_.GetRasterYSize();
55
int nbands = dataset_.GetRasterCount();
118
58
dataset_.GetGeoTransform(tr);
119
59
double x0 = tr[0];
125
65
Envelope<double> intersection = raster_extent.intersect(query_extent_);
126
66
Envelope<double> box = t.forward(intersection);
128
int start_x = int(box.minx());
129
int start_y = int(box.miny());
130
int width = int(box.width());
131
int height = int(box.height());
68
int start_x = int(box.minx()+0.5);
69
int start_y = int(box.miny()+0.5);
70
int width = int(box.width()+0.5);
71
int height = int(box.height()+0.5);
74
std::cout << boost::format("RasterWidth=%d RasterHeight=%d \n") % raster_xsize % raster_ysize;
75
std::cout << boost::format("StartX=%d StartY=%d Width=%d Height=%d \n") % start_x % start_y % width % height;
133
78
if (width > 0 && height > 0)
80
// Some GDAL drivers operate more efficiently if they know in advance
81
// what set of upcoming read requests will be made. The AdviseRead()
82
// method allows an application to notify the driver of the region and
83
// bands of interest, and at what resolution the region will be read.
85
// dataset_.AdviseRead (start_x, start_y, width, height, width, height, GDT_Byte, nbands, NULL, NULL);
87
for (int i = 0; i < nbands; ++i)
89
GDALRasterBand * band = dataset_.GetRasterBand(i+1);
90
int band_overviews = band->GetOverviewCount();
92
if (band_overviews > 0)
95
for (int b = 0; b < band_overviews; b++)
97
GDALRasterBand * overview = band->GetOverview (b);
98
std::cout << boost::format("Overview=%d Width=%d Height=%d \n")
99
% b % overview->GetXSize() % overview->GetYSize();
104
for (int b = band_overviews; --b >= 0;)
106
GDALRasterBand * overview = band->GetOverview (b);
107
if ((start_x + width) <= overview->GetXSize()
108
&& (start_y + height) <= overview->GetYSize())
111
std::cout << boost::format("Picked Overview=%d \n") %b;
118
// band = band->GetRasterSampleOverview (width / height);
119
// band = band->GetOverview (band->GetOverviewCount() - 1);
126
band->GetBlockSize(&bsx,&bsy);
127
scale = band->GetScale();
128
std::cout << boost::format("Block=%dx%d Scale=%f Type=%s Color=%s \n") % bsx % bsy % scale
129
% GDALGetDataTypeName(band->GetRasterDataType())
130
% GDALGetColorInterpretationName(band->GetColorInterpretation());
133
GDALColorInterp color_interp = band->GetColorInterpretation();
134
switch (color_interp)
151
case GCI_PaletteIndex:
154
GDALColorTable *color_table = band->GetColorTable();
158
int count = color_table->GetColorEntryCount();
160
std::cout << "Color Table count = " << count << "\n";
162
for ( int i = 0; i < count; i++ )
164
const GDALColorEntry *ce = color_table->GetColorEntry ( i );
167
std::cout << "color entry RGB (" << ce->c1 <<"," <<ce->c2 << "," << ce->c3 << ")\n";
135
181
mapnik::ImageData32 image(width,height);
136
182
image.set(0xffffffff);
138
184
if (red && green && blue)
186
//red->AdviseRead (start_x, start_y, width, height, width, height, GDT_Byte, nbands, NULL);
187
//green->AdviseRead(start_x, start_y, width, height, width, height, GDT_Byte, nbands, NULL);
188
//blue->AdviseRead (start_x, start_y, width, height, width, height, GDT_Byte, nbands, NULL);
140
189
red->RasterIO (GF_Read,start_x,start_y,width,height, image.getBytes() + 0, width,height, GDT_Byte,4,4*width);
141
190
green->RasterIO(GF_Read,start_x,start_y,width,height, image.getBytes() + 1, width,height, GDT_Byte,4,4*width);
142
191
blue->RasterIO (GF_Read,start_x,start_y,width,height, image.getBytes() + 2, width,height, GDT_Byte,4,4*width);
145
alpha->RasterIO(GF_Read,start_x,start_y,width,height, image.getBytes() + 3, width,height, GDT_Byte,4,4*width);
195
// grey->AdviseRead (start_x, start_y, width, height, width, height, GDT_Byte, nbands, NULL);
150
196
grey->RasterIO(GF_Read,start_x,start_y,width,height,image.getBytes() + 0, width, height,GDT_Byte,4,4*width);
151
197
grey->RasterIO(GF_Read,start_x,start_y,width,height,image.getBytes() + 1, width, height,GDT_Byte,4,4*width);
152
198
grey->RasterIO(GF_Read,start_x,start_y,width,height,image.getBytes() + 2, width, height,GDT_Byte,4,4*width);
156
alpha->RasterIO(GF_Read,start_x,start_y,width,height, image.getBytes() + 3, width,height, GDT_Byte,4,4*width);
203
//alpha->AdviseRead (start_x, start_y, width, height, width, height, GDT_Byte, nbands, NULL);
204
alpha->RasterIO(GF_Read,start_x,start_y,width,height, image.getBytes() + 3, width,height, GDT_Byte,4,4*width);
159
207
feature->set_raster(mapnik::raster_ptr(new mapnik::raster(intersection,image)));