~ubuntu-branches/ubuntu/trusty/mapnik/trusty-proposed

« back to all changes in this revision

Viewing changes to plugins/input/gdal/gdal_featureset.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2009-08-27 00:28:37 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090827002837-ztqzfg2rmclfh4i9
Tags: 0.6.1-0ubuntu1
* New upstream release.
* Change usr/lib to usr/lib* to enable build on 64 bits systems due to new
  configuration in SConstruct in :
  - debian/libmapnik-dev.install
  - debian/libmapnik0.6.install
  - debian/mapnik-plugin-base

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
   {
44
44
      first_ = false;
45
45
      feature_ptr feature(new Feature(1));
 
46
 
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)
52
 
      {
53
 
         GDALRasterBand * band = dataset_.GetRasterBand(i+1);
54
 
         //if (band->GetOverviewCount() > 0)
55
 
         //{
56
 
         //  band = band->GetOverview(0);
57
 
         //}
58
 
         
59
 
#ifdef MAPNIK_DEBUG         
60
 
         int bsx,bsy;
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());   
65
 
#endif
66
 
         GDALColorInterp color_interp = band->GetColorInterpretation();
67
 
         switch (color_interp)
68
 
         {
69
 
            case GCI_RedBand:
70
 
               red = band;
71
 
               break;
72
 
            case GCI_GreenBand:
73
 
               green = band;
74
 
               break;
75
 
            case GCI_BlueBand:
76
 
               blue = band;
77
 
               break;
78
 
            case GCI_AlphaBand:
79
 
               alpha = band;
80
 
               break;
81
 
            case GCI_GrayIndex:
82
 
               grey = band;
83
 
               break;
84
 
            case GCI_PaletteIndex:
85
 
            {   
86
 
               grey = band;
87
 
               GDALColorTable *color_table = band->GetColorTable();
88
 
                                
89
 
               if ( color_table)
90
 
               {
91
 
                  int count = color_table->GetColorEntryCount();
92
 
#ifdef MAPNIK_DEBUG
93
 
                  std::cout << "Color Table count = " << count << "\n";
94
 
#endif 
95
 
                  for ( int i = 0; i < count; i++ )
96
 
                  {
97
 
                     const GDALColorEntry *ce = color_table->GetColorEntry ( i );
98
 
                     if (!ce ) continue;
99
 
#ifdef MAPNIK_DEBUG
100
 
                     std::cout << "color entry RGB (" << ce->c1 <<"," <<ce->c2 << "," << ce->c3 << ")\n"; 
101
 
#endif
102
 
                  }
103
 
               }        
104
 
               break;
105
 
            }
106
 
            case GCI_Undefined:
107
 
               grey = band;
108
 
               break;   
109
 
            default:
110
 
               break;
111
 
               ;
112
 
         }
113
 
      }
114
 
      
 
52
 
115
53
      unsigned raster_xsize = dataset_.GetRasterXSize();
116
54
      unsigned raster_ysize = dataset_.GetRasterYSize();
 
55
      int nbands = dataset_.GetRasterCount();
 
56
 
117
57
      double tr[6];
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);
127
67
      
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());
132
 
      
 
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);
 
72
 
 
73
#ifdef MAPNIK_DEBUG         
 
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;
 
76
#endif
 
77
 
133
78
      if (width > 0 && height > 0)
