@@ -10,7 +10,8 @@ GIS::ShapeRenderer::ShapeRenderer(const std::string shapeFile, const cv::Scalar
1010 , mAltitude(altitude)
1111 , mThicknes(5 )
1212 , mPointRadius(10 )
13- , mFontScale(2 )
13+ , mFontHeight(40 )
14+ , mFontLineWidth(2 )
1415{
1516
1617}
@@ -25,7 +26,7 @@ void GIS::ShapeRenderer::setTextFieldName(const std::string &name)
2526 mTextFieldName = name;
2627}
2728
28- void GIS::ShapeRenderer::drawShapeMercator (cv::Mat &src, float xStart, float yStart)
29+ void GIS::ShapeRenderer::drawShapeMercator (cv::Mat &src, float xStart, float yStart, float scale )
2930{
3031 if (!load ()) {
3132 return ;
@@ -43,7 +44,7 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
4344 for (polyLineIterator->begin (); *polyLineIterator != polyLineIterator->end (); ++(*polyLineIterator)) {
4445 // std::cout << polyLineIterator->point.x << " " << polyLineIterator->point.y << std::endl;
4546
46- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection ( polyLineIterator->point .y , polyLineIterator->point .x , mEarthRadius + mAltitude );
47+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection< float >({ polyLineIterator->point .y , polyLineIterator->point .x , 0 }, mEarthRadius + mAltitude , scale );
4748
4849 coordinate.x += -xStart;
4950 coordinate.y += -yStart;
@@ -65,7 +66,7 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
6566 for (recordIterator->begin (); *recordIterator != recordIterator->end (); ++(*recordIterator)) {
6667 ShapeReader::Point point (*recordIterator);
6768
68- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection ( point.y , point.x , mEarthRadius + mAltitude );
69+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection< float >({ point.y , point.x , 0 }, mEarthRadius + mAltitude , scale );
6970 coordinate.x += -xStart;
7071 coordinate.y += -yStart;
7172
@@ -83,7 +84,7 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
8384 ShapeReader::Point point (*recordIterator);
8485 std::vector<std::string> fieldValues = dbFilereader.getFieldValues (i);
8586
86- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection ( point.y , point.x , mEarthRadius + mAltitude );
87+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection< float >({ point.y , point.x , 0 }, mEarthRadius + mAltitude , scale );
8788 coordinate.x += -xStart;
8889 coordinate.y += -yStart;
8990
@@ -113,18 +114,19 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
113114 }
114115
115116 if (drawName) {
117+ double fontScale = cv::getFontScaleFromHeight (cv::FONT_ITALIC, mFontHeight , mFontLineWidth );
116118 int baseLine;
117- cv::Size size = cv::getTextSize (fieldValues[namePos], cv::FONT_ITALIC, mFontScale , mThicknes , &baseLine);
118- cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, mFontScale , cv::Scalar (0 ,0 ,0 ), mThicknes +1 , cv::LINE_AA);
119- cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, mFontScale , mColor , mThicknes , cv::LINE_AA);
119+ cv::Size size = cv::getTextSize (fieldValues[namePos], cv::FONT_ITALIC, fontScale, mFontLineWidth , &baseLine);
120+ cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, fontScale , cv::Scalar (0 ,0 ,0 ), mFontLineWidth +1 , cv::LINE_AA);
121+ cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, fontScale , mColor , mFontLineWidth , cv::LINE_AA);
120122 }
121123 }
122124 }
123125 }
124126 }
125127}
126128
127- void GIS::ShapeRenderer::drawShapeEquidistant (cv::Mat &src, float xStart, float yStart, float centerLatitude, float centerLongitude)
129+ void GIS::ShapeRenderer::drawShapeEquidistant (cv::Mat &src, float xStart, float yStart, float centerLatitude, float centerLongitude, float scale )
128130{
129131 if (!load ()) {
130132 return ;
@@ -142,7 +144,7 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
142144 for (polyLineIterator->begin (); *polyLineIterator != polyLineIterator->end (); ++(*polyLineIterator)) {
143145 // std::cout << polyLineIterator->point.x << " " << polyLineIterator->point.y << std::endl;
144146
145- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection ( polyLineIterator->point .y , polyLineIterator->point .x , centerLatitude, centerLongitude, mEarthRadius + mAltitude );
147+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection< float >({ polyLineIterator->point .y , polyLineIterator->point .x , 0 }, { centerLatitude, centerLongitude, 0 }, mEarthRadius + mAltitude , scale );
146148
147149 coordinate.x += -xStart;
148150 coordinate.y += -yStart;
@@ -166,7 +168,7 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
166168 for (recordIterator->begin (); *recordIterator != recordIterator->end (); ++(*recordIterator)) {
167169 ShapeReader::Point point (*recordIterator);
168170
169- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection ( point.y , point.x , centerLatitude, centerLongitude, mEarthRadius + mAltitude );
171+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection< float >({ point.y , point.x , 0 }, { centerLatitude, centerLongitude, 0 }, mEarthRadius + mAltitude , scale );
170172 coordinate.x += -xStart;
171173 coordinate.y += -yStart;
172174
@@ -188,7 +190,7 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
188190 ShapeReader::Point point (*recordIterator);
189191 std::vector<std::string> fieldValues = dbFilereader.getFieldValues (i);
190192
191- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection ( point.y , point.x , centerLatitude, centerLongitude, mEarthRadius + mAltitude );
193+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection< float >({ point.y , point.x , 0 }, { centerLatitude, centerLongitude, 0 }, mEarthRadius + mAltitude , scale );
192194 coordinate.x += -xStart;
193195 coordinate.y += -yStart;
194196
@@ -222,10 +224,11 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
222224 }
223225
224226 if (drawName) {
227+ double fontScale = cv::getFontScaleFromHeight (cv::FONT_ITALIC, mFontHeight , mFontLineWidth );
225228 int baseLine;
226- cv::Size size = cv::getTextSize (fieldValues[namePos], cv::FONT_ITALIC, mFontScale , mThicknes , &baseLine);
227- cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, mFontScale , cv::Scalar (0 ,0 ,0 ), mThicknes +1 , cv::LINE_AA);
228- cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, mFontScale , mColor , mThicknes , cv::LINE_AA);
229+ cv::Size size = cv::getTextSize (fieldValues[namePos], cv::FONT_ITALIC, fontScale, mFontLineWidth , &baseLine);
230+ cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, fontScale , cv::Scalar (0 ,0 ,0 ), mFontLineWidth +1 , cv::LINE_AA);
231+ cv::putText (src, fieldValues[namePos], cv::Point2d (coordinate.x - (size.width /2 ), coordinate.y - size.height + baseLine), cv::FONT_ITALIC, fontScale , mColor , mFontLineWidth , cv::LINE_AA);
229232 }
230233 }
231234 }
@@ -235,36 +238,17 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
235238
236239bool GIS::ShapeRenderer::equidistantCheck (float latitude, float longitude, float centerLatitude, float centerLongitude)
237240{
238- bool longResult = true ;
239- bool latResult = true ;
240-
241- int minLongitude = static_cast <int >(centerLongitude - 90 );
242- int maxLongitude = static_cast <int >(centerLongitude + 90 );
243- int minLatitude = static_cast <int >(centerLatitude - 45 );
244- int maxLatitude = static_cast <int >(centerLatitude + 45 );
245-
246- // Normalize
247- minLongitude = ((minLongitude + 540 ) % 360 - 180 );
248- maxLongitude = ((maxLongitude + 540 ) % 360 - 180 );
249- minLatitude = ((minLatitude + 270 ) % 180 - 90 );
250- maxLatitude = ((maxLatitude + 270 ) % 180 - 90 );
251-
252- if (maxLatitude < minLatitude)
253- {
254- latResult = latitude > minLatitude || latitude < maxLatitude;
255- }
256- else
257- {
258- latResult = latitude > minLatitude && latitude < maxLatitude;
259- }
260- if (maxLongitude < minLongitude)
261- {
262- longResult = longitude < minLongitude || longitude < maxLongitude;
263- }
264- else
241+ // Degree To radian
242+ latitude = M_PI * latitude / 180 .0f ;
243+ longitude = M_PI * longitude / 180 .0f ;
244+ centerLatitude= M_PI * centerLatitude / 180 .0f ;
245+ centerLongitude= M_PI * centerLongitude / 180 .0f ;
246+
247+ float deltaSigma = std::sin (centerLatitude) * std::sin (latitude) + std::cos (latitude) * std::cos (longitude - centerLongitude);
248+ if (deltaSigma < 0.0 )
265249 {
266- longResult = longitude > minLongitude && longitude < maxLongitude ;
250+ return false ;
267251 }
268252
269- return longResult && latResult ;
253+ return true ;
270254}
0 commit comments