提交 57ddab4f8405c1de867aa037421c2f054faf1cb3
Merge branch 'master' of http://gitlab.ctune.cn/DMapServer/DMapServer4.1
正在显示
61 个修改的文件
包含
2913 行增加
和
260 行删除
dmapserver4.tar.gz
0 → 100644
不能预览此文件类型
| @@ -24,7 +24,7 @@ SET(DMAP_CORE_SRCS | @@ -24,7 +24,7 @@ SET(DMAP_CORE_SRCS | ||
| 24 | dmptilematrixset.cpp | 24 | dmptilematrixset.cpp |
| 25 | dmpvectordataprovider.cpp | 25 | dmpvectordataprovider.cpp |
| 26 | dmpvectorlayer.cpp | 26 | dmpvectorlayer.cpp |
| 27 | - dmpvectorthinlayer.cpp | 27 | + dmpvectorvacuatelayer.cpp |
| 28 | dmpvectorlayerrenderer.cpp | 28 | dmpvectorlayerrenderer.cpp |
| 29 | dmpxmlutils.cpp | 29 | dmpxmlutils.cpp |
| 30 | 30 | ||
| @@ -76,7 +76,7 @@ SET(DMAP_CORE_HDRS | @@ -76,7 +76,7 @@ SET(DMAP_CORE_HDRS | ||
| 76 | dmptilematrixset.h | 76 | dmptilematrixset.h |
| 77 | dmpvectordataprovider.h | 77 | dmpvectordataprovider.h |
| 78 | dmpvectorlayer.h | 78 | dmpvectorlayer.h |
| 79 | - dmpvectorthinlayer.h | 79 | + dmpvectorvacuatelayer.h |
| 80 | dmpvectorlayerrenderer.h | 80 | dmpvectorlayerrenderer.h |
| 81 | dmpxmlutils.h | 81 | dmpxmlutils.h |
| 82 | 82 |
| @@ -223,4 +223,115 @@ DmpMapLayer *DmpProject::getLayer() const | @@ -223,4 +223,115 @@ DmpMapLayer *DmpProject::getLayer() const | ||
| 223 | { | 223 | { |
| 224 | return nullptr; | 224 | return nullptr; |
| 225 | } | 225 | } |
| 226 | +} | ||
| 227 | + | ||
| 228 | +bool DmpProject::initVectorLayerVacuate(std::function<std::string(const std::string &)> getVacuateFun) | ||
| 229 | +{ | ||
| 230 | + try | ||
| 231 | + { | ||
| 232 | + std::string tableguids = ""; | ||
| 233 | + for (int i = 0; i < vectorLayers_.size(); i++) | ||
| 234 | + { | ||
| 235 | + DmpMapLayer *layer = vectorLayers_.at(i); | ||
| 236 | + if (layer->type() == DmpMapLayerType::VectorLayer) | ||
| 237 | + { | ||
| 238 | + if (!tableguids.empty()) | ||
| 239 | + { | ||
| 240 | + tableguids += ","; | ||
| 241 | + } | ||
| 242 | + tableguids += layer->id(); | ||
| 243 | + } | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + if (tableguids.empty()) | ||
| 247 | + { | ||
| 248 | + return false; | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + std::string vacuateInfo = getVacuateFun(tableguids); | ||
| 252 | + if (vacuateInfo.empty()) | ||
| 253 | + { | ||
| 254 | + return false; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + std::istringstream stream(vacuateInfo); | ||
| 258 | + ptree pt; | ||
| 259 | + read_json(stream, pt); | ||
| 260 | + bool result = pt.get<bool>("result"); | ||
| 261 | + if (!result) | ||
| 262 | + { | ||
| 263 | + return false; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + //图层 | ||
| 267 | + ptree pLayers = pt.get_child("data"); | ||
| 268 | + // for (BOOST_AUTO(pos, pLayers.begin()); pos != pLayers.end(); ++pos) | ||
| 269 | + for (ptree::iterator pos = pLayers.begin(); pos != pLayers.end(); ++pos) | ||
| 270 | + { | ||
| 271 | + ptree pLayer = pos->second; | ||
| 272 | + int vacuateCount = pLayer.get<int>("vacuate_count"); | ||
| 273 | + if (vacuateCount > 0) | ||
| 274 | + { | ||
| 275 | + std::string tableGuid = pLayer.get<std::string>("table_guid"); | ||
| 276 | + std::string tableName = pLayer.get<std::string>("table_name"); | ||
| 277 | + | ||
| 278 | + DmpMapLayer *layer = this->getLayer(tableName); | ||
| 279 | + if (layer && layer->type() == DmpMapLayerType::VectorLayer) | ||
| 280 | + { | ||
| 281 | + DmpVectorLayer *vectorLayer = (DmpVectorLayer *)layer; | ||
| 282 | + ptree ptableVacuates = pLayer.get_child("table_vacuate"); | ||
| 283 | + for (BOOST_AUTO(pos1, ptableVacuates.begin()); pos1 != ptableVacuates.end(); ++pos1) | ||
| 284 | + { | ||
| 285 | + ptree pVacuateLayer = pos1->second; | ||
| 286 | + shared_ptr<DmpVectorVacuateLayer> vacuateLayer(new DmpVectorVacuateLayer()); | ||
| 287 | + std::string name = pVacuateLayer.get<std::string>("name"); | ||
| 288 | + std::string connectStr = pVacuateLayer.get<std::string>("connectstr"); | ||
| 289 | + double pixel_distance = pVacuateLayer.get<double>("pixel_distance"); | ||
| 290 | + vacuateLayer->Init(pixel_distance, name, connectStr); | ||
| 291 | + vectorLayer->ApplendCurrentScaleTable(vacuateLayer); | ||
| 292 | + } | ||
| 293 | + } | ||
| 294 | + } | ||
| 295 | + }//for | ||
| 296 | + return true; | ||
| 297 | + } | ||
| 298 | + catch (const std::exception &e) | ||
| 299 | + { | ||
| 300 | + std::cerr << e.what() << '\n'; | ||
| 301 | + return false; | ||
| 302 | + } | ||
| 303 | + return false; | ||
| 304 | +} | ||
| 305 | + | ||
| 306 | +std::shared_ptr<DmpRectangle> DmpProject::GetExtent() | ||
| 307 | +{ | ||
| 308 | + shared_ptr<DmpRectangle> rect(new DmpRectangle()); | ||
| 309 | + for (size_t i = 0; i < this->vectorLayers_.size(); i++) | ||
| 310 | + { | ||
| 311 | + DmpMapLayer* layer = this->vectorLayers_.at(i); | ||
| 312 | + DmpRectangle layerExtent = layer->extent(); | ||
| 313 | + rect->merge(layerExtent); | ||
| 314 | + } | ||
| 315 | + return rect; | ||
| 316 | +} | ||
| 317 | + | ||
| 318 | +bool DmpProject::initVectorLayerVacuate(DmpProject* project) | ||
| 319 | +{ | ||
| 320 | + if(!project) return false; | ||
| 321 | + for (size_t i = 0; i < project->vectorLayers().size(); i++) | ||
| 322 | + { | ||
| 323 | + DmpMapLayer *layer = project->vectorLayers().at(i); | ||
| 324 | + if (layer->type() == DmpMapLayerType::VectorLayer) | ||
| 325 | + { | ||
| 326 | + DmpVectorLayer *vectorLayer = (DmpVectorLayer *)layer; | ||
| 327 | + DmpVectorLayer *thisVectorLayer = (DmpVectorLayer*)this->getLayer(layer->name()); | ||
| 328 | + for (size_t i0 = 0; i0 < vectorLayer->vacuateLayers().size(); i0++) | ||
| 329 | + { | ||
| 330 | + std::shared_ptr<DmpVectorVacuateLayer> pvectorVacuateLayer = vectorLayer->vacuateLayers().at(i0); | ||
| 331 | + thisVectorLayer->vacuateLayers().push_back(pvectorVacuateLayer->clone()); | ||
| 332 | + } | ||
| 333 | + | ||
| 334 | + } | ||
| 335 | + } | ||
| 336 | + return true; | ||
| 226 | } | 337 | } |
| @@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
| 16 | #include <boost/filesystem.hpp> | 16 | #include <boost/filesystem.hpp> |
| 17 | #include "dmpcoordinatereferencesystem.h" | 17 | #include "dmpcoordinatereferencesystem.h" |
| 18 | #include "dmpmaplayer.h" | 18 | #include "dmpmaplayer.h" |
| 19 | +#include <memory> | ||
| 19 | 20 | ||
| 20 | //配图文件 | 21 | //配图文件 |
| 21 | class CORE_EXPORT DmpProject | 22 | class CORE_EXPORT DmpProject |
| @@ -27,6 +28,9 @@ class CORE_EXPORT DmpProject | @@ -27,6 +28,9 @@ class CORE_EXPORT DmpProject | ||
| 27 | bool Read(const std::string &data); | 28 | bool Read(const std::string &data); |
| 28 | bool Write(const std::string &filename, const std::string &data); | 29 | bool Write(const std::string &filename, const std::string &data); |
| 29 | bool WritePtree(boost::property_tree::ptree& ptDoc); | 30 | bool WritePtree(boost::property_tree::ptree& ptDoc); |
| 31 | + //初始化矢量图层金字塔信息 | ||
| 32 | + bool initVectorLayerVacuate(std::function<std::string(const std::string &)> getVacuateFun); | ||
| 33 | + bool initVectorLayerVacuate(DmpProject* project); | ||
| 30 | std::string WriteXml(); | 34 | std::string WriteXml(); |
| 31 | std::string WriteJson(); | 35 | std::string WriteJson(); |
| 32 | DmpCoordinateReferenceSystem crs() const; | 36 | DmpCoordinateReferenceSystem crs() const; |
| @@ -34,6 +38,7 @@ class CORE_EXPORT DmpProject | @@ -34,6 +38,7 @@ class CORE_EXPORT DmpProject | ||
| 34 | std::vector<DmpMapLayer*> vectorLayers() const; | 38 | std::vector<DmpMapLayer*> vectorLayers() const; |
| 35 | DmpMapLayer* getLayer(const std::string &layerName) const; | 39 | DmpMapLayer* getLayer(const std::string &layerName) const; |
| 36 | DmpMapLayer* getLayer()const; | 40 | DmpMapLayer* getLayer()const; |
| 41 | + std::shared_ptr<DmpRectangle> GetExtent(); | ||
| 37 | private: | 42 | private: |
| 38 | static DmpProject *project_; | 43 | static DmpProject *project_; |
| 39 | std::string projectName_; | 44 | std::string projectName_; |
| @@ -215,8 +215,8 @@ void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::str | @@ -215,8 +215,8 @@ void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::str | ||
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | DmpWkbTypes::GeometryType DmpVectorLayer::GeometryType() const | 217 | DmpWkbTypes::GeometryType DmpVectorLayer::GeometryType() const |
| 218 | -{ | ||
| 219 | - return DmpWkbTypes::GeometryType(wkbType_); | 218 | +{ |
| 219 | + return DmpWkbTypes::geometryType(wkbType_); | ||
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | bool DmpVectorLayer::setDataProvider(const std::string &provider) | 222 | bool DmpVectorLayer::setDataProvider(const std::string &provider) |
| @@ -293,39 +293,29 @@ bool DmpVectorLayer::setDataProvider(const std::string &provider) | @@ -293,39 +293,29 @@ bool DmpVectorLayer::setDataProvider(const std::string &provider) | ||
| 293 | return true; | 293 | return true; |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | -shared_ptr<DmpVectorThinLayer> DmpVectorLayer::GetCurrentScaleTable(double dx) | 296 | +bool sortVacuateLayers(shared_ptr<DmpVectorVacuateLayer> p1,shared_ptr<DmpVectorVacuateLayer> p2) |
| 297 | { | 297 | { |
| 298 | + return p1->dis() > p2->dis(); | ||
| 299 | +} | ||
| 298 | 300 | ||
| 299 | - /* | ||
| 300 | - int outTime = 600; | ||
| 301 | - if(this->dataCount >500000 && this->m_pDataset->m_MapLayerThinning.size() ==0) | ||
| 302 | - { | ||
| 303 | - outTime = 20; | ||
| 304 | - } | ||
| 305 | - | ||
| 306 | - clsLockClass lock(_wlock); | ||
| 307 | - time_t now = time(0); | ||
| 308 | - //shared_ptr<WMSServer> wmsServer = this->m_mapWmsServer[servicename]; | ||
| 309 | - if(now - this->m_pDataset->m_loadMapLayerThinning > outTime) | ||
| 310 | - { | ||
| 311 | - this->m_pDataset->m_loadMapLayerThinning = now; | ||
| 312 | - shared_ptr<Workspace> pWorkspaceDef = DataSourcePools::get_instance()->GetDefaultWorkspace(); | 301 | +void DmpVectorLayer::ApplendCurrentScaleTable(shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer) |
| 302 | +{ | ||
| 303 | + this->vacuateLayers_.push_back(pVectorVacuateLayer); | ||
| 304 | + sort(this->vacuateLayers_.begin(), this->vacuateLayers_.end(),sortVacuateLayers); | ||
| 305 | + return; | ||
| 306 | +} | ||
| 313 | 307 | ||
| 314 | - this->m_pDataset->InitMapLayerThinning(pWorkspaceDef.get(),this->m_layerName, this->m_dbSource); | ||
| 315 | - } | ||
| 316 | - else | ||
| 317 | - { | ||
| 318 | - this->m_pDataset->m_loadMapLayerThinning = now; | ||
| 319 | - } | ||
| 320 | -*/ | ||
| 321 | 308 | ||
| 322 | - for (int i = 0; i < this->thinLayers_.size(); i++) | 309 | +shared_ptr<DmpVectorVacuateLayer> DmpVectorLayer::GetCurrentScaleTable(double dx) |
| 310 | +{ | ||
| 311 | + dx *= 2; | ||
| 312 | + for (int i = 0; i < this->vacuateLayers_.size(); i++) | ||
| 323 | { | 313 | { |
| 324 | - shared_ptr<DmpVectorThinLayer> mapLayerThinning = this->thinLayers_[i]; | 314 | + shared_ptr<DmpVectorVacuateLayer> vacuateLayer = this->vacuateLayers_[i]; |
| 325 | 315 | ||
| 326 | - if (mapLayerThinning->IsCurrentLayer(dx)) | 316 | + if (vacuateLayer->IsCurrentLayer(dx)) |
| 327 | { | 317 | { |
| 328 | - return mapLayerThinning; | 318 | + return vacuateLayer; |
| 329 | } | 319 | } |
| 330 | } | 320 | } |
| 331 | return nullptr; | 321 | return nullptr; |
| @@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
| 15 | #include "dmpmaplayer.h" | 15 | #include "dmpmaplayer.h" |
| 16 | #include "dmpwkbtypes.h" | 16 | #include "dmpwkbtypes.h" |
| 17 | #include "dmpvectordataprovider.h" | 17 | #include "dmpvectordataprovider.h" |
| 18 | -#include "dmpvectorthinlayer.h" | 18 | +#include "dmpvectorvacuatelayer.h" |
| 19 | #include "Renderer.h" | 19 | #include "Renderer.h" |
| 20 | #include <vector> | 20 | #include <vector> |
| 21 | 21 | ||
| @@ -50,12 +50,14 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | @@ -50,12 +50,14 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | ||
| 50 | void setRenderer(DmpFeatureRenderer *renderer); | 50 | void setRenderer(DmpFeatureRenderer *renderer); |
| 51 | void setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag); | 51 | void setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag); |
| 52 | DmpWkbTypes::GeometryType GeometryType() const; | 52 | DmpWkbTypes::GeometryType GeometryType() const; |
| 53 | + DmpWkbTypes::Type GeomWkbType() const{ return wkbType_;} | ||
| 53 | bool setDataProvider(std::string const &provider); | 54 | bool setDataProvider(std::string const &provider); |
| 54 | 55 | ||
| 55 | 56 | ||
| 56 | shared_ptr<DmapCore_30::Renderer> GetRenderer30() { return renderer_30_; } | 57 | shared_ptr<DmapCore_30::Renderer> GetRenderer30() { return renderer_30_; } |
| 57 | - vector<shared_ptr<DmpVectorThinLayer>> thinLayers() const { return thinLayers_; } | ||
| 58 | - shared_ptr<DmpVectorThinLayer> GetCurrentScaleTable(double dx); | 58 | + vector<shared_ptr<DmpVectorVacuateLayer>> vacuateLayers() const { return vacuateLayers_; } |
| 59 | + shared_ptr<DmpVectorVacuateLayer> GetCurrentScaleTable(double dx); | ||
| 60 | + void ApplendCurrentScaleTable(shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer); | ||
| 59 | 61 | ||
| 60 | std::string schema() { return schema_;} | 62 | std::string schema() { return schema_;} |
| 61 | std::string geom() { return geom_;} | 63 | std::string geom() { return geom_;} |
| @@ -64,6 +66,8 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | @@ -64,6 +66,8 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | ||
| 64 | std::string srid(){return srid_;} | 66 | std::string srid(){return srid_;} |
| 65 | size_t featurecount(){return featurecount_;} | 67 | size_t featurecount(){return featurecount_;} |
| 66 | bool IsInit(){return isinit_;} | 68 | bool IsInit(){return isinit_;} |
| 69 | + | ||
| 70 | + void setSrid(string srid){ srid_ = srid;} | ||
| 67 | private: | 71 | private: |
| 68 | bool readExtentFromXml_; | 72 | bool readExtentFromXml_; |
| 69 | DmpWkbTypes::Type wkbType_ = DmpWkbTypes::Unknown; | 73 | DmpWkbTypes::Type wkbType_ = DmpWkbTypes::Unknown; |
| @@ -79,9 +83,9 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | @@ -79,9 +83,9 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | ||
| 79 | std::string wherestr_; | 83 | std::string wherestr_; |
| 80 | bool isinit_ = false; | 84 | bool isinit_ = false; |
| 81 | shared_ptr<DmapCore_30::Renderer> renderer_30_ = nullptr; | 85 | shared_ptr<DmapCore_30::Renderer> renderer_30_ = nullptr; |
| 82 | - vector<shared_ptr<DmpVectorThinLayer>> thinLayers_; | 86 | + vector<shared_ptr<DmpVectorVacuateLayer>> vacuateLayers_; |
| 87 | + | ||
| 83 | 88 | ||
| 84 | - | ||
| 85 | 89 | ||
| 86 | }; | 90 | }; |
| 87 | #endif //__dmpvectorlayer_h__ | 91 | #endif //__dmpvectorlayer_h__ |
| 1 | /************************************************************************** | 1 | /************************************************************************** |
| 2 | -* file: dmpvectorthinlayer.cpp | 2 | +* file: dmpvectorvacuatelayer.cpp |
| 3 | 3 | ||
| 4 | * Author: qingxiongf | 4 | * Author: qingxiongf |
| 5 | * Date: 2021-12-13 10:05:35 | 5 | * Date: 2021-12-13 10:05:35 |
| 6 | * Email: qingxiongf@chinadci.com | 6 | * Email: qingxiongf@chinadci.com |
| 7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
| 8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
| 9 | -#include "dmpvectorthinlayer.h" | 9 | +#include "dmpvectorvacuatelayer.h" |
| 10 | 10 | ||
| 11 | -DmpVectorThinLayer::DmpVectorThinLayer(/* args */) | 11 | +DmpVectorVacuateLayer::DmpVectorVacuateLayer(/* args */) |
| 12 | { | 12 | { |
| 13 | - | 13 | + |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -DmpVectorThinLayer::~DmpVectorThinLayer() | 16 | +DmpVectorVacuateLayer::~DmpVectorVacuateLayer() |
| 17 | { | 17 | { |
| 18 | 18 | ||
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | - bool DmpVectorThinLayer::IsCurrentLayer(double d) | 21 | +bool DmpVectorVacuateLayer::IsCurrentLayer(double d) |
| 22 | { | 22 | { |
| 23 | if(d > m_ddis) | 23 | if(d > m_ddis) |
| 24 | { | 24 | { |
| @@ -27,21 +27,22 @@ DmpVectorThinLayer::~DmpVectorThinLayer() | @@ -27,21 +27,22 @@ DmpVectorThinLayer::~DmpVectorThinLayer() | ||
| 27 | return false; | 27 | return false; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | -bool DmpVectorThinLayer::Init(double minX, double minY, double maxX, double maxY, int dxCount, int dyCount,std::string tableName) | ||
| 31 | -{ | ||
| 32 | - m_ddis = std::max( (maxX - minX)/ dxCount, (maxY - minY)/ dyCount); | ||
| 33 | - m_tableName = tableName; | ||
| 34 | - return true; | ||
| 35 | -} | 30 | + std::shared_ptr<DmpVectorVacuateLayer> DmpVectorVacuateLayer::clone() |
| 31 | + { | ||
| 32 | + std::shared_ptr<DmpVectorVacuateLayer> vacuateLayer(new DmpVectorVacuateLayer(*this)); | ||
| 33 | + return vacuateLayer; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | 36 | ||
| 37 | -bool DmpVectorThinLayer::Init(double dis,std::string tableName) | 37 | +bool DmpVectorVacuateLayer::Init(double dis, const std::string& tableName, const std::string& connectstr) |
| 38 | { | 38 | { |
| 39 | m_ddis =dis; | 39 | m_ddis =dis; |
| 40 | m_tableName = tableName; | 40 | m_tableName = tableName; |
| 41 | + connectstr_ = connectstr; | ||
| 41 | return true; | 42 | return true; |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | -double DmpVectorThinLayer::GeDisPix() | 45 | +double DmpVectorVacuateLayer::GeDisPix() |
| 45 | { | 46 | { |
| 46 | return this->m_ddis; | 47 | return this->m_ddis; |
| 47 | } | 48 | } |
| 1 | /************************************************************************** | 1 | /************************************************************************** |
| 2 | -* file: dmpvectorthinlayer.h | 2 | +* file: dmpvectorvacuatelayer.h |
| 3 | 3 | ||
| 4 | * Author: qingxiongf | 4 | * Author: qingxiongf |
| 5 | * Date: 2021-12-13 10:05:42 | 5 | * Date: 2021-12-13 10:05:42 |
| @@ -7,33 +7,35 @@ | @@ -7,33 +7,35 @@ | ||
| 7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
| 8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
| 9 | 9 | ||
| 10 | -#ifndef __dmpvectorthinlayer_h__ | ||
| 11 | -#define __dmpvectorthinlayer_h__ | 10 | +#ifndef __dmpvectorvacuatelayer_h__ |
| 11 | +#define __dmpvectorvacuatelayer_h__ | ||
| 12 | 12 | ||
| 13 | #include "dmap_core.h" | 13 | #include "dmap_core.h" |
| 14 | #include <string> | 14 | #include <string> |
| 15 | +#include <memory> | ||
| 15 | 16 | ||
| 16 | -class CORE_EXPORT DmpVectorThinLayer | 17 | +class CORE_EXPORT DmpVectorVacuateLayer |
| 17 | { | 18 | { |
| 18 | public: | 19 | public: |
| 19 | - DmpVectorThinLayer(/* args */); | 20 | + DmpVectorVacuateLayer(/* args */); |
| 20 | 21 | ||
| 21 | - ~DmpVectorThinLayer(); | 22 | + ~DmpVectorVacuateLayer(); |
| 22 | 23 | ||
| 23 | bool IsCurrentLayer(double d); | 24 | bool IsCurrentLayer(double d); |
| 24 | 25 | ||
| 25 | - bool Init(double minX, double minY, | ||
| 26 | - double maxX, double maxY, | ||
| 27 | - int dxCount, int dyCount, | ||
| 28 | - std::string tableName); | ||
| 29 | 26 | ||
| 30 | - bool Init(double minX, | ||
| 31 | - std::string tableName); | 27 | + bool Init(double dis, const std::string& tableName, const std::string& connectstr); |
| 28 | + | ||
| 29 | + std::shared_ptr<DmpVectorVacuateLayer> clone(); | ||
| 32 | 30 | ||
| 33 | double GeDisPix(); | 31 | double GeDisPix(); |
| 34 | 32 | ||
| 33 | + double dis() const { return m_ddis; } | ||
| 34 | + | ||
| 35 | std::string tableName()const { return m_tableName;} | 35 | std::string tableName()const { return m_tableName;} |
| 36 | 36 | ||
| 37 | + std::string connectStr() const {return connectstr_;} | ||
| 38 | + | ||
| 37 | private: | 39 | private: |
| 38 | int m_indexLevel; | 40 | int m_indexLevel; |
| 39 | int m_dataCount; | 41 | int m_dataCount; |
| @@ -44,6 +46,7 @@ class CORE_EXPORT DmpVectorThinLayer | @@ -44,6 +46,7 @@ class CORE_EXPORT DmpVectorThinLayer | ||
| 44 | double m_ddis; | 46 | double m_ddis; |
| 45 | std::string m_tableName; | 47 | std::string m_tableName; |
| 46 | std::string polygon_area = "geodmap_area"; | 48 | std::string polygon_area = "geodmap_area"; |
| 49 | + std::string connectstr_ = ""; | ||
| 47 | }; | 50 | }; |
| 48 | 51 | ||
| 49 | -#endif // __dmpvectorthinlayer_h__ | 52 | +#endif // __dmpvectorvacuatelayer_h__ |
| @@ -33,6 +33,24 @@ void DmpRectangle::normalize() | @@ -33,6 +33,24 @@ void DmpRectangle::normalize() | ||
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | +void DmpRectangle::merge(DmpRectangle &rectangle) | ||
| 37 | +{ | ||
| 38 | + if(xmin_ == 0 && ymin_ ==0 && xmax_ ==0 && ymax_ ==0 ) | ||
| 39 | + { | ||
| 40 | + this->xmin_ = rectangle.xmin(); | ||
| 41 | + this->ymin_ = rectangle.ymin(); | ||
| 42 | + this->xmax_ = rectangle.xmax(); | ||
| 43 | + this->ymax_ = rectangle.ymax(); | ||
| 44 | + } | ||
| 45 | + else | ||
| 46 | + { | ||
| 47 | + if(rectangle.xmin() < this->xmin_ ) this->xmin_ = rectangle.xmin(); | ||
| 48 | + if(rectangle.ymin() < this->ymin_ ) this->ymin_ = rectangle.ymin(); | ||
| 49 | + if(rectangle.xmax() > this->xmax_ ) this->xmax_ = rectangle.xmax(); | ||
| 50 | + if(rectangle.ymax() < this->ymax_ ) this->ymax_ = rectangle.ymax(); | ||
| 51 | + } | ||
| 52 | +} | ||
| 53 | + | ||
| 36 | 54 | ||
| 37 | bool DmpRectangle::isNull() | 55 | bool DmpRectangle::isNull() |
| 38 | { | 56 | { |
| @@ -38,6 +38,13 @@ class CORE_EXPORT DmpRectangle | @@ -38,6 +38,13 @@ class CORE_EXPORT DmpRectangle | ||
| 38 | double width() const { return xmax_ - xmin_; } | 38 | double width() const { return xmax_ - xmin_; } |
| 39 | double height() const { return ymax_ - ymin_; } | 39 | double height() const { return ymax_ - ymin_; } |
| 40 | 40 | ||
| 41 | + void setXmax(double xmax){xmax_ = xmax; } | ||
| 42 | + void setYmax(double ymax){ymax_ = ymax; } | ||
| 43 | + void setXmin(double xmin){xmin_ = xmin; } | ||
| 44 | + void setYmin(double ymin){ymin_ = ymin; } | ||
| 45 | + | ||
| 46 | + void merge(DmpRectangle &rectangle); | ||
| 47 | + | ||
| 41 | private: | 48 | private: |
| 42 | double xmin_ = 0.0; | 49 | double xmin_ = 0.0; |
| 43 | double ymin_ = 0.0; | 50 | double ymin_ = 0.0; |
| @@ -12,7 +12,7 @@ namespace DmapCore_30 | @@ -12,7 +12,7 @@ namespace DmapCore_30 | ||
| 12 | 12 | ||
| 13 | SimpleLineSymbol::SimpleLineSymbol() | 13 | SimpleLineSymbol::SimpleLineSymbol() |
| 14 | { | 14 | { |
| 15 | - m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT; | 15 | + m_iAntialiasing = CAIRO_ANTIALIAS_FAST; |
| 16 | m_iColor = clsUtil::RandomColor(); | 16 | m_iColor = clsUtil::RandomColor(); |
| 17 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); | 17 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); |
| 18 | //m_pClsSurfBackup = NULL; | 18 | //m_pClsSurfBackup = NULL; |
| @@ -12,7 +12,7 @@ namespace DmapCore_30 | @@ -12,7 +12,7 @@ namespace DmapCore_30 | ||
| 12 | { | 12 | { |
| 13 | SimpleMarkerSymbol::SimpleMarkerSymbol() | 13 | SimpleMarkerSymbol::SimpleMarkerSymbol() |
| 14 | { | 14 | { |
| 15 | - m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT; | 15 | + m_iAntialiasing = CAIRO_ANTIALIAS_FAST; |
| 16 | m_bBoundary = true; | 16 | m_bBoundary = true; |
| 17 | m_iColor = clsUtil::RandomColor(); | 17 | m_iColor = clsUtil::RandomColor(); |
| 18 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); | 18 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); |
| @@ -12,7 +12,7 @@ namespace DmapCore_30 | @@ -12,7 +12,7 @@ namespace DmapCore_30 | ||
| 12 | { | 12 | { |
| 13 | SimplePolygonSymbol::SimplePolygonSymbol() | 13 | SimplePolygonSymbol::SimplePolygonSymbol() |
| 14 | { | 14 | { |
| 15 | - m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT; | 15 | + m_iAntialiasing = CAIRO_ANTIALIAS_FAST; |
| 16 | m_iBackgroundColor = clsUtil::RandomColor(); | 16 | m_iBackgroundColor = clsUtil::RandomColor(); |
| 17 | clsUtil::ToCairoColor(m_iBackgroundColor, r, g, b, a); | 17 | clsUtil::ToCairoColor(m_iBackgroundColor, r, g, b, a); |
| 18 | m_iLineType = 0; | 18 | m_iLineType = 0; |
| @@ -116,25 +116,24 @@ namespace DmapCore_30 | @@ -116,25 +116,24 @@ namespace DmapCore_30 | ||
| 116 | 116 | ||
| 117 | clsPtree::PtreeAttrParse("glowing", ptRenderer, m_bGlowing); | 117 | clsPtree::PtreeAttrParse("glowing", ptRenderer, m_bGlowing); |
| 118 | if (m_bGlowing) | 118 | if (m_bGlowing) |
| 119 | - clsPtree::PtreeAttrParseColor("glowingcolor", "glowingtransparency", ptRenderer, m_iBGColor); | 119 | + clsPtree::PtreeAttrParseColor("glowingcolor", "glowingtransparency", ptRenderer, m_iGlowingColor); |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | - clsPtree::PtreeAttrParse("shadow", ptRenderer, m_bGlowing); | ||
| 123 | - if (m_bGlowing) | 122 | + clsPtree::PtreeAttrParse("shadow", ptRenderer, m_bShadow); |
| 123 | + if (m_bShadow) | ||
| 124 | clsPtree::PtreeAttrParseColor("shadowcolor", "shadowtransparency", ptRenderer, m_iShadowColor); | 124 | clsPtree::PtreeAttrParseColor("shadowcolor", "shadowtransparency", ptRenderer, m_iShadowColor); |
| 125 | 125 | ||
| 126 | pt.add_child("TEXTSYMBOL",ptRenderer); | 126 | pt.add_child("TEXTSYMBOL",ptRenderer); |
| 127 | return true; | 127 | return true; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | - void TextSymbol::ToJson(AppendBuffer *ab) | 130 | + void TextSymbol::ToJson(AppendBuffer *ab) |
| 131 | { | 131 | { |
| 132 | char buff[300] = {0}; | 132 | char buff[300] = {0}; |
| 133 | char resultbuff[5000] ={0}; | 133 | char resultbuff[5000] ={0}; |
| 134 | sprintf(resultbuff, R"("TEXTSYMBOL":{"antialiasing":"antialias_default",)"); | 134 | sprintf(resultbuff, R"("TEXTSYMBOL":{"antialiasing":"antialias_default",)"); |
| 135 | clsJson::JsonAttrParse("font", resultbuff, buff, this->m_sFont); | 135 | clsJson::JsonAttrParse("font", resultbuff, buff, this->m_sFont); |
| 136 | clsJson::JsonAttrParse("fontsize", resultbuff, buff, this->m_iFontSize); | 136 | clsJson::JsonAttrParse("fontsize", resultbuff, buff, this->m_iFontSize); |
| 137 | - // | ||
| 138 | clsJson::JsonAttrParseColor("fontcolor", "fonttransparency", resultbuff, buff, m_iFontColor); | 137 | clsJson::JsonAttrParseColor("fontcolor", "fonttransparency", resultbuff, buff, m_iFontColor); |
| 139 | clsJson::JsonAttrParse("x_dis", resultbuff, buff, this->m_dXdis); | 138 | clsJson::JsonAttrParse("x_dis", resultbuff, buff, this->m_dXdis); |
| 140 | clsJson::JsonAttrParse("y_dis", resultbuff, buff, this->m_dYdis); | 139 | clsJson::JsonAttrParse("y_dis", resultbuff, buff, this->m_dYdis); |
| @@ -147,11 +146,11 @@ namespace DmapCore_30 | @@ -147,11 +146,11 @@ namespace DmapCore_30 | ||
| 147 | 146 | ||
| 148 | clsJson::JsonAttrParse("glowing", resultbuff, buff, m_bGlowing); | 147 | clsJson::JsonAttrParse("glowing", resultbuff, buff, m_bGlowing); |
| 149 | if (m_bGlowing) | 148 | if (m_bGlowing) |
| 150 | - clsJson::JsonAttrParseColor("glowingcolor", "glowingtransparency", resultbuff, buff, m_iBGColor); | 149 | + clsJson::JsonAttrParseColor("glowingcolor", "glowingtransparency", resultbuff, buff, m_iGlowingColor); |
| 151 | 150 | ||
| 152 | 151 | ||
| 153 | - clsJson::JsonAttrParse("shadow", resultbuff, buff, m_bGlowing); | ||
| 154 | - if (m_bGlowing) | 152 | + clsJson::JsonAttrParse("shadow", resultbuff, buff, m_bShadow); |
| 153 | + if (m_bShadow) | ||
| 155 | clsJson::JsonAttrParseColor("shadowcolor", "shadowtransparency", resultbuff, buff, m_iShadowColor); | 154 | clsJson::JsonAttrParseColor("shadowcolor", "shadowtransparency", resultbuff, buff, m_iShadowColor); |
| 156 | 155 | ||
| 157 | clsJson::JsonAttrEnd(resultbuff); | 156 | clsJson::JsonAttrEnd(resultbuff); |
| @@ -317,16 +316,21 @@ namespace DmapCore_30 | @@ -317,16 +316,21 @@ namespace DmapCore_30 | ||
| 317 | x += m_dXdis; | 316 | x += m_dXdis; |
| 318 | y += m_dYdis; | 317 | y += m_dYdis; |
| 319 | cairo_t* cr = pClsCS->m_pCr; | 318 | cairo_t* cr = pClsCS->m_pCr; |
| 320 | - //cairo_font_options_set_antialias(cfo, CAIRO_ANTIALIAS_GRAY); | 319 | + //cairo_font_options_set_antialias(cr, CAIRO_ANTIALIAS_BEST); |
| 321 | cairo_text_extents(cr, sUTF8, m_pCrExtents); | 320 | cairo_text_extents(cr, sUTF8, m_pCrExtents); |
| 322 | int iX = (int)x; int iY = (int)y; | 321 | int iX = (int)x; int iY = (int)y; |
| 323 | int iTextW = (int)(m_pCrExtents->x_advance); int iTextH = (int)(m_pCrExtents->height); | 322 | int iTextW = (int)(m_pCrExtents->x_advance); int iTextH = (int)(m_pCrExtents->height); |
| 324 | //int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH; | 323 | //int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH; |
| 324 | + | ||
| 325 | + //文字被截取 | ||
| 326 | + if(iX < 0 || (iX + iTextW) > pClsCS->m_iW || (iY - iTextH ) < 0 || iY > pClsCS->m_iH) | ||
| 327 | + { | ||
| 328 | + return false; | ||
| 329 | + } | ||
| 325 | 330 | ||
| 326 | /* | 331 | /* |
| 327 | 文字避让部分 | 332 | 文字避让部分 |
| 328 | */ | 333 | */ |
| 329 | - | ||
| 330 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 334 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 331 | int xFrom = iX / gridsize; | 335 | int xFrom = iX / gridsize; |
| 332 | int xTo = (iX + iTextW) / gridsize; | 336 | int xTo = (iX + iTextW) / gridsize; |
| @@ -372,6 +376,10 @@ namespace DmapCore_30 | @@ -372,6 +376,10 @@ namespace DmapCore_30 | ||
| 372 | //if (pFlag[iFlagW*i + j]) return false; | 376 | //if (pFlag[iFlagW*i + j]) return false; |
| 373 | } | 377 | } |
| 374 | } | 378 | } |
| 379 | + | ||
| 380 | + //文字截取部分 | ||
| 381 | + | ||
| 382 | + | ||
| 375 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 383 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 376 | 384 | ||
| 377 | 385 |
| @@ -8,7 +8,7 @@ namespace DmapCore_30 | @@ -8,7 +8,7 @@ namespace DmapCore_30 | ||
| 8 | { | 8 | { |
| 9 | m_pSurf = surface; | 9 | m_pSurf = surface; |
| 10 | m_pCr = cairo_create(m_pSurf); | 10 | m_pCr = cairo_create(m_pSurf); |
| 11 | - //cairo_set_antialias(m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | 11 | + cairo_set_antialias(m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); |
| 12 | m_iN = 1; | 12 | m_iN = 1; |
| 13 | m_iW = cairo_image_surface_get_width(surface); | 13 | m_iW = cairo_image_surface_get_width(surface); |
| 14 | m_iH = cairo_image_surface_get_height(surface); | 14 | m_iH = cairo_image_surface_get_height(surface); |
| 1 | #ifndef _clsMalloc_H_ | 1 | #ifndef _clsMalloc_H_ |
| 2 | #define _clsMalloc_H_ | 2 | #define _clsMalloc_H_ |
| 3 | + | ||
| 4 | +#include "dmap_core.h" | ||
| 5 | +#include "stdio.h" | ||
| 6 | +#include <string> | ||
| 3 | namespace DmapCore_30 | 7 | namespace DmapCore_30 |
| 4 | { | 8 | { |
| 5 | - class clsMalloc | 9 | + class CORE_EXPORT clsMalloc |
| 6 | { | 10 | { |
| 7 | public: | 11 | public: |
| 8 | clsMalloc(); | 12 | clsMalloc(); |
| @@ -287,7 +287,7 @@ namespace DmapCore_30 | @@ -287,7 +287,7 @@ namespace DmapCore_30 | ||
| 287 | //CAIRO_ANTIALIAS_FAST, | 287 | //CAIRO_ANTIALIAS_FAST, |
| 288 | // CAIRO_ANTIALIAS_GOOD, | 288 | // CAIRO_ANTIALIAS_GOOD, |
| 289 | // CAIRO_ANTIALIAS_BEST | 289 | // CAIRO_ANTIALIAS_BEST |
| 290 | - cairo_set_antialias(cr,CAIRO_ANTIALIAS_FAST); | 290 | + cairo_set_antialias(cr,CAIRO_ANTIALIAS_FAST); |
| 291 | return true; | 291 | return true; |
| 292 | switch (iAntialias) | 292 | switch (iAntialias) |
| 293 | { | 293 | { |
| @@ -30,7 +30,7 @@ namespace DmapCore_30 | @@ -30,7 +30,7 @@ namespace DmapCore_30 | ||
| 30 | 30 | ||
| 31 | bool legendParamater::next(char * title) | 31 | bool legendParamater::next(char * title) |
| 32 | { | 32 | { |
| 33 | - if(index/row_maxsize> current_Col_Index) | 33 | + if( row_maxsize >0 && index/row_maxsize > current_Col_Index) |
| 34 | { | 34 | { |
| 35 | current_Col_Index ++; | 35 | current_Col_Index ++; |
| 36 | pixXIndex = 10 + (current_Col_Index *100); | 36 | pixXIndex = 10 + (current_Col_Index *100); |
| @@ -57,7 +57,7 @@ public: | @@ -57,7 +57,7 @@ public: | ||
| 57 | { | 57 | { |
| 58 | return; | 58 | return; |
| 59 | } | 59 | } |
| 60 | - | 60 | + // printf("%s\r\n", szRequest); |
| 61 | 61 | ||
| 62 | DmpSpServerRequest dmpRequest(request); | 62 | DmpSpServerRequest dmpRequest(request); |
| 63 | DmpSpServerResponse dmpResponse(response); | 63 | DmpSpServerResponse dmpResponse(response); |
| @@ -116,7 +116,7 @@ public: | @@ -116,7 +116,7 @@ public: | ||
| 116 | 116 | ||
| 117 | int main(int argc, char *argv[]) | 117 | int main(int argc, char *argv[]) |
| 118 | { | 118 | { |
| 119 | - int port = 8088, maxThreads = 10; | 119 | + int port = 8820, maxThreads = 10; |
| 120 | const char *serverType = "lf"; | 120 | const char *serverType = "lf"; |
| 121 | #ifndef WIN32 | 121 | #ifndef WIN32 |
| 122 | extern char *optarg; | 122 | extern char *optarg; |
| 1 | [MetaData] | 1 | [MetaData] |
| 2 | pgsqlConnect="hostaddr=localhost port=5432 dbname='dmap_dms' user='postgres' password='chinadci'" | 2 | pgsqlConnect="hostaddr=localhost port=5432 dbname='dmap_dms' user='postgres' password='chinadci'" |
| 3 | -metaUrl=http://172.26.60.100:8841/ | ||
| 3 | +metaUrl=http://172.26.60.101:8840/ |
| @@ -44,19 +44,19 @@ DmpServerManager::~DmpServerManager() | @@ -44,19 +44,19 @@ DmpServerManager::~DmpServerManager() | ||
| 44 | delete mapProject; | 44 | delete mapProject; |
| 45 | mapProject = nullptr; | 45 | mapProject = nullptr; |
| 46 | } | 46 | } |
| 47 | - } | 47 | + } |
| 48 | projects_.clear(); | 48 | projects_.clear(); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void DmpServerManager::init(const boost::filesystem::path &modulePath) | 51 | void DmpServerManager::init(const boost::filesystem::path &modulePath) |
| 52 | { | 52 | { |
| 53 | serverRegistry_->init(modulePath); | 53 | serverRegistry_->init(modulePath); |
| 54 | - if(!loadServices()) | 54 | + if (!loadServices()) |
| 55 | { | 55 | { |
| 56 | std::cout << "加载服务失败!" << std::endl; | 56 | std::cout << "加载服务失败!" << std::endl; |
| 57 | LOGGER_ERROR("加载服务失败!"); | 57 | LOGGER_ERROR("加载服务失败!"); |
| 58 | } | 58 | } |
| 59 | - //LoadDmpServices(); | 59 | + // LoadDmpServices(); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | std::string DmpServerManager::getCapabilities() | 62 | std::string DmpServerManager::getCapabilities() |
| @@ -106,9 +106,9 @@ bool DmpServerManager::removeProject(const std::string &serviceName) | @@ -106,9 +106,9 @@ bool DmpServerManager::removeProject(const std::string &serviceName) | ||
| 106 | return true; | 106 | return true; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | -bool DmpServerManager::publish(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData) | 109 | +bool DmpServerManager::publish(const std::string &serverName, const std::string &serviceName, const std::string &title, int capabilities, const std::string &projectData) |
| 110 | { | 110 | { |
| 111 | - //project | 111 | + // project |
| 112 | std::string projData; | 112 | std::string projData; |
| 113 | if (!DmpServerUtils::Base64Decode(projectData, &projData)) | 113 | if (!DmpServerUtils::Base64Decode(projectData, &projData)) |
| 114 | { | 114 | { |
| @@ -121,13 +121,16 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | @@ -121,13 +121,16 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | ||
| 121 | return false; | 121 | return false; |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | + project->initVectorLayerVacuate([](const std::string &tableguid) | ||
| 125 | + { return DmpHttp::get(DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); }); | ||
| 126 | + | ||
| 124 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) | 127 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) |
| 125 | { | 128 | { |
| 126 | delete project; | 129 | delete project; |
| 127 | return false; | 130 | return false; |
| 128 | } | 131 | } |
| 129 | projects_[serviceName] = project; | 132 | projects_[serviceName] = project; |
| 130 | - | 133 | + |
| 131 | return true; | 134 | return true; |
| 132 | } | 135 | } |
| 133 | 136 | ||
| @@ -154,36 +157,46 @@ bool DmpServerManager::stopService(const std::string &serverName, const std::str | @@ -154,36 +157,46 @@ bool DmpServerManager::stopService(const std::string &serverName, const std::str | ||
| 154 | } | 157 | } |
| 155 | bool DmpServerManager::loadServices() | 158 | bool DmpServerManager::loadServices() |
| 156 | { | 159 | { |
| 157 | - boost::property_tree::ptree pt,ptList; | ||
| 158 | - std::string conn = DmpServerConfig::Instance()->getMetaUrl(); | ||
| 159 | - const std::string url= conn + URI_RELOAD; | ||
| 160 | - std::string strContent=DmpHttp::get(url); | ||
| 161 | - if(strContent.length()==0) | ||
| 162 | - { | ||
| 163 | - return false; | ||
| 164 | - } | ||
| 165 | - std::stringstream ssData; | ||
| 166 | - ssData<<strContent.c_str(); | ||
| 167 | - boost::property_tree::read_json(ssData, pt); | ||
| 168 | - int iCount = std::atoi(pt.get<std::string>("data.count").c_str()); | ||
| 169 | - if(iCount>0) | 160 | + std::string strContent; |
| 161 | + try | ||
| 170 | { | 162 | { |
| 171 | - ptList=pt.get_child("data.list"); | ||
| 172 | - for (auto& e : ptList) | 163 | + boost::property_tree::ptree pt, ptList; |
| 164 | + std::string conn = DmpServerConfig::Instance()->getMetaUrl(); | ||
| 165 | + const std::string url = conn + URI_RELOAD; | ||
| 166 | + strContent = DmpHttp::get(url); | ||
| 167 | + if (strContent.length() == 0) | ||
| 168 | + { | ||
| 169 | + return false; | ||
| 170 | + } | ||
| 171 | + std::stringstream ssData; | ||
| 172 | + ssData << strContent.c_str(); | ||
| 173 | + boost::property_tree::read_json(ssData, pt); | ||
| 174 | + int iCount = std::atoi(pt.get<std::string>("data.count").c_str()); | ||
| 175 | + if (iCount > 0) | ||
| 173 | { | 176 | { |
| 174 | - std::string name = e.second.get<std::string>("name"); | ||
| 175 | - std::string title = e.second.get<std::string>("title"); | ||
| 176 | - std::string type = e.second.get<std::string>("type"); | ||
| 177 | - int capabilities =e.second.get<int>("capabilities"); | ||
| 178 | - std::string project = e.second.get<std::string>("project"); | ||
| 179 | - this->initServices(type,name,title,capabilities,project); | 177 | + ptList = pt.get_child("data.list"); |
| 178 | + for (auto &e : ptList) | ||
| 179 | + { | ||
| 180 | + std::string name = e.second.get<std::string>("name"); | ||
| 181 | + std::string title = e.second.get<std::string>("title"); | ||
| 182 | + std::string type = e.second.get<std::string>("type"); | ||
| 183 | + int capabilities = e.second.get<int>("capabilities"); | ||
| 184 | + std::string project = e.second.get<std::string>("project"); | ||
| 185 | + this->initServices(type, name, title, capabilities, project); | ||
| 186 | + } | ||
| 180 | } | 187 | } |
| 181 | } | 188 | } |
| 189 | + catch(const std::exception& e) | ||
| 190 | + { | ||
| 191 | + std::cerr << e.what() << strContent.c_str() << '\n'; | ||
| 192 | + return false; | ||
| 193 | + } | ||
| 194 | + | ||
| 182 | return true; | 195 | return true; |
| 183 | } | 196 | } |
| 184 | -bool DmpServerManager::initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData) | 197 | +bool DmpServerManager::initServices(const std::string &serverName, const std::string &serviceName, const std::string &title, int capabilities, const std::string &projectData) |
| 185 | { | 198 | { |
| 186 | - //project | 199 | + // project |
| 187 | std::string projData; | 200 | std::string projData; |
| 188 | if (!DmpServerUtils::Base64Decode(projectData, &projData)) | 201 | if (!DmpServerUtils::Base64Decode(projectData, &projData)) |
| 189 | { | 202 | { |
| @@ -196,12 +209,14 @@ bool DmpServerManager::initServices(const std::string& serverName, const std::st | @@ -196,12 +209,14 @@ bool DmpServerManager::initServices(const std::string& serverName, const std::st | ||
| 196 | return false; | 209 | return false; |
| 197 | } | 210 | } |
| 198 | 211 | ||
| 212 | + project->initVectorLayerVacuate([](const std::string &tableguid) | ||
| 213 | + { return DmpHttp::get(DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); }); | ||
| 214 | + | ||
| 199 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) | 215 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) |
| 200 | { | 216 | { |
| 201 | delete project; | 217 | delete project; |
| 202 | return false; | 218 | return false; |
| 203 | } | 219 | } |
| 204 | - projects_[serviceName] = project; | 220 | + projects_[serviceName] = project; |
| 205 | return true; | 221 | return true; |
| 206 | - | ||
| 207 | } | 222 | } |
| @@ -20,7 +20,8 @@ | @@ -20,7 +20,8 @@ | ||
| 20 | #include "dmpserverregistry.h" | 20 | #include "dmpserverregistry.h" |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | -#define URI_RELOAD ("/API/Service/Reload") //加载已注册服务接口 | 23 | +#define URI_RELOAD ("/API/Service/Reload") //加载已注册服务接口 |
| 24 | +#define URL_VACUATE ("/API/Manager/TableVacuateDetail?table_guids=") //加载矢量数据抽稀图层 | ||
| 24 | class SERVER_EXPORT DmpServerManager | 25 | class SERVER_EXPORT DmpServerManager |
| 25 | { | 26 | { |
| 26 | public: | 27 | public: |
| @@ -8,6 +8,7 @@ SET (MAPSERVER_SRCS | @@ -8,6 +8,7 @@ SET (MAPSERVER_SRCS | ||
| 8 | dmppgsql.cpp | 8 | dmppgsql.cpp |
| 9 | dmppgsqlpool.cpp | 9 | dmppgsqlpool.cpp |
| 10 | dmppgsqlsourcepools.cpp | 10 | dmppgsqlsourcepools.cpp |
| 11 | + dmpgeometry.cpp | ||
| 11 | wfs/dmpwfs.cpp | 12 | wfs/dmpwfs.cpp |
| 12 | wfs/dmpwfsfilter.cpp | 13 | wfs/dmpwfsfilter.cpp |
| 13 | wfs/dmpgmlfilter.cpp | 14 | wfs/dmpgmlfilter.cpp |
| @@ -20,9 +21,18 @@ SET (MAPSERVER_SRCS | @@ -20,9 +21,18 @@ SET (MAPSERVER_SRCS | ||
| 20 | wms/dmpwmsparameters.cpp | 21 | wms/dmpwmsparameters.cpp |
| 21 | wms/dmpwmsgetcapabilities.cpp | 22 | wms/dmpwmsgetcapabilities.cpp |
| 22 | wms/dmpwmsgetmap.cpp | 23 | wms/dmpwmsgetmap.cpp |
| 24 | + wms/dmpwmsgetprint.cpp | ||
| 23 | wms/dmpwmsserviceinfo.cpp | 25 | wms/dmpwmsserviceinfo.cpp |
| 24 | wms/dmpwmsgetfeatureinfo.cpp | 26 | wms/dmpwmsgetfeatureinfo.cpp |
| 25 | - wms/dmpprint.cpp | 27 | + wms/print/dmpmapprint.cpp |
| 28 | + wms/print/dmpprintlayer.cpp | ||
| 29 | + wms/print/dmpprinttext.cpp | ||
| 30 | + wms/print/dmpprintrect.cpp | ||
| 31 | + wms/print/dmpprintscale.cpp | ||
| 32 | + wms/print/dmpprintcompass.cpp | ||
| 33 | + wms/print/dmpprintlayout.cpp | ||
| 34 | + wms/print/dmpprintparameter.cpp | ||
| 35 | + wms/print/dmpprintwmsservice.cpp | ||
| 26 | mapping/dmpmapping.cpp | 36 | mapping/dmpmapping.cpp |
| 27 | mapping/dmpeditservice.cpp | 37 | mapping/dmpeditservice.cpp |
| 28 | mapping/dmpmappingparameters.cpp | 38 | mapping/dmpmappingparameters.cpp |
| @@ -35,6 +45,7 @@ SET (MAPSERVER_HDRS | @@ -35,6 +45,7 @@ SET (MAPSERVER_HDRS | ||
| 35 | dmppgsql.h | 45 | dmppgsql.h |
| 36 | dmppgsqlpool.h | 46 | dmppgsqlpool.h |
| 37 | dmppgsqlsourcepools.h | 47 | dmppgsqlsourcepools.h |
| 48 | + dmpgeometry.h | ||
| 38 | wfs/dmpwfs.h | 49 | wfs/dmpwfs.h |
| 39 | wfs/dmpwfsfilter.h | 50 | wfs/dmpwfsfilter.h |
| 40 | wfs/dmpgmlfilter.h | 51 | wfs/dmpgmlfilter.h |
| @@ -47,9 +58,18 @@ SET (MAPSERVER_HDRS | @@ -47,9 +58,18 @@ SET (MAPSERVER_HDRS | ||
| 47 | wms/dmpwmsparameters.h | 58 | wms/dmpwmsparameters.h |
| 48 | wms/dmpwmsgetcapabilities.h | 59 | wms/dmpwmsgetcapabilities.h |
| 49 | wms/dmpwmsgetmap.h | 60 | wms/dmpwmsgetmap.h |
| 61 | + wms/dmpwmsgetprint.h | ||
| 50 | wms/dmpwmsserviceinfo.h | 62 | wms/dmpwmsserviceinfo.h |
| 51 | wms/dmpwmsgetfeatureinfo.h | 63 | wms/dmpwmsgetfeatureinfo.h |
| 52 | - wms/dmpprint.h | 64 | + wms/print/dmpmapprint.h |
| 65 | + wms/print/dmpprintlayer.h | ||
| 66 | + wms/print/dmpprinttext.h | ||
| 67 | + wms/print/dmpprintrect.h | ||
| 68 | + wms/print/dmpprintscale.h | ||
| 69 | + wms/print/dmpprintcompass.h | ||
| 70 | + wms/print/dmpprintlayout.h | ||
| 71 | + wms/print/dmpprintparameter.h | ||
| 72 | + wms/print/dmpprintwmsservice.h | ||
| 53 | mapping/dmpmapping.h | 73 | mapping/dmpmapping.h |
| 54 | mapping/dmpeditservice.h | 74 | mapping/dmpeditservice.h |
| 55 | mapping/dmpmappingparameters.h | 75 | mapping/dmpmappingparameters.h |
| 1 | +/************************************************************************** | ||
| 2 | +* file: DmpGeometry.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-02-22 10:13:27 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "DmpGeometry.h" | ||
| 10 | +#include <iostream> | ||
| 11 | +#include <string.h> | ||
| 12 | +#include <sstream> | ||
| 13 | + | ||
| 14 | +namespace mapserver | ||
| 15 | +{ | ||
| 16 | + std::string DmpGeometry::geoJsonfromWKB(const char* wkb) | ||
| 17 | + { | ||
| 18 | + unsigned char* pwkb = (unsigned char*)wkb; | ||
| 19 | + unsigned char hasZorSrsid = ((unsigned char *)(pwkb + 4))[0] / 16; | ||
| 20 | + | ||
| 21 | + unsigned char type = ((unsigned char *)(pwkb + 1))[0]; | ||
| 22 | + this->hasZ_ = hasZorSrsid / 8; | ||
| 23 | + this->hasSrid_ = hasZorSrsid % 8; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + notbig_ = this->ReadByte(pwkb); | ||
| 27 | + int shape = this->ReadInt(pwkb, notbig_); | ||
| 28 | + if (hasSrid_) | ||
| 29 | + { | ||
| 30 | + srid_ = this->ReadInt(pwkb, notbig_); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + std::stringstream sstream; | ||
| 34 | + | ||
| 35 | + switch (type) | ||
| 36 | + { | ||
| 37 | + case DmpWkbTypes::Type::Point: | ||
| 38 | + // case DmpWkbTypes::Type::PointZ: | ||
| 39 | + // case DmpWkbTypes::Type::PointM: | ||
| 40 | + // case DmpWkbTypes::Type::PointZM: | ||
| 41 | + { | ||
| 42 | + sstream << R"({"type":"Point","coordinates": [)"; | ||
| 43 | + readPointfromWKB(pwkb,sstream); | ||
| 44 | + break; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + case DmpWkbTypes::Type::MultiPoint: | ||
| 49 | + // case DmpWkbTypes::Type::MultiPointZ: | ||
| 50 | + // case DmpWkbTypes::Type::MultiPointM: | ||
| 51 | + // case DmpWkbTypes::Type::MultiPointZM: | ||
| 52 | + { | ||
| 53 | + sstream << R"({"type":"MultiPoint","coordinates": [)"; | ||
| 54 | + int nPoint = this->ReadInt(pwkb, notbig_); | ||
| 55 | + for (int j = 0; j < nPoint; j++) | ||
| 56 | + { | ||
| 57 | + pwkb += 5; | ||
| 58 | + if(j>0) sstream << ","; | ||
| 59 | + readPointfromWKB(pwkb,sstream); | ||
| 60 | + } | ||
| 61 | + break; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + case DmpWkbTypes::Type::LineString: | ||
| 65 | + // case DmpWkbTypes::Type::LineStringZ: | ||
| 66 | + // case DmpWkbTypes::Type::LineStringM: | ||
| 67 | + // case DmpWkbTypes::Type::LineStringZM: | ||
| 68 | + { | ||
| 69 | + sstream << R"({"type":"LineString","coordinates": [)"; | ||
| 70 | + readLinefromWKB(pwkb,sstream); | ||
| 71 | + break; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + | ||
| 75 | + case DmpWkbTypes::Type::MultiLineString: | ||
| 76 | + // case DmpWkbTypes::Type::MultiLineStringZ: | ||
| 77 | + // case DmpWkbTypes::Type::MultiLineStringM: | ||
| 78 | + // case DmpWkbTypes::Type::MultiLineStringZM: | ||
| 79 | + { | ||
| 80 | + sstream << R"({"type":"MultiLineString","coordinates": [)"; | ||
| 81 | + int nLine = this->ReadInt(pwkb, notbig_); | ||
| 82 | + for (int j = 0; j < nLine; j++) | ||
| 83 | + { | ||
| 84 | + pwkb += 5; | ||
| 85 | + if(j>0) sstream << ","; | ||
| 86 | + readLinefromWKB(pwkb,sstream); | ||
| 87 | + } | ||
| 88 | + break; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + case DmpWkbTypes::Type::Polygon: | ||
| 92 | + // case DmpWkbTypes::Type::PolygonZ: | ||
| 93 | + // case DmpWkbTypes::Type::PolygonM: | ||
| 94 | + // case DmpWkbTypes::Type::PolygonZM: | ||
| 95 | + { | ||
| 96 | + sstream << R"({"type":"Polygon","coordinates": [)"; | ||
| 97 | + readPolygonfromWKB(pwkb,sstream); | ||
| 98 | + break; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + case DmpWkbTypes::Type::MultiPolygon: | ||
| 102 | + // case DmpWkbTypes::Type::MultiPolygonZ: | ||
| 103 | + // case DmpWkbTypes::Type::MultiPolygonM: | ||
| 104 | + // case DmpWkbTypes::Type::MultiPolygonZM: | ||
| 105 | + { | ||
| 106 | + sstream << R"({"type":"MultiPolygon","coordinates": [)"; | ||
| 107 | + int nPolygon = this->ReadInt(pwkb, notbig_); | ||
| 108 | + for (int j = 0; j < nPolygon; j++) | ||
| 109 | + { | ||
| 110 | + pwkb += 5; | ||
| 111 | + if(j>0) sstream << ","; | ||
| 112 | + readPolygonfromWKB(pwkb,sstream); | ||
| 113 | + } | ||
| 114 | + break; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + default: | ||
| 118 | + break; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + sstream << "]}"; | ||
| 122 | + | ||
| 123 | + return sstream.str();; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + bool DmpGeometry::readPointfromWKB(unsigned char*& pwkb, stringstream& sstream ) | ||
| 127 | + { | ||
| 128 | + double xx = this->ReadDouble(pwkb,notbig_); | ||
| 129 | + double yy = this->ReadDouble(pwkb,notbig_); | ||
| 130 | + | ||
| 131 | + // sprintf(buff, "[%.6f,%.6f]" ,xx,yy); | ||
| 132 | + sstream << "[" << ToDoubleStr(xx) << "," << ToDoubleStr(yy) << "]"; | ||
| 133 | + | ||
| 134 | + if(hasZ_) | ||
| 135 | + { | ||
| 136 | + pwkb += 8; | ||
| 137 | + // double zz = this->ReadDouble(pwkb,notbig_); | ||
| 138 | + } | ||
| 139 | + return true; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + char* DmpGeometry::ToDoubleStr(double value) | ||
| 143 | + { | ||
| 144 | + int len = sprintf(buff, "%.6f" ,value); | ||
| 145 | + for ( len --; len >0; len--) | ||
| 146 | + { | ||
| 147 | + if(buff[len] == '0') | ||
| 148 | + { | ||
| 149 | + buff[len] = 0; | ||
| 150 | + } | ||
| 151 | + else if(buff[len] == '.') | ||
| 152 | + { | ||
| 153 | + buff[len] = 0; | ||
| 154 | + break; | ||
| 155 | + } | ||
| 156 | + else | ||
| 157 | + { | ||
| 158 | + break; | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + return buff; | ||
| 163 | + | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + bool DmpGeometry::readLinefromWKB(unsigned char*& pwkb, stringstream& sstream) | ||
| 167 | + { | ||
| 168 | + int nPoint = this->ReadInt(pwkb, notbig_); | ||
| 169 | + sstream << "["; | ||
| 170 | + for (size_t i = 0; i < nPoint; i++) | ||
| 171 | + { | ||
| 172 | + if(i>0) sstream << ","; | ||
| 173 | + readPointfromWKB(pwkb, sstream); | ||
| 174 | + } | ||
| 175 | + sstream << "]"; | ||
| 176 | + | ||
| 177 | + return true; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + bool DmpGeometry::readPolygonfromWKB(unsigned char*& pwkb, stringstream& sstream) | ||
| 181 | + { | ||
| 182 | + int nline = this->ReadInt(pwkb, notbig_); | ||
| 183 | + sstream << "["; | ||
| 184 | + for (size_t i = 0; i < nline; i++) | ||
| 185 | + { | ||
| 186 | + if(i>0) sstream << ","; | ||
| 187 | + readLinefromWKB(pwkb, sstream); | ||
| 188 | + } | ||
| 189 | + sstream << "]"; | ||
| 190 | + | ||
| 191 | + return true; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + | ||
| 195 | + | ||
| 196 | +int DmpGeometry::ReadInt(unsigned char*& here, int not_big1) | ||
| 197 | +{ | ||
| 198 | + unsigned char * mem = (unsigned char *)malloc(4); | ||
| 199 | + memcpy(mem, here, 4); | ||
| 200 | + if (!not_big1) | ||
| 201 | + this->Exchange4(mem); | ||
| 202 | + int num = ((int*)mem)[0]; | ||
| 203 | + free(mem); | ||
| 204 | + here += 4; | ||
| 205 | + return num; | ||
| 206 | +} | ||
| 207 | +int DmpGeometry::ReadByte(unsigned char*& here) | ||
| 208 | +{ | ||
| 209 | + int num = ((char*)here)[0]; | ||
| 210 | + here++; | ||
| 211 | + return num; | ||
| 212 | +} | ||
| 213 | + | ||
| 214 | +double DmpGeometry::ReadDouble(unsigned char*& here, int not_big) | ||
| 215 | +{ | ||
| 216 | + //DmapCore_30::clsMalloc clsM(8); | ||
| 217 | + unsigned char * mem = (unsigned char *)malloc(8); | ||
| 218 | + memcpy(mem, here, 8); | ||
| 219 | + if (!not_big) | ||
| 220 | + Exchange8(mem); | ||
| 221 | + double num = ((double*)mem)[0]; | ||
| 222 | + free(mem); | ||
| 223 | + here += 8; | ||
| 224 | + return num; | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +bool DmpGeometry::Exchange4(unsigned char * here) | ||
| 228 | +{ | ||
| 229 | + unsigned char temp; | ||
| 230 | + for (int i = 0; i < 2; i++) | ||
| 231 | + { | ||
| 232 | + temp = here[i]; | ||
| 233 | + here[i] = here[3 - i]; | ||
| 234 | + here[3 - i] = temp; | ||
| 235 | + } | ||
| 236 | + return true; | ||
| 237 | +} | ||
| 238 | + | ||
| 239 | +bool DmpGeometry::Exchange8(unsigned char * here) | ||
| 240 | +{ | ||
| 241 | + unsigned char temp; | ||
| 242 | + for (int i = 0; i < 4; i++) | ||
| 243 | + { | ||
| 244 | + temp = here[i]; | ||
| 245 | + here[i] = here[7 - i]; | ||
| 246 | + here[7 - i] = temp; | ||
| 247 | + } | ||
| 248 | + return true; | ||
| 249 | +} | ||
| 250 | + | ||
| 251 | + | ||
| 252 | +} | ||
| 253 | + |
src/server/services/mapserver/dmpgeometry.h
0 → 100644
| 1 | +/************************************************************************** | ||
| 2 | +* file: DmpGeometry.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-02-22 10:07:04 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __DmpGeometry_h__ | ||
| 11 | +#define __DmpGeometry_h__ | ||
| 12 | +#include <geometry/dmpwkbtypes.h> | ||
| 13 | +#include <string> | ||
| 14 | +using namespace std; | ||
| 15 | +namespace mapserver | ||
| 16 | +{ | ||
| 17 | + class DmpGeometry | ||
| 18 | + { | ||
| 19 | + /* data */ | ||
| 20 | + public: | ||
| 21 | + // DmpGeometry(/* args */); | ||
| 22 | + // ~DmpGeometry(); | ||
| 23 | + | ||
| 24 | + // static DmpGeometry geometryfromWKT(const char* wkt); | ||
| 25 | + | ||
| 26 | + std::string geoJsonfromWKB(const char* wkb); | ||
| 27 | + | ||
| 28 | + bool readPointfromWKB(unsigned char*& pwkb, stringstream& outstream); | ||
| 29 | + bool readLinefromWKB(unsigned char*& pwkb, stringstream& outstream); | ||
| 30 | + bool readPolygonfromWKB(unsigned char*& pwkb, stringstream& outstream); | ||
| 31 | + | ||
| 32 | + // static string geoJsonfromWKT(const char* wkt); | ||
| 33 | + private: | ||
| 34 | + int ReadInt(unsigned char*& pwkb, int not_big1); | ||
| 35 | + double ReadDouble(unsigned char*& pwkb, int not_big1); | ||
| 36 | + int ReadByte(unsigned char*& pwkb); | ||
| 37 | + bool Exchange4(unsigned char* pwkb); | ||
| 38 | + bool Exchange8(unsigned char* pwkb); | ||
| 39 | + | ||
| 40 | + char* ToDoubleStr(double value); | ||
| 41 | + private: | ||
| 42 | + int srid_; | ||
| 43 | + bool hasZ_; | ||
| 44 | + bool hasSrid_; | ||
| 45 | + int notbig_; | ||
| 46 | + | ||
| 47 | + DmpWkbTypes::Type type_; | ||
| 48 | + char buff[100]; | ||
| 49 | + | ||
| 50 | + }; | ||
| 51 | + | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +#endif // __DmpGeometry_h__ |
| @@ -12,12 +12,29 @@ | @@ -12,12 +12,29 @@ | ||
| 12 | #include <ostream> | 12 | #include <ostream> |
| 13 | #include <string> | 13 | #include <string> |
| 14 | #include <boost/asio.hpp> | 14 | #include <boost/asio.hpp> |
| 15 | - | 15 | +#include "dmpgeometry.h" |
| 16 | using boost::asio::ip::tcp; | 16 | using boost::asio::ip::tcp; |
| 17 | 17 | ||
| 18 | namespace mapserver | 18 | namespace mapserver |
| 19 | { | 19 | { |
| 20 | 20 | ||
| 21 | + void DmpMapServerUtil::initVectorLayerSrid(shared_ptr<DmpPgsql> pPgsqlConn,DmpVectorLayer* layer) | ||
| 22 | + { | ||
| 23 | + if(layer->srid().empty()) | ||
| 24 | + { | ||
| 25 | + string name = layer->name(); | ||
| 26 | + string sql = "select t.f_geometry_column shapeField, t.type ,f_table_schema,t.srid from public.geometry_columns t where lower( t.f_table_name) = lower('"+ name +"');"; | ||
| 27 | + if(pPgsqlConn->ExecWait(sql)) | ||
| 28 | + { | ||
| 29 | + string geom = pPgsqlConn->getString(0); | ||
| 30 | + string value = pPgsqlConn->getString( 1); | ||
| 31 | + string strSchema = pPgsqlConn->getString(2); | ||
| 32 | + string srid = pPgsqlConn->getString(3); | ||
| 33 | + layer->setSrid(srid); | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + | ||
| 21 | void DmpMapServerUtil::responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData, const string &layerName, const std::string &srid) | 38 | void DmpMapServerUtil::responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData, const string &layerName, const std::string &srid) |
| 22 | { | 39 | { |
| 23 | 40 | ||
| @@ -39,17 +56,9 @@ namespace mapserver | @@ -39,17 +56,9 @@ namespace mapserver | ||
| 39 | int fieldsCount = pPgsqlConn->GetFieldCount(); | 56 | int fieldsCount = pPgsqlConn->GetFieldCount(); |
| 40 | for (; pPgsqlConn->next();) | 57 | for (; pPgsqlConn->next();) |
| 41 | { | 58 | { |
| 42 | - // css++; | ||
| 43 | - //if(css!=24)continue; | ||
| 44 | - //break; | ||
| 45 | - //string geometry = ""; | ||
| 46 | - //string properties = ""; | ||
| 47 | responseData.append("<gims:featureMember>"); | 59 | responseData.append("<gims:featureMember>"); |
| 48 | sprintf(buff, "<gims:%s fid=\"%s.%d\">", layerName.c_str(), layerName.c_str(), count + 1); | 60 | sprintf(buff, "<gims:%s fid=\"%s.%d\">", layerName.c_str(), layerName.c_str(), count + 1); |
| 49 | responseData.append(buff); | 61 | responseData.append(buff); |
| 50 | - //responseData.append("\r\n"); | ||
| 51 | - | ||
| 52 | - //columns[md[ i ].getString(MetaData::ATTR_NAME)] = i; | ||
| 53 | for (int i = 0; i < fieldsCount; i++) | 62 | for (int i = 0; i < fieldsCount; i++) |
| 54 | { | 63 | { |
| 55 | const char *sfieldName = pPgsqlConn->GetFieldName(i); //pPgsqlConn->field_name[i].c_str(); | 64 | const char *sfieldName = pPgsqlConn->GetFieldName(i); //pPgsqlConn->field_name[i].c_str(); |
| @@ -60,7 +69,7 @@ namespace mapserver | @@ -60,7 +69,7 @@ namespace mapserver | ||
| 60 | if (strncmp(sfieldName, "RN_RN", 5) == 0) | 69 | if (strncmp(sfieldName, "RN_RN", 5) == 0) |
| 61 | continue; | 70 | continue; |
| 62 | std::string strFieldName = sfieldName; | 71 | std::string strFieldName = sfieldName; |
| 63 | - //DmapDll::StringHelp::ToXMLString(strFieldName); | 72 | + //DmapDll::StringHelp::ToXMLString(strFieldName); |
| 64 | 73 | ||
| 65 | if (strFieldName == "geometry_as_gml") | 74 | if (strFieldName == "geometry_as_gml") |
| 66 | { | 75 | { |
| @@ -77,8 +86,6 @@ namespace mapserver | @@ -77,8 +86,6 @@ namespace mapserver | ||
| 77 | responseData.append(buff); | 86 | responseData.append(buff); |
| 78 | } | 87 | } |
| 79 | } | 88 | } |
| 80 | - //tickAA=GetTickCount(); | ||
| 81 | - | ||
| 82 | sprintf(buff, "</gims:%s>\r", layerName.c_str()); | 89 | sprintf(buff, "</gims:%s>\r", layerName.c_str()); |
| 83 | responseData.append(buff); | 90 | responseData.append(buff); |
| 84 | responseData.append("</gims:featureMember>"); | 91 | responseData.append("</gims:featureMember>"); |
| @@ -88,17 +95,11 @@ namespace mapserver | @@ -88,17 +95,11 @@ namespace mapserver | ||
| 88 | 95 | ||
| 89 | if (pointCountTemp > 2000) | 96 | if (pointCountTemp > 2000) |
| 90 | break; | 97 | break; |
| 91 | - //Sleep(5000); | ||
| 92 | - // break; | ||
| 93 | } | 98 | } |
| 94 | } | 99 | } |
| 95 | catch (...) | 100 | catch (...) |
| 96 | { | 101 | { |
| 97 | } | 102 | } |
| 98 | - | ||
| 99 | - //sprintf(buff, "numberMatched=\"%ld\" numberReturned=\"%ld\" ", count, count); | ||
| 100 | - //responseData.append(insertBuf, sql, strlen(sql)); | ||
| 101 | - | ||
| 102 | responseData.append("</wfs:FeatureCollection>"); | 103 | responseData.append("</wfs:FeatureCollection>"); |
| 103 | 104 | ||
| 104 | return; | 105 | return; |
| @@ -148,10 +149,17 @@ namespace mapserver | @@ -148,10 +149,17 @@ namespace mapserver | ||
| 148 | geometry = pPgsqlConn->getString(i); | 149 | geometry = pPgsqlConn->getString(i); |
| 149 | continue; | 150 | continue; |
| 150 | } | 151 | } |
| 152 | + else if(strFieldName == "geometry_as_wkb") | ||
| 153 | + { | ||
| 154 | + DmpGeometry dmpgeometry; | ||
| 155 | + geometry = dmpgeometry.geoJsonfromWKB(pPgsqlConn->getString(i)); | ||
| 156 | + continue; | ||
| 157 | + } | ||
| 151 | else | 158 | else |
| 152 | { | 159 | { |
| 153 | - const char *v = pPgsqlConn->getString(i); | ||
| 154 | - std::sprintf(buff, R"(,"%s":"%s")", sfieldName, v); | 160 | + string value = pPgsqlConn->getString(i); |
| 161 | + DmpMapServerUtil::toJsonString(value); | ||
| 162 | + std::sprintf(buff, R"(,"%s":"%s")", sfieldName, value.c_str()); | ||
| 155 | properties += buff; | 163 | properties += buff; |
| 156 | } | 164 | } |
| 157 | } | 165 | } |
| @@ -518,7 +526,7 @@ namespace mapserver | @@ -518,7 +526,7 @@ namespace mapserver | ||
| 518 | 526 | ||
| 519 | for (i = 0; i < strlen(cd); i++) | 527 | for (i = 0; i < strlen(cd); i++) |
| 520 | { | 528 | { |
| 521 | - memset(p, '/0', 2); | 529 | + memset(p, '\0', 2); |
| 522 | if (cd[i] != '%') | 530 | if (cd[i] != '%') |
| 523 | { | 531 | { |
| 524 | decd[j++] = cd[i]; | 532 | decd[j++] = cd[i]; |
| @@ -532,7 +540,7 @@ namespace mapserver | @@ -532,7 +540,7 @@ namespace mapserver | ||
| 532 | p[1] = p[1] - 48 - ((p[1] >= 'A') ? 7 : 0) - ((p[1] >= 'a') ? 32 : 0); | 540 | p[1] = p[1] - 48 - ((p[1] >= 'A') ? 7 : 0) - ((p[1] >= 'a') ? 32 : 0); |
| 533 | decd[j++] = (unsigned char)(p[0] * 16 + p[1]); | 541 | decd[j++] = (unsigned char)(p[0] * 16 + p[1]); |
| 534 | } | 542 | } |
| 535 | - decd[j] = '/0'; | 543 | + decd[j] = '\0'; |
| 536 | 544 | ||
| 537 | return decd; | 545 | return decd; |
| 538 | } | 546 | } |
| @@ -13,13 +13,16 @@ | @@ -13,13 +13,16 @@ | ||
| 13 | #include <string> | 13 | #include <string> |
| 14 | #include <memory> | 14 | #include <memory> |
| 15 | #include "dmppgsqlsourcepools.h" | 15 | #include "dmppgsqlsourcepools.h" |
| 16 | - | 16 | +#include "dmpproject.h" |
| 17 | +#include "dmpvectorlayer.h" | ||
| 17 | 18 | ||
| 18 | namespace mapserver | 19 | namespace mapserver |
| 19 | { | 20 | { |
| 20 | class DmpMapServerUtil | 21 | class DmpMapServerUtil |
| 21 | { | 22 | { |
| 22 | public: | 23 | public: |
| 24 | + static void initVectorLayerSrid(shared_ptr<DmpPgsql> pPgsqlConn,DmpVectorLayer* layer); | ||
| 25 | + | ||
| 23 | static void responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); | 26 | static void responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); |
| 24 | static void responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); | 27 | static void responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); |
| 25 | static void toXmlString(std::string &s); | 28 | static void toXmlString(std::string &s); |
| @@ -454,9 +454,14 @@ namespace mapserver | @@ -454,9 +454,14 @@ namespace mapserver | ||
| 454 | 454 | ||
| 455 | bool DmpPgsqlSourcePools::AddDatabasePool(string guid) | 455 | bool DmpPgsqlSourcePools::AddDatabasePool(string guid) |
| 456 | { | 456 | { |
| 457 | - if (guid.find(" ") != string::npos && guid.size() > 50) | 457 | + if (guid.find(" ") != string::npos || guid.size() > 100) |
| 458 | { | 458 | { |
| 459 | - std::string connStr = guid; | 459 | + std::string connStr = guid; |
| 460 | + if(connStr.find(" ") == string::npos) | ||
| 461 | + { | ||
| 462 | + connStr = DmpServerDes::DesBase64Decrypt(connStr, "Chinadci"); | ||
| 463 | + } | ||
| 464 | + | ||
| 460 | shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool(guid,guid,guid)); | 465 | shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool(guid,guid,guid)); |
| 461 | newPool->Connect(connStr.c_str()); | 466 | newPool->Connect(connStr.c_str()); |
| 462 | //newPool->Connect("PostgreSQLConn=hostaddr=172.26.99.173 port=5433 dbname='postgres' user='postgres' password='chinadci'"); | 467 | //newPool->Connect("PostgreSQLConn=hostaddr=172.26.99.173 port=5433 dbname='postgres' user='postgres' password='chinadci'"); |
| @@ -48,8 +48,8 @@ namespace DmpMapping | @@ -48,8 +48,8 @@ namespace DmpMapping | ||
| 48 | 48 | ||
| 49 | std::string guid = pt.get<std::string>("guid"); | 49 | std::string guid = pt.get<std::string>("guid"); |
| 50 | 50 | ||
| 51 | - DmpProject* project = (DmpProject*)context.serverProject()->project(); | ||
| 52 | - std::string projectData = project->WriteXml(); | 51 | + DmpProject* projectold = (DmpProject*)context.serverProject()->project(); |
| 52 | + std::string projectData = projectold->WriteXml(); | ||
| 53 | // printf("%s\r\n",projectData.c_str()); | 53 | // printf("%s\r\n",projectData.c_str()); |
| 54 | if(!guid.empty() && !projectData.empty()) | 54 | if(!guid.empty() && !projectData.empty()) |
| 55 | { | 55 | { |
| @@ -60,6 +60,9 @@ namespace DmpMapping | @@ -60,6 +60,9 @@ namespace DmpMapping | ||
| 60 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"加载DMD符号化失败!\"}"); | 60 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"加载DMD符号化失败!\"}"); |
| 61 | return false; | 61 | return false; |
| 62 | } | 62 | } |
| 63 | + | ||
| 64 | + project->initVectorLayerVacuate(projectold); | ||
| 65 | + | ||
| 63 | vectorMappingProjects[guid] = project; | 66 | vectorMappingProjects[guid] = project; |
| 64 | 67 | ||
| 65 | // int i = 0; | 68 | // int i = 0; |
| @@ -137,7 +140,7 @@ namespace DmpMapping | @@ -137,7 +140,7 @@ namespace DmpMapping | ||
| 137 | bool loadProjectService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) | 140 | bool loadProjectService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) |
| 138 | { | 141 | { |
| 139 | const char *data = (char *)(context.request()->GetData()); | 142 | const char *data = (char *)(context.request()->GetData()); |
| 140 | - if(data== nullptr || *data == '\0') | 143 | + if(data== nullptr || *data == '\0' || context.request()->method() != DmpServerRequest::Method::POST_METHOD) |
| 141 | { | 144 | { |
| 142 | LOGGER_ERROR("post 参数错误"); | 145 | LOGGER_ERROR("post 参数错误"); |
| 143 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); | 146 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); |
| @@ -166,31 +169,36 @@ namespace DmpMapping | @@ -166,31 +169,36 @@ namespace DmpMapping | ||
| 166 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); | 169 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); |
| 167 | return false; | 170 | return false; |
| 168 | } | 171 | } |
| 169 | - vectorMappingProjects[guid] = project; | ||
| 170 | - | ||
| 171 | - double minx, miny, maxx, maxy; | ||
| 172 | - std::vector<DmpMapLayer *> vectorLayers = project->vectorLayers(); | ||
| 173 | - for (size_t i = 0; i < vectorLayers.size(); i++) | ||
| 174 | - { | ||
| 175 | - DmpMapLayer *layer = vectorLayers[i]; | ||
| 176 | - if (i == 0) | ||
| 177 | - { | ||
| 178 | - minx = layer->extent().xmin(); | ||
| 179 | - miny = layer->extent().ymin(); | ||
| 180 | - maxx = layer->extent().xmax(); | ||
| 181 | - maxy = layer->extent().ymax(); | ||
| 182 | - } | ||
| 183 | - else | 172 | + project->initVectorLayerVacuate([](const std::string &tableguid) |
| 173 | + { | ||
| 174 | + return DmpServerConfig::Instance()->HttpGet( DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); | ||
| 175 | + }); | ||
| 176 | + | ||
| 177 | + vectorMappingProjects[guid] = project; | ||
| 178 | + | ||
| 179 | + double minx, miny, maxx, maxy; | ||
| 180 | + std::vector<DmpMapLayer *> vectorLayers = project->vectorLayers(); | ||
| 181 | + for (size_t i = 0; i < vectorLayers.size(); i++) | ||
| 184 | { | 182 | { |
| 185 | - if (minx > layer->extent().xmin()) | 183 | + DmpMapLayer *layer = vectorLayers[i]; |
| 184 | + if (i == 0) | ||
| 185 | + { | ||
| 186 | minx = layer->extent().xmin(); | 186 | minx = layer->extent().xmin(); |
| 187 | - if (miny > layer->extent().ymin()) | ||
| 188 | miny = layer->extent().ymin(); | 187 | miny = layer->extent().ymin(); |
| 189 | - if (maxx < layer->extent().xmax()) | ||
| 190 | maxx = layer->extent().xmax(); | 188 | maxx = layer->extent().xmax(); |
| 191 | - if (maxy < layer->extent().ymax()) | ||
| 192 | maxy = layer->extent().ymax(); | 189 | maxy = layer->extent().ymax(); |
| 193 | - } | 190 | + } |
| 191 | + else | ||
| 192 | + { | ||
| 193 | + if (minx > layer->extent().xmin()) | ||
| 194 | + minx = layer->extent().xmin(); | ||
| 195 | + if (miny > layer->extent().ymin()) | ||
| 196 | + miny = layer->extent().ymin(); | ||
| 197 | + if (maxx < layer->extent().xmax()) | ||
| 198 | + maxx = layer->extent().xmax(); | ||
| 199 | + if (maxy < layer->extent().ymax()) | ||
| 200 | + maxy = layer->extent().ymax(); | ||
| 201 | + } | ||
| 194 | } | 202 | } |
| 195 | 203 | ||
| 196 | char buff[250]; | 204 | char buff[250]; |
| @@ -242,7 +250,7 @@ namespace DmpMapping | @@ -242,7 +250,7 @@ namespace DmpMapping | ||
| 242 | bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) | 250 | bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) |
| 243 | { | 251 | { |
| 244 | const char *data = (char *)(context.request()->GetData()); | 252 | const char *data = (char *)(context.request()->GetData()); |
| 245 | - if(data== nullptr || *data == '\0') | 253 | + if(data== nullptr || *data == '\0' || context.request()->method() != DmpServerRequest::Method::POST_METHOD) |
| 246 | { | 254 | { |
| 247 | LOGGER_ERROR("post 参数错误"); | 255 | LOGGER_ERROR("post 参数错误"); |
| 248 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); | 256 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); |
| @@ -271,6 +279,10 @@ namespace DmpMapping | @@ -271,6 +279,10 @@ namespace DmpMapping | ||
| 271 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); | 279 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); |
| 272 | return false; | 280 | return false; |
| 273 | } | 281 | } |
| 282 | + project->initVectorLayerVacuate([](const std::string &tableguid) | ||
| 283 | + { | ||
| 284 | + return DmpServerConfig::Instance()->HttpGet(DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); | ||
| 285 | + }); | ||
| 274 | vectorMappingProjects[guid] = project; | 286 | vectorMappingProjects[guid] = project; |
| 275 | context.response()->writeJson("{\"status\":\"true\",\"message\":\"创建编辑服务工作空间成功!\"}"); | 287 | context.response()->writeJson("{\"status\":\"true\",\"message\":\"创建编辑服务工作空间成功!\"}"); |
| 276 | return true; | 288 | return true; |
| @@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
| 15 | #include "dmpproject.h" | 15 | #include "dmpproject.h" |
| 16 | #include "dmpservercontext.h" | 16 | #include "dmpservercontext.h" |
| 17 | #include "dmppgsqlsourcepools.h" | 17 | #include "dmppgsqlsourcepools.h" |
| 18 | +#include "dmpservermanager.h" | ||
| 18 | 19 | ||
| 19 | namespace DmpMapping | 20 | namespace DmpMapping |
| 20 | { | 21 | { |
| @@ -19,7 +19,6 @@ | @@ -19,7 +19,6 @@ | ||
| 19 | #include "../wms/dmpwmsgetmap.h" | 19 | #include "../wms/dmpwmsgetmap.h" |
| 20 | #include "../wms/dmpwmsparameters.h" | 20 | #include "../wms/dmpwmsparameters.h" |
| 21 | #include "dmpmapping.h" | 21 | #include "dmpmapping.h" |
| 22 | -#include "dmpmappingparameters.h" | ||
| 23 | #include "dmpimageinfo.h" | 22 | #include "dmpimageinfo.h" |
| 24 | 23 | ||
| 25 | using namespace std; | 24 | using namespace std; |
| @@ -71,19 +70,38 @@ namespace DmpMapping | @@ -71,19 +70,38 @@ namespace DmpMapping | ||
| 71 | getImage(context); | 70 | getImage(context); |
| 72 | } | 71 | } |
| 73 | else if(boost::iequals(request, "getmaplog")){ | 72 | else if(boost::iequals(request, "getmaplog")){ |
| 74 | - const std::string mapGuid = params.MapGuid(); | 73 | + getmaplog(context,params); |
| 74 | + } | ||
| 75 | + else if (boost::iequals(request, "getmap")) | ||
| 76 | + { | ||
| 77 | + getmap(context,params); | ||
| 78 | + } | ||
| 79 | + else | ||
| 80 | + { | ||
| 81 | + std::string responseData = "{\"result\":\"false\",\"message\":\"配图服务未实现" + request + "接口\"}"; | ||
| 82 | + context.response()->writeJson(responseData); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + bool DmpMappingService::getmaplog(const DmpServerContext &context,const DmpMappingParameters& params) | ||
| 88 | + { | ||
| 89 | + const std::string mapGuid = params.MapGuid(); | ||
| 75 | if (vectorMappingProjects_.find(mapGuid) != vectorMappingProjects_.end()) | 90 | if (vectorMappingProjects_.find(mapGuid) != vectorMappingProjects_.end()) |
| 76 | { | 91 | { |
| 77 | shared_ptr<DmpProject> project = vectorMappingProjects_.find(mapGuid)->second; | 92 | shared_ptr<DmpProject> project = vectorMappingProjects_.find(mapGuid)->second; |
| 78 | const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); | 93 | const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); |
| 79 | DmpWms::writeGetMapLog(context, wmsParams, project.get()); | 94 | DmpWms::writeGetMapLog(context, wmsParams, project.get()); |
| 95 | + return true; | ||
| 80 | } | 96 | } |
| 81 | else | 97 | else |
| 82 | { | 98 | { |
| 83 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"未找到服务\"}"); | 99 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"未找到服务\"}"); |
| 100 | + return false; | ||
| 84 | } | 101 | } |
| 85 | } | 102 | } |
| 86 | - else if (boost::iequals(request, "getmap")) | 103 | + |
| 104 | + bool DmpMappingService::getmap(const DmpServerContext &context,const DmpMappingParameters& params) | ||
| 87 | { | 105 | { |
| 88 | const std::string mapGuid = params.MapGuid(); | 106 | const std::string mapGuid = params.MapGuid(); |
| 89 | if (vectorMappingProjects_.find(mapGuid) != vectorMappingProjects_.end()) | 107 | if (vectorMappingProjects_.find(mapGuid) != vectorMappingProjects_.end()) |
| @@ -91,6 +109,7 @@ namespace DmpMapping | @@ -91,6 +109,7 @@ namespace DmpMapping | ||
| 91 | shared_ptr<DmpProject> project = vectorMappingProjects_.find(mapGuid)->second; | 109 | shared_ptr<DmpProject> project = vectorMappingProjects_.find(mapGuid)->second; |
| 92 | const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); | 110 | const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); |
| 93 | DmpWms::writeGetMap(context, wmsParams, project.get()); | 111 | DmpWms::writeGetMap(context, wmsParams, project.get()); |
| 112 | + return true; | ||
| 94 | } | 113 | } |
| 95 | else | 114 | else |
| 96 | { | 115 | { |
| @@ -114,27 +133,31 @@ namespace DmpMapping | @@ -114,27 +133,31 @@ namespace DmpMapping | ||
| 114 | if (!DmpServerUtils::Base64Decode(mapRenderer, &projData)) | 133 | if (!DmpServerUtils::Base64Decode(mapRenderer, &projData)) |
| 115 | { | 134 | { |
| 116 | context.response()->writeJson("{\"status\":\"false\",\"message\":\""+ mapRenderer +" base64转码错误\"}"); | 135 | context.response()->writeJson("{\"status\":\"false\",\"message\":\""+ mapRenderer +" base64转码错误\"}"); |
| 117 | - return; | 136 | + return false; |
| 118 | } | 137 | } |
| 119 | shared_ptr<DmpProject> project(new DmpProject()); | 138 | shared_ptr<DmpProject> project(new DmpProject()); |
| 120 | if (!project->Read(projData)) | 139 | if (!project->Read(projData)) |
| 121 | { | 140 | { |
| 122 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); | 141 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); |
| 123 | - return; | 142 | + return false; |
| 124 | } | 143 | } |
| 144 | + project->initVectorLayerVacuate([](const std::string &tableguid) | ||
| 145 | + { | ||
| 146 | + return DmpServerConfig::Instance()->HttpGet( DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); | ||
| 147 | + }); | ||
| 125 | const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); | 148 | const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); |
| 126 | DmpWms::writeGetMap(context, wmsParams, project.get()); | 149 | DmpWms::writeGetMap(context, wmsParams, project.get()); |
| 127 | if(!mapGuid.empty()) | 150 | if(!mapGuid.empty()) |
| 128 | { | 151 | { |
| 129 | vectorMappingProjects_[mapGuid] = project; | 152 | vectorMappingProjects_[mapGuid] = project; |
| 130 | } | 153 | } |
| 131 | - return; | 154 | + return true; |
| 132 | } | 155 | } |
| 133 | } | 156 | } |
| 134 | } | 157 | } |
| 158 | + | ||
| 159 | + return false; | ||
| 135 | } | 160 | } |
| 136 | - | ||
| 137 | - } | ||
| 138 | 161 | ||
| 139 | 162 | ||
| 140 | 163 |
| @@ -10,11 +10,13 @@ | @@ -10,11 +10,13 @@ | ||
| 10 | #define __dmpmapping_h__ | 10 | #define __dmpmapping_h__ |
| 11 | #include <string> | 11 | #include <string> |
| 12 | #include <string> | 12 | #include <string> |
| 13 | -#include "dmpeditservice.h" | ||
| 14 | -#include "dmpservice.h" | ||
| 15 | #include <boost/thread/shared_mutex.hpp> | 13 | #include <boost/thread/shared_mutex.hpp> |
| 16 | #include <boost/thread.hpp> | 14 | #include <boost/thread.hpp> |
| 17 | 15 | ||
| 16 | +#include "dmpeditservice.h" | ||
| 17 | +#include "dmpservice.h" | ||
| 18 | +#include "dmpmappingparameters.h" | ||
| 19 | + | ||
| 18 | typedef boost::shared_mutex rwmutex; | 20 | typedef boost::shared_mutex rwmutex; |
| 19 | typedef boost::shared_lock<rwmutex> readLock; | 21 | typedef boost::shared_lock<rwmutex> readLock; |
| 20 | typedef boost::unique_lock<rwmutex> writeLock; | 22 | typedef boost::unique_lock<rwmutex> writeLock; |
| @@ -31,6 +33,9 @@ namespace DmpMapping | @@ -31,6 +33,9 @@ namespace DmpMapping | ||
| 31 | bool allowMethod(DmpServerRequest::Method method) const override { return method == DmpServerRequest::GET_METHOD; } | 33 | bool allowMethod(DmpServerRequest::Method method) const override { return method == DmpServerRequest::GET_METHOD; } |
| 32 | void executeRequest(const DmpServerContext &context) override; | 34 | void executeRequest(const DmpServerContext &context) override; |
| 33 | private: | 35 | private: |
| 36 | + bool getmaplog(const DmpServerContext &context,const DmpMappingParameters& params); | ||
| 37 | + bool getmap(const DmpServerContext &context, const DmpMappingParameters& params); | ||
| 38 | + private: | ||
| 34 | 39 | ||
| 35 | //存储工程文档实例 | 40 | //存储工程文档实例 |
| 36 | ProjectMap vectorMappingProjects_; | 41 | ProjectMap vectorMappingProjects_; |
| @@ -56,6 +56,11 @@ namespace DmpWfs | @@ -56,6 +56,11 @@ namespace DmpWfs | ||
| 56 | { | 56 | { |
| 57 | writeGetFeature(context,params, project); | 57 | writeGetFeature(context,params, project); |
| 58 | } | 58 | } |
| 59 | + else | ||
| 60 | + { | ||
| 61 | + std::string responseData = "{\"result\":\"false\",\"message\":\"WFS 未实现" + request + "接口\"}"; | ||
| 62 | + context.response()->writeJson(responseData); | ||
| 63 | + } | ||
| 59 | } | 64 | } |
| 60 | } | 65 | } |
| 61 | 66 |
| @@ -23,7 +23,31 @@ namespace DmpWfs | @@ -23,7 +23,31 @@ namespace DmpWfs | ||
| 23 | const DmpProject *project, | 23 | const DmpProject *project, |
| 24 | bool projectSettings) | 24 | bool projectSettings) |
| 25 | { | 25 | { |
| 26 | - WfsGetFeature(context, params, project, projectSettings); | 26 | + std::string errorinfo = WfsGetFeature(context, params, project, projectSettings); |
| 27 | + if(!errorinfo.empty()) | ||
| 28 | + { | ||
| 29 | + DmpWfsParameters::Format resultType = params.ResultType(); | ||
| 30 | + if (resultType == DmpWfsParameters::Format::GeoJson) | ||
| 31 | + { | ||
| 32 | + std::string responseData; | ||
| 33 | + responseData = "{\"result\":\"false\",\"message\":\"" + errorinfo + "\"}"; | ||
| 34 | + context.response()->writeJson(responseData); | ||
| 35 | + } | ||
| 36 | + else | ||
| 37 | + { | ||
| 38 | + boost::property_tree::ptree ptreeDoc; | ||
| 39 | + boost::property_tree::ptree ptreeRoot; | ||
| 40 | + ptreeRoot.add<bool>("result", false); | ||
| 41 | + ptreeRoot.add<std::string>("message", errorinfo); | ||
| 42 | + ptreeDoc.add_child("WfsGetfeatureResponse",ptreeRoot); | ||
| 43 | + std::stringstream stream; | ||
| 44 | + write_xml(stream, ptreeDoc); | ||
| 45 | + std::string responseData = stream.str(); | ||
| 46 | + context.response()->removeHeader("Content-Type"); | ||
| 47 | + context.response()->setHeader("Content-Type", "text/xml;charset=utf-8"); | ||
| 48 | + context.response()->write(responseData); | ||
| 49 | + } | ||
| 50 | + } | ||
| 27 | } | 51 | } |
| 28 | 52 | ||
| 29 | std::string WfsGetFeature(const DmpServerContext &context, const DmpWfsParameters ¶ms, | 53 | std::string WfsGetFeature(const DmpServerContext &context, const DmpWfsParameters ¶ms, |
| @@ -287,7 +311,7 @@ namespace DmpWfs | @@ -287,7 +311,7 @@ namespace DmpWfs | ||
| 287 | typeInt = PGFieldType::ShapeFieldType; | 311 | typeInt = PGFieldType::ShapeFieldType; |
| 288 | if (format == DmpWfsParameters::Format::GeoJson) | 312 | if (format == DmpWfsParameters::Format::GeoJson) |
| 289 | { | 313 | { |
| 290 | - fields_str += " st_asgeojson(\"" + (fieldname) + "\") as geometry_as_geojson"; | 314 | + fields_str += " \"" + (fieldname) + "\" as geometry_as_wkb"; |
| 291 | } | 315 | } |
| 292 | else | 316 | else |
| 293 | { | 317 | { |
| 1 | -/************************************************************************** | ||
| 2 | -* file: dmpprint.cpp | ||
| 3 | - | ||
| 4 | -* Author: qingxiongf | ||
| 5 | -* Date: 2022-01-20 18:50:40 | ||
| 6 | -* Email: qingxiongf@chinadci.com | ||
| 7 | -* copyright: 广州城市信息研究所有限公司 | ||
| 8 | -***************************************************************************/ | ||
| 9 | -#include "dmpprint.h" | ||
| 10 | - |
| @@ -21,6 +21,7 @@ | @@ -21,6 +21,7 @@ | ||
| 21 | #include "dmpwmsgetmap.h" | 21 | #include "dmpwmsgetmap.h" |
| 22 | #include "dmpwmsserviceinfo.h" | 22 | #include "dmpwmsserviceinfo.h" |
| 23 | #include "dmpwmsgetfeatureinfo.h" | 23 | #include "dmpwmsgetfeatureinfo.h" |
| 24 | +#include "dmpwmsgetprint.h" | ||
| 24 | using namespace std; | 25 | using namespace std; |
| 25 | 26 | ||
| 26 | namespace DmpWms | 27 | namespace DmpWms |
| @@ -40,6 +41,7 @@ namespace DmpWms | @@ -40,6 +41,7 @@ namespace DmpWms | ||
| 40 | const DmpWmsParameters params(context.request()->serverParameters()); | 41 | const DmpWmsParameters params(context.request()->serverParameters()); |
| 41 | const DmpProject* project = context.serverProject()->project(); | 42 | const DmpProject* project = context.serverProject()->project(); |
| 42 | const std::string request = params.Request(); | 43 | const std::string request = params.Request(); |
| 44 | + // printf("%s\r\n", request.c_str()); | ||
| 43 | if (request.empty()) | 45 | if (request.empty()) |
| 44 | { | 46 | { |
| 45 | context.response()->writeHtml("wms,Operation is null"); | 47 | context.response()->writeHtml("wms,Operation is null"); |
| @@ -66,12 +68,21 @@ namespace DmpWms | @@ -66,12 +68,21 @@ namespace DmpWms | ||
| 66 | } | 68 | } |
| 67 | else if(boost::iequals(request, "getserviceinfo")) | 69 | else if(boost::iequals(request, "getserviceinfo")) |
| 68 | { | 70 | { |
| 69 | - writeGetServiceInfo(context,params, project); | 71 | + writeGetServiceInfo(context,params, project); |
| 70 | } | 72 | } |
| 71 | - else if(request == "getlegendgraphic") | 73 | + else if(boost::iequals(request, "getlegendgraphic")) |
| 72 | { | 74 | { |
| 73 | 75 | ||
| 74 | } | 76 | } |
| 77 | + else if(boost::iequals(request, "getprint")) | ||
| 78 | + { | ||
| 79 | + writeGetPrint(context,params, project); | ||
| 80 | + } | ||
| 81 | + else | ||
| 82 | + { | ||
| 83 | + std::string responseData = "{\"result\":\"false\",\"message\":\"WMS 未实现" + request + "接口\"}"; | ||
| 84 | + context.response()->writeJson(responseData); | ||
| 85 | + } | ||
| 75 | } | 86 | } |
| 76 | } | 87 | } |
| 77 | 88 |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpwmsgetprint.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-02-10 14:18:07 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpwmsgetprint.h" | ||
| 10 | +#include "print/dmpmapprint.h" | ||
| 11 | +#include "dmpwmsrenderer.h" | ||
| 12 | +#include "dmpserverresponse.h" | ||
| 13 | +#include "dmpserverrequest.h" | ||
| 14 | +#include "dmpserverproject.h" | ||
| 15 | +#include <map> | ||
| 16 | +#include <memory> | ||
| 17 | +namespace DmpWms | ||
| 18 | +{ | ||
| 19 | + void writeGetPrint(const DmpServerContext &context,const DmpWmsParameters& params, | ||
| 20 | + const DmpProject* project, | ||
| 21 | + bool projectSettings ) | ||
| 22 | + { | ||
| 23 | + DmpWmsParameters::Format outformat = params.ResFormat(); | ||
| 24 | + DmpMapPrint mapPrint(outformat); | ||
| 25 | + | ||
| 26 | + std::string responseData; | ||
| 27 | + | ||
| 28 | + std::string name = context.serverProject()->name(); | ||
| 29 | + std::string title = context.serverProject()->title(); | ||
| 30 | + std::string boxx = params.BBox(); | ||
| 31 | + std::string printTemp = params.printTemp(); | ||
| 32 | + std::string printPara = params.printPara(); | ||
| 33 | + | ||
| 34 | + if(mapPrint.getPrintTempFile(responseData,project,printTemp.c_str(),boxx.c_str(),printPara.c_str())) | ||
| 35 | + { | ||
| 36 | + if(outformat == DmpWmsParameters::Format::PDF) | ||
| 37 | + { | ||
| 38 | + context.response()->setHeader("Content-Type", "application/pdf"); | ||
| 39 | + } | ||
| 40 | + else if(outformat == DmpWmsParameters::Format::SVG) | ||
| 41 | + { | ||
| 42 | + context.response()->setHeader("Content-Type", "image/svg"); | ||
| 43 | + } | ||
| 44 | + else | ||
| 45 | + { | ||
| 46 | + context.response()->setHeader("Content-Type", "image/png"); | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + else | ||
| 50 | + { | ||
| 51 | + context.response()->setHeader("Content-Type", "text/xml"); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + context.response()->write(responseData); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + void writeGetPrintParaList(const DmpServerContext &context,const DmpWmsParameters& params, | ||
| 58 | + const DmpProject* project, | ||
| 59 | + bool projectSettings) | ||
| 60 | + { | ||
| 61 | + | ||
| 62 | + } | ||
| 63 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpwmsgetprint.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-02-10 14:17:58 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __dmpwmsgetprint_h__ | ||
| 11 | +#define __dmpwmsgetprint_h__ | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +#include <boost/property_tree/ptree.hpp> | ||
| 15 | +#include <boost/property_tree/xml_parser.hpp> | ||
| 16 | +#include <boost/typeof/typeof.hpp> | ||
| 17 | +#include <memory> | ||
| 18 | +#include <vector> | ||
| 19 | +#include "dmpproject.h" | ||
| 20 | +#include "dmpwmsparameters.h" | ||
| 21 | +#include "dmpservercontext.h" | ||
| 22 | + | ||
| 23 | +namespace DmpWms | ||
| 24 | +{ | ||
| 25 | + void writeGetPrint(const DmpServerContext &context,const DmpWmsParameters& params, | ||
| 26 | + const DmpProject* project, | ||
| 27 | + bool projectSettings = false ); | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +#endif // __dmpwmsgetprint_h__ |
| @@ -169,6 +169,20 @@ namespace DmpWms | @@ -169,6 +169,20 @@ namespace DmpWms | ||
| 169 | return value; | 169 | return value; |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | + std::string DmpWmsParameters::printTemp() const | ||
| 173 | + { | ||
| 174 | + std::string value = ""; | ||
| 175 | + GetStringParameter("PRINTTEMP",value); | ||
| 176 | + return value; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + std::string DmpWmsParameters::printPara() const | ||
| 180 | + { | ||
| 181 | + std::string value = ""; | ||
| 182 | + GetStringParameter("PRINTPARA",value); | ||
| 183 | + return value; | ||
| 184 | + } | ||
| 185 | + | ||
| 172 | DmpWmsParameters::Format DmpWmsParameters::InfoFormat() const | 186 | DmpWmsParameters::Format DmpWmsParameters::InfoFormat() const |
| 173 | { | 187 | { |
| 174 | std::string value = ""; | 188 | std::string value = ""; |
| @@ -241,6 +255,16 @@ namespace DmpWms | @@ -241,6 +255,16 @@ namespace DmpWms | ||
| 241 | if (frm.compare("jpg") == 0 || frm.compare("jpeg") == 0 || frm.compare("image/jpeg") == 0 ) { | 255 | if (frm.compare("jpg") == 0 || frm.compare("jpeg") == 0 || frm.compare("image/jpeg") == 0 ) { |
| 242 | f = DmpWmsParameters::Format::JPG; | 256 | f = DmpWmsParameters::Format::JPG; |
| 243 | } | 257 | } |
| 258 | + else if(frm.compare("pdf") == 0){ | ||
| 259 | + f = DmpWmsParameters::Format::PDF; | ||
| 260 | + }else if(frm.compare("svg") == 0){ | ||
| 261 | + f = DmpWmsParameters::Format::SVG; | ||
| 262 | + }else if(frm.compare("xml") == 0 || frm.compare("gml") == 0){ | ||
| 263 | + f = DmpWmsParameters::Format::GML; | ||
| 264 | + }else if(frm.compare("json") == 0 || frm.compare("geojson") == 0){ | ||
| 265 | + f = DmpWmsParameters::Format::GeoJson; | ||
| 266 | + } | ||
| 267 | + | ||
| 244 | return f; | 268 | return f; |
| 245 | } | 269 | } |
| 246 | return DmpWmsParameters::Format::NONE; | 270 | return DmpWmsParameters::Format::NONE; |
| @@ -25,7 +25,9 @@ namespace DmpWms | @@ -25,7 +25,9 @@ namespace DmpWms | ||
| 25 | XML, | 25 | XML, |
| 26 | HTML, | 26 | HTML, |
| 27 | GML, | 27 | GML, |
| 28 | - GeoJson | 28 | + GeoJson, |
| 29 | + PDF, | ||
| 30 | + SVG | ||
| 29 | }; | 31 | }; |
| 30 | DmpWmsParameters(const DmpServerParameters ¶meters); | 32 | DmpWmsParameters(const DmpServerParameters ¶meters); |
| 31 | DmpWmsParameters(); | 33 | DmpWmsParameters(); |
| @@ -59,6 +61,10 @@ namespace DmpWms | @@ -59,6 +61,10 @@ namespace DmpWms | ||
| 59 | int Y() const; //地图上查询点的Y坐标,以像素为单位。0是左侧。j是WMS 1.3.0中使用的参数键。 | 61 | int Y() const; //地图上查询点的Y坐标,以像素为单位。0是左侧。j是WMS 1.3.0中使用的参数键。 |
| 60 | 62 | ||
| 61 | DmpWmsParameters::Format ResFormat() const; //GetMap URL为Format GetFeatureInfo url为:info_format | 63 | DmpWmsParameters::Format ResFormat() const; //GetMap URL为Format GetFeatureInfo url为:info_format |
| 64 | + | ||
| 65 | + std::string printTemp() const; | ||
| 66 | + | ||
| 67 | + std::string printPara() const; | ||
| 62 | private: | 68 | private: |
| 63 | bool GetStringParameter(const char* key, std::string &value) const; | 69 | bool GetStringParameter(const char* key, std::string &value) const; |
| 64 | bool GetIntParameter(const char* key, int& value) const; | 70 | bool GetIntParameter(const char* key, int& value) const; |
| @@ -149,11 +149,11 @@ namespace DmpWms | @@ -149,11 +149,11 @@ namespace DmpWms | ||
| 149 | 149 | ||
| 150 | string tableName = layer->name(); //layer->name(); | 150 | string tableName = layer->name(); //layer->name(); |
| 151 | string shapeName = layer->geom(); | 151 | string shapeName = layer->geom(); |
| 152 | - shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR); | 152 | + shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer = layer->GetCurrentScaleTable(1 / this->m_dR); |
| 153 | 153 | ||
| 154 | - if (pVectorThinLayer != nullptr) | 154 | + if (pVectorVacuateLayer != nullptr) |
| 155 | { | 155 | { |
| 156 | - tableName = pVectorThinLayer->tableName(); | 156 | + tableName = pVectorVacuateLayer->tableName(); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName | 159 | ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName |
| @@ -173,6 +173,25 @@ namespace DmpWms | @@ -173,6 +173,25 @@ namespace DmpWms | ||
| 173 | //ss += " limit 40000 "; | 173 | //ss += " limit 40000 "; |
| 174 | 174 | ||
| 175 | double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft; | 175 | double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft; |
| 176 | + //点 标注 避免被截取 | ||
| 177 | + if(layer->GeometryType() == DmpWkbTypes::GeometryType::PointGeometry) | ||
| 178 | + { | ||
| 179 | + double drh = (pRect->m_dTop - pRect->m_dBottom)/this->m_dHeight; | ||
| 180 | + double drw = (pRect->m_dRight - pRect->m_dLeft)/this->m_dWidth; | ||
| 181 | + t = t + drh * 15; | ||
| 182 | + b = b - drh * 15; | ||
| 183 | + if(length > 0) | ||
| 184 | + { | ||
| 185 | + l = l - drw * 30; | ||
| 186 | + r = r + drw * 20; | ||
| 187 | + } | ||
| 188 | + else | ||
| 189 | + { | ||
| 190 | + l = l - drw * 15; | ||
| 191 | + r = r + drw * 15; | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + | ||
| 176 | std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str(), l, b, r, t); | 195 | std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str(), l, b, r, t); |
| 177 | //printf("%s\r\n",sql.c_str()); | 196 | //printf("%s\r\n",sql.c_str()); |
| 178 | return sql; | 197 | return sql; |
| @@ -207,11 +226,11 @@ namespace DmpWms | @@ -207,11 +226,11 @@ namespace DmpWms | ||
| 207 | 226 | ||
| 208 | string tableName = layer->name(); //layer->name(); | 227 | string tableName = layer->name(); //layer->name(); |
| 209 | string shapeName = layer->geom(); | 228 | string shapeName = layer->geom(); |
| 210 | - shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR); | 229 | + shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer = layer->GetCurrentScaleTable(1 / this->m_dR); |
| 211 | 230 | ||
| 212 | - if (pVectorThinLayer != nullptr) | 231 | + if (pVectorVacuateLayer != nullptr) |
| 213 | { | 232 | { |
| 214 | - tableName = pVectorThinLayer->tableName(); | 233 | + tableName = pVectorVacuateLayer->tableName(); |
| 215 | } | 234 | } |
| 216 | 235 | ||
| 217 | ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName | 236 | ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName |
| @@ -294,11 +313,11 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -294,11 +313,11 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 294 | 313 | ||
| 295 | string tableName = layer->name(); //layer->name(); | 314 | string tableName = layer->name(); //layer->name(); |
| 296 | string shapeName = layer->geom(); | 315 | string shapeName = layer->geom(); |
| 297 | - shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR); | 316 | + shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer = layer->GetCurrentScaleTable(1 / this->m_dR); |
| 298 | 317 | ||
| 299 | - if (pVectorThinLayer != nullptr) | 318 | + if (pVectorVacuateLayer != nullptr) |
| 300 | { | 319 | { |
| 301 | - tableName = pVectorThinLayer->tableName(); | 320 | + tableName = pVectorVacuateLayer->tableName(); |
| 302 | } | 321 | } |
| 303 | 322 | ||
| 304 | ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName | 323 | ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName |
| @@ -332,7 +351,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -332,7 +351,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 332 | return ""; | 351 | return ""; |
| 333 | } | 352 | } |
| 334 | 353 | ||
| 335 | - string DmpWmsRenderer::GetDrawSQLAll_Catch(DmpVectorLayer *layer, shared_ptr<DmpVectorThinLayer> pVectorThinLayer) | 354 | + string DmpWmsRenderer::GetDrawSQLAll_Catch(DmpVectorLayer *layer, shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer) |
| 336 | { | 355 | { |
| 337 | if (layer == 0 || layer->geom().size() == 0) | 356 | if (layer == 0 || layer->geom().size() == 0) |
| 338 | return ""; | 357 | return ""; |
| @@ -363,9 +382,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -363,9 +382,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 363 | } | 382 | } |
| 364 | 383 | ||
| 365 | string tableName = layer->name(); | 384 | string tableName = layer->name(); |
| 366 | - if (pVectorThinLayer != nullptr) | 385 | + if (pVectorVacuateLayer != nullptr) |
| 367 | { | 386 | { |
| 368 | - tableName = pVectorThinLayer->tableName(); | 387 | + tableName = pVectorVacuateLayer->tableName(); |
| 369 | } | 388 | } |
| 370 | 389 | ||
| 371 | string shapeName = layer->geom(); | 390 | string shapeName = layer->geom(); |
| @@ -470,9 +489,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -470,9 +489,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 470 | string tableName = layer->name(); | 489 | string tableName = layer->name(); |
| 471 | string shapeName = layer->geom(); | 490 | string shapeName = layer->geom(); |
| 472 | 491 | ||
| 473 | - if (layer->thinLayers().size() > 0) | 492 | + if (layer->vacuateLayers().size() > 0) |
| 474 | { | 493 | { |
| 475 | - tableName = layer->thinLayers()[0]->tableName(); | 494 | + tableName = layer->vacuateLayers()[0]->tableName(); |
| 476 | } | 495 | } |
| 477 | 496 | ||
| 478 | std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str()); | 497 | std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str()); |
| @@ -518,7 +537,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -518,7 +537,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 518 | { | 537 | { |
| 519 | typeString = "geometry"; | 538 | typeString = "geometry"; |
| 520 | typeInt = PGFieldType::ShapeFieldType; | 539 | typeInt = PGFieldType::ShapeFieldType; |
| 521 | - fields_str += " st_asgeojson(\"" + (fieldname) + "\") as geometry_as_geojson"; | 540 | + fields_str += " \"" + (fieldname) + "\" as geometry_as_wkb "; |
| 522 | } | 541 | } |
| 523 | else if (typeString == "integer") | 542 | else if (typeString == "integer") |
| 524 | { | 543 | { |
| @@ -572,8 +591,14 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -572,8 +591,14 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 572 | std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str()); | 591 | std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str()); |
| 573 | 592 | ||
| 574 | string shapeName = layer->geom(); | 593 | string shapeName = layer->geom(); |
| 575 | - sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s), %f) limit %d ", | ||
| 576 | - shapeName.c_str(), x, y, layer->srid().c_str(), dis, feature_count); | 594 | + // WHERE \"%s\" && \'BOX3D(%lf %lf,%lf %lf)\'::box3d |
| 595 | + //sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s),%f) limit %d ", | ||
| 596 | + // shapeName.c_str(), x, y,layer->srid().c_str(), dis, feature_count); | ||
| 597 | + | ||
| 598 | + sql += format(" \"%s\" && \'BOX3D(%lf %lf,%lf %lf)\'::box3d limit %d ", | ||
| 599 | + shapeName.c_str(), x - dis, y - dis, x + dis, y + dis, feature_count); | ||
| 600 | + | ||
| 601 | + | ||
| 577 | //cout<<sql.c_str() <<endl; | 602 | //cout<<sql.c_str() <<endl; |
| 578 | return sql; | 603 | return sql; |
| 579 | } | 604 | } |
| @@ -596,16 +621,15 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -596,16 +621,15 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 596 | double start = clock(); | 621 | double start = clock(); |
| 597 | double cost, cost2; | 622 | double cost, cost2; |
| 598 | 623 | ||
| 599 | - string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis, feature_count); //sql语句中使用 ::box | ||
| 600 | - if (sql == "") | ||
| 601 | - continue; | ||
| 602 | - //printf("%s\r\n",sql.c_str()); | ||
| 603 | - string layerName = layer->name(); | ||
| 604 | try | 624 | try |
| 605 | { | 625 | { |
| 606 | shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); | 626 | shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); |
| 607 | if (pPgsqlConn == nullptr) | 627 | if (pPgsqlConn == nullptr) |
| 608 | break; | 628 | break; |
| 629 | + DmpMapServerUtil::initVectorLayerSrid(pPgsqlConn, layer); | ||
| 630 | + string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis, feature_count); //sql语句中使用 ::box | ||
| 631 | + if (sql == "") continue; | ||
| 632 | + string layerName = layer->name(); | ||
| 609 | if (pPgsqlConn->ExecWaitBinary(sql)) | 633 | if (pPgsqlConn->ExecWaitBinary(sql)) |
| 610 | { | 634 | { |
| 611 | if(pPgsqlConn->GetRowCount()>0 || i==0) | 635 | if(pPgsqlConn->GetRowCount()>0 || i==0) |
| @@ -753,6 +777,11 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -753,6 +777,11 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 753 | return true; | 777 | return true; |
| 754 | } | 778 | } |
| 755 | 779 | ||
| 780 | + shared_ptr<Rect> DmpWmsRenderer::GetExtent() | ||
| 781 | + { | ||
| 782 | + return m_pExtent; | ||
| 783 | + } | ||
| 784 | + | ||
| 756 | bool DmpWmsRenderer::SetExtent(shared_ptr<Rect> rect) | 785 | bool DmpWmsRenderer::SetExtent(shared_ptr<Rect> rect) |
| 757 | { | 786 | { |
| 758 | m_pExtent = rect; | 787 | m_pExtent = rect; |
| @@ -944,7 +973,8 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -944,7 +973,8 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 944 | } | 973 | } |
| 945 | } | 974 | } |
| 946 | 975 | ||
| 947 | - for (int i = 0; i < (int)(m_vLayers.size()); i++) | 976 | + //for (int i = 0; i < (int)(m_vLayers.size()); i++) |
| 977 | + for (int i = (int)(m_vLayers.size()) -1; i >= 0; i--) | ||
| 948 | { | 978 | { |
| 949 | DmpVectorLayer *layer = m_vLayers[i]; | 979 | DmpVectorLayer *layer = m_vLayers[i]; |
| 950 | sprintf(buff, "<log>draw layer %s</log>", layer->name().c_str()); | 980 | sprintf(buff, "<log>draw layer %s</log>", layer->name().c_str()); |
| @@ -1038,7 +1068,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1038,7 +1068,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1038 | outputStream << buff; | 1068 | outputStream << buff; |
| 1039 | 1069 | ||
| 1040 | string sql = ""; | 1070 | string sql = ""; |
| 1041 | - shared_ptr<DmpVectorThinLayer> pVectorThinLayer = nullptr; | 1071 | + shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer = nullptr; |
| 1042 | 1072 | ||
| 1043 | shared_ptr<DataCollection> data(new DataCollection()); | 1073 | shared_ptr<DataCollection> data(new DataCollection()); |
| 1044 | 1074 | ||
| @@ -1051,7 +1081,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1051,7 +1081,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1051 | sql = GetRegionQuerySQL(layer, pExtent.get(), format("%d", layer->crs().srid()), strRegionLayerNameDefs, strRegionColDefs, strLayerDef); | 1081 | sql = GetRegionQuerySQL(layer, pExtent.get(), format("%d", layer->crs().srid()), strRegionLayerNameDefs, strRegionColDefs, strLayerDef); |
| 1052 | } | 1082 | } |
| 1053 | 1083 | ||
| 1054 | - pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR); | 1084 | + pVectorVacuateLayer = layer->GetCurrentScaleTable(1 / this->m_dR); |
| 1055 | 1085 | ||
| 1056 | string sqlLog = sql; | 1086 | string sqlLog = sql; |
| 1057 | DmpMapServerUtil::toXmlString(sqlLog); | 1087 | DmpMapServerUtil::toXmlString(sqlLog); |
| @@ -1064,9 +1094,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1064,9 +1094,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1064 | 1094 | ||
| 1065 | string tableName = layer->name(); | 1095 | string tableName = layer->name(); |
| 1066 | 1096 | ||
| 1067 | - if (pVectorThinLayer != nullptr) | 1097 | + if (pVectorVacuateLayer != nullptr) |
| 1068 | { | 1098 | { |
| 1069 | - tableName = pVectorThinLayer->tableName(); | 1099 | + tableName = pVectorVacuateLayer->tableName(); |
| 1070 | } | 1100 | } |
| 1071 | 1101 | ||
| 1072 | if (tableName.length() > 32) | 1102 | if (tableName.length() > 32) |
| @@ -1080,13 +1110,13 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1080,13 +1110,13 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1080 | { | 1110 | { |
| 1081 | 1111 | ||
| 1082 | shared_ptr<DmpPgsql> pPgsqlConn = nullptr; | 1112 | shared_ptr<DmpPgsql> pPgsqlConn = nullptr; |
| 1083 | - if (pVectorThinLayer == nullptr) | 1113 | + if (pVectorVacuateLayer == nullptr) |
| 1084 | { | 1114 | { |
| 1085 | pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); | 1115 | pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); |
| 1086 | } | 1116 | } |
| 1087 | else | 1117 | else |
| 1088 | { | 1118 | { |
| 1089 | - pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetDefaultPgsqlConn(); | 1119 | + pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(pVectorVacuateLayer->connectStr()); |
| 1090 | } | 1120 | } |
| 1091 | 1121 | ||
| 1092 | if (pPgsqlConn == nullptr) | 1122 | if (pPgsqlConn == nullptr) |
| @@ -1106,7 +1136,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1106,7 +1136,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1106 | sprintf(buff,"<log>draw success</log>"); | 1136 | sprintf(buff,"<log>draw success</log>"); |
| 1107 | outputStream << buff; | 1137 | outputStream << buff; |
| 1108 | } | 1138 | } |
| 1109 | - else if (pVectorThinLayer != nullptr) | 1139 | + else if (pVectorVacuateLayer != nullptr) |
| 1110 | { | 1140 | { |
| 1111 | /*shared_ptr<DmpPgsql> pPgsqlConn1 = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); | 1141 | /*shared_ptr<DmpPgsql> pPgsqlConn1 = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); |
| 1112 | sprintf(buff,"<log>从抽稀图层获取数据%s</log>", pMapLayerThinning->m_tableName.c_str()); | 1142 | sprintf(buff,"<log>从抽稀图层获取数据%s</log>", pMapLayerThinning->m_tableName.c_str()); |
| @@ -1201,7 +1231,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1201,7 +1231,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1201 | 1231 | ||
| 1202 | map<DmpVectorLayer *, shared_ptr<DataCollection>> map_DataCollection; | 1232 | map<DmpVectorLayer *, shared_ptr<DataCollection>> map_DataCollection; |
| 1203 | 1233 | ||
| 1204 | - for (int i = 0; i < (int)(m_vLayers.size()); i++) | 1234 | + |
| 1235 | + //for (int i = 0; i < (int)(m_vLayers.size()); i++) | ||
| 1236 | + for (int i = (int)(m_vLayers.size()) -1; i >= 0; i--) | ||
| 1205 | { | 1237 | { |
| 1206 | DmpVectorLayer *layer = m_vLayers[i]; | 1238 | DmpVectorLayer *layer = m_vLayers[i]; |
| 1207 | 1239 | ||
| @@ -1231,7 +1263,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1231,7 +1263,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1231 | double cost, cost2; | 1263 | double cost, cost2; |
| 1232 | 1264 | ||
| 1233 | string sql = ""; | 1265 | string sql = ""; |
| 1234 | - shared_ptr<DmpVectorThinLayer> pVectorThinLayer = nullptr; | 1266 | + shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer = nullptr; |
| 1235 | 1267 | ||
| 1236 | bool renderHeat = false; | 1268 | bool renderHeat = false; |
| 1237 | shared_ptr<DataCollection> data(new DataCollection()); | 1269 | shared_ptr<DataCollection> data(new DataCollection()); |
| @@ -1245,7 +1277,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1245,7 +1277,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1245 | sql = GetRegionQuerySQL(layer, pExtent.get(), format("%d", layer->crs().srid()), strRegionLayerNameDefs, strRegionColDefs, strLayerDef); | 1277 | sql = GetRegionQuerySQL(layer, pExtent.get(), format("%d", layer->crs().srid()), strRegionLayerNameDefs, strRegionColDefs, strLayerDef); |
| 1246 | } | 1278 | } |
| 1247 | 1279 | ||
| 1248 | - pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR); | 1280 | + pVectorVacuateLayer = layer->GetCurrentScaleTable(1 / this->m_dR); |
| 1249 | 1281 | ||
| 1250 | // printf( "%s\r\n", sql.c_str()); | 1282 | // printf( "%s\r\n", sql.c_str()); |
| 1251 | // this->GetDrawSQL(layer, pExtent.get(), strLayerDef); //sql语句中使用 ::box | 1283 | // this->GetDrawSQL(layer, pExtent.get(), strLayerDef); //sql语句中使用 ::box |
| @@ -1254,9 +1286,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1254,9 +1286,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1254 | 1286 | ||
| 1255 | string tableName = layer->name(); | 1287 | string tableName = layer->name(); |
| 1256 | 1288 | ||
| 1257 | - if (pVectorThinLayer != nullptr) | 1289 | + if (pVectorVacuateLayer != nullptr) |
| 1258 | { | 1290 | { |
| 1259 | - tableName = pVectorThinLayer->tableName(); | 1291 | + tableName = pVectorVacuateLayer->tableName(); |
| 1260 | } | 1292 | } |
| 1261 | 1293 | ||
| 1262 | if (tableName.length() > 32) | 1294 | if (tableName.length() > 32) |
| @@ -1270,13 +1302,13 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1270,13 +1302,13 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1270 | { | 1302 | { |
| 1271 | 1303 | ||
| 1272 | shared_ptr<DmpPgsql> pPgsqlConn = nullptr; | 1304 | shared_ptr<DmpPgsql> pPgsqlConn = nullptr; |
| 1273 | - if (pVectorThinLayer == nullptr) | 1305 | + if (pVectorVacuateLayer == nullptr) |
| 1274 | { | 1306 | { |
| 1275 | pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); | 1307 | pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); |
| 1276 | } | 1308 | } |
| 1277 | else | 1309 | else |
| 1278 | { | 1310 | { |
| 1279 | - pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetDefaultPgsqlConn(); | 1311 | + pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(pVectorVacuateLayer->connectStr()); |
| 1280 | } | 1312 | } |
| 1281 | 1313 | ||
| 1282 | if (pPgsqlConn == nullptr) | 1314 | if (pPgsqlConn == nullptr) |
| @@ -1287,7 +1319,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1287,7 +1319,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1287 | if (PQntuples(res) == 0) | 1319 | if (PQntuples(res) == 0) |
| 1288 | continue; | 1320 | continue; |
| 1289 | 1321 | ||
| 1290 | - int shapeType = layer->GeometryType(); | 1322 | + int shapeType = layer->GeomWkbType(); |
| 1291 | shared_ptr<DataCollection> data(new DataCollection()); | 1323 | shared_ptr<DataCollection> data(new DataCollection()); |
| 1292 | data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis); | 1324 | data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis); |
| 1293 | 1325 | ||
| @@ -1300,7 +1332,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1300,7 +1332,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1300 | this->DrawSimpleData(data.get(), layer->GetRenderer30().get(), pClsSurfThis); | 1332 | this->DrawSimpleData(data.get(), layer->GetRenderer30().get(), pClsSurfThis); |
| 1301 | 1333 | ||
| 1302 | } | 1334 | } |
| 1303 | - else if (pVectorThinLayer != nullptr) | 1335 | + else if (pVectorVacuateLayer != nullptr) |
| 1304 | { | 1336 | { |
| 1305 | shared_ptr<DmpPgsql> pPgsqlConn1 = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); | 1337 | shared_ptr<DmpPgsql> pPgsqlConn1 = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); |
| 1306 | 1338 | ||
| @@ -1312,7 +1344,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1312,7 +1344,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1312 | if (PQntuples(res) == 0) | 1344 | if (PQntuples(res) == 0) |
| 1313 | continue; | 1345 | continue; |
| 1314 | 1346 | ||
| 1315 | - int shapeType = layer->GeometryType(); | 1347 | + int shapeType = layer->GeomWkbType(); |
| 1316 | shared_ptr<DataCollection> data(new DataCollection()); | 1348 | shared_ptr<DataCollection> data(new DataCollection()); |
| 1317 | if (!renderHeat) | 1349 | if (!renderHeat) |
| 1318 | { | 1350 | { |
| @@ -1356,6 +1388,76 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1356,6 +1388,76 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
| 1356 | return true; | 1388 | return true; |
| 1357 | } | 1389 | } |
| 1358 | 1390 | ||
| 1391 | + bool DmpWmsRenderer::GetMapLegend( std::stringstream& ab, shared_ptr<legendParamater> pLegendParamater) | ||
| 1392 | + { | ||
| 1393 | + clsCrSurf *pClsSurfThis; | ||
| 1394 | + | ||
| 1395 | + pClsSurfThis = m_pClsSurfBuff; //refresh画图在 buff 中 | ||
| 1396 | + this->DoSetBackGround(pClsSurfThis, m_iBackColor); | ||
| 1397 | + | ||
| 1398 | + for (int layerType = 0; layerType < 3; layerType++) | ||
| 1399 | + { | ||
| 1400 | + | ||
| 1401 | + for (int i = 0; i < (int)(m_vLayers.size()); i++) | ||
| 1402 | + { | ||
| 1403 | + DmpVectorLayer *layer = m_vLayers[i]; | ||
| 1404 | + | ||
| 1405 | + //if ((ml->m_bVisible) == false) | ||
| 1406 | + // continue; | ||
| 1407 | + | ||
| 1408 | + //if (ml->m_pDataset == nullptr) | ||
| 1409 | + // continue; | ||
| 1410 | + | ||
| 1411 | + //double r1 = ml->m_dUpperScale; // * | ||
| 1412 | + //double r2 = ml->m_dLowerScale; // * | ||
| 1413 | + std::shared_ptr<DmapCore_30::Renderer> renderer = layer->GetRenderer30(); | ||
| 1414 | + renderer->DrawLegend(pClsSurfThis, pLegendParamater, layerType, (char *)layer->name().c_str()); | ||
| 1415 | + } | ||
| 1416 | + } | ||
| 1417 | + | ||
| 1418 | + this->BufferCopy(m_pClsSurfBuff, m_pClsMaxSurfBuffer); | ||
| 1419 | + this->BufferCopy(m_pClsSurfBuff, m_pClsSurfDC); | ||
| 1420 | + | ||
| 1421 | + pLegendParamater->next(nullptr); | ||
| 1422 | + | ||
| 1423 | + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)m_dWidth, pLegendParamater->pixYIndex + 10); //cairo_win32_surface_create(hdc); | ||
| 1424 | + clsCrSurf surfDC(surface); | ||
| 1425 | + this->BufferCopy(m_pClsSurfDC, &surfDC); | ||
| 1426 | + | ||
| 1427 | + cairo_surface_write_to_png_stream(surfDC.m_pSurf, cairo_write_func, &ab); | ||
| 1428 | + | ||
| 1429 | + return true; | ||
| 1430 | + } | ||
| 1431 | + | ||
| 1432 | + bool DmpWmsRenderer::GetMapLegend( shared_ptr<legendParamater> pLegendParamater, clsCrSurf* pClsSurf) | ||
| 1433 | + { | ||
| 1434 | + if(pClsSurf == nullptr) | ||
| 1435 | + { | ||
| 1436 | + pClsSurf = m_pClsSurfBuff; | ||
| 1437 | + } | ||
| 1438 | + | ||
| 1439 | + for (int layerType = 0; layerType < 3; layerType++) | ||
| 1440 | + { | ||
| 1441 | + for (int i = 0; i < (int)(m_vLayers.size()); i++) | ||
| 1442 | + { | ||
| 1443 | + DmpVectorLayer *layer = m_vLayers[i]; | ||
| 1444 | + | ||
| 1445 | + //if ((ml->m_bVisible) == false) | ||
| 1446 | + // continue; | ||
| 1447 | + | ||
| 1448 | + //if (ml->m_pDataset == nullptr) | ||
| 1449 | + // continue; | ||
| 1450 | + | ||
| 1451 | + //double r1 = ml->m_dUpperScale; // * | ||
| 1452 | + //double r2 = ml->m_dLowerScale; // * | ||
| 1453 | + std::shared_ptr<DmapCore_30::Renderer> renderer = layer->GetRenderer30(); | ||
| 1454 | + renderer->DrawLegend(pClsSurf, pLegendParamater, layerType, (char *)layer->name().c_str()); | ||
| 1455 | + } | ||
| 1456 | + | ||
| 1457 | + } | ||
| 1458 | + return true; | ||
| 1459 | + } | ||
| 1460 | + | ||
| 1359 | bool DmpWmsRenderer::ToStream(std::string &responseData) | 1461 | bool DmpWmsRenderer::ToStream(std::string &responseData) |
| 1360 | { | 1462 | { |
| 1361 | responseData.reserve(10240); | 1463 | responseData.reserve(10240); |
| @@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
| 22 | #include "clsUtil.h" | 22 | #include "clsUtil.h" |
| 23 | #include "DataCollection.h" | 23 | #include "DataCollection.h" |
| 24 | #include "dmpvectorlayer.h" | 24 | #include "dmpvectorlayer.h" |
| 25 | -#include "dmpvectorthinlayer.h" | 25 | +#include "dmpvectorvacuatelayer.h" |
| 26 | #include "dmprasterbuffer.h" | 26 | #include "dmprasterbuffer.h" |
| 27 | #include "dmpproject.h" | 27 | #include "dmpproject.h" |
| 28 | #include "dmppgsqlsourcepools.h" | 28 | #include "dmppgsqlsourcepools.h" |
| @@ -32,8 +32,6 @@ using namespace DmapCore_30; | @@ -32,8 +32,6 @@ using namespace DmapCore_30; | ||
| 32 | using namespace mapserver; | 32 | using namespace mapserver; |
| 33 | namespace DmpWms | 33 | namespace DmpWms |
| 34 | { | 34 | { |
| 35 | - | ||
| 36 | - | ||
| 37 | class DmpWmsRenderer | 35 | class DmpWmsRenderer |
| 38 | { | 36 | { |
| 39 | public: | 37 | public: |
| @@ -49,7 +47,7 @@ namespace DmpWms | @@ -49,7 +47,7 @@ namespace DmpWms | ||
| 49 | bool GetMapLegend( std::stringstream& ab, shared_ptr<legendParamater> pLegendParamater); | 47 | bool GetMapLegend( std::stringstream& ab, shared_ptr<legendParamater> pLegendParamater); |
| 50 | bool GetMapLegend( shared_ptr<legendParamater> pLegendParamater, clsCrSurf* pClsSurf); | 48 | bool GetMapLegend( shared_ptr<legendParamater> pLegendParamater, clsCrSurf* pClsSurf); |
| 51 | 49 | ||
| 52 | - string GetDrawSQLAll_Catch(DmpVectorLayer* layer,shared_ptr<DmpVectorThinLayer> pMapLayerThinning); | 50 | + string GetDrawSQLAll_Catch(DmpVectorLayer* layer,shared_ptr<DmpVectorVacuateLayer> pVectorVacuateLayer); |
| 53 | string GetDrawSQL(DmpVectorLayer* layer, Rect* pRect,const char* layerdef = nullptr); | 51 | string GetDrawSQL(DmpVectorLayer* layer, Rect* pRect,const char* layerdef = nullptr); |
| 54 | string GetDrawSQLAll(DmpVectorLayer* layer); | 52 | string GetDrawSQLAll(DmpVectorLayer* layer); |
| 55 | string GetDrawSQLAllOrderby(DmpVectorLayer* layer); | 53 | string GetDrawSQLAllOrderby(DmpVectorLayer* layer); |
| @@ -71,7 +69,7 @@ namespace DmpWms | @@ -71,7 +69,7 @@ namespace DmpWms | ||
| 71 | bool DrawSimpleData(DataCollection* data, Renderer* renderer, clsCrSurf* pClsSurf); | 69 | bool DrawSimpleData(DataCollection* data, Renderer* renderer, clsCrSurf* pClsSurf); |
| 72 | 70 | ||
| 73 | //shared_ptr<Rect> GetFullExtent(bool bRecalculate); //加一个bool值,如果为false , 无需计算 | 71 | //shared_ptr<Rect> GetFullExtent(bool bRecalculate); //加一个bool值,如果为false , 无需计算 |
| 74 | - //shared_ptr<Rect> GetExtent(); | 72 | + shared_ptr<Rect> GetExtent(); |
| 75 | bool SetExtent(shared_ptr<Rect> rect); | 73 | bool SetExtent(shared_ptr<Rect> rect); |
| 76 | bool GetParameters(double* pR, double* pXdis, double* pYdis); | 74 | bool GetParameters(double* pR, double* pXdis, double* pYdis); |
| 77 | bool SetParameters(double r = -1, double xdis = 0, double ydis = 0); | 75 | bool SetParameters(double r = -1, double xdis = 0, double ydis = 0); |
| @@ -74,7 +74,11 @@ namespace DmpWms | @@ -74,7 +74,11 @@ namespace DmpWms | ||
| 74 | ptGeographicBoundingbox.add("southBoundLatitude", miny); | 74 | ptGeographicBoundingbox.add("southBoundLatitude", miny); |
| 75 | ptGeographicBoundingbox.add("northBoundLatitude", maxy); | 75 | ptGeographicBoundingbox.add("northBoundLatitude", maxy); |
| 76 | ptProject.add_child("EX_GeographicBoundingBox",ptGeographicBoundingbox); | 76 | ptProject.add_child("EX_GeographicBoundingBox",ptGeographicBoundingbox); |
| 77 | - | 77 | + if( mapLayers.begin() != mapLayers.end()) |
| 78 | + { | ||
| 79 | + ptProject.add("source", mapLayers.begin()->second->source()); | ||
| 80 | + } | ||
| 81 | + | ||
| 78 | boost::property_tree::ptree ptLayers; | 82 | boost::property_tree::ptree ptLayers; |
| 79 | for (std::map<std::string, DmpMapLayer*>::iterator iter= mapLayers.begin();iter != mapLayers.end(); iter++) | 83 | for (std::map<std::string, DmpMapLayer*>::iterator iter= mapLayers.begin();iter != mapLayers.end(); iter++) |
| 80 | { | 84 | { |
| @@ -90,8 +94,9 @@ namespace DmpWms | @@ -90,8 +94,9 @@ namespace DmpWms | ||
| 90 | boost::property_tree::ptree ptLayer; | 94 | boost::property_tree::ptree ptLayer; |
| 91 | ptLayer.add("Name", layer->name()); | 95 | ptLayer.add("Name", layer->name()); |
| 92 | ptLayer.add("Title", layer->title()); | 96 | ptLayer.add("Title", layer->title()); |
| 93 | - ptLayer.add("CRS", srs); | 97 | + ptLayer.add("CRS", layer->srid().empty()?srs:("EPSG:" + layer->srid())); |
| 94 | ptLayer.add("Type", layer->GeomTypeString()); | 98 | ptLayer.add("Type", layer->GeomTypeString()); |
| 99 | + ptLayer.add("source", layer->source()); | ||
| 95 | 100 | ||
| 96 | boost::property_tree::ptree ptGeographicBoundingbox; | 101 | boost::property_tree::ptree ptGeographicBoundingbox; |
| 97 | ptGeographicBoundingbox.add("westBoundLongitude", layer->extent().xmin()); | 102 | ptGeographicBoundingbox.add("westBoundLongitude", layer->extent().xmin()); |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpmapprint.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-20 18:50:40 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpmapprint.h" | ||
| 10 | +#include <unistd.h> | ||
| 11 | +#include <algorithm> | ||
| 12 | +#include <cairo/cairo-svg.h> | ||
| 13 | + | ||
| 14 | +namespace DmpWms | ||
| 15 | +{ | ||
| 16 | + static cairo_status_t cairo_write_func_print(void *pbuff, const unsigned char *data, unsigned int length) | ||
| 17 | + { | ||
| 18 | + // vector<unsigned char>& vecData = *((vector<unsigned char>*)closure); | ||
| 19 | + string *pResponseData = (string *)pbuff; | ||
| 20 | + pResponseData->append((char *)data, length); | ||
| 21 | + return CAIRO_STATUS_SUCCESS; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + DmpMapPrint::DmpMapPrint(DmpWmsParameters::Format outformat) | ||
| 25 | + { | ||
| 26 | + this->format = outformat; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + bool DmpMapPrint::getPrint(std::string &responseData,const DmpProject *project, const string &xml, const string& servername) | ||
| 30 | + { | ||
| 31 | + string result_msg; | ||
| 32 | + | ||
| 33 | + try | ||
| 34 | + { | ||
| 35 | + std::stringstream stream(xml); | ||
| 36 | + boost::property_tree::ptree ptree; | ||
| 37 | + boost::property_tree::read_xml(stream, ptree); | ||
| 38 | + | ||
| 39 | + std::string templateStr = ptree.get<string>("template"); | ||
| 40 | + InitTemplateValue(templateStr); | ||
| 41 | + | ||
| 42 | + m_height = 1122; | ||
| 43 | + m_width = 793; | ||
| 44 | + | ||
| 45 | + double xmin = ptree.get<double>("extent/xmin"); | ||
| 46 | + double ymin = ptree.get<double>("extent/ymin"); | ||
| 47 | + double xmax = ptree.get<double>("extent/xmax"); | ||
| 48 | + double ymax = ptree.get<double>("extent/ymax"); | ||
| 49 | + | ||
| 50 | + shared_ptr<DmpPrintParameter> pDmpPrintParameter(new DmpPrintParameter()); | ||
| 51 | + | ||
| 52 | + shared_ptr<DmpPrintWMSService> dmapLayer(new DmpPrintWMSService()); | ||
| 53 | + dmapLayer->serviceName_ = servername; | ||
| 54 | + | ||
| 55 | + dmapLayer->project_ = project; | ||
| 56 | + //shared_ptr<DmpRectangle> dmpRectangle | ||
| 57 | + //Rect *rect = dmapLayer->project_->GetExtent(); | ||
| 58 | + pDmpPrintParameter->InitParameter(xmin, xmax, ymax, ymin, m_width - 100, m_height - 120); | ||
| 59 | + | ||
| 60 | + // dmapLayer->serviceName = "土地利用现状"; | ||
| 61 | + // dmapLayer->m_id = "土地利用现状"; | ||
| 62 | + // dmapLayer->boxX1 = 683497; | ||
| 63 | + // dmapLayer->boxX2 = 695357; | ||
| 64 | + // dmapLayer->boxY1 = 2534922; | ||
| 65 | + // dmapLayer->boxY2 = 2543053; | ||
| 66 | + | ||
| 67 | + //Rect *rect = dmapLayer->m_wmsServer->GetExtent(); | ||
| 68 | + | ||
| 69 | + dmapLayer->boxX1_ = xmin; | ||
| 70 | + dmapLayer->boxX2_ = xmax; | ||
| 71 | + dmapLayer->boxY1_ = ymin; | ||
| 72 | + dmapLayer->boxY2_ = ymax; | ||
| 73 | + | ||
| 74 | + shared_ptr<DmpPrintLayout> dmapLayout(new DmpPrintLayout()); | ||
| 75 | + this->vector_DmpPrintLayout.push_back(dmapLayout); | ||
| 76 | + | ||
| 77 | + dmapLayout->data.push_back(dmapLayer); | ||
| 78 | + dmapLayout->localtionX_ = 50; | ||
| 79 | + dmapLayout->localtionY_ = 70; | ||
| 80 | + | ||
| 81 | + dmapLayout->height_ = m_height - 70; | ||
| 82 | + dmapLayout->width_ = m_width - 50; | ||
| 83 | + | ||
| 84 | + this->m_height = m_height; | ||
| 85 | + this->m_width = m_width; | ||
| 86 | + | ||
| 87 | + shared_ptr<DmpPrintScale> geomLayer_scale(new DmpPrintScale()); | ||
| 88 | + geomLayer_scale->pPrintParameter_ = pDmpPrintParameter; | ||
| 89 | + shared_ptr<DmpPrintLayout> dmapLayout_scale(new DmpPrintLayout()); | ||
| 90 | + this->vector_DmpPrintLayout.push_back(dmapLayout_scale); | ||
| 91 | + geomLayer_scale->localtionX_ = 150; | ||
| 92 | + geomLayer_scale->localtionY_ = m_height - 50; | ||
| 93 | + dmapLayout_scale->data.push_back(geomLayer_scale); | ||
| 94 | + | ||
| 95 | + shared_ptr<DmpPrintCompass> geomLayer_compass(new DmpPrintCompass()); | ||
| 96 | + geomLayer_compass->pPrintParameter_ = pDmpPrintParameter; | ||
| 97 | + shared_ptr<DmpPrintLayout> dmapLayout_compass(new DmpPrintLayout()); | ||
| 98 | + this->vector_DmpPrintLayout.push_back(dmapLayout_compass); | ||
| 99 | + geomLayer_compass->localtionX_ = 80; | ||
| 100 | + geomLayer_compass->localtionY_ = m_height - 80; | ||
| 101 | + dmapLayout_compass->data.push_back(geomLayer_compass); | ||
| 102 | + | ||
| 103 | + ToPrint(responseData); | ||
| 104 | + return true; | ||
| 105 | + | ||
| 106 | + } | ||
| 107 | + catch (...) | ||
| 108 | + { | ||
| 109 | + | ||
| 110 | + } | ||
| 111 | + return false; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + bool DmpMapPrint::getPrint(std::string &responseData,const DmpProject *project, const string& servername, | ||
| 115 | + const char *printTemp, const char *bbox) | ||
| 116 | + { | ||
| 117 | + string result_msg; | ||
| 118 | + | ||
| 119 | + if (printTemp == nullptr || bbox == nullptr) | ||
| 120 | + return false; | ||
| 121 | + | ||
| 122 | + m_height = 1122; | ||
| 123 | + m_width = 793; | ||
| 124 | + | ||
| 125 | + double boxX1, boxY1, boxX2, boxY2; | ||
| 126 | + sscanf(bbox, "%lf,%lf,%lf,%lf", &boxY1, &boxX1, &boxY2, &boxX2); // &x1,&y1,&x2,&y2); | ||
| 127 | + | ||
| 128 | + InitTemplateValue(printTemp); | ||
| 129 | + | ||
| 130 | + shared_ptr<DmpPrintParameter> pDmpPrintParameter(new DmpPrintParameter()); | ||
| 131 | + | ||
| 132 | + shared_ptr<DmpPrintWMSService> dmapLayer(new DmpPrintWMSService()); | ||
| 133 | + dmapLayer->serviceName_ = servername; | ||
| 134 | + | ||
| 135 | + | ||
| 136 | + xmin = min(boxX1, boxX2); | ||
| 137 | + ymin = min(boxY1, boxY2); | ||
| 138 | + xmax = max(boxX1, boxX2); | ||
| 139 | + ymax = max(boxY1, boxY2); | ||
| 140 | + pDmpPrintParameter->InitParameter(xmin, xmax, ymax, ymin, m_width - 100, m_height - 120); | ||
| 141 | + // double scaleDenominator = this->RecalculateScale(rect->m_dRight,rect->m_dLeft,rect->m_dTop,rect->m_dBottom,1022,693); | ||
| 142 | + | ||
| 143 | + | ||
| 144 | + // dmapLayer->serviceName = "土地利用现状"; | ||
| 145 | + // dmapLayer->m_id = "土地利用现状"; | ||
| 146 | + // dmapLayer->boxX1 = 683497; | ||
| 147 | + // dmapLayer->boxX2 = 695357; | ||
| 148 | + // dmapLayer->boxY1 = 2534922; | ||
| 149 | + // dmapLayer->boxY2 = 2543053; | ||
| 150 | + | ||
| 151 | + // Rect *rect = dmapLayer->m_wmsServer->GetExtent(); | ||
| 152 | + | ||
| 153 | + dmapLayer->boxX1_ = xmin; | ||
| 154 | + dmapLayer->boxX2_ = xmax; | ||
| 155 | + dmapLayer->boxY1_ = ymin; | ||
| 156 | + dmapLayer->boxY2_ = ymax; | ||
| 157 | + | ||
| 158 | + shared_ptr<DmpPrintLayout> dmapLayout(new DmpPrintLayout()); | ||
| 159 | + this->vector_DmpPrintLayout.push_back(dmapLayout); | ||
| 160 | + | ||
| 161 | + dmapLayout->data.push_back(dmapLayer); | ||
| 162 | + dmapLayout->localtionX_ = 50; | ||
| 163 | + dmapLayout->localtionY_ = 70; | ||
| 164 | + | ||
| 165 | + dmapLayout->height_ = m_height - 120; | ||
| 166 | + dmapLayout->width_ = m_width - 100; | ||
| 167 | + | ||
| 168 | + this->m_height = m_height; | ||
| 169 | + this->m_width = m_width; | ||
| 170 | + | ||
| 171 | + shared_ptr<DmpPrintScale> geomLayer_scale(new DmpPrintScale()); | ||
| 172 | + geomLayer_scale->pPrintParameter_ = pDmpPrintParameter; | ||
| 173 | + shared_ptr<DmpPrintLayout> dmapLayout_scale(new DmpPrintLayout()); | ||
| 174 | + this->vector_DmpPrintLayout.push_back(dmapLayout_scale); | ||
| 175 | + geomLayer_scale->localtionX_ = 150; | ||
| 176 | + geomLayer_scale->localtionY_ = m_height - 110; | ||
| 177 | + dmapLayout_scale->data.push_back(geomLayer_scale); | ||
| 178 | + | ||
| 179 | + shared_ptr<DmpPrintCompass> geomLayer_compass(new DmpPrintCompass()); | ||
| 180 | + geomLayer_compass->pPrintParameter_ = pDmpPrintParameter; | ||
| 181 | + shared_ptr<DmpPrintLayout> dmapLayout_compass(new DmpPrintLayout()); | ||
| 182 | + this->vector_DmpPrintLayout.push_back(dmapLayout_compass); | ||
| 183 | + geomLayer_compass->localtionX_ = 80; | ||
| 184 | + geomLayer_compass->localtionY_ = m_height - 140; | ||
| 185 | + dmapLayout_compass->data.push_back(geomLayer_compass); | ||
| 186 | + | ||
| 187 | + ToPrint(responseData); | ||
| 188 | + return true; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + bool DmpMapPrint::getPrintTempFile(string &responseData,const DmpProject *project, const char *tempName, const char *bbox, | ||
| 192 | + const char *paras) | ||
| 193 | + { | ||
| 194 | + string path = "../template/"; | ||
| 195 | + path += tempName; | ||
| 196 | + path += ".xml"; | ||
| 197 | + | ||
| 198 | + ifstream fin(path.c_str(), ios::binary); | ||
| 199 | + if (!fin) | ||
| 200 | + { | ||
| 201 | + responseData = "<Error>打印模板未找到</Error>"; | ||
| 202 | + return false; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + stringstream buffer; | ||
| 206 | + buffer << fin.rdbuf(); | ||
| 207 | + string content(buffer.str()); | ||
| 208 | + fin.close(); | ||
| 209 | + return getPrintLayout(responseData, project, content.c_str(), bbox, paras); | ||
| 210 | + // return true; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + bool DmpMapPrint::getPrintLayout(string &responseData,const DmpProject *project, const char *xml, const char *bbox,const char *paras) | ||
| 214 | + { | ||
| 215 | + string result_msg; | ||
| 216 | + if (xml == nullptr || bbox == nullptr) | ||
| 217 | + return false; | ||
| 218 | + | ||
| 219 | + m_height = 1122; | ||
| 220 | + m_width = 793; | ||
| 221 | + | ||
| 222 | + try | ||
| 223 | + { | ||
| 224 | + map<string,string> mapParas; | ||
| 225 | + map<string,string> mapParasList; | ||
| 226 | + if(paras) | ||
| 227 | + { | ||
| 228 | + std::stringstream streampara(paras); | ||
| 229 | + boost::property_tree::ptree ptreepara; | ||
| 230 | + boost::property_tree::read_json(streampara, ptreepara); | ||
| 231 | + | ||
| 232 | + for (boost::property_tree::ptree::iterator pos = ptreepara.begin(); pos != ptreepara.end(); ++pos) | ||
| 233 | + { | ||
| 234 | + std::string name = pos->first; | ||
| 235 | + std::string value = pos->second.get_value<std::string>(); | ||
| 236 | + mapParas[name] = value; | ||
| 237 | + } | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + std::stringstream stream(xml); | ||
| 241 | + boost::property_tree::ptree ptree; | ||
| 242 | + boost::property_tree::read_xml(stream, ptree); | ||
| 243 | + | ||
| 244 | + std::string templateStr = ptree.get<string>("printlayout.template"); | ||
| 245 | + InitTemplateValue(templateStr); | ||
| 246 | + | ||
| 247 | + double boxX1, boxY1, boxX2, boxY2; | ||
| 248 | + sscanf(bbox, "%lf,%lf,%lf,%lf", &boxX1, &boxY1, &boxX2, &boxY2); // &x1,&y1,&x2,&y2); | ||
| 249 | + shared_ptr<DmpPrintParameter> pDmpPrintParameter(new DmpPrintParameter()); | ||
| 250 | + // Rect *rect_service = pWmsServer->GetExtent(); | ||
| 251 | + // if (rect_service) | ||
| 252 | + //{ | ||
| 253 | + // rect_service->GetExtent(boxX1, boxX2, boxY1, boxY2); | ||
| 254 | + // } | ||
| 255 | + | ||
| 256 | + xmin = min(boxX1, boxX2); | ||
| 257 | + ymin = min(boxY1, boxY2); | ||
| 258 | + xmax = max(boxX1, boxX2); | ||
| 259 | + ymax = max(boxY1, boxY2); | ||
| 260 | + pDmpPrintParameter->pWmsService = project; | ||
| 261 | + pDmpPrintParameter->InitParameter(xmin, xmax, ymax, ymin, m_width - 100, m_height - 120); | ||
| 262 | + | ||
| 263 | + shared_ptr<DmpPrintLayout> printLayout(new DmpPrintLayout()); | ||
| 264 | + boost::property_tree::ptree ptreelayout = ptree.get_child("printlayout"); | ||
| 265 | + if (printLayout->ReadXML(ptreelayout, pDmpPrintParameter, result_msg,mapParas,mapParasList)) | ||
| 266 | + { | ||
| 267 | + this->vector_DmpPrintLayout.push_back(printLayout); | ||
| 268 | + ToPrint(responseData); | ||
| 269 | + return true; | ||
| 270 | + } | ||
| 271 | + } | ||
| 272 | + catch (const std::exception& e) | ||
| 273 | + { | ||
| 274 | + std::cerr << e.what() << '\n'; | ||
| 275 | + result_msg = "<Error>error:Post参数是XML格式</Error>"; | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + responseData = result_msg; | ||
| 279 | + return false; | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + bool DmpMapPrint::ToPrint(string &responseData) | ||
| 283 | + { | ||
| 284 | + if (format == DmpWmsParameters::Format::SVG) | ||
| 285 | + { | ||
| 286 | + // string path = this->GetFilePath("mapPrint.pdf"); | ||
| 287 | + cairo_surface_t *surface = cairo_svg_surface_create_for_stream(cairo_write_func_print, &responseData, | ||
| 288 | + (int)m_width, | ||
| 289 | + (int)m_height); | ||
| 290 | + | ||
| 291 | + // cairo_surface_set_fallback_resolution(surface,900,900); | ||
| 292 | + clsCrSurf mClsSurfDC(surface, (int)m_width, (int)m_height, false); | ||
| 293 | + cairo_set_antialias(mClsSurfDC.m_pCr, cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
| 294 | + DoSetBackGround(&mClsSurfDC, 0xffffffff); | ||
| 295 | + | ||
| 296 | + for (size_t i = 0; i < vector_DmpPrintLayout.size(); i++) | ||
| 297 | + { | ||
| 298 | + shared_ptr<DmpPrintLayout> layout = vector_DmpPrintLayout.at(i); | ||
| 299 | + layout->DrawData(&mClsSurfDC, DmpWmsParameters::Format::SVG); | ||
| 300 | + } | ||
| 301 | + } | ||
| 302 | + else if (format == DmpWmsParameters::Format::PDF) | ||
| 303 | + { | ||
| 304 | + // string path = this->GetFilePath("mapPrint.pdf"); | ||
| 305 | + cairo_surface_t *surface = cairo_pdf_surface_create_for_stream(cairo_write_func_print, &responseData, | ||
| 306 | + (int)m_width, | ||
| 307 | + (int)m_height); | ||
| 308 | + | ||
| 309 | + // cairo_surface_set_fallback_resolution(surface,900,900); | ||
| 310 | + clsCrSurf mClsSurfDC(surface, (int)m_width, (int)m_height, false); | ||
| 311 | + cairo_set_antialias(mClsSurfDC.m_pCr, cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
| 312 | + DoSetBackGround(&mClsSurfDC, 0xffffffff); | ||
| 313 | + | ||
| 314 | + for (size_t i = 0; i < vector_DmpPrintLayout.size(); i++) | ||
| 315 | + { | ||
| 316 | + shared_ptr<DmpPrintLayout> layout = vector_DmpPrintLayout.at(i); | ||
| 317 | + layout->DrawData(&mClsSurfDC, DmpWmsParameters::Format::PDF); | ||
| 318 | + } | ||
| 319 | + } | ||
| 320 | + else | ||
| 321 | + { | ||
| 322 | + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, | ||
| 323 | + (int)m_width, | ||
| 324 | + (int)m_height); | ||
| 325 | + | ||
| 326 | + // cairo_surface_set_fallback_resolution(surface); | ||
| 327 | + // double dpix, dpiy; | ||
| 328 | + // cairo_surface_get_fallback_resolution(surface,&dpix, &dpiy); | ||
| 329 | + // printf("%f,%f",dpix,dpiy); | ||
| 330 | + | ||
| 331 | + clsCrSurf mClsSurfDC(surface); | ||
| 332 | + DoSetBackGround(&mClsSurfDC, 0xffffffff); | ||
| 333 | + | ||
| 334 | + for (size_t i = 0; i < vector_DmpPrintLayout.size(); i++) | ||
| 335 | + { | ||
| 336 | + shared_ptr<DmpPrintLayout> layout = vector_DmpPrintLayout.at(i); | ||
| 337 | + layout->DrawData(&mClsSurfDC, DmpWmsParameters::Format::PNG); | ||
| 338 | + } | ||
| 339 | + | ||
| 340 | + cairo_surface_write_to_png_stream(surface, cairo_write_func_print, &responseData); | ||
| 341 | + } | ||
| 342 | + return true; | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + bool DmpMapPrint::InitTemplateValue(string templateValue) | ||
| 346 | + { | ||
| 347 | + | ||
| 348 | + if (templateValue == "A4竖" || templateValue == "A4-hoch") | ||
| 349 | + { | ||
| 350 | + m_height = 1122; | ||
| 351 | + m_width = 793; | ||
| 352 | + } | ||
| 353 | + else if (templateValue == "A4横" || templateValue == "A4-quer") | ||
| 354 | + { | ||
| 355 | + m_height = 793; | ||
| 356 | + m_width = 1122; | ||
| 357 | + } | ||
| 358 | + else if (templateValue == "A3竖" || templateValue == "A3-hoch") | ||
| 359 | + { | ||
| 360 | + m_height = 1122 * 2; | ||
| 361 | + m_width = 793 * 2; | ||
| 362 | + } | ||
| 363 | + else if (templateValue == "A3横" || templateValue == "A3-quer") | ||
| 364 | + { | ||
| 365 | + m_height = 793 * 2; | ||
| 366 | + m_width = 1122 * 2; | ||
| 367 | + } | ||
| 368 | + else if (templateValue == "A5竖" || templateValue == "A5-hoch") | ||
| 369 | + { | ||
| 370 | + m_height = 1122 / 2; | ||
| 371 | + m_width = 793 / 2; | ||
| 372 | + } | ||
| 373 | + else if (templateValue == "A5横" || templateValue == "A5-quer") | ||
| 374 | + { | ||
| 375 | + m_height = 793 / 2; | ||
| 376 | + m_width = 1122 / 2; | ||
| 377 | + } | ||
| 378 | + return true; | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + | ||
| 382 | + | ||
| 383 | + double DmpMapPrint::RecalculateScale(double right, double left, double top, double bottom, double width, double height) | ||
| 384 | + { | ||
| 385 | + double w = right - left; | ||
| 386 | + double h = top - bottom; | ||
| 387 | + double oneInchInLayoutUnits = 0.0254; | ||
| 388 | + double resolution = 96; | ||
| 389 | + if ((w > std::pow(10, 12)) || (w < std::pow(10, -12))) | ||
| 390 | + return false; | ||
| 391 | + if ((h > std::pow(10, 12)) || (h < std::pow(10, -12))) | ||
| 392 | + return false; | ||
| 393 | + | ||
| 394 | + long double R1 = width / w; | ||
| 395 | + long double R2 = height / h; | ||
| 396 | + double r = R1 < R2 ? R1 : R2; | ||
| 397 | + if ((r > std::pow(10, 12)) || (r < std::pow(10, -12))) | ||
| 398 | + return false; | ||
| 399 | + | ||
| 400 | + // m_dR = R1 < R2 ? R1 : R2; | ||
| 401 | + double m_dR = r; | ||
| 402 | + double m_dXdis = width / 2.0 - m_dR * (right + left) / 2.0; | ||
| 403 | + double m_dYdis = height / 2.0 + m_dR * (top + bottom) / 2.0; | ||
| 404 | + | ||
| 405 | + bool isWGS84 = left <= 180 && right < 180 && | ||
| 406 | + left >= -180 && right >= -180 && | ||
| 407 | + top < 90 && bottom < 90; | ||
| 408 | + | ||
| 409 | + double scaleDenominator = 0; | ||
| 410 | + if (isWGS84) | ||
| 411 | + { | ||
| 412 | + scaleDenominator = (resolution / oneInchInLayoutUnits) * (1 / r) * 111000; | ||
| 413 | + // m_dR = r *(96 / 0.0254) *111000 ;//111000 为赤道1经度等于 111000米 | ||
| 414 | + } | ||
| 415 | + else | ||
| 416 | + { | ||
| 417 | + scaleDenominator = (resolution / oneInchInLayoutUnits) * 1 / r; | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + return scaleDenominator; | ||
| 421 | + } | ||
| 422 | + | ||
| 423 | + string DmpMapPrint::GetFilePath(string path) | ||
| 424 | + { | ||
| 425 | + char sz[200] = {0}; | ||
| 426 | + if (GetCurrentFolderPath(sz, sizeof(sz)) > 0) | ||
| 427 | + { | ||
| 428 | + std::string s; | ||
| 429 | + s = sz; | ||
| 430 | + size_t t = s.rfind('/'); | ||
| 431 | + sz[t] = 0; | ||
| 432 | + if (path[0] == '/') | ||
| 433 | + { | ||
| 434 | + return path; | ||
| 435 | + } | ||
| 436 | + int i = 0; | ||
| 437 | + if (path[0] == '.') | ||
| 438 | + { | ||
| 439 | + if (path[1] == '.') | ||
| 440 | + { | ||
| 441 | + i++; | ||
| 442 | + s = sz; | ||
| 443 | + t = s.rfind('/'); | ||
| 444 | + sz[t] = 0; | ||
| 445 | + } | ||
| 446 | + i++; | ||
| 447 | + } | ||
| 448 | + if ((sz[t] == '/' || sz[t] == '\\') && (path[i] == '/' || path[i] == '\\')) | ||
| 449 | + { | ||
| 450 | + i++; | ||
| 451 | + } | ||
| 452 | + | ||
| 453 | + int j = t; | ||
| 454 | + for (j = t; i < path.length(); i++, j++) | ||
| 455 | + { | ||
| 456 | + if (path[i] == '\\') | ||
| 457 | + { | ||
| 458 | + sz[j] = '/'; | ||
| 459 | + } | ||
| 460 | + else | ||
| 461 | + { | ||
| 462 | + sz[j] = path[i]; | ||
| 463 | + } | ||
| 464 | + } | ||
| 465 | + sz[j] = 0; | ||
| 466 | + // strcat(sz, path.c_str()); | ||
| 467 | + return sz; | ||
| 468 | + } | ||
| 469 | + else | ||
| 470 | + return 0; | ||
| 471 | + } | ||
| 472 | + | ||
| 473 | + int DmpMapPrint::GetCurrentFolderPath(char *processdir, size_t len) | ||
| 474 | + { | ||
| 475 | + char *path_end; | ||
| 476 | + if (readlink("/proc/self/exe", processdir, len) <= 0) | ||
| 477 | + return -1; | ||
| 478 | + path_end = strrchr(processdir, '/'); | ||
| 479 | + if (path_end == NULL) | ||
| 480 | + return -1; | ||
| 481 | + ++path_end; | ||
| 482 | + // strcpy(processname, path_end); | ||
| 483 | + *path_end = '\0'; | ||
| 484 | + return (size_t)(path_end - processdir); | ||
| 485 | + } | ||
| 486 | + | ||
| 487 | + bool DmpMapPrint::DoSetBackGround(clsCrSurf *pClsCS, int iColor) | ||
| 488 | + { | ||
| 489 | + cairo_surface_t *surface = pClsCS->m_pSurf; | ||
| 490 | + cairo_t *cr = pClsCS->m_pCr; | ||
| 491 | + int surf_w = cairo_image_surface_get_width(surface); | ||
| 492 | + int surf_h = cairo_image_surface_get_height(surface); | ||
| 493 | + //画一个矩形背景 | ||
| 494 | + cairo_rectangle(cr, 0, 0, surf_w, surf_h); | ||
| 495 | + double r, g, b, a; | ||
| 496 | + //MyUtil::ToCairoColor(iColor, r, g, b, a); | ||
| 497 | + cairo_set_source_rgb(cr, 255, 255, 255); | ||
| 498 | + cairo_fill(cr); | ||
| 499 | + return true; | ||
| 500 | + } | ||
| 501 | +} |
src/server/services/mapserver/wms/dmpprint.h
→
src/server/services/mapserver/wms/print/dmpmapprint.h
| 1 | /************************************************************************** | 1 | /************************************************************************** |
| 2 | -* file: dmpprint.h | 2 | +* file: dmpmapprint.h |
| 3 | 3 | ||
| 4 | * Author: qingxiongf | 4 | * Author: qingxiongf |
| 5 | * Date: 2022-01-20 18:50:30 | 5 | * Date: 2022-01-20 18:50:30 |
| @@ -7,22 +7,31 @@ | @@ -7,22 +7,31 @@ | ||
| 7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
| 8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
| 9 | 9 | ||
| 10 | -#ifndef __dmpprint_h__ | ||
| 11 | -#define __dmpprint_h__ | 10 | +#ifndef __dmpmapprint_h__ |
| 11 | +#define __dmpmapprint_h__ | ||
| 12 | 12 | ||
| 13 | #include <string> | 13 | #include <string> |
| 14 | #include <string.h> | 14 | #include <string.h> |
| 15 | #include <vector> | 15 | #include <vector> |
| 16 | #include <map> | 16 | #include <map> |
| 17 | - | 17 | +#include <math.h> |
| 18 | +#include "dmpproject.h" | ||
| 18 | #include "clsCrSurf.h" | 19 | #include "clsCrSurf.h" |
| 19 | #include "clsRect.h" | 20 | #include "clsRect.h" |
| 20 | #include "clsUtil.h" | 21 | #include "clsUtil.h" |
| 22 | +#include <boost/property_tree/ptree.hpp> | ||
| 23 | +#include <boost/property_tree/xml_parser.hpp> | ||
| 24 | +#include <boost/property_tree/json_parser.hpp> | ||
| 25 | +#include <boost/typeof/typeof.hpp> | ||
| 26 | +#include "dmpprintlayout.h" | ||
| 27 | +#include "dmpprintparameter.h" | ||
| 28 | +#include "../dmpwmsrenderer.h" | ||
| 29 | +#include "../dmpwmsparameters.h" | ||
| 21 | using namespace std; | 30 | using namespace std; |
| 22 | using namespace DmapCore_30; | 31 | using namespace DmapCore_30; |
| 23 | namespace DmpWms | 32 | namespace DmpWms |
| 24 | { | 33 | { |
| 25 | - class DmpPrint | 34 | + class DmpMapPrint |
| 26 | { | 35 | { |
| 27 | private: | 36 | private: |
| 28 | std::string m_name; | 37 | std::string m_name; |
| @@ -37,7 +46,7 @@ namespace DmpWms | @@ -37,7 +46,7 @@ namespace DmpWms | ||
| 37 | int m_wkid; | 46 | int m_wkid; |
| 38 | int m_dpi; | 47 | int m_dpi; |
| 39 | double m_scale; | 48 | double m_scale; |
| 40 | - int isPicture; | 49 | + DmpWmsParameters::Format format; |
| 41 | 50 | ||
| 42 | private: | 51 | private: |
| 43 | bool DoSetBackGround(clsCrSurf *pClsCS, int iColor); | 52 | bool DoSetBackGround(clsCrSurf *pClsCS, int iColor); |
| @@ -46,30 +55,30 @@ namespace DmpWms | @@ -46,30 +55,30 @@ namespace DmpWms | ||
| 46 | int GetCurrentFolderPath(char *processdir, size_t len); | 55 | int GetCurrentFolderPath(char *processdir, size_t len); |
| 47 | bool InitTemplateValue(string templateValue); | 56 | bool InitTemplateValue(string templateValue); |
| 48 | bool ToPrint(std::string &responseData); | 57 | bool ToPrint(std::string &responseData); |
| 49 | - | ||
| 50 | public: | 58 | public: |
| 51 | - DmpPrint(int isPicture); | ||
| 52 | -/* | ||
| 53 | - bool getPrint(AppendBuffer *ab, map<string, shared_ptr<WMSServer>> &mapWmsServer, const char *xml, string servername); | ||
| 54 | - bool getPrint(AppendBuffer *ab, map<string, shared_ptr<WMSServer>> &mapWmsServer, string servername, const char *printTemp, const char *bbox); | 59 | + DmpMapPrint(DmpWmsParameters::Format outformat); |
| 60 | + | ||
| 61 | + bool getPrint(std::string &responseData,const DmpProject* project,const string & xml, const string& servername); | ||
| 62 | + bool getPrint(std::string &responseData,const DmpProject* project, const string& servername, const char *printTemp, const char *bbox); | ||
| 55 | 63 | ||
| 56 | - bool getPrintLayout(AppendBuffer *ab, | ||
| 57 | - shared_ptr<WMSServer> pWmsServer, | 64 | + bool getPrintLayout(std::string &responseData, |
| 65 | + const DmpProject* project, | ||
| 58 | const char *xml, | 66 | const char *xml, |
| 59 | - const char *bbox); | 67 | + const char *bbox, |
| 68 | + const char *paras); | ||
| 60 | 69 | ||
| 61 | - bool getPrintTempFile(AppendBuffer *ab, | ||
| 62 | - shared_ptr<WMSServer> pWmsServer, | 70 | + bool getPrintTempFile(std::string &responseData, |
| 71 | + const DmpProject* project, | ||
| 63 | const char *tempName, | 72 | const char *tempName, |
| 64 | - const char *bbox); | ||
| 65 | - | ||
| 66 | - bool Test(AppendBuffer *ab, map<string, shared_ptr<WMSServer>> &mapWmsServer, string servername); | 73 | + const char *bbox, |
| 74 | + const char *paras); | ||
| 67 | 75 | ||
| 68 | - vector<shared_ptr<DmapPrintLayout>> vector_dmapPrintLayout; | 76 | + // bool Test(std::string &responseData, DmpProject* project, string servername); |
| 69 | 77 | ||
| 70 | - vector<shared_ptr<OperationalLayer>> vector_operationalLayer; | ||
| 71 | - */ | 78 | + vector<shared_ptr<DmpPrintLayout>> vector_DmpPrintLayout; |
| 79 | + // vector<shared_ptr<OperationalLayer>> vector_operationalLayer; | ||
| 80 | + | ||
| 72 | }; | 81 | }; |
| 73 | } | 82 | } |
| 74 | 83 | ||
| 75 | -#endif // __dmpprint_h__ | 84 | +#endif // __dmpmapprint_h__ |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintcompass.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 16:51:01 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprintcompass.h" | ||
| 10 | + | ||
| 11 | +namespace DmpWms | ||
| 12 | +{ | ||
| 13 | + bool DmpPrintCompass::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) | ||
| 14 | + { | ||
| 15 | + | ||
| 16 | + return false; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + bool DmpPrintCompass::ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 20 | + string& errorstr, map<string,string>& para, map<string,string>& paraList) | ||
| 21 | + { | ||
| 22 | + this->ReadXmlAttribute(pt,localtionX_,"localtion_x", para, paraList); | ||
| 23 | + this->ReadXmlAttribute(pt,localtionY_,"localtion_y", para, paraList); | ||
| 24 | + //this->ReadXmlAttribute(pt,type,"type"); | ||
| 25 | + | ||
| 26 | + this->ReadXmlAttribute(pt, boundSize_, "bound_size", para, paraList); | ||
| 27 | + this->ReadXmlAttribute(pt, showbound_, "showBound", para, paraList); | ||
| 28 | + | ||
| 29 | + this->pPrintParameter_ = pPrintParameter; | ||
| 30 | + | ||
| 31 | + return true; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + | ||
| 35 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintcompass.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 16:50:56 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#ifndef __dmpprintcompass_h__ | ||
| 10 | +#define __dmpprintcompass_h__ | ||
| 11 | + | ||
| 12 | +#include "dmpprintlayer.h" | ||
| 13 | +namespace DmpWms | ||
| 14 | +{ | ||
| 15 | + class DmpPrintCompass :public DmpPrintLayer | ||
| 16 | + { | ||
| 17 | + public: | ||
| 18 | + string serviceName; | ||
| 19 | + | ||
| 20 | + shared_ptr<DmpPrintParameter> pPrintParameter_ = nullptr; | ||
| 21 | + | ||
| 22 | + string type = "undefine"; | ||
| 23 | + | ||
| 24 | + public: | ||
| 25 | + //bool DrawImage(); | ||
| 26 | + bool DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format); | ||
| 27 | + bool ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pPrintParameter, string& errorstr, | ||
| 28 | + map<string,string>& para, map<string,string>& paraList); | ||
| 29 | + }; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +#endif // __dmpprintcompass_h__ |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintlayer.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 15:21:31 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprintlayer.h" | ||
| 10 | + | ||
| 11 | +namespace DmpWms | ||
| 12 | +{ | ||
| 13 | + | ||
| 14 | + bool DmpPrintLayer::DrawBound(clsCrSurf* pClsCS,double width, double height) | ||
| 15 | + { | ||
| 16 | + if(this->showbound_) | ||
| 17 | + { | ||
| 18 | + cairo_t *cr = pClsCS->m_pCr; | ||
| 19 | + cairo_set_source_rgb (cr, 0, 0, 0); | ||
| 20 | + cairo_set_line_width (cr, this->boundSize_); | ||
| 21 | + | ||
| 22 | + cairo_rectangle (cr, localtionX_, localtionY_, width, height); | ||
| 23 | + cairo_stroke_preserve (cr); | ||
| 24 | + return false; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + return true; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + shared_ptr<clsCrSurf> DmpPrintLayer::CreateSurface(int width, int height, DmpWmsParameters::Format format) | ||
| 31 | + { | ||
| 32 | + cairo_surface_t *surface = nullptr; | ||
| 33 | + | ||
| 34 | + bool isImage = true; | ||
| 35 | + | ||
| 36 | + if (format == DmpWmsParameters::Format::PDF) | ||
| 37 | + { | ||
| 38 | + surface = cairo_pdf_surface_create_for_stream(nullptr, nullptr, (int)width, (int)height); | ||
| 39 | + isImage = false; | ||
| 40 | + } | ||
| 41 | + else if (format == DmpWmsParameters::Format::SVG) | ||
| 42 | + { | ||
| 43 | + surface = cairo_svg_surface_create_for_stream(nullptr, nullptr, (int)width, (int)height); | ||
| 44 | + isImage = false; | ||
| 45 | + } | ||
| 46 | + else | ||
| 47 | + { | ||
| 48 | + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)width, (int)height); | ||
| 49 | + isImage = true; | ||
| 50 | + } | ||
| 51 | + shared_ptr<clsCrSurf> mClsSurfDC(new clsCrSurf(surface, (int)width, (int)height, isImage)); | ||
| 52 | + return mClsSurfDC; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + std::string DmpPrintLayer::replace(std::string strsrc, std::string strfind, std::string strrep) | ||
| 56 | + { | ||
| 57 | + for (std::string::size_type pos(0); pos != std::string::npos; pos += strrep.length()) | ||
| 58 | + { | ||
| 59 | + if ((pos = strsrc.find(strfind, pos)) != std::string::npos) | ||
| 60 | + strsrc.replace(pos, strfind.length(), strrep); | ||
| 61 | + else | ||
| 62 | + break; | ||
| 63 | + } | ||
| 64 | + return strsrc; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + bool DmpPrintLayer::ReadXmlAttribute(boost::property_tree::ptree &pt,double& v, const char* key, | ||
| 68 | + map<string,string>& para, map<string,string>& paraList) | ||
| 69 | + { | ||
| 70 | + try | ||
| 71 | + { | ||
| 72 | + string xmlattrkey = "<xmlattr>."; | ||
| 73 | + xmlattrkey += key; | ||
| 74 | + string value = pt.get<std::string>(xmlattrkey,"0"); | ||
| 75 | + if(value.find_first_of('#') ==0 && value.find_last_of('#') == value.length()-1) | ||
| 76 | + { | ||
| 77 | + value = replace(value, "#", ""); | ||
| 78 | + if(para.size() ==0) | ||
| 79 | + { | ||
| 80 | + paraList[value] = "double"; | ||
| 81 | + } | ||
| 82 | + else | ||
| 83 | + { | ||
| 84 | + value = para[value] ; | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + v = atof(value.c_str()); | ||
| 88 | + | ||
| 89 | + return true; | ||
| 90 | + } | ||
| 91 | + catch(...) | ||
| 92 | + { | ||
| 93 | + return false; | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + bool DmpPrintLayer::ReadXmlAttribute(boost::property_tree::ptree &pt,int& v, const char* key, | ||
| 98 | + map<string,string>& para, map<string,string>& paraList) | ||
| 99 | + { | ||
| 100 | + try | ||
| 101 | + { | ||
| 102 | + string xmlattrkey = "<xmlattr>."; | ||
| 103 | + xmlattrkey += key; | ||
| 104 | + //string value = pt.get<std::string>(xmlattrkey,"0"); | ||
| 105 | + // v = atoi(value.c_str()); | ||
| 106 | + | ||
| 107 | + string value = pt.get<std::string>(xmlattrkey,"0"); | ||
| 108 | + if(value.find_first_of('#') ==0 && value.find_last_of('#') == value.length()-1) | ||
| 109 | + { | ||
| 110 | + value = replace(value, "#", ""); | ||
| 111 | + if(para.size() ==0) | ||
| 112 | + { | ||
| 113 | + paraList[value] = "int"; | ||
| 114 | + } | ||
| 115 | + else | ||
| 116 | + { | ||
| 117 | + value = para[value] ; | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + v = atof(value.c_str()); | ||
| 122 | + return true; | ||
| 123 | + } | ||
| 124 | + catch(...) | ||
| 125 | + { | ||
| 126 | + return false; | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + bool DmpPrintLayer::ReadXmlAttribute(boost::property_tree::ptree &pt,bool& v, const char* key, | ||
| 131 | + map<string,string>& para, map<string,string>& paraList) | ||
| 132 | + { | ||
| 133 | + try | ||
| 134 | + { | ||
| 135 | + string xmlattrkey = "<xmlattr>."; | ||
| 136 | + xmlattrkey += key; | ||
| 137 | + string value = pt.get<std::string>(xmlattrkey,"false"); | ||
| 138 | + | ||
| 139 | + if(value.find_first_of('#') ==0 && value.find_last_of('#') == value.length()-1) | ||
| 140 | + { | ||
| 141 | + value = replace(value, "#", ""); | ||
| 142 | + if(para.size() ==0) | ||
| 143 | + { | ||
| 144 | + paraList[value] = "bool"; | ||
| 145 | + } | ||
| 146 | + else | ||
| 147 | + { | ||
| 148 | + value = para[value] ; | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + if(value == "false")v = false; | ||
| 153 | + if(value == "true") v= true; | ||
| 154 | + | ||
| 155 | + return true; | ||
| 156 | + } | ||
| 157 | + catch(...) | ||
| 158 | + { | ||
| 159 | + return false; | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + | ||
| 164 | + bool DmpPrintLayer::ReadXmlColorAttribute(boost::property_tree::ptree &pt,int& r, int& g, int& b, const char* key, | ||
| 165 | + map<string,string>& para, map<string,string>& paraList) | ||
| 166 | + { | ||
| 167 | + string color; | ||
| 168 | + if(this->ReadXmlAttribute(pt, color, key,para ,paraList)) | ||
| 169 | + { | ||
| 170 | + string str_red; | ||
| 171 | + string str_greed; | ||
| 172 | + string str_blue; | ||
| 173 | + int i = color.find_first_of(','); | ||
| 174 | + if(i != string::npos) | ||
| 175 | + { | ||
| 176 | + str_red = color.substr(0,i); | ||
| 177 | + color = color.substr(i+1); | ||
| 178 | + } | ||
| 179 | + else | ||
| 180 | + { | ||
| 181 | + return false; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + i = color.find_first_of(','); | ||
| 185 | + if(i != string::npos) | ||
| 186 | + { | ||
| 187 | + str_greed = color.substr(0,i); | ||
| 188 | + str_blue = color.substr(i+1); | ||
| 189 | + } | ||
| 190 | + else | ||
| 191 | + { | ||
| 192 | + return false; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + r = atoi(str_red.c_str()); | ||
| 196 | + g = atoi(str_greed.c_str()); | ||
| 197 | + b = atoi(str_blue.c_str()); | ||
| 198 | + return true; | ||
| 199 | + } | ||
| 200 | + return false; | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + bool DmpPrintLayer::ReadXmlAttribute(boost::property_tree::ptree &pt,std::string& v, const char* key, | ||
| 204 | + map<string,string>& para, map<string,string>& paraList) | ||
| 205 | + { | ||
| 206 | + try | ||
| 207 | + { | ||
| 208 | + string xmlattrkey = "<xmlattr>."; | ||
| 209 | + xmlattrkey += key; | ||
| 210 | + v = pt.get<std::string>(xmlattrkey,""); | ||
| 211 | + if(v.find_first_of('#') != v.find_last_of('#')) | ||
| 212 | + { | ||
| 213 | + int begin = v.find_first_of('#'); | ||
| 214 | + int end = v.find_last_of('#'); | ||
| 215 | + int length = end - begin +1; | ||
| 216 | + std::string parakey = v.substr(begin, length); | ||
| 217 | + std::string sparakey = replace(parakey, "#", ""); | ||
| 218 | + | ||
| 219 | + if(para.size() ==0 || para.find(sparakey) == para.end()) | ||
| 220 | + { | ||
| 221 | + paraList[sparakey] = "string"; | ||
| 222 | + } | ||
| 223 | + else | ||
| 224 | + { | ||
| 225 | + std::string paravalue = para[sparakey]; | ||
| 226 | + v = replace(v, parakey, paravalue); | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + return true; | ||
| 231 | + } | ||
| 232 | + catch(...) | ||
| 233 | + { | ||
| 234 | + return false; | ||
| 235 | + } | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + bool DmpPrintLayer::ReadXmlValue(boost::property_tree::ptree &pt,std::string& v, const char* key, | ||
| 239 | + map<string,string>& para, map<string,string>& paraList) | ||
| 240 | + { | ||
| 241 | + try | ||
| 242 | + { | ||
| 243 | + string xmlattrkey = key; | ||
| 244 | + v = pt.get<std::string>(xmlattrkey,""); | ||
| 245 | + if(v.find_first_of('#') ==0 && v.find_last_of('#') == v.length()-1) | ||
| 246 | + { | ||
| 247 | + v = replace(v, "#", ""); | ||
| 248 | + if(para.size() ==0) | ||
| 249 | + { | ||
| 250 | + paraList[v] = "bool"; | ||
| 251 | + } | ||
| 252 | + else | ||
| 253 | + { | ||
| 254 | + v = para[v] ; | ||
| 255 | + } | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + return true; | ||
| 259 | + } | ||
| 260 | + catch(...) | ||
| 261 | + { | ||
| 262 | + return false; | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintlayer.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 15:21:25 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __dmpprintlayer_h__ | ||
| 11 | +#define __dmpprintlayer_h__ | ||
| 12 | +#include <string> | ||
| 13 | +#include <memory.h> | ||
| 14 | +#include <cairo/cairo-pdf.h> | ||
| 15 | +#include <cairo/cairo-svg.h> | ||
| 16 | +#include <boost/property_tree/ptree.hpp> | ||
| 17 | +#include <boost/property_tree/xml_parser.hpp> | ||
| 18 | +#include <boost/typeof/typeof.hpp> | ||
| 19 | +#include "clsCrSurf.h" | ||
| 20 | +#include "dmpprintparameter.h" | ||
| 21 | +#include "../dmpwmsparameters.h" | ||
| 22 | +using namespace DmapCore_30; | ||
| 23 | +using namespace std; | ||
| 24 | +namespace DmpWms | ||
| 25 | +{ | ||
| 26 | + class DmpPrintLayer | ||
| 27 | + { | ||
| 28 | + public: | ||
| 29 | + std::string id_; | ||
| 30 | + | ||
| 31 | + std::string title_; | ||
| 32 | + | ||
| 33 | + std::string layerType_; | ||
| 34 | + | ||
| 35 | + //背景颜色 | ||
| 36 | + int backColor_; | ||
| 37 | + | ||
| 38 | + //边框颜色 | ||
| 39 | + int frameColor_; | ||
| 40 | + //边框类型 | ||
| 41 | + int frameType_; | ||
| 42 | + | ||
| 43 | + int localtionX_; | ||
| 44 | + | ||
| 45 | + int localtionY_; | ||
| 46 | + | ||
| 47 | + bool showbound_ = false; | ||
| 48 | + | ||
| 49 | + double boundSize_ = 0; | ||
| 50 | + | ||
| 51 | + public: | ||
| 52 | + // virtual bool InitNodeClass(); | ||
| 53 | + virtual bool DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) = 0; | ||
| 54 | + | ||
| 55 | + virtual bool ReadXML(boost::property_tree::ptree &pt, shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 56 | + std::string& errorstr, map<string,string>& para, map<string,string>& paraList)= 0; | ||
| 57 | + | ||
| 58 | + bool DrawBound(clsCrSurf* pClsCS,double width, double height); | ||
| 59 | + | ||
| 60 | + bool ReadXmlAttribute(boost::property_tree::ptree &pt,double& v, const char* key,map<string,string>& para, map<string,string>& paraList); | ||
| 61 | + | ||
| 62 | + bool ReadXmlAttribute(boost::property_tree::ptree &pt,int& v, const char* key,map<string,string>& para, map<string,string>& paraList); | ||
| 63 | + | ||
| 64 | + bool ReadXmlAttribute(boost::property_tree::ptree &pt,std::string& v, const char* key,map<string,string>& para, map<string,string>& paraList); | ||
| 65 | + | ||
| 66 | + bool ReadXmlAttribute(boost::property_tree::ptree &pt,bool& v, const char* key,map<string,string>& para, map<string,string>& paraList); | ||
| 67 | + | ||
| 68 | + bool ReadXmlColorAttribute(boost::property_tree::ptree &pt,int& r, int& g, int& b, const char* key,map<string,string>& para, map<string,string>& paraList); | ||
| 69 | + | ||
| 70 | + bool ReadXmlValue(boost::property_tree::ptree &pt,std::string& v, const char* key,map<string,string>& para, map<string,string>& paraList); | ||
| 71 | + | ||
| 72 | + shared_ptr<clsCrSurf> CreateSurface(int width, int height, DmpWmsParameters::Format format); | ||
| 73 | + | ||
| 74 | + std::string replace(std::string strsrc, std::string strfind, std::string strrep); | ||
| 75 | + }; | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +#endif // __dmpprintlayer_h__ |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintlayout.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-25 15:12:38 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprintlayout.h" | ||
| 10 | +namespace DmpWms | ||
| 11 | +{ | ||
| 12 | + bool DmpPrintLayout::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) | ||
| 13 | + { | ||
| 14 | + for(size_t i =0; i< this->data.size(); i++) | ||
| 15 | + { | ||
| 16 | + shared_ptr<DmpPrintLayer> printlayer = this->data.at(i); | ||
| 17 | + printlayer->DrawData(pClsCS,format); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + DrawBound(pClsCS); | ||
| 21 | + return true; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + bool DmpPrintLayout::ReadXML(boost::property_tree::ptree &pt, shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 25 | + string& errorstr, map<string,string>& para, map<string,string>& paraList) | ||
| 26 | + { | ||
| 27 | + | ||
| 28 | + try | ||
| 29 | + { | ||
| 30 | + boost::property_tree::ptree ptlayouts = pt.get_child("layouts"); | ||
| 31 | + for (boost::property_tree::ptree::iterator pos = ptlayouts.begin(); pos != ptlayouts.end(); ++pos) | ||
| 32 | + { | ||
| 33 | + string type; | ||
| 34 | + boost::property_tree::ptree ptlayout = pos->second; | ||
| 35 | + this->ReadXmlAttribute(ptlayout, type, "type",para,paraList); | ||
| 36 | + bool result = true; | ||
| 37 | + if (type == "text") | ||
| 38 | + { | ||
| 39 | + shared_ptr<DmpPrintLayer> layer(new DmpPrintText()); | ||
| 40 | + result = layer->ReadXML(ptlayout, pPrintParameter, errorstr,para,paraList); | ||
| 41 | + this->data.push_back(layer); | ||
| 42 | + } | ||
| 43 | + else if (type == "dmapservice") | ||
| 44 | + { | ||
| 45 | + shared_ptr<DmpPrintLayer> layer(new DmpPrintWMSService()); | ||
| 46 | + result = layer->ReadXML(ptlayout, pPrintParameter, errorstr,para,paraList); | ||
| 47 | + this->data.push_back(layer); | ||
| 48 | + } | ||
| 49 | + else if (type == "scale") | ||
| 50 | + { | ||
| 51 | + shared_ptr<DmpPrintLayer> layer(new DmpPrintScale()); | ||
| 52 | + result = layer->ReadXML(ptlayout, pPrintParameter, errorstr,para,paraList); | ||
| 53 | + this->data.push_back(layer); | ||
| 54 | + } | ||
| 55 | + else if (type == "compass") | ||
| 56 | + { | ||
| 57 | + shared_ptr<DmpPrintLayer> layer(new DmpPrintCompass()); | ||
| 58 | + result = layer->ReadXML(ptlayout, pPrintParameter, errorstr,para,paraList); | ||
| 59 | + this->data.push_back(layer); | ||
| 60 | + } | ||
| 61 | + else if (type == "rectangle" || type == "rect") | ||
| 62 | + { | ||
| 63 | + shared_ptr<DmpPrintLayer> layer(new DmpPrintRect()); | ||
| 64 | + result = layer->ReadXML(ptlayout, pPrintParameter, errorstr,para,paraList); | ||
| 65 | + this->data.push_back(layer); | ||
| 66 | + } | ||
| 67 | + else | ||
| 68 | + { | ||
| 69 | + errorstr = "布局元素错误,layout 值为(text,dmapservice,scale,compass)"; | ||
| 70 | + result = false; | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + catch (const std::exception &e) | ||
| 75 | + { | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + return true; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + bool DmpPrintLayout::DrawBound(clsCrSurf* pClsCS) | ||
| 82 | + { | ||
| 83 | + cairo_t *cr = pClsCS->m_pCr; | ||
| 84 | + //cairo_set_antialias(pClsCS->m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
| 85 | + cairo_set_source_rgb (cr, 0, 0, 0); | ||
| 86 | + cairo_set_line_width (cr, 1); | ||
| 87 | + | ||
| 88 | + cairo_rectangle (cr, localtionX_, localtionY_, width_, height_); | ||
| 89 | + cairo_stroke_preserve (cr); | ||
| 90 | + return true; | ||
| 91 | + } | ||
| 92 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintlayout.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-25 15:12:34 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __dmpprintlayout_h__ | ||
| 11 | +#define __dmpprintlayout_h__ | ||
| 12 | +#include "dmpprintlayer.h" | ||
| 13 | +#include "dmpprintrect.h" | ||
| 14 | +#include "dmpprintscale.h" | ||
| 15 | +#include "dmpprinttext.h" | ||
| 16 | +#include "dmpprintcompass.h" | ||
| 17 | +#include "dmpprintwmsservice.h" | ||
| 18 | +#include <vector> | ||
| 19 | +namespace DmpWms | ||
| 20 | +{ | ||
| 21 | + | ||
| 22 | + class DmpPrintLayout :public DmpPrintLayer | ||
| 23 | + { | ||
| 24 | + public: | ||
| 25 | + | ||
| 26 | + int width_; | ||
| 27 | + int height_; | ||
| 28 | + bool showbound_; | ||
| 29 | + int bound_size_ =1; | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + vector<shared_ptr<DmpPrintLayer>> data; | ||
| 33 | + | ||
| 34 | + public: | ||
| 35 | + | ||
| 36 | + bool DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format); | ||
| 37 | + bool ReadXML(boost::property_tree::ptree &pt, shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 38 | + string& errorstr, map<string,string>& para, map<string,string>& paraList); | ||
| 39 | + private: | ||
| 40 | + bool DrawBound(clsCrSurf* pClsCS); | ||
| 41 | + | ||
| 42 | + }; | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +#endif // __dmpprintlayout_h__ | ||
| 46 | + | ||
| 47 | + |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintparameter.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 16:22:44 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprintparameter.h" | ||
| 10 | + | ||
| 11 | +namespace DmpWms | ||
| 12 | +{ | ||
| 13 | + void DmpPrintParameter::InitParameter(double l0, double r0, double t0, double b0, int w0, int h0) | ||
| 14 | + { | ||
| 15 | + // if(rect) | ||
| 16 | + { | ||
| 17 | + right = r0; | ||
| 18 | + left = l0; | ||
| 19 | + top = t0; | ||
| 20 | + bottom = b0; | ||
| 21 | + width = w0; | ||
| 22 | + height = h0; | ||
| 23 | + | ||
| 24 | + double w = right - left; | ||
| 25 | + double h = top - bottom; | ||
| 26 | + | ||
| 27 | + if ((w > pow(10, 12)) || (w < pow(10, -12))) | ||
| 28 | + return; | ||
| 29 | + if ((h > pow(10, 12)) || (h < pow(10, -12))) | ||
| 30 | + return; | ||
| 31 | + | ||
| 32 | + long double R1 = width / w; | ||
| 33 | + long double R2 = height / h; | ||
| 34 | + double r = R1 < R2 ? R1 : R2; | ||
| 35 | + if ((r > pow(10, 12)) || (r < pow(10, -12))) | ||
| 36 | + return; | ||
| 37 | + | ||
| 38 | + // m_dR = R1 < R2 ? R1 : R2; | ||
| 39 | + m_dR = r; | ||
| 40 | + m_dXdis = width / 2.0 - m_dR * (right + left) / 2.0; | ||
| 41 | + m_dYdis = height / 2.0 + m_dR * (top + bottom) / 2.0; | ||
| 42 | + | ||
| 43 | + isWGS84 = left <= 180 && right < 180 && | ||
| 44 | + left >= -180 && right >= -180 && | ||
| 45 | + top < 90 && bottom < 90; | ||
| 46 | + | ||
| 47 | + double scaleDenominator = 0; | ||
| 48 | + if (isWGS84) | ||
| 49 | + { | ||
| 50 | + scaleDenominator = (resolution / oneInchInLayoutUnits) * (1 / r) * 111000; | ||
| 51 | + // m_dR = r *(96 / 0.0254) *111000 ;//111000 为赤道1经度等于 111000米 | ||
| 52 | + } | ||
| 53 | + else | ||
| 54 | + { | ||
| 55 | + scaleDenominator = (resolution / oneInchInLayoutUnits) * 1 / r; | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintparameter.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 16:22:41 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __dmpprintparameter_h__ | ||
| 11 | +#define __dmpprintparameter_h__ | ||
| 12 | +#include <math.h> | ||
| 13 | +#include "dmpproject.h" | ||
| 14 | +#include <memory> | ||
| 15 | +#include <map> | ||
| 16 | +using namespace std; | ||
| 17 | +namespace DmpWms | ||
| 18 | +{ | ||
| 19 | + class DmpPrintParameter | ||
| 20 | + { | ||
| 21 | + public: | ||
| 22 | + const DmpProject* pWmsService = nullptr; | ||
| 23 | + | ||
| 24 | + bool isWGS84 = false; | ||
| 25 | + double dWgs = 111000; | ||
| 26 | + double scaleDenominator = 0; | ||
| 27 | + int width =0; | ||
| 28 | + int height =0; | ||
| 29 | + | ||
| 30 | + double left = 0; | ||
| 31 | + double right = 0; | ||
| 32 | + double top =0; | ||
| 33 | + double bottom =0; | ||
| 34 | + | ||
| 35 | + double oneInchInLayoutUnits = 0.0254; | ||
| 36 | + double resolution = 96; | ||
| 37 | + | ||
| 38 | + double m_dR = 0; | ||
| 39 | + double m_dXdis = 0;//width / 2.0 - m_dR * (right + left) / 2.0; | ||
| 40 | + double m_dYdis = 0;//height / 2.0 + m_dR * (top + bottom) / 2.0; | ||
| 41 | + | ||
| 42 | + map<string,string> params; | ||
| 43 | + public: | ||
| 44 | + void InitParameter(double l0,double r0,double t0,double b0, int w0,int h0); | ||
| 45 | + | ||
| 46 | + }; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +#endif // __dmpprintparameter_h__ |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintrect.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 15:46:35 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprintrect.h" | ||
| 10 | + | ||
| 11 | +namespace DmpWms | ||
| 12 | +{ | ||
| 13 | + bool DmpPrintRect::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) | ||
| 14 | + { | ||
| 15 | + cairo_t *cr = pClsCS->m_pCr; | ||
| 16 | + //cairo_set_antialias(pClsCS->m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
| 17 | + cairo_set_source_rgb (cr, 0, 0, 0); | ||
| 18 | + cairo_set_line_width (cr, boundSize_); | ||
| 19 | + | ||
| 20 | + cairo_rectangle (cr, localtionX_, localtionY_, width_, height_); | ||
| 21 | + cairo_stroke_preserve (cr); | ||
| 22 | + return true; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + bool DmpPrintRect::ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 26 | + string& errorstr,map<string,string>& para, map<string,string>& paraList) | ||
| 27 | + { | ||
| 28 | + //this->ReadXmlAttribute(bound_node, showbound, "show"); | ||
| 29 | + this->ReadXmlAttribute(pt, localtionX_, "localtion_x",para,paraList); | ||
| 30 | + this->ReadXmlAttribute(pt, localtionY_, "localtion_y",para,paraList); | ||
| 31 | + | ||
| 32 | + this->ReadXmlAttribute(pt, width_, "width",para,paraList); | ||
| 33 | + this->ReadXmlAttribute(pt, height_, "height",para,paraList); | ||
| 34 | + | ||
| 35 | + this->ReadXmlAttribute(pt, boundSize_, "bound_size",para,paraList); | ||
| 36 | + this->pPrintParameter_ = pPrintParameter; | ||
| 37 | + | ||
| 38 | + return true; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintrect.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 15:46:31 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __dmpprintrect_h__ | ||
| 11 | +#define __dmpprintrect_h__ | ||
| 12 | +#include "dmpprintlayer.h" | ||
| 13 | +namespace DmpWms | ||
| 14 | +{ | ||
| 15 | + class DmpPrintRect :public DmpPrintLayer | ||
| 16 | + { | ||
| 17 | + public: | ||
| 18 | + shared_ptr<DmpPrintParameter> pPrintParameter_ = nullptr; | ||
| 19 | + bool DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format); | ||
| 20 | + bool ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 21 | + string& errorstr,map<string,string>& para, map<string,string>& paraList); | ||
| 22 | + | ||
| 23 | + private: | ||
| 24 | + int width_ =0; | ||
| 25 | + int height_ =0; | ||
| 26 | + | ||
| 27 | + }; | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +#endif // __dmpprintrect_h__ |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintscale.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 17:24:56 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprintscale.h" | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +namespace DmpWms | ||
| 13 | +{ | ||
| 14 | + bool DmpPrintScale::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) | ||
| 15 | + { | ||
| 16 | + bool isImage = true; | ||
| 17 | + int width = 1000; | ||
| 18 | + int height = 30; | ||
| 19 | + double xdis = 0; | ||
| 20 | + | ||
| 21 | + if(this->pPrintParameter_->isWGS84) | ||
| 22 | + { | ||
| 23 | + xdis = this->pPrintParameter_->dWgs/this->pPrintParameter_->m_dR ; | ||
| 24 | + } | ||
| 25 | + else | ||
| 26 | + { | ||
| 27 | + xdis = 1/this->pPrintParameter_->m_dR; | ||
| 28 | + } | ||
| 29 | + // double d = (resolution / oneInchInLayoutUnits)*(1/this->scaleDenominator); | ||
| 30 | + double xdis_100 = xdis*100; | ||
| 31 | + int ld = (int)log10(xdis_100); | ||
| 32 | + double hd = xdis_100/pow(10,ld); | ||
| 33 | + | ||
| 34 | + double hh = 100; | ||
| 35 | + if(hd>=1 && hd<2) | ||
| 36 | + { | ||
| 37 | + hh = 100; | ||
| 38 | + } | ||
| 39 | + else if(hd>=2 && hd<3.5) | ||
| 40 | + { | ||
| 41 | + hh = 200; | ||
| 42 | + } | ||
| 43 | + else if(hd>=3.5 && hd<7.5) | ||
| 44 | + { | ||
| 45 | + hh = 500; | ||
| 46 | + } | ||
| 47 | + else | ||
| 48 | + { | ||
| 49 | + hh = 1000; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + double px_width = (hh/hd); | ||
| 53 | + | ||
| 54 | + string dw = "M"; | ||
| 55 | + string dw2 = "M"; | ||
| 56 | + int v =hh*pow(10,ld - 2); | ||
| 57 | + | ||
| 58 | + if(v >= 1000) | ||
| 59 | + { | ||
| 60 | + char buff[100] = {0}; | ||
| 61 | + v = v/1000; | ||
| 62 | + sprintf(buff,"%d KM",v); | ||
| 63 | + dw = buff; | ||
| 64 | + v = v*2; | ||
| 65 | + sprintf(buff,"%d KM",v); | ||
| 66 | + dw2 = buff; | ||
| 67 | + } | ||
| 68 | + else | ||
| 69 | + { | ||
| 70 | + char buff[100] = {0}; | ||
| 71 | + sprintf(buff,"%d M",v); | ||
| 72 | + dw = buff; | ||
| 73 | + | ||
| 74 | + | ||
| 75 | + sprintf(buff,"%d M",v*2); | ||
| 76 | + dw2 = buff; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + shared_ptr<clsCrSurf> mClsSurfDC = this->CreateSurface((int)width, (int)height, format); | ||
| 80 | + | ||
| 81 | + cairo_t *cr = mClsSurfDC->m_pCr; //创建画笔 | ||
| 82 | + int startPix = 10; | ||
| 83 | + for(int i =0; i<2; i++) | ||
| 84 | + { | ||
| 85 | + cairo_set_source_rgb(cr, 0, 0, 0); //设置画笔颜色,也就是红,绿,蓝,这里设置成绿色。 | ||
| 86 | + cairo_move_to(cr, startPix + px_width*i, 20); //三角形第一个顶点 | ||
| 87 | + cairo_line_to(cr, startPix + px_width*i, 25); //三角形第二个顶点 | ||
| 88 | + cairo_line_to(cr, startPix + px_width*(i+1), 25); //三角形第三个顶点 | ||
| 89 | + cairo_line_to(cr, startPix + px_width*(i+1), 20); //三角形第三个顶点 | ||
| 90 | + cairo_set_line_width(cr, 1); | ||
| 91 | + cairo_stroke(cr); | ||
| 92 | + | ||
| 93 | + // const char *str = "N"; | ||
| 94 | + cairo_select_font_face(cr, "宋体", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | ||
| 95 | + cairo_set_font_size(cr, 10); | ||
| 96 | + //cairo_move_to(cr, 8, 15); | ||
| 97 | + | ||
| 98 | + cairo_move_to(cr, startPix + px_width*(i+1) - 15, 15); | ||
| 99 | + if(i ==0) | ||
| 100 | + { | ||
| 101 | + cairo_show_text(cr, dw.c_str()); | ||
| 102 | + } | ||
| 103 | + else | ||
| 104 | + { | ||
| 105 | + cairo_show_text(cr, dw2.c_str()); | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + //const char *str = "0"; | ||
| 110 | + cairo_move_to(cr, startPix -3 , 15); | ||
| 111 | + cairo_show_text(cr, "0"); | ||
| 112 | + | ||
| 113 | + cairo_set_source_surface(pClsCS->m_pCr, mClsSurfDC->m_pSurf, localtionX_, localtionY_); | ||
| 114 | + cairo_paint(pClsCS->m_pCr); | ||
| 115 | + return true; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + bool DmpPrintScale::ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 119 | + string& errorstr, map<string,string>& para, map<string,string>& paraList) | ||
| 120 | + { | ||
| 121 | + this->ReadXmlAttribute(pt,localtionX_,"localtion_x",para,paraList); | ||
| 122 | + this->ReadXmlAttribute(pt,localtionY_,"localtion_y",para,paraList); | ||
| 123 | + // this->ReadXmlAttribute(pt,type,"type"); | ||
| 124 | + | ||
| 125 | + this->ReadXmlAttribute(pt, boundSize_, "bound_size",para,paraList); | ||
| 126 | + this->ReadXmlAttribute(pt, showbound_, "showBound",para,paraList); | ||
| 127 | + | ||
| 128 | + this->pPrintParameter_ = pPrintParameter; | ||
| 129 | + | ||
| 130 | + return true; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + | ||
| 134 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintscale.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 17:24:52 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __dmpprintscale_h__ | ||
| 11 | +#define __dmpprintscale_h__ | ||
| 12 | + | ||
| 13 | +#include "dmpprintlayer.h" | ||
| 14 | +namespace DmpWms | ||
| 15 | +{ | ||
| 16 | + class DmpPrintScale :public DmpPrintLayer | ||
| 17 | + { | ||
| 18 | + public: | ||
| 19 | + string serviceName; | ||
| 20 | + shared_ptr<DmpPrintParameter> pPrintParameter_ = nullptr; | ||
| 21 | + public: | ||
| 22 | + //bool DrawImage(); | ||
| 23 | + bool DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format); | ||
| 24 | + bool ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 25 | + string& errorstr, map<string,string>& para, map<string,string>& paraList); | ||
| 26 | + }; | ||
| 27 | +} | ||
| 28 | +#endif // __dmpprintscale_h__ |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprinttext.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 16:36:43 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprinttext.h" | ||
| 10 | +namespace DmpWms | ||
| 11 | +{ | ||
| 12 | + bool DmpPrintText::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) | ||
| 13 | + { | ||
| 14 | + cairo_set_antialias(pClsCS->m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
| 15 | + cairo_set_source_rgb(pClsCS->m_pCr, r_, g_, b_); | ||
| 16 | + cairo_select_font_face(pClsCS->m_pCr, font_.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | ||
| 17 | + cairo_set_font_size(pClsCS->m_pCr,fontSize_); | ||
| 18 | + | ||
| 19 | + cairo_move_to(pClsCS->m_pCr,localtionX_, localtionY_); | ||
| 20 | + | ||
| 21 | + cairo_show_text(pClsCS->m_pCr, text_.c_str()); | ||
| 22 | + | ||
| 23 | + return true; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + bool DmpPrintText::ReadXML(boost::property_tree::ptree &pt, shared_ptr<DmpPrintParameter> pMapParameter, | ||
| 27 | + string& errorstr, map<string,string>& para, map<string,string>& paraList) | ||
| 28 | + { | ||
| 29 | + try | ||
| 30 | + { | ||
| 31 | + this->ReadXmlAttribute(pt, localtionX_, "localtion_x",para,paraList); | ||
| 32 | + this->ReadXmlAttribute(pt, localtionY_, "localtion_y",para,paraList); | ||
| 33 | + | ||
| 34 | + this->ReadXmlAttribute(pt, boundSize_, "bound_size",para,paraList); | ||
| 35 | + this->ReadXmlAttribute(pt, showbound_, "showBound",para,paraList); | ||
| 36 | + boost::property_tree::ptree pttext = pt.get_child("text"); | ||
| 37 | + this->ReadXmlColorAttribute(pttext, r_, g_, b_, "fontcolor",para,paraList); | ||
| 38 | + this->ReadXmlAttribute(pttext, text_, "title",para,paraList); | ||
| 39 | + this->ReadXmlAttribute(pttext, fontSize_, "fontsize",para,paraList); | ||
| 40 | + this->ReadXmlAttribute(pttext, font_, "font",para,paraList); | ||
| 41 | + this->ReadXmlAttribute(pttext, isBold_, "bold",para,paraList); | ||
| 42 | + return true; | ||
| 43 | + } | ||
| 44 | + catch(const std::exception& e) | ||
| 45 | + { | ||
| 46 | + return false; | ||
| 47 | + } | ||
| 48 | + return false; | ||
| 49 | + } | ||
| 50 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprinttext.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-27 16:36:39 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#ifndef __dmpprinttext_h__ | ||
| 10 | +#define __dmpprinttext_h__ | ||
| 11 | + | ||
| 12 | +#include "dmpprintlayer.h" | ||
| 13 | +namespace DmpWms | ||
| 14 | +{ | ||
| 15 | + class DmpPrintText : public DmpPrintLayer | ||
| 16 | + { | ||
| 17 | + private: | ||
| 18 | + | ||
| 19 | + int r_,g_,b_; | ||
| 20 | + std::string text_; | ||
| 21 | + std::string font_; | ||
| 22 | + int fontSize_; | ||
| 23 | + bool isBold_; | ||
| 24 | + | ||
| 25 | + public: | ||
| 26 | + bool DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format); | ||
| 27 | + bool ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pMapParameter, | ||
| 28 | + string& errorstr, map<string,string>& para, map<string,string>& paraList); | ||
| 29 | + }; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +#endif // __dmpprinttext_h__ |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintwmsservice.cpp | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-28 15:31:15 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpprintwmsservice.h" | ||
| 10 | + | ||
| 11 | +namespace DmpWms | ||
| 12 | +{ | ||
| 13 | + bool DmpPrintWMSService::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) | ||
| 14 | + { | ||
| 15 | + try | ||
| 16 | + { | ||
| 17 | + shared_ptr<DmpWmsRenderer> _WmsRenderer(new DmpWmsRenderer( height_, width_)); | ||
| 18 | + | ||
| 19 | + shared_ptr<clsCrSurf> mClsSurfDC = this->CreateSurface((int)width_, (int)height_, format); | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + // cairo_surface_set_fallback_resolution( _map->GetSurfDC()->m_pSurf,900,900); | ||
| 23 | + | ||
| 24 | + // if (this->m_mapWmsServer.find(serviceName) != this->m_mapWmsServer.end()) | ||
| 25 | + { | ||
| 26 | + //shared_ptr<WMSServer> wmsServer = this->m_mapWmsServer[serviceName]; | ||
| 27 | + _WmsRenderer->AddWmsMapLayers(project_); | ||
| 28 | + | ||
| 29 | + //Rect *rect_service = project_->GetExtent(); | ||
| 30 | + | ||
| 31 | + shared_ptr<Rect> rect(new Rect(boxY2_, boxX2_, boxY1_, boxX1_)); | ||
| 32 | + _WmsRenderer->SetExtent(rect); | ||
| 33 | + _WmsRenderer->GetMap(nullptr, nullptr, mClsSurfDC.get()); | ||
| 34 | + | ||
| 35 | + if (this->showMapLegend_) | ||
| 36 | + { | ||
| 37 | + DrawLegend(mClsSurfDC.get(), _WmsRenderer, format, localtionX_, localtionY_, this->width_, this->height_); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + cairo_set_source_surface(pClsCS->m_pCr, mClsSurfDC->m_pSurf, localtionX_, localtionY_); | ||
| 41 | + cairo_paint(pClsCS->m_pCr); | ||
| 42 | + if(this->showCoord_) | ||
| 43 | + { | ||
| 44 | + DrawCoord(pClsCS, _WmsRenderer, format, localtionX_, localtionY_, this->width_, this->height_); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + DrawBound(pClsCS, width_, height_); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + catch (const std::exception &e) | ||
| 54 | + { | ||
| 55 | + | ||
| 56 | + std::cerr << " Refresh " << e.what() << '\n'; | ||
| 57 | + return false; | ||
| 58 | + } | ||
| 59 | + return false; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /*bool DmpPrintWMSService::DrawCoord(clsCrSurf* pClsCS,PrintOutputFormat format) | ||
| 63 | + { | ||
| 64 | + format. | ||
| 65 | + }*/ | ||
| 66 | + bool DmpPrintWMSService::DrawCoord(clsCrSurf* pClsCS, shared_ptr<DmpWmsRenderer> _map,DmpWmsParameters::Format format, | ||
| 67 | + int locationX,int locationY,int width,int height) | ||
| 68 | + { | ||
| 69 | + if(pLegendParamater_ == nullptr) | ||
| 70 | + return false; | ||
| 71 | + shared_ptr<Rect> rect = _map->GetExtent(); | ||
| 72 | + if(rect == nullptr) | ||
| 73 | + return false; | ||
| 74 | + | ||
| 75 | + //double x0 =(x - m_dXdis)/ m_dR ; | ||
| 76 | + //double y0 = ( y + m_dYdis)/m_dR ; | ||
| 77 | + double x_width = rect->m_dRight - rect->m_dLeft; | ||
| 78 | + double dx = 100/ _map->m_dR; | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + int ld = (int)log10(dx); | ||
| 82 | + double hd = dx/pow(10,ld); | ||
| 83 | + | ||
| 84 | + double hh = 1; | ||
| 85 | + | ||
| 86 | + if(hd>=1 && hd<2) hh = 1; | ||
| 87 | + else if(hd>=2 && hd<3.5) hh = 2; | ||
| 88 | + else if(hd>=3.5 && hd<7.5) hh = 5; | ||
| 89 | + else hh = 10; | ||
| 90 | + | ||
| 91 | + dx = hh * pow(10,ld); | ||
| 92 | + double xbegin = ((int) (rect->m_dLeft/dx) +1) * dx; | ||
| 93 | + cairo_t *cr = pClsCS->m_pCr; //创建画笔 | ||
| 94 | + | ||
| 95 | + cairo_set_source_rgb(cr, 0, 0, 0); | ||
| 96 | + char drawText[100]= {0}; | ||
| 97 | + shared_ptr<cairo_text_extents_t> pCrExtents(new cairo_text_extents_t()); | ||
| 98 | + for(double pos_x = xbegin; pos_x <= rect->m_dRight; pos_x += dx ) | ||
| 99 | + { | ||
| 100 | + double x0 = _map->m_dR * pos_x + _map->m_dXdis + locationX; | ||
| 101 | + sprintf(drawText, "%.4f", pos_x); | ||
| 102 | + DoubleRemoveZero(drawText); | ||
| 103 | + // double y0 = -m_dR * y + m_dYdis; | ||
| 104 | + //设置画笔颜色,也就是红,绿,蓝,这里设置成绿色。 | ||
| 105 | + | ||
| 106 | + cairo_move_to(cr, x0, locationY); | ||
| 107 | + cairo_line_to(cr, x0, locationY -5); | ||
| 108 | + cairo_set_line_width(cr, 1.5); | ||
| 109 | + cairo_stroke(cr); | ||
| 110 | + | ||
| 111 | + cairo_move_to(cr, x0, locationY + height); | ||
| 112 | + cairo_line_to(cr, x0, locationY+ height +5); | ||
| 113 | + cairo_set_line_width(cr, 1.5); | ||
| 114 | + cairo_stroke(cr); | ||
| 115 | + | ||
| 116 | + | ||
| 117 | + cairo_select_font_face(cr, "宋体", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | ||
| 118 | + cairo_set_font_size(cr, 10); | ||
| 119 | + //cairo_move_to(cr, 8, 15); | ||
| 120 | + | ||
| 121 | + cairo_text_extents(cr, drawText, pCrExtents.get()); | ||
| 122 | + | ||
| 123 | + cairo_move_to(cr, x0 - pCrExtents->width/2 ,locationY - 3 - pCrExtents->height); | ||
| 124 | + cairo_show_text(cr, drawText); | ||
| 125 | + | ||
| 126 | + cairo_move_to(cr, x0 - pCrExtents->width/2 ,locationY + height + 3 + 1.5* pCrExtents->height); | ||
| 127 | + cairo_show_text(cr, drawText); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + | ||
| 131 | + /// 画Y轴 | ||
| 132 | + | ||
| 133 | + //double y_height = rect->m_dTop - rect->m_dBottom; | ||
| 134 | + | ||
| 135 | + double ybegin = ((int) (rect->m_dBottom/dx) +1) * dx; | ||
| 136 | + | ||
| 137 | + | ||
| 138 | + for(double pos_y = ybegin; pos_y <= rect->m_dTop; pos_y += dx ) | ||
| 139 | + { | ||
| 140 | + double y0 = - _map->m_dR * pos_y + _map->m_dYdis + locationY; | ||
| 141 | + sprintf(drawText, "%.4f", pos_y); | ||
| 142 | + DoubleRemoveZero(drawText); | ||
| 143 | + // double y0 = -m_dR * y + m_dYdis; | ||
| 144 | + //设置画笔颜色,也就是红,绿,蓝,这里设置成绿色。 | ||
| 145 | + cairo_move_to(cr,locationX -6, y0); | ||
| 146 | + cairo_line_to(cr,locationX, y0); | ||
| 147 | + cairo_set_line_width(cr, 1.5); | ||
| 148 | + cairo_stroke(cr); | ||
| 149 | + | ||
| 150 | + cairo_move_to(cr, locationX + width, y0); | ||
| 151 | + cairo_line_to(cr, locationX+ width +6,y0); | ||
| 152 | + cairo_set_line_width(cr, 1.5); | ||
| 153 | + cairo_stroke(cr); | ||
| 154 | + | ||
| 155 | + | ||
| 156 | + cairo_select_font_face(cr, "宋体", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | ||
| 157 | + cairo_set_font_size(cr, 10); | ||
| 158 | + | ||
| 159 | + | ||
| 160 | + cairo_text_extents(cr, drawText, pCrExtents.get()); | ||
| 161 | + | ||
| 162 | + cairo_move_to(cr, locationX - pCrExtents->height -3 ,y0 + pCrExtents->width/2); | ||
| 163 | + cairo_rotate(cr, -3.141592/2); | ||
| 164 | + cairo_show_text(cr, drawText); | ||
| 165 | + cairo_rotate(cr, 3.141592/2); | ||
| 166 | + | ||
| 167 | + cairo_move_to(cr, locationX + width + 3 + 1.5*pCrExtents->height ,y0 + pCrExtents->width/2); | ||
| 168 | + cairo_rotate(cr, -3.141592/2); | ||
| 169 | + cairo_show_text(cr, drawText); | ||
| 170 | + cairo_rotate(cr, 3.141592/2); | ||
| 171 | + } | ||
| 172 | + return true; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + void DmpPrintWMSService::DoubleRemoveZero(char* str) | ||
| 176 | + { | ||
| 177 | + int len = strlen(str); | ||
| 178 | + for(int i=0; i< len; i++) | ||
| 179 | + { | ||
| 180 | + if(str[i] == '.') | ||
| 181 | + break; | ||
| 182 | + if(i ==len -1) | ||
| 183 | + return; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + for(int i=len -1; i>0; i--) | ||
| 187 | + { | ||
| 188 | + if(str[i] == '0') | ||
| 189 | + { | ||
| 190 | + str[i] = 0; | ||
| 191 | + } | ||
| 192 | + else if(str[i] == '.') | ||
| 193 | + { | ||
| 194 | + str[i] = 0; | ||
| 195 | + break; | ||
| 196 | + } | ||
| 197 | + else | ||
| 198 | + { | ||
| 199 | + break; | ||
| 200 | + } | ||
| 201 | + } | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + bool DmpPrintWMSService::DrawLegend(clsCrSurf* pClsCS, shared_ptr<DmpWmsRenderer> _map, DmpWmsParameters::Format format, | ||
| 205 | + int locationX,int locationY,int _width,int _height) | ||
| 206 | + { | ||
| 207 | + | ||
| 208 | + int height = 1000; | ||
| 209 | + int width = 1800; | ||
| 210 | + | ||
| 211 | + shared_ptr<clsCrSurf> mClsSurfDC = this->CreateSurface(width_, height_, format); | ||
| 212 | + // shared_ptr<legendParamater> pLegendParamater_(new legendParamater() ); | ||
| 213 | + pLegendParamater_->m_dScaleDenominator = _map->m_dScaleDenominator; | ||
| 214 | + | ||
| 215 | + _map->GetMapLegend(pLegendParamater_,mClsSurfDC.get()); | ||
| 216 | + | ||
| 217 | + pLegendParamater_->next(nullptr); | ||
| 218 | + | ||
| 219 | + shared_ptr<clsCrSurf> mClsSurfDC2 = this->CreateSurface(pLegendParamater_->max_pixXIndex+100, (int)pLegendParamater_->max_pixYIndex+15, format); | ||
| 220 | + | ||
| 221 | + | ||
| 222 | + cairo_set_source_rgba (mClsSurfDC2->m_pCr, pLegendParamater_->back_r/255.0, | ||
| 223 | + pLegendParamater_->back_g/255.0, pLegendParamater_->back_b/255.0, pLegendParamater_->back_a/255.0); | ||
| 224 | + | ||
| 225 | + cairo_rectangle (mClsSurfDC2->m_pCr, 3, 3, pLegendParamater_->max_pixXIndex + 100 -6, pLegendParamater_->max_pixYIndex + 10 ); | ||
| 226 | + cairo_fill_preserve(mClsSurfDC2->m_pCr); | ||
| 227 | + | ||
| 228 | + cairo_set_source_rgb (mClsSurfDC2->m_pCr, 0, 0, 0); | ||
| 229 | + cairo_set_line_width (mClsSurfDC2->m_pCr, 1); | ||
| 230 | + cairo_stroke(mClsSurfDC2->m_pCr); | ||
| 231 | + | ||
| 232 | + | ||
| 233 | + cairo_set_source_surface(mClsSurfDC2->m_pCr, mClsSurfDC->m_pSurf,0, 0); | ||
| 234 | + cairo_paint(mClsSurfDC2->m_pCr); | ||
| 235 | + | ||
| 236 | + cairo_set_source_surface(pClsCS->m_pCr, mClsSurfDC2->m_pSurf,_width - pLegendParamater_->max_pixXIndex - 100- 10, | ||
| 237 | + _height - pLegendParamater_->max_pixYIndex -20); | ||
| 238 | + cairo_paint(pClsCS->m_pCr); | ||
| 239 | + | ||
| 240 | + return true; | ||
| 241 | + | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + | ||
| 245 | + bool DmpPrintWMSService::ReadXML(boost::property_tree::ptree &pt,shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 246 | + string& errorstr, map<string,string>& para, map<string,string>& paraList) | ||
| 247 | + { | ||
| 248 | + try | ||
| 249 | + { | ||
| 250 | + this->ReadXmlAttribute(pt, localtionX_, "localtion_x",para,paraList ); | ||
| 251 | + this->ReadXmlAttribute(pt, localtionY_, "localtion_y",para,paraList); | ||
| 252 | + this->ReadXmlAttribute(pt, width_, "width",para,paraList); | ||
| 253 | + this->ReadXmlAttribute(pt, height_, "height",para,paraList); | ||
| 254 | + this->ReadXmlAttribute(pt, showCoord_, "showCoord",para,paraList); | ||
| 255 | + this->ReadXmlAttribute(pt, boundSize_, "bound_size",para,paraList); | ||
| 256 | + this->ReadXmlAttribute(pt, showbound_, "showBound",para,paraList); | ||
| 257 | + | ||
| 258 | + // rapidxml::xml_node<char> *text_node = node->first_node("legend"); | ||
| 259 | + | ||
| 260 | + try | ||
| 261 | + { | ||
| 262 | + boost::property_tree::ptree ptlegend = pt.get_child("legend"); | ||
| 263 | + shared_ptr<legendParamater> pLegendParamater_0(new legendParamater()); | ||
| 264 | + pLegendParamater_ = pLegendParamater_0; | ||
| 265 | + | ||
| 266 | + this->ReadXmlColorAttribute(ptlegend, pLegendParamater_->r, pLegendParamater_->g, pLegendParamater_->b, "fontcolor",para,paraList); | ||
| 267 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->title, "title",para,paraList); | ||
| 268 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->fontSize, "fontsize",para,paraList); | ||
| 269 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->font, "font",para,paraList); | ||
| 270 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->isbold, "bold",para,paraList); | ||
| 271 | + this->ReadXmlColorAttribute(ptlegend, pLegendParamater_->back_r, pLegendParamater_->back_g, pLegendParamater_->back_b, "backgroundcolor",para,paraList); | ||
| 272 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->back_a, "backgroundalpha",para,paraList); | ||
| 273 | + | ||
| 274 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->showclassification, "showclassification",para,paraList); | ||
| 275 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->rowspacing, "rowspacing",para,paraList); | ||
| 276 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->size_x, "size_x",para,paraList); | ||
| 277 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->size_y, "size_y",para,paraList); | ||
| 278 | + this->ReadXmlAttribute(ptlegend, pLegendParamater_->row_maxsize, "row_maxsize",para,paraList); | ||
| 279 | + showMapLegend_ = true; | ||
| 280 | + } | ||
| 281 | + catch(...) | ||
| 282 | + { | ||
| 283 | + showMapLegend_ = false; | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + this->boxX1_ = pPrintParameter->left; | ||
| 287 | + this->boxX2_ = pPrintParameter->right; | ||
| 288 | + this->boxY1_ = pPrintParameter->bottom; | ||
| 289 | + this->boxY2_ = pPrintParameter->top; | ||
| 290 | + | ||
| 291 | + this->project_ = pPrintParameter->pWmsService; | ||
| 292 | + | ||
| 293 | + pPrintParameter->InitParameter(this->boxX1_, this->boxX2_, this->boxY1_, this->boxY2_, this->width_, this->height_); | ||
| 294 | + } | ||
| 295 | + catch(const std::exception& e) | ||
| 296 | + { | ||
| 297 | + showMapLegend_ = false; | ||
| 298 | + return false; | ||
| 299 | + } | ||
| 300 | + return true; | ||
| 301 | + } | ||
| 302 | +} |
| 1 | +/************************************************************************** | ||
| 2 | +* file: dmpprintwmsservice.h | ||
| 3 | + | ||
| 4 | +* Author: qingxiongf | ||
| 5 | +* Date: 2022-01-28 15:31:10 | ||
| 6 | +* Email: qingxiongf@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | + | ||
| 10 | +#ifndef __dmpprintwmsservice_h__ | ||
| 11 | +#define __dmpprintwmsservice_h__ | ||
| 12 | +#include "dmpprintlayer.h" | ||
| 13 | +#include "dmpproject.h" | ||
| 14 | +#include "legendParamater.h" | ||
| 15 | +#include "../dmpwmsrenderer.h" | ||
| 16 | +using namespace DmapCore_30; | ||
| 17 | + | ||
| 18 | +namespace DmpWms | ||
| 19 | +{ | ||
| 20 | + class DmpPrintWMSService :public DmpPrintLayer | ||
| 21 | + { | ||
| 22 | + public: | ||
| 23 | + int width_; | ||
| 24 | + int height_; | ||
| 25 | + string serviceName_; | ||
| 26 | + //不透明度 | ||
| 27 | + double opacity_; | ||
| 28 | + | ||
| 29 | + const DmpProject* project_; | ||
| 30 | + | ||
| 31 | + double boxX1_, boxY1_, boxX2_, boxY2_; | ||
| 32 | + | ||
| 33 | + // clsLock m_clsMapLock; | ||
| 34 | + | ||
| 35 | + bool showMapLegend_ = false; | ||
| 36 | + | ||
| 37 | + bool showCoord_ = false; | ||
| 38 | + | ||
| 39 | + shared_ptr<legendParamater> pLegendParamater_ = nullptr; | ||
| 40 | + | ||
| 41 | + //bool DrawImage(); | ||
| 42 | + bool DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format); | ||
| 43 | + | ||
| 44 | + bool ReadXML(boost::property_tree::ptree &pt, shared_ptr<DmpPrintParameter> pPrintParameter, | ||
| 45 | + string& errorstr, map<string,string>& para, map<string,string>& paraList); | ||
| 46 | + private: | ||
| 47 | + | ||
| 48 | + bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<DmpWmsRenderer> _map, DmpWmsParameters::Format format,int locationX,int localtionY,int width,int height); | ||
| 49 | + | ||
| 50 | + bool DrawCoord(clsCrSurf* pClsCS, shared_ptr<DmpWmsRenderer> _map, DmpWmsParameters::Format format,int locationX,int localtionY,int width,int height); | ||
| 51 | + | ||
| 52 | + bool DrawCoordXText(clsCrSurf* pClsCS,shared_ptr<DmpWmsRenderer> _map, | ||
| 53 | + int locationX,int localtionY,int width,int height); | ||
| 54 | + | ||
| 55 | + void DoubleRemoveZero(char* str); | ||
| 56 | + }; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +#endif // __dmpprintwmsservice_h__ |
请
注册
或
登录
后发表评论