134
79
      {
 
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.
 
84
         //
 
85
         // dataset_.AdviseRead (start_x, start_y, width, height, width, height, GDT_Byte, nbands, NULL, NULL);
 
86
 
 
87
         for (int i = 0; i < nbands; ++i)
 
88
         {
 
89
            GDALRasterBand * band = dataset_.GetRasterBand(i+1);
 
90
            int band_overviews = band->GetOverviewCount();
 
91
         
 
92
            if (band_overviews > 0)
 
93
            {
 
94
#ifdef MAPNIK_DEBUG
 
95
                for (int b = 0; b < band_overviews; b++)
 
96
                {
 
97
                    GDALRasterBand * overview = band->GetOverview (b);
 
98
                    std::cout << boost::format("Overview=%d Width=%d Height=%d \n")
 
99
                                           % b % overview->GetXSize() % overview->GetYSize();
 
100
                }
 
101
#endif
 
102
 
 
103
#if 0
 
104
                for (int b = band_overviews; --b >= 0;)
 
105
                {
 
106
                    GDALRasterBand * overview = band->GetOverview (b);
 
107
                    if ((start_x + width) <= overview->GetXSize()
 
108
                         && (start_y + height) <= overview->GetYSize())
 
109
                    {
 
110
#ifdef MAPNIK_DEBUG
 
111
                        std::cout << boost::format("Picked Overview=%d \n") %b;
 
112
#endif
 
113
                        band = overview;
 
114
                        break;
 
115
                    }
 
116
                }
 
117
 
 
118
                // band = band->GetRasterSampleOverview (width / height);
 
119
                // band = band->GetOverview (band->GetOverviewCount() - 1);
 
120
#endif
 
121
            }
 
122
         
 
123
#ifdef MAPNIK_DEBUG     
 
124
            int bsx,bsy;
 
125
            double scale;
 
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());   
 
131
#endif
 
132
 
 
133
            GDALColorInterp color_interp = band->GetColorInterpretation();
 
134
            switch (color_interp)
 
135
            {
 
136
               case GCI_RedBand:
 
137
                  red = band;
 
138
                  break;
 
139
               case GCI_GreenBand:
 
140
                  green = band;
 
141
                  break;
 
142
               case GCI_BlueBand:
 
143
                  blue = band;
 
144
                  break;
 
145
               case GCI_AlphaBand:
 
146
                  alpha = band;
 
147
                  break;
 
148
               case GCI_GrayIndex:
 
149
                  grey = band;
 
150
                  break;
 
151
               case GCI_PaletteIndex:
 
152
               {        
 
153
                  grey = band;
 
154
                  GDALColorTable *color_table = band->GetColorTable();
 
155
                                
 
156
                  if ( color_table)
 
157
                  {
 
158
                     int count = color_table->GetColorEntryCount();
 
159
#ifdef MAPNIK_DEBUG
 
160
                     std::cout << "Color Table count = " << count << "\n";
 
161
#endif 
 
162
                     for ( int i = 0; i < count; i++ )
 
163
                     {
 
164
                        const GDALColorEntry *ce = color_table->GetColorEntry ( i );
 
165
                        if (!ce ) continue;
 
166
#ifdef MAPNIK_DEBUG
 
167
                        std::cout << "color entry RGB (" << ce->c1 <<"," <<ce->c2 << "," << ce->c3 << ")\n"; 
 
168
#endif
 
169
                     }
 
170
                  }     
 
171
                  break;
 
172
               }
 
173
               case GCI_Undefined:
 
174
                  grey = band;
 
175
                  break;        
 
176
               default:
 
177
                  break;
 
178
            }
 
179
         }
 
180
      
135
181
         mapnik::ImageData32 image(width,height);
136
182
         image.set(0xffffffff);
137
183
         
138
184
         if (red && green && blue)
139
185
         {
 
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);
143
 
            if (alpha)
144
 
            {
145
 
               alpha->RasterIO(GF_Read,start_x,start_y,width,height, image.getBytes() + 3, width,height, GDT_Byte,4,4*width);
146
 
            }
147
192
         }
148
193
         else if (grey)
149
194
         {
 
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);
153
 
            
154
 
            if (alpha)
155
 
            {
156
 
               alpha->RasterIO(GF_Read,start_x,start_y,width,height, image.getBytes() + 3, width,height, GDT_Byte,4,4*width);
157
 
            }
158
 
         }
 
199
         }
 
200
 
 
201
         if (alpha)
 
202
         {
 
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);
 
205
         }
 
206
 
159
207
         feature->set_raster(mapnik::raster_ptr(new mapnik::raster(intersection,image)));
160
208
         return feature;
161
209
      }