@@ -25,7 +25,7 @@ void GIS::ShapeRenderer::setTextFieldName(const std::string &name)
2525 mTextFieldName = name;
2626}
2727
28- void GIS::ShapeRenderer::drawShapeMercator (cv::Mat &src, float xStart, float yStart)
28+ void GIS::ShapeRenderer::drawShapeMercator (cv::Mat &src, float xStart, float yStart, float scale )
2929{
3030 if (!load ()) {
3131 return ;
@@ -43,7 +43,7 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
4343 for (polyLineIterator->begin (); *polyLineIterator != polyLineIterator->end (); ++(*polyLineIterator)) {
4444 // std::cout << polyLineIterator->point.x << " " << polyLineIterator->point.y << std::endl;
4545
46- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection ( polyLineIterator->point .y , polyLineIterator->point .x , mEarthRadius + mAltitude );
46+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection< float >({ polyLineIterator->point .y , polyLineIterator->point .x , 0 }, mEarthRadius + mAltitude , scale );
4747
4848 coordinate.x += -xStart;
4949 coordinate.y += -yStart;
@@ -65,7 +65,7 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
6565 for (recordIterator->begin (); *recordIterator != recordIterator->end (); ++(*recordIterator)) {
6666 ShapeReader::Point point (*recordIterator);
6767
68- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection ( point.y , point.x , mEarthRadius + mAltitude );
68+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection< float >({ point.y , point.x , 0 }, mEarthRadius + mAltitude , scale );
6969 coordinate.x += -xStart;
7070 coordinate.y += -yStart;
7171
@@ -83,7 +83,7 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
8383 ShapeReader::Point point (*recordIterator);
8484 std::vector<std::string> fieldValues = dbFilereader.getFieldValues (i);
8585
86- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection ( point.y , point.x , mEarthRadius + mAltitude );
86+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToMercatorProjection< float >({ point.y , point.x , 0 }, mEarthRadius + mAltitude , scale );
8787 coordinate.x += -xStart;
8888 coordinate.y += -yStart;
8989
@@ -124,7 +124,7 @@ void GIS::ShapeRenderer::drawShapeMercator(cv::Mat &src, float xStart, float ySt
124124 }
125125}
126126
127- void GIS::ShapeRenderer::drawShapeEquidistant (cv::Mat &src, float xStart, float yStart, float centerLatitude, float centerLongitude)
127+ void GIS::ShapeRenderer::drawShapeEquidistant (cv::Mat &src, float xStart, float yStart, float centerLatitude, float centerLongitude, float scale )
128128{
129129 if (!load ()) {
130130 return ;
@@ -142,7 +142,7 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
142142 for (polyLineIterator->begin (); *polyLineIterator != polyLineIterator->end (); ++(*polyLineIterator)) {
143143 // std::cout << polyLineIterator->point.x << " " << polyLineIterator->point.y << std::endl;
144144
145- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection ( polyLineIterator->point .y , polyLineIterator->point .x , centerLatitude, centerLongitude, mEarthRadius + mAltitude );
145+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection< float >({ polyLineIterator->point .y , polyLineIterator->point .x , 0 }, { centerLatitude, centerLongitude, 0 }, mEarthRadius + mAltitude , scale );
146146
147147 coordinate.x += -xStart;
148148 coordinate.y += -yStart;
@@ -166,7 +166,7 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
166166 for (recordIterator->begin (); *recordIterator != recordIterator->end (); ++(*recordIterator)) {
167167 ShapeReader::Point point (*recordIterator);
168168
169- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection ( point.y , point.x , centerLatitude, centerLongitude, mEarthRadius + mAltitude );
169+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection< float >({ point.y , point.x , 0 }, { centerLatitude, centerLongitude, 0 }, mEarthRadius + mAltitude , scale );
170170 coordinate.x += -xStart;
171171 coordinate.y += -yStart;
172172
@@ -188,7 +188,7 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
188188 ShapeReader::Point point (*recordIterator);
189189 std::vector<std::string> fieldValues = dbFilereader.getFieldValues (i);
190190
191- PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection ( point.y , point.x , centerLatitude, centerLongitude, mEarthRadius + mAltitude );
191+ PixelGeolocationCalculator::CartesianCoordinateF coordinate = PixelGeolocationCalculator::coordinateToAzimuthalEquidistantProjection< float >({ point.y , point.x , 0 }, { centerLatitude, centerLongitude, 0 }, mEarthRadius + mAltitude , scale );
192192 coordinate.x += -xStart;
193193 coordinate.y += -yStart;
194194
@@ -235,36 +235,17 @@ void GIS::ShapeRenderer::drawShapeEquidistant(cv::Mat &src, float xStart, float
235235
236236bool GIS::ShapeRenderer::equidistantCheck (float latitude, float longitude, float centerLatitude, float centerLongitude)
237237{
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
238+ // Degree To radian
239+ latitude = M_PI * latitude / 180 .0f ;
240+ longitude = M_PI * longitude / 180 .0f ;
241+ centerLatitude= M_PI * centerLatitude / 180 .0f ;
242+ centerLongitude= M_PI * centerLongitude / 180 .0f ;
243+
244+ float deltaSigma = std::sin (centerLatitude) * std::sin (latitude) + std::cos (latitude) * std::cos (longitude - centerLongitude);
245+ if (deltaSigma < 0.0 )
265246 {
266- longResult = longitude > minLongitude && longitude < maxLongitude ;
247+ return false ;
267248 }
268249
269- return longResult && latResult ;
250+ return true ;
270251}
0 commit comments