Article Directory
- Preface
- 1. Development environment
- Two, specific ideas
Preface
Subject to the limitations of the RasterImage object in AutoCAD, images of large files in the native CAD environment will be abnormally stuck when loading images. This article demonstrates how to combine gdal to load dozens of hundreds of G of tif and image services published by WMS/TMS/WTMS in AutoCAD .
Global thumbnail
Zoom to Imperial Capital
1. Development tools and environment
This time using objectarx2020 (64-bit)+vs2017+gdal3.14 environment
objectarx2020 can be downloaded from the Autodesk official website
Recommended download address for gdal development environment
https://www.gisinternals.com/release.php
Two, specific ideas
1.gdal RaterIO
About rasterIO, gdal god Li Minlu has written in detail, for specific reference
https://blog.csdn.net/liminlu0314/article/details/7072224
raterIO can open the RGB data at the specified location in WMS/WMTS/TMS/geogiff
2.objectarx custom entity
When cad custom entity overloads subworldDraw, use the rasterIO method in gdal to request the RGB drawing information block according to the current screen range
After requesting the data, you can call the mode->rawGeometry()->image(....) method in the CAD custom entity to draw according to the specified length and width
When the View size changes, CAD can request to refresh the image again according to the scope. The final result is to load images of different levels according to the current display scope size, and the actual coordinates match the image coordinates 1:1.
3. Coordinate conversion
How to obtain CAD screen coordinates
void ImageIOThread::getScreenCorners(AcGePoint2d& ptLeftLower, AcGePoint2d& ptRightUpper)
{
CRect rc;
CView* pCurView = acedGetAcadDwgView();
pCurView->GetClientRect(&rc);
CPoint ptTopLeft = rc.TopLeft();
CPoint ptBottomRight = rc.BottomRight();
acedDwgPoint pt1, pt2;
acedCoordFromPixelToWorld(ptTopLeft, pt1);
acedCoordFromPixelToWorld(ptBottomRight, pt2);
ptLeftLower.x = pt1[0];
ptLeftLower.y = pt2[1];
ptRightUpper.x = pt2[0];
ptRightUpper.y = pt1[1];
}
Use the current screen coordinates to calculate the corresponding row and column number in the Image. It should be noted that services such as WMS use EPSG3857, which is pseudo Mercator shadow. In actual use, the current coordinates need to be converted to latitude and longitude before turning the latitude and longitude. Converted to 3857, the specific conversion method can refer to Li Minlu blog, and the proj library can also be used for coordinate conversion. Different coordinate systems can define different ellipsoid parameters or use 4 parameters/7 parameters for conversion.
4. Call method
Call example:
Link: https://pan.baidu.com/s/17xG5Sh1rhndPqq5fqizZqg
Extraction code: bb7g