正在显示
5 个修改的文件
包含
109 行增加
和
29 行删除
| @@ -19,7 +19,7 @@ namespace tileserver | @@ -19,7 +19,7 @@ namespace tileserver | ||
| 19 | DmpEsriBundleV1Provider:: DmpEsriBundleV1Provider(const std::string& rootPath) | 19 | DmpEsriBundleV1Provider:: DmpEsriBundleV1Provider(const std::string& rootPath) |
| 20 | : DmpAbstractEsriBundleProvider(rootPath) | 20 | : DmpAbstractEsriBundleProvider(rootPath) |
| 21 | { | 21 | { |
| 22 | - // _rootPath ="/mnt/d/Data/tile/GDMap/_alllayers"; | 22 | + //rootPath_ ="/mnt/d/Code/tiles/GDMap/_alllayers"; |
| 23 | } | 23 | } |
| 24 | void DmpEsriBundleV1Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) | 24 | void DmpEsriBundleV1Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) |
| 25 | { | 25 | { |
| @@ -91,14 +91,14 @@ namespace tileserver | @@ -91,14 +91,14 @@ namespace tileserver | ||
| 91 | std::string format=dmpTileLayer->getFormat(); | 91 | std::string format=dmpTileLayer->getFormat(); |
| 92 | // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); | 92 | // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); |
| 93 | // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); | 93 | // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); |
| 94 | - DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
| 95 | - DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | 94 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymax()); |
| 95 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymin()); | ||
| 96 | std::vector<DmpTileMatrixSet*> tileMatrixSets; | 96 | std::vector<DmpTileMatrixSet*> tileMatrixSets; |
| 97 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); | 97 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); |
| 98 | double resolution; | 98 | double resolution; |
| 99 | DmpPoint origin; | 99 | DmpPoint origin; |
| 100 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; | 100 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; |
| 101 | - if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | 101 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,origin,resolution)) |
| 102 | { | 102 | { |
| 103 | response.sendError(500, "缩略图范围错误:("); | 103 | response.sendError(500, "缩略图范围错误:("); |
| 104 | return; | 104 | return; |
| @@ -122,13 +122,45 @@ namespace tileserver | @@ -122,13 +122,45 @@ namespace tileserver | ||
| 122 | //cairo_surface_write_to_png (surface, "./wmts.png"); | 122 | //cairo_surface_write_to_png (surface, "./wmts.png"); |
| 123 | } | 123 | } |
| 124 | } | 124 | } |
| 125 | + | ||
| 126 | + cairo_surface_t* newimage=surface; | ||
| 127 | + | ||
| 128 | + int w,h; | ||
| 129 | + w = cairo_image_surface_get_width (newimage); | ||
| 130 | + h = cairo_image_surface_get_height (newimage); | ||
| 131 | + DmpPoint topLeft; | ||
| 132 | + // yMinTile=190; | ||
| 133 | + // xMinTile=143; | ||
| 134 | + TileProviderFactory::RowColToPoint(origin,xMinTile,yMaxTile,resolution,topLeft); | ||
| 135 | + DmpPoint botRight; | ||
| 136 | + // yMaxTile=191; | ||
| 137 | + // xMaxTile=144; | ||
| 138 | + //TileProviderFactory::RowColToPoint(origin,xMaxTile+1,yMinTile+1,resolution,botRight); | ||
| 139 | + | ||
| 140 | + DmpPoint clipPoint; | ||
| 141 | + int wClip,hClip; | ||
| 142 | + TileProviderFactory::GetClipBox(topLeft,min,max,resolution,clipPoint,wClip,hClip); | ||
| 143 | + | ||
| 144 | + cairo_surface_t *surface0 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,wClip, hClip); | ||
| 145 | + cairo_t *cr0 =cairo_create (surface0); | ||
| 146 | + | ||
| 147 | + //cairo_rectangle(cr0,clipPoint.x(),clipPoint.y(),wClip,hClip); | ||
| 148 | + cairo_rectangle(cr0,0,0,wClip,hClip); | ||
| 149 | + cairo_set_source_surface (cr0, surface,-clipPoint.x(), -clipPoint.y()); | ||
| 150 | + cairo_clip(cr0); | ||
| 151 | + cairo_paint(cr0); | ||
| 152 | + | ||
| 153 | + //cairo_surface_write_to_png (surface0, "./wmtsbbox.png"); | ||
| 154 | + | ||
| 125 | std::string responseData; | 155 | std::string responseData; |
| 126 | - cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData); | 156 | + cairo_surface_write_to_png_stream(surface0, TileProviderFactory::cairo_write_func, &responseData); |
| 127 | 157 | ||
| 128 | response.removeHeader("Content-Type"); | 158 | response.removeHeader("Content-Type"); |
| 129 | std::string f = (format == "jpg") ? "image/jpg" : "image/png"; | 159 | std::string f = (format == "jpg") ? "image/jpg" : "image/png"; |
| 130 | response.setHeader("Content-Type", f); | 160 | response.setHeader("Content-Type", f); |
| 131 | - response.write(responseData); | 161 | + response.write(responseData); |
| 162 | + cairo_destroy (cr0); | ||
| 163 | + cairo_surface_destroy (surface0); | ||
| 132 | cairo_destroy (cr); | 164 | cairo_destroy (cr); |
| 133 | cairo_surface_destroy (surface); | 165 | cairo_surface_destroy (surface); |
| 134 | } | 166 | } |
| @@ -81,14 +81,15 @@ namespace tileserver | @@ -81,14 +81,15 @@ namespace tileserver | ||
| 81 | std::string format=dmpTileLayer->getFormat(); | 81 | std::string format=dmpTileLayer->getFormat(); |
| 82 | // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); | 82 | // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); |
| 83 | // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); | 83 | // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); |
| 84 | - DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
| 85 | - DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | 84 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymax()); |
| 85 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymin()); | ||
| 86 | std::vector<DmpTileMatrixSet*> tileMatrixSets; | 86 | std::vector<DmpTileMatrixSet*> tileMatrixSets; |
| 87 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); | 87 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); |
| 88 | - double resolution; | ||
| 89 | DmpPoint origin; | 88 | DmpPoint origin; |
| 89 | + double resolution; | ||
| 90 | + | ||
| 90 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; | 91 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; |
| 91 | - if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | 92 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,origin,resolution)) |
| 92 | { | 93 | { |
| 93 | response.sendError(500, "缩略图范围错误:("); | 94 | response.sendError(500, "缩略图范围错误:("); |
| 94 | return; | 95 | return; |
| @@ -116,27 +117,40 @@ namespace tileserver | @@ -116,27 +117,40 @@ namespace tileserver | ||
| 116 | 117 | ||
| 117 | } | 118 | } |
| 118 | 119 | ||
| 119 | - cairo_surface_t *newimage=cairo_image_surface_create_from_png ("/mnt/d/56.png"); | 120 | + //cairo_surface_t *newimage=cairo_image_surface_create_from_png ("/mnt/d/56.png"); |
| 121 | + cairo_surface_t* newimage=surface; | ||
| 120 | 122 | ||
| 121 | - //cairo_arc (newcr, 128.0, 128.0, 76.8, 0, 2*3.14); | ||
| 122 | int w,h; | 123 | int w,h; |
| 123 | w = cairo_image_surface_get_width (newimage); | 124 | w = cairo_image_surface_get_width (newimage); |
| 124 | h = cairo_image_surface_get_height (newimage); | 125 | h = cairo_image_surface_get_height (newimage); |
| 126 | + DmpPoint topLeft; | ||
| 127 | + // yMinTile=190; | ||
| 128 | + // xMinTile=143; | ||
| 129 | + TileProviderFactory::RowColToPoint(origin,xMinTile,yMaxTile,resolution,topLeft); | ||
| 130 | + //DmpPoint botRight=DmpPoint((xMaxTile-xMinTile+1)*resolution,(yMaxTile-xMinTile+1)*resolution); | ||
| 131 | + // yMaxTile=191; | ||
| 132 | + // xMaxTile=144; | ||
| 133 | + //TileProviderFactory::RowColToPoint(origin,xMaxTile+1,yMinTile+1,resolution,botRight); | ||
| 134 | + DmpPoint clipPoint; | ||
| 135 | + int wClip,hClip; | ||
| 125 | 136 | ||
| 126 | - cairo_surface_t *surface0 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w/2, h/2); | 137 | + TileProviderFactory::GetClipBox(topLeft,min,max,resolution,clipPoint,wClip,hClip); |
| 138 | + | ||
| 139 | + cairo_surface_t *surface0 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,wClip, hClip); | ||
| 127 | cairo_t *cr0 =cairo_create (surface0); | 140 | cairo_t *cr0 =cairo_create (surface0); |
| 141 | + cairo_rectangle(cr0,0,0,wClip,hClip); | ||
| 142 | + //cairo_rectangle(cr0,w/4,h/4,w/2,h/4); | ||
| 128 | cairo_clip(cr0); | 143 | cairo_clip(cr0); |
| 129 | - //cairo_scale (cr0, w/2, h/2); | ||
| 130 | - cairo_set_source_surface (cr0, newimage, 0, 0); | ||
| 131 | - | ||
| 132 | 144 | ||
| 145 | + cairo_set_source_surface (cr0, newimage,-clipPoint.x(), -clipPoint.y()); | ||
| 146 | + | ||
| 133 | cairo_paint(cr0); | 147 | cairo_paint(cr0); |
| 134 | //cairo_surface_write_to_png (surface0, "./wmts.png"); | 148 | //cairo_surface_write_to_png (surface0, "./wmts.png"); |
| 135 | - cairo_surface_destroy (surface0); | ||
| 136 | - | 149 | + // cairo_surface_destroy (surface0); |
| 150 | + | ||
| 137 | 151 | ||
| 138 | std::string responseData; | 152 | std::string responseData; |
| 139 | - cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData); | 153 | + cairo_surface_write_to_png_stream(surface0, TileProviderFactory::cairo_write_func, &responseData); |
| 140 | //cairo_surface_write_to_png_stream(newimage, TileProviderFactory::cairo_write_func, &responseData); | 154 | //cairo_surface_write_to_png_stream(newimage, TileProviderFactory::cairo_write_func, &responseData); |
| 141 | 155 | ||
| 142 | response.removeHeader("Content-Type"); | 156 | response.removeHeader("Content-Type"); |
| @@ -144,8 +158,8 @@ namespace tileserver | @@ -144,8 +158,8 @@ namespace tileserver | ||
| 144 | response.setHeader("Content-Type", f); | 158 | response.setHeader("Content-Type", f); |
| 145 | response.write(responseData); | 159 | response.write(responseData); |
| 146 | //response.writeContent(&responseData,imageLen); | 160 | //response.writeContent(&responseData,imageLen); |
| 147 | - | ||
| 148 | - | 161 | + cairo_destroy (cr0); |
| 162 | + cairo_surface_destroy (surface0); | ||
| 149 | cairo_destroy (cr); | 163 | cairo_destroy (cr); |
| 150 | cairo_surface_destroy (surface); | 164 | cairo_surface_destroy (surface); |
| 151 | } | 165 | } |
| @@ -77,7 +77,7 @@ namespace tileserver | @@ -77,7 +77,7 @@ namespace tileserver | ||
| 77 | double resolution; | 77 | double resolution; |
| 78 | DmpPoint origin; | 78 | DmpPoint origin; |
| 79 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile; | 79 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile; |
| 80 | - if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | 80 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,origin,resolution)) |
| 81 | { | 81 | { |
| 82 | response.sendError(500, "缩略图范围错误:("); | 82 | response.sendError(500, "缩略图范围错误:("); |
| 83 | return; | 83 | return; |
| @@ -135,7 +135,7 @@ namespace tileserver | @@ -135,7 +135,7 @@ namespace tileserver | ||
| 135 | xTile=floor(abs(origin.x()-point.x())/resolution); | 135 | xTile=floor(abs(origin.x()-point.x())/resolution); |
| 136 | yTile=floor(abs(origin.y()-point.y())/resolution); | 136 | yTile=floor(abs(origin.y()-point.y())/resolution); |
| 137 | } | 137 | } |
| 138 | - bool TileProviderFactory::GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile) | 138 | + bool TileProviderFactory::GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile,DmpPoint& origin,double& resolution) |
| 139 | { | 139 | { |
| 140 | std::string tilePath=dmpTileLayer->getDataSource(); | 140 | std::string tilePath=dmpTileLayer->getDataSource(); |
| 141 | DmpRectangle rectangle=dmpTileLayer->extent(); | 141 | DmpRectangle rectangle=dmpTileLayer->extent(); |
| @@ -143,8 +143,8 @@ namespace tileserver | @@ -143,8 +143,8 @@ namespace tileserver | ||
| 143 | DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | 143 | DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); |
| 144 | std::vector<DmpTileMatrixSet*> tileMatrixSets; | 144 | std::vector<DmpTileMatrixSet*> tileMatrixSets; |
| 145 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); | 145 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); |
| 146 | - DmpPoint origin; | ||
| 147 | - double resolution; | 146 | + // DmpPoint origin; |
| 147 | + // double resolution; | ||
| 148 | //筛选合适的切片层级 | 148 | //筛选合适的切片层级 |
| 149 | iLevel=TileProviderFactory::screenTileMatrix(min,max,tileMatrixSets,resolution,origin); | 149 | iLevel=TileProviderFactory::screenTileMatrix(min,max,tileMatrixSets,resolution,origin); |
| 150 | if(iLevel==-1) | 150 | if(iLevel==-1) |
| @@ -157,6 +157,13 @@ namespace tileserver | @@ -157,6 +157,13 @@ namespace tileserver | ||
| 157 | TileProviderFactory::PointToRowCol(max,origin,resolution,xMaxTile,yMaxTile); | 157 | TileProviderFactory::PointToRowCol(max,origin,resolution,xMaxTile,yMaxTile); |
| 158 | return true; | 158 | return true; |
| 159 | } | 159 | } |
| 160 | + void TileProviderFactory::RowColToPoint(DmpPoint& origin,int xTile,int yTile,double resolution,DmpPoint& tileTopleft) | ||
| 161 | + { | ||
| 162 | + double xTileP=origin.x()+(xTile)*resolution; | ||
| 163 | + double yTileP=origin.y()-(yTile)*resolution; | ||
| 164 | + | ||
| 165 | + tileTopleft=DmpPoint(xTileP,yTileP); | ||
| 166 | + } | ||
| 160 | bool TileProviderFactory::BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo, cairo_t *cr,int x,int y) | 167 | bool TileProviderFactory::BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo, cairo_t *cr,int x,int y) |
| 161 | { | 168 | { |
| 162 | if (pClsCSFrom == NULL||pClsCSTo == NULL) | 169 | if (pClsCSFrom == NULL||pClsCSTo == NULL) |
| @@ -178,4 +185,30 @@ namespace tileserver | @@ -178,4 +185,30 @@ namespace tileserver | ||
| 178 | return CAIRO_STATUS_SUCCESS; | 185 | return CAIRO_STATUS_SUCCESS; |
| 179 | } | 186 | } |
| 180 | 187 | ||
| 188 | + void TileProviderFactory::GetClipBox(DmpPoint& point0,DmpPoint& bboxPoint0,DmpPoint& bboxPoint1,const double& resolution,DmpPoint & topLeftP,int& wBbox,int &hBbox) | ||
| 189 | + { | ||
| 190 | + //默认切片256*256 | ||
| 191 | + double xTile,yTile,xBox,yBox,xTop,yTop,xTopleft,yTopleft; | ||
| 192 | + // //大图坐标距离 | ||
| 193 | + // xTile=abs(point0.x()-point1.x()); | ||
| 194 | + // yTile=abs(point0.y()-point1.y()); | ||
| 195 | + // //bbox坐标距离 distance pixel | ||
| 196 | + xBox=abs(bboxPoint1.x()-bboxPoint0.x()); | ||
| 197 | + yBox=abs(bboxPoint1.y()-bboxPoint0.y()); | ||
| 198 | + //bbox左上与大图距离 | ||
| 199 | + xTopleft=abs(bboxPoint0.x()-point0.x()); | ||
| 200 | + yTopleft=abs(bboxPoint0.y()-point0.y()); | ||
| 201 | + // //获取bbox在合成大图种的范围及左上角坐标,默认大图左上角坐标为(0,0)像素坐标 | ||
| 202 | + // int xTopLeftDistance=wImage*xTopleft/xTile; | ||
| 203 | + // int yTopLeftDistance=hImage*yTopleft/yTile; | ||
| 204 | + | ||
| 205 | + // int wBboxDistance=wImage*xBox/xTile; | ||
| 206 | + // int hBboxDistance=hImage*yBox/yTile; | ||
| 207 | + DmpPoint BboxP=DmpPoint(xTopleft*256/resolution,yTopleft*256/resolution); | ||
| 208 | + topLeftP=BboxP; | ||
| 209 | + wBbox=xBox*256/resolution; | ||
| 210 | + hBbox=yBox*256/resolution; | ||
| 211 | + | ||
| 212 | + | ||
| 213 | + } | ||
| 181 | } | 214 | } |
| @@ -42,13 +42,14 @@ namespace tileserver | @@ -42,13 +42,14 @@ namespace tileserver | ||
| 42 | static int screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); | 42 | static int screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); |
| 43 | static int screenTileMatrix2(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); | 43 | static int screenTileMatrix2(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); |
| 44 | static void PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile); | 44 | static void PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile); |
| 45 | - static bool GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile); | 45 | + static bool GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile,DmpPoint& origin,double& resolution); |
| 46 | static cairo_status_t cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length); | 46 | static cairo_status_t cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length); |
| 47 | - | 47 | + static void RowColToPoint(DmpPoint& origin,int xTile,int yTile,double resolution,DmpPoint& point0); |
| 48 | + static void GetClipBox(DmpPoint& point0,DmpPoint& bboxPoint0,DmpPoint& bboxPoint1,const double& resolution ,DmpPoint & topLeftP,int& wBbox,int &hBbox); | ||
| 48 | private: | 49 | private: |
| 49 | TileProviderFactory(); | 50 | TileProviderFactory(); |
| 51 | + | ||
| 50 | }; | 52 | }; |
| 51 | - | ||
| 52 | - | 53 | + |
| 53 | } | 54 | } |
| 54 | #endif //__dmptileproviderfactory_h__ | 55 | #endif //__dmptileproviderfactory_h__ |
请
注册
或
登录
后发表评论