正在显示
6 个修改的文件
包含
137 行增加
和
8 行删除
@@ -45,6 +45,14 @@ public: | @@ -45,6 +45,14 @@ public: | ||
45 | virtual void handle(SP_HttpRequest *request, SP_HttpResponse *response) | 45 | virtual void handle(SP_HttpRequest *request, SP_HttpResponse *response) |
46 | { | 46 | { |
47 | char *szRequest = (char *)(request->getURL()); | 47 | char *szRequest = (char *)(request->getURL()); |
48 | + if(!szRequest){ | ||
49 | + // response->setStatusCode( 500 ); | ||
50 | + // response->appendContent( "<html><head>" | ||
51 | + // "<title>dmap server</title>" | ||
52 | + // "</head><body>"); | ||
53 | + // response->appendContent( "error</body></html>\n" ); | ||
54 | + return; | ||
55 | + } | ||
48 | if (strcmp("/favicon.ico", szRequest) == 0) | 56 | if (strcmp("/favicon.ico", szRequest) == 0) |
49 | { | 57 | { |
50 | return; | 58 | return; |
@@ -310,6 +310,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | @@ -310,6 +310,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | ||
310 | 310 | ||
311 | boost::property_tree::read_json(stream, pt); | 311 | boost::property_tree::read_json(stream, pt); |
312 | path= pt.get<std::string>("projectlayers.maplayer.datasource"); | 312 | path= pt.get<std::string>("projectlayers.maplayer.datasource"); |
313 | + | ||
313 | confcdipath=path+"/conf.cdi"; | 314 | confcdipath=path+"/conf.cdi"; |
314 | confxmlpath=path+"/conf.xml"; | 315 | confxmlpath=path+"/conf.xml"; |
315 | std::ifstream fread(confxmlpath, std::ifstream::binary); | 316 | std::ifstream fread(confxmlpath, std::ifstream::binary); |
@@ -334,7 +335,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | @@ -334,7 +335,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | ||
334 | boost::property_tree::ptree pt_confxml; | 335 | boost::property_tree::ptree pt_confxml; |
335 | boost::property_tree::read_xml(confxmlpath,pt_confxml); | 336 | boost::property_tree::read_xml(confxmlpath,pt_confxml); |
336 | std::string strWKT=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.SpatialReference.WKT"); | 337 | std::string strWKT=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.SpatialReference.WKT"); |
337 | - std::string wkid=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.SpatialReference.WKID"); | 338 | + //std::string wkid=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.SpatialReference.WKID"); |
338 | std::string top=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileOrigin.X"); | 339 | std::string top=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileOrigin.X"); |
339 | std::string left=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileOrigin.Y"); | 340 | std::string left=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileOrigin.Y"); |
340 | std::string tileCols=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileCols"); | 341 | std::string tileCols=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileCols"); |
@@ -343,7 +344,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | @@ -343,7 +344,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | ||
343 | std::string storageFormat=pt_confxml.get<std::string>("CacheInfo.CacheStorageInfo.StorageFormat"); | 344 | std::string storageFormat=pt_confxml.get<std::string>("CacheInfo.CacheStorageInfo.StorageFormat"); |
344 | pt.put("vendor",storageFormat); | 345 | pt.put("vendor",storageFormat); |
345 | pt.put("projectCrs.spatialrefsys.wkt",strWKT); | 346 | pt.put("projectCrs.spatialrefsys.wkt",strWKT); |
346 | - pt.put("projectCrs.spatialrefsys.srid",wkid); | 347 | + //pt.put("projectCrs.spatialrefsys.srid",wkid); |
347 | 348 | ||
348 | boost::property_tree::ptree pt_tileMatrixSets=pt.get_child("tileMatrixSets"); | 349 | boost::property_tree::ptree pt_tileMatrixSets=pt.get_child("tileMatrixSets"); |
349 | BOOST_FOREACH(boost::property_tree::ptree::value_type &v1,pt_tileMatrixSets) | 350 | BOOST_FOREACH(boost::property_tree::ptree::value_type &v1,pt_tileMatrixSets) |
@@ -367,7 +368,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | @@ -367,7 +368,7 @@ void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context | ||
367 | } | 368 | } |
368 | std::string id_=v1.second.get<std::string>("tileMatrixSet.id"); | 369 | std::string id_=v1.second.get<std::string>("tileMatrixSet.id"); |
369 | pt_tileMatrixSet.add("id",id_); | 370 | pt_tileMatrixSet.add("id",id_); |
370 | - pt_tileMatrixSet.add("crs","EPSG::"+wkid); | 371 | + //pt_tileMatrixSet.add("crs","EPSG::"+wkid); |
371 | pt_tileMatrixSet.add("tileCols",tileCols); | 372 | pt_tileMatrixSet.add("tileCols",tileCols); |
372 | pt_tileMatrixSet.add("tileRows",tileRows); | 373 | pt_tileMatrixSet.add("tileRows",tileRows); |
373 | pt_tileMatrixSet.add("dpi",dpi); | 374 | pt_tileMatrixSet.add("dpi",dpi); |
@@ -7,14 +7,18 @@ | @@ -7,14 +7,18 @@ | ||
7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | #include "dmpesribundlev2provider.h" | 9 | #include "dmpesribundlev2provider.h" |
10 | +#include "dmpesribundlev1provider.h" | ||
11 | +#include "dmptileproviderfactory.h" | ||
10 | #include "dmpwmtsutils.h" | 12 | #include "dmpwmtsutils.h" |
13 | +#include <cairo/cairo.h> | ||
14 | +#include "dmptilelayer.h" | ||
11 | 15 | ||
12 | namespace tileserver | 16 | namespace tileserver |
13 | { | 17 | { |
14 | DmpEsriBundleV2Provider::DmpEsriBundleV2Provider(const std::string& rootPath) | 18 | DmpEsriBundleV2Provider::DmpEsriBundleV2Provider(const std::string& rootPath) |
15 | : DmpAbstractEsriBundleProvider(rootPath) | 19 | : DmpAbstractEsriBundleProvider(rootPath) |
16 | { | 20 | { |
17 | - // _rootPath ="/mnt/d/Data/SDZT_DIANZDT_2016_FS2K/Layers/_alllayers"; | 21 | + rootPath_ ="/mnt/d/Code/tiles/SDYX_WEIP_2021_M07_FS2K/Layers/_alllayers"; |
18 | } | 22 | } |
19 | void DmpEsriBundleV2Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) | 23 | void DmpEsriBundleV2Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) |
20 | { | 24 | { |
@@ -70,8 +74,111 @@ namespace tileserver | @@ -70,8 +74,111 @@ namespace tileserver | ||
70 | } | 74 | } |
71 | delete[] imgBuffer; | 75 | delete[] imgBuffer; |
72 | } | 76 | } |
73 | - void DmpEsriBundleV2Provider::GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons) | 77 | + void DmpEsriBundleV2Provider::GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) |
74 | { | 78 | { |
79 | + std::string tilePath=dmpTileLayer->getDataSource(); | ||
80 | + DmpRectangle rectangle=dmpTileLayer->extent(); | ||
81 | + std::string format=dmpTileLayer->getFormat(); | ||
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()); | ||
84 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
85 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | ||
86 | + std::vector<DmpTileMatrixSet*> tileMatrixSets; | ||
87 | + dmpTileLayer->getTileMatrixSets(tileMatrixSets); | ||
88 | + double resolution; | ||
89 | + DmpPoint origin; | ||
90 | + int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; | ||
91 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | ||
92 | + { | ||
93 | + response.sendError(500, "缩略图范围错误:("); | ||
94 | + return; | ||
95 | + } | ||
96 | + | ||
97 | + int imageLen=0; | ||
98 | + int heigth=abs(yMaxTile-yMinTile); | ||
99 | + int width=abs(xMaxTile-xMinTile); | ||
100 | + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1)); | ||
101 | + cairo_t *cr =cairo_create (surface); | ||
102 | + for( int i = 0 ; i <= width ; i++ ) | ||
103 | + { | ||
104 | + for(int j=0;j<=heigth;j++) | ||
105 | + { | ||
106 | + std::string strBuff; | ||
107 | + GetTile(yMaxTile+j,xMinTile+i,iLevel,strBuff,buffLen); | ||
108 | + | ||
109 | + const char* buff=strBuff.c_str(); | ||
110 | + st_png_data pngData = {(unsigned char*)buff, 0}; | ||
111 | + cairo_surface_t *image = cairo_image_surface_create_from_png_stream(cairo_read_func,&pngData); | ||
112 | + TileProviderFactory::BufferCopy(image,surface,cr,i*256,j*256); | ||
113 | + //cairo_surface_write_to_png (surface, "./wmts.png"); | ||
114 | + } | ||
115 | + } | ||
116 | + std::string responseData; | ||
117 | + cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData); | ||
118 | + | ||
119 | + response.removeHeader("Content-Type"); | ||
120 | + std::string f = (format == "jpg") ? "image/jpg" : "image/png"; | ||
121 | + response.setHeader("Content-Type", f); | ||
122 | + response.write(responseData); | ||
123 | + //response.writeContent(&responseData,imageLen); | ||
124 | + cairo_destroy (cr); | ||
125 | + cairo_surface_destroy (surface); | ||
126 | + } | ||
127 | + bool DmpEsriBundleV2Provider::GetTile(int row, int col, int level,std::string& refbuff,int& length ) | ||
128 | + { | ||
129 | + int packSize = _packetSize; | ||
130 | + int rGroup = (int)row/packSize; | ||
131 | + rGroup = rGroup * packSize; | ||
132 | + int cGroup = (int)col/packSize; | ||
133 | + cGroup = cGroup*packSize; | ||
75 | 134 | ||
135 | + std::string bundleBase = GetBundlePath(level,rGroup,cGroup); | ||
136 | + std::string bundleFilePath = bundleBase + ".bundle"; | ||
137 | + | ||
138 | + int index = packSize * (row - rGroup) + (col - cGroup); | ||
139 | + | ||
140 | + //读取bundle文件,计算偏移量 | ||
141 | + std::ifstream fread(bundleFilePath, std::ifstream::binary); | ||
142 | + if(!fread) | ||
143 | + { | ||
144 | + return false; | ||
145 | + } | ||
146 | + fread.seekg(64 + 8 * index, fread.beg); | ||
147 | + char* buffer = new char[4]; | ||
148 | + fread.read(buffer,4); | ||
149 | + long offset = (long)(buffer[0]&0xff) | ||
150 | + + (long)(buffer[1]&0xff) * 256 | ||
151 | + + (long)(buffer[2]&0xff) * 65536 | ||
152 | + + (long)(buffer[3]&0xff) * 16777216 | ||
153 | + -4; | ||
154 | + delete [] buffer; | ||
155 | + | ||
156 | + //读取bundle文件获取切片 | ||
157 | + fread.seekg(offset, fread.beg); | ||
158 | + char* buff = new char[4]; | ||
159 | + fread.read(buff, 4); | ||
160 | + long len = (long)(buff[0]&0xff) | ||
161 | + + (long)(buff[1]&0xff) * 256 | ||
162 | + + (long)(buff[2]&0xff) * 65536 | ||
163 | + + (long)(buff[3]&0xff) * 16777216; | ||
164 | + delete[] buff; | ||
165 | + | ||
166 | + char* imgBuffer = new char[len]; | ||
167 | + fread.read(imgBuffer, len); | ||
168 | + fread.close(); | ||
169 | + if(len > 0) | ||
170 | + { | ||
171 | + refbuff.append(imgBuffer,len); | ||
172 | + } | ||
173 | + | ||
174 | + delete[] imgBuffer; | ||
175 | + return true; | ||
176 | + } | ||
177 | + cairo_status_t DmpEsriBundleV2Provider::cairo_read_func (void *closure, unsigned char *data, unsigned int length) | ||
178 | + { | ||
179 | + st_png_data* pPngData = (st_png_data*)closure; | ||
180 | + memcpy(data, pPngData->pdata + pPngData->length, length); | ||
181 | + pPngData->length += length; | ||
182 | + return CAIRO_STATUS_SUCCESS; | ||
76 | } | 183 | } |
77 | } | 184 | } |
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | #include "dmpabstractesribundleprovider.h" | 13 | #include "dmpabstractesribundleprovider.h" |
14 | #include "dmptilelayer.h" | 14 | #include "dmptilelayer.h" |
15 | 15 | ||
16 | + | ||
16 | namespace tileserver | 17 | namespace tileserver |
17 | { | 18 | { |
18 | class DmpEsriBundleV2Provider : public DmpAbstractEsriBundleProvider | 19 | class DmpEsriBundleV2Provider : public DmpAbstractEsriBundleProvider |
@@ -20,8 +21,11 @@ namespace tileserver | @@ -20,8 +21,11 @@ namespace tileserver | ||
20 | public: | 21 | public: |
21 | DmpEsriBundleV2Provider(const std::string& rootPath); | 22 | DmpEsriBundleV2Provider(const std::string& rootPath); |
22 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; | 23 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; |
23 | - void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons) override; | 24 | + void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) override; |
25 | + bool GetTile(const int row,const int col,const int level,std::string& rebuff,int& length); | ||
26 | + static cairo_status_t cairo_read_func (void *closure, unsigned char *data, unsigned int length); | ||
24 | }; | 27 | }; |
28 | + | ||
25 | } | 29 | } |
26 | 30 | ||
27 | #endif //__dmpesribundlev2provider_h__ | 31 | #endif //__dmpesribundlev2provider_h__ |
@@ -27,6 +27,10 @@ namespace tileserver | @@ -27,6 +27,10 @@ namespace tileserver | ||
27 | std::shared_ptr<DmpTileProvider> TileProviderFactory::GetProvider(DmpTileLayer* dmpTileLayer) | 27 | std::shared_ptr<DmpTileProvider> TileProviderFactory::GetProvider(DmpTileLayer* dmpTileLayer) |
28 | { | 28 | { |
29 | std::shared_ptr<DmpTileProvider> provider; | 29 | std::shared_ptr<DmpTileProvider> provider; |
30 | + if(!dmpTileLayer) | ||
31 | + { | ||
32 | + return provider; | ||
33 | + } | ||
30 | try | 34 | try |
31 | { | 35 | { |
32 | std::string tileVersion= dmpTileLayer->getVendor(); | 36 | std::string tileVersion= dmpTileLayer->getVendor(); |
@@ -94,13 +98,13 @@ namespace tileserver | @@ -94,13 +98,13 @@ namespace tileserver | ||
94 | int id=(*leviter)->id; | 98 | int id=(*leviter)->id; |
95 | double relus = (*leviter)->resolution; | 99 | double relus = (*leviter)->resolution; |
96 | relus=relus*256; | 100 | relus=relus*256; |
97 | - origin=DmpPoint(pOrigin->y(),pOrigin->x()); | 101 | + origin=DmpPoint(pOrigin->x(),pOrigin->y()); |
98 | int xMinTile,yMinTile,xMaxTile,yMaxTile; | 102 | int xMinTile,yMinTile,xMaxTile,yMaxTile; |
99 | TileProviderFactory::PointToRowCol(min,origin,relus,xMinTile,yMinTile); | 103 | TileProviderFactory::PointToRowCol(min,origin,relus,xMinTile,yMinTile); |
100 | TileProviderFactory::PointToRowCol(max,origin,relus,xMaxTile,yMaxTile); | 104 | TileProviderFactory::PointToRowCol(max,origin,relus,xMaxTile,yMaxTile); |
101 | int heigth=abs(yMaxTile-yMinTile); | 105 | int heigth=abs(yMaxTile-yMinTile); |
102 | int width=abs(xMaxTile-xMinTile); | 106 | int width=abs(xMaxTile-xMinTile); |
103 | - if((heigth+1)*(width+1)<9 && (heigth+2)*(width+2)>10) | 107 | + if((heigth+1)*(width+1)<9 && (heigth+2)*(width+2)>=9) |
104 | { | 108 | { |
105 | iLevel=id; | 109 | iLevel=id; |
106 | resolution=relus; | 110 | resolution=relus; |
@@ -75,6 +75,11 @@ namespace tileserver | @@ -75,6 +75,11 @@ namespace tileserver | ||
75 | { | 75 | { |
76 | string f = (format == DmpWmtsParameters::Format::JPG) ? "jpg" : "png"; | 76 | string f = (format == DmpWmtsParameters::Format::JPG) ? "jpg" : "png"; |
77 | std::shared_ptr<DmpTileProvider> provider = TileProviderFactory::GetProvider(tileLayer); | 77 | std::shared_ptr<DmpTileProvider> provider = TileProviderFactory::GetProvider(tileLayer); |
78 | + if(!provider) | ||
79 | + { | ||
80 | + context.response()->writeHtml("wmts,layer is error"); | ||
81 | + return ; | ||
82 | + } | ||
78 | provider->WriteTile(tileRow, tileCol, tileMatrix, f, *context.response()); | 83 | provider->WriteTile(tileRow, tileCol, tileMatrix, f, *context.response()); |
79 | } | 84 | } |
80 | else if(boost::iequals(req, "GetThumbnail")) | 85 | else if(boost::iequals(req, "GetThumbnail")) |
请
注册
或
登录
后发表评论