27 #include "../../../common/StringUtils.h" 28 #include "../../../geometry/Envelope.h" 29 #include "../../../geometry/MultiLineString.h" 30 #include "../../../geometry/Utils.h" 31 #include "../../../maptools/Utils.h" 69 const double& s1urx,
const double& s1ury,
70 double s2width,
double s2height) :
566 double xInit = verticalLineInitial;
571 int nParts =
static_cast<int>(difx / verticalLineGap);
573 xInit = (nParts == 0) ?
574 verticalLineInitial :
575 xInit + (nParts * verticalLineGap);
594 double yInit = horizontalLineInitial;
599 int nParts =
static_cast<int>(dify / horizontalLineGap);
601 yInit = (nParts == 0) ?
602 horizontalLineInitial :
603 yInit + (nParts * horizontalLineGap);
625 std::vector<te::gm::LineString> res;
628 if (planarBox.
getWidth() / verticalLineGap > maxGaps)
632 double initialX =
CalculateInitialX(planarBox, verticalLineInitial, verticalLineGap);
635 for (; initialX <= planarBox.
getUpperRightX(); initialX += verticalLineGap)
645 res.push_back(lineString);
667 std::vector<te::gm::LineString> lines;
670 if (world.
getHeight() / horizontalLineGap > maxGaps)
673 double initialY =
CalculateInitialY(world, horizontalLineInitial, horizontalLineGap);
675 for (; initialY <= world.
getUpperRightY(); initialY += horizontalLineGap)
685 lines.push_back(lineString);
702 double GetInitialCoord(
const double& initialCoord,
const double& distance,
double& gap)
710 const size_t size = 25;
711 int gaps[size] = { 1000, 1500, 2000, 2500, 5000, 7500, 10000, 12500, 15000, 20000, 25000, 50000, 100000, 125000, 150000, 175000, 200000, 250000, 500000, 750000, 1000000, 1250000, 1500000,
713 int numberOfIntervals = 5;
715 gap = distance / numberOfIntervals;
717 for (
size_t i = 0; i < size; i++)
728 int interval =
static_cast<int>(initialCoord / gap);
730 return interval * gap;
767 QFontMetrics fm(font);
784 void DrawLine(QPainter* painter, QLineF&
line,
const int& txtOffSet,
const bool& vertical)
786 QPaintDevice* device = painter->device();
791 int offSet = oneMMPx/2 + txtOffSet;
804 y2 = device->height() - (offSet + oneMMPx + oneMMPx/2);
810 x2 = device->width() - offSet;
814 line.setP1(QPointF(x1, y1));
815 line.setP2(QPointF(x2, y2));
817 painter->drawLine(line);
833 void DrawLines(
WorldTransformer transf, QPainter* painter,
const std::vector<te::gm::LineString>& lines,
const int& txtOffSet,
const bool& vertical)
835 std::vector<te::gm::LineString>::const_iterator it;
843 for(it = lines.cbegin(); it != lines.cend(); ++it)
845 transf.
system1Tosystem2((*it).getPointN(0)->getX(), (*it).getPointN(0)->getY(), x1, y1);
846 transf.
system1Tosystem2((*it).getPointN(1)->getX(), (*it).getPointN(1)->getY(), x2, y2);
848 line.setP1(QPointF(x1, y1));
849 line.setP2(QPointF(x2, y2));
851 DrawLine(painter, line, txtOffSet, vertical);
868 void DrawAllLines(
WorldTransformer transf, QPainter* painter,
const std::vector<te::gm::LineString>& vlines,
const std::vector<te::gm::LineString>& hlines,
876 DrawLines(transf, painter, vlines, txtH,
true);
877 DrawLines(transf, painter, hlines, txtW,
false);
891 QPixmap*
GetTextPixmap(
const QString& txt,
const QFont& font,
const QPen& pen)
896 QPixmap* res =
nullptr;
903 pixDimensions.setWidth(txtW);
904 pixDimensions.setHeight(txtH);
906 res =
new QPixmap(pixDimensions);
907 res->fill(Qt::white);
909 pixRect.setWidth(pixDimensions.width());
910 pixRect.setHeight(pixDimensions.height());
917 p.drawText(QRect(0, 0, pixDimensions.width(), pixDimensions.height()), Qt::AlignLeft, txt);
940 const QSize& displayDimensions)
948 QPixmap* res =
nullptr;
953 std::vector<te::gm::LineString>::const_iterator it;
959 pixDimensions.setWidth(displayDimensions.width());
960 pixDimensions.setHeight(txtH);
964 pixDimensions.setWidth(displayDimensions.height());
965 pixDimensions.setHeight(txtH);
968 res =
new QPixmap(pixDimensions);
970 res->fill(Qt::transparent);
974 for(it = lines.cbegin(); it != lines.cend(); ++it)
976 std::unique_ptr<QPixmap> pixValue;
981 lValue = (vertical) ?
982 static_cast<long>((*it).getPointN(0)->getX()) :
983 static_cast<long>((*it).getPointN(0)->getY());
985 sValue = QString::number(lValue);
989 subpixRect.setSize(pixValue->size());
993 center.setX(static_cast<int>(col));
994 center.setY(subpixRect.height()/2);
998 center.setX(static_cast<int>(row));
999 center.setY(subpixRect.height()/2);
1002 subpixRect.moveCenter(center);
1004 p.drawPixmap(subpixRect, *pixValue.get());
1023 void DrawTexts(
WorldTransformer transf, QPainter* painter,
const std::vector<te::gm::LineString>& vlines,
const std::vector<te::gm::LineString>& hlines,
1029 std::unique_ptr<QPixmap> horizontalLabel;
1030 std::unique_ptr<QPixmap> verticalLabel;
1032 QSize deviceSize(painter->device()->width(), painter->device()->height());
1035 devR.setSize(deviceSize);
1038 horizontalLabel.reset(
GetTextsPixmap(transf, vlines, font, painter->pen(),
true, deviceSize));
1039 painter->drawPixmap(0, oneMMPx, *horizontalLabel.get());
1040 painter->drawPixmap(0, deviceSize.height() - (oneMMPx+horizontalLabel->height()), *horizontalLabel.get());
1042 dx = devR.center().x();
1043 dy = devR.center().y();
1046 verticalLabel.reset(
GetTextsPixmap(transf, hlines, font, painter->pen(),
false, deviceSize));
1048 painter->translate(devR.center());
1049 painter->rotate(90);
1050 painter->translate(-dy, -dx);
1052 painter->drawPixmap(oneMMPx, 0, *verticalLabel.get());
1053 painter->drawPixmap(oneMMPx, deviceSize.width() - verticalLabel->height(), *verticalLabel.get());
1082 std::string authName =
"EPSG";
1087 if (!unitPtr || !copyWorldBox.
isValid())
1088 return copyWorldBox;
1091 copyWorldBox.
transform(static_cast<int>(sourceSRID), static_cast<int>(targetSRID));
1092 return copyWorldBox;
1116 converter->setSourceSRID(sourceSRID);
1117 converter->setTargetSRID(planarSRID);
1127 std::vector<te::gm::Coord2D> vecValidCoords;
1129 for (std::size_t i = 0; i < npoints; ++i)
1131 double xin = line->
getX(i);
1132 double yin = line->
getY(i);
1136 bool wasConverted = converter->convert(xin, yin, xout, yout);
1141 vecValidCoords.push_back(coord);
1148 for (std::size_t i = 0; i < vecValidCoords.size(); ++i)
1149 line->
setPoint(i, vecValidCoords[i].x, vecValidCoords[i].y);
1169 for(std::size_t i = 0 ; i < npoints ; ++i)
1171 double currentX = line->
getX(i);
1172 double currentY = line->
getY(i);
1209 const te::gm::Envelope& boxMM,
const double& verticalLineInitial,
const double& verticalLineGap,
1210 const int& maxGaps,
const int& planarSRID,
const int& geodesicSRID)
1212 std::vector<te::gm::LineString> verticalLines;
1218 if (geodesicSRID == -1)
1219 return verticalLines;
1222 if (geographicBox.getWidth() / verticalLineGap > maxGaps)
1223 return verticalLines;
1228 double x1 =
CalculateInitialX(geographicBox, verticalLineInitial, verticalLineGap);
1229 double x2 = geographicBox.getUpperRightX();
1230 double y1 = geographicBox.getLowerLeftY();
1231 double y2 = geographicBox.getUpperRightY();
1250 for (; x1 <= x2; x1 += verticalLineGap)
1259 if(planarSRID != -1)
1266 std::unique_ptr<te::gm::Geometry> clippedGeometry(line.
intersection(rectPolygon.get()));
1268 if (clippedGeometry ==
nullptr || !clippedGeometry->isValid())
1274 te::gm::LineString lineString(*static_cast<te::gm::LineString*>(clippedGeometry.get()));
1275 verticalLines.push_back(lineString);
1282 verticalLines.push_back(*static_cast<te::gm::LineString*>(multiLineString.
getGeometryN(i)));
1288 return verticalLines;
1315 const te::gm::Envelope& boxMM,
const double& horizontalLineInitial,
const double& horizontalLineGap,
1316 const int& maxGaps,
const int& planarSRID,
const int& geodesicSRID)
1318 std::vector<te::gm::LineString> horizontalLines;
1324 if (geodesicSRID == -1)
1325 return horizontalLines;
1328 if (geographicBox.getHeight() / horizontalLineGap > maxGaps)
1329 return horizontalLines;
1331 double x1 = geographicBox.getLowerLeftX();
1332 double x2 = geographicBox.getUpperRightX();
1333 double y1 =
CalculateInitialY(geographicBox, horizontalLineInitial, horizontalLineGap);
1334 double y2 = geographicBox.getUpperRightY();
1353 for (; y1 <= y2; y1 += horizontalLineGap)
1362 if(planarSRID != -1)
1369 std::unique_ptr<te::gm::Geometry> clippedGeometry(line.
intersection(rectPolygon.get()));
1371 if (clippedGeometry ==
nullptr || !clippedGeometry->isValid())
1377 te::gm::LineString lineString(*static_cast<te::gm::LineString*>(clippedGeometry.get()));
1379 horizontalLines.push_back(lineString);
1386 horizontalLines.push_back(*static_cast<te::gm::LineString*>(multiLineString.
getGeometryN(i)));
1392 return horizontalLines;
1405 proj4 +=
"+proj=longlat";
1406 proj4 +=
" +datum=WGS84";
1407 proj4 +=
" +no_defs ";
1424 std::string authName =
"EPSG";
1447 std::string authName =
"EPSG";
1452 if (!unitPtr || !copyWorldBox.
isValid())
1453 return copyWorldBox;
1456 copyWorldBox.
transform(sourceSRID, targetSRID);
1458 return copyWorldBox;
1475 if (!unitPtr || !worldBox.
isValid())
1478 targetSRID = sourceSRID;
1479 std::string unitPtrStr = unitPtr->getName();
1482 if (unitPtrStr.compare(
"DEGREE") == 0)
1504 if (!unitPtr || !worldBoxPlanar.
isValid())
1507 targetSRID = sourceSRID;
1508 std::string unitPtrStr = unitPtr->getName();
1511 if (unitPtrStr.compare(
"DEGREE") != 0)
1517 targetSRID =
static_cast<int>(projGeographic.second);
1538 for(
size_t i = 0; i < nPts; i++)
1557 return static_cast<int>(value+.5);
1559 return static_cast<int>(value-.5);
1579 std::string degreeValue;
1585 degree =
static_cast<int>(value);
1586 dbValue = value - degree;
1588 min = std::fabs((dbValue-static_cast<int>(dbValue)*60.));
1589 sec = std::fabs(std::fabs((min-
int(min))*60.));
1597 min = std::floor(min);
1607 const QChar degreeChar(0260);
1624 if(bDegrees ==
false && bMinutes ==
false && bSeconds ==
false)
1650 const bool& vertical,
const bool& top,
const int& geoSrid)
1658 QPixmap* res =
nullptr;
1661 QSize pixDimensions;
1663 std::vector<te::gm::LineString>::const_iterator it;
1668 QSize displayDimensions(painter.device()->width(), painter.device()->height());
1672 pixDimensions.setWidth(displayDimensions.width());
1673 pixDimensions.setHeight(txtH);
1677 pixDimensions.setWidth(displayDimensions.height());
1678 pixDimensions.setHeight(txtH);
1681 res =
new QPixmap(pixDimensions);
1683 res->fill(Qt::transparent);
1687 for(it = lines.cbegin(); it != lines.cend(); ++it)
1689 std::unique_ptr<QPixmap> pixValue;
1708 lValue = (!vertical) ?
1714 pixValue.reset(
GetTextPixmap(sValue, painter.font(), painter.pen()));
1716 subpixRect.setSize(pixValue->size());
1720 center.setX(static_cast<int>((*it).getPointN(lineIdx)->getX()));
1721 center.setY(subpixRect.height()/2);
1725 center.setX(static_cast<int>((*it).getPointN(lineIdx)->getY()));
1726 center.setY(subpixRect.height()/2);
1729 subpixRect.moveCenter(center);
1731 p.drawPixmap(subpixRect, *pixValue.get());
1746 void SetSRID(std::vector<te::gm::LineString>& lines,
const int& srid)
1748 std::vector<te::gm::LineString>::iterator it;
1750 for(it = lines.begin(); it != lines.end(); ++it)
1751 (*it).setSRID(srid);
1763 QFrame(parent, Qt::SubWindow),
1770 m_backGround(nullptr),
1774 m_font(QFont(
"times", 10)),
1777 setAttribute(Qt::WA_TranslucentBackground);
1783 connect(
m_display, SIGNAL(drawLayersFinished(
const QMap<QString, QString>&)), SLOT(
redraw()));
1876 std::vector<te::gm::LineString>::iterator it;
1885 for(
size_t i = 0; i < nPts; i++)
1900 for(
size_t i = 0; i < nPts; i++)
1921 p.drawPixmap(0, oneMMPx, *hori.get());
1922 p.drawPixmap(0, s.height() - hori2->height(), *hori2.get());
1930 dx = devR.center().x();
1931 dy = devR.center().y();
1935 p.translate(devR.center());
1937 p.translate(-dy, -dx);
1938 p.drawPixmap(oneMMPx, 0, *vert.get());
1940 p.drawPixmap(oneMMPx, 0, *vert.get());
1941 p.drawPixmap(oneMMPx, s.width() - vert2->height(), *vert2.get());
1953 std::string authName =
"EPSG";
2001 bool isGeo = (srid ==
m_srid);
2013 planarBox =
WorldBoxTo(geographicBox, geodesicSRID, planarSRID);
2020 geographicBox = bbox;
2048 QFrame::paintEvent(event);
2055 QFrame::closeEvent(event);
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
void computeMBR(bool cascade) const
It computes the minimum bounding rectangle for the linestring.
static te::dt::Date dx(2010, 12, 31)
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
void makeEmpty()
It clears all the coordinates.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
virtual Geometry * intersection(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set intersection with another geometry...
std::unique_ptr< Point > getPointN(std::size_t i) const
It returns the specified point in this LineString.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
double getWidth() const
It returns the envelope width.
An utility struct for representing 2D coordinates.
double getY() const
It returns the y-coordinate.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
LineString is a curve with linear interpolation between points.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
A point with x and y coordinate values.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
An Envelope defines a 2D rectangular region.
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
void setNumCoordinates(std::size_t size)
It reserves room for the number of coordinates in this LineString.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
MultiLineString is a MultiCurve whose elements are LineStrings.
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
double getX() const
It returns the x-coordinate.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
void setSRID(int srid)
It sets the Spatial Reference System ID of the linestring.
TEMAPEXPORT int CalculatePlanarZone(te::gm::Envelope latLongBox)
Calculates the UTM zone from a Geographic envelope.
void setPointN(std::size_t i, const Point &p)
It sets the value of the specified point to this new one.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
double getHeight() const
It returns the envelope height.
bool isValid() const
It tells if the rectangle is valid or not.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
void transform(int srid)
It converts the coordinate values of the linestring to the new spatial reference system.