1

我有一张美国各地的温度位图,显示为地图叠加层。这部分工作正常 - 位图温度叠加完美地位于相对于边界和地理点的地图上。

我的目标是能够点击此温度位图,然后根据该像素颜色输出温度。位图叠加层正在根据当前地图投影进行缩放和定位。我在点击时获取位图像素的解决方案要求我使用地理点向后退,考虑缩放,然后从原始位图图像中检索点击点。

敲击工作正常,但我注意到检索到的像素不准确。例如,我可以点击位图的可见部分下方(如在墨西哥)并仍然返回一个彩色像素 - 相反,在地图顶部(靠近加拿大)我可以点击可见位图而不返回任何像素。就好像返回的像素值都向南移动了大约 50 英里。缩小时错误并不大或不明显,但放大时它们变得明显,因为返回了明显错误的像素(温度)值。

我认为我的方法是合理的,但我想知道我正在处理的大量数字是否会导致“双打”问题。我是否需要切换到 BigDecimal(没有经验)或其他数字格式?有一个更好的方法吗?

代码如下>>>>

public class BitmapOverlay extends Overlay {

Bitmap bmp;
Bitmap bmp2;
Context mContext;
GeoPoint upperLeft;
GeoPoint lowerRight;
Paint paint;
Paint lpaint;
Point ppupperLeft;
Point pplowerRight;
Rect src;
Rect src2;
Rect dst;
int frame;
int complete=100;

boolean shadow;
AnimationDrawable animation;
ImageView radarView;

Double W=(-129.357400913)* 1E6;
Double S=(23.560962423770285)* 1E6;
Double E=(-64.6787004566)* 1E6;
Double N=(50.3092170302897)* 1E6;

Projection currentProjection;

boolean mExternalStorageAvailable = false;
String fullPath;

boolean running;

public BitmapOverlay (Context freshContext){

    paint = new Paint(Paint.FILTER_BITMAP_FLAG);

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);



    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = true;

    Log.i("isSdReadable", "External storage card is readable.");

    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    Log.i("isSdReadable", "External storage card is readable.");
    mExternalStorageAvailable = true;
    } else {
    // Something else is wrong. It may be one of many other
    // states, but all we need to know is we can neither read nor write
    mExternalStorageAvailable = false;
    }








    upperLeft=new GeoPoint(N.intValue(),W.intValue());
    lowerRight=new GeoPoint(S.intValue(),E.intValue());


    ppupperLeft = new Point();
    pplowerRight = new Point();



    mContext=freshContext;




}






public void UpdateFrame(int sentframe , String ET){
    frame=sentframe;
//  complete=sentcomplete;




    if ( mExternalStorageAvailable == true) {

    //  Log.i("MyRadarOverlay", "got BMP Frame="+frame);

        //have to convert complete to frame to sequence... otherwise it gets to 5     
and stops..
        //might need to figure better wayt o tell when bmp is done
        //complete=frame-1;

        if (ET.equals("temp")){fullPath =  
Environment.getExternalStorageDirectory().getAbsolutePath() +  
                "/Pictures/ti0.png";}

        if (ET.equals("radar")){fullPath = 
Environment.getExternalStorageDirectory().getAbsolutePath() +  
                "/Pictures/ri"+frame+".png";}



        // Look for the file on the external storage
        try {



        bmp = BitmapFactory.decodeFile(fullPath);
        //}
        } catch (Exception e) {
        Log.e("getThumbnail() on external storage", e.getMessage());
        }


        if (ET.equals("radar")){    
        fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() +  
                "/Pictures/si"+frame+".png";

    //  Log.i("MyRadarOverlay", "sifile path="+fullPath);

        // Look for the file on the external storage
        try {
        //if (tools.isSdReadable() == true) {

        bmp2 = BitmapFactory.decodeFile(fullPath);
        //}
        } catch (Exception e) {
        Log.e("getThumbnail() on external storage", e.getMessage());
        }
        //end of second if et == radar
 }

    }



}




  public void draw(Canvas canvas, MapView mapView, boolean shadow) {



    currentProjection=mapView.getProjection();

    currentProjection.toPixels(upperLeft, ppupperLeft);
    currentProjection.toPixels(lowerRight, pplowerRight);



    dst = new Rect( ppupperLeft.x, ppupperLeft.y, pplowerRight.x, pplowerRight.y );

    if (bmp2 != null ){

        src = new Rect( 0,0, bmp2.getWidth() , bmp2.getHeight()  );

        canvas.drawBitmap(bmp2, src, dst, paint);


      } 



  if (bmp != null ){


    src = new Rect( 0,0, bmp.getWidth() , bmp.getHeight()  );

    canvas.drawBitmap(bmp, src, dst, paint);



  } 



}




//###################ON TAP#################################   


@Override
public boolean onTap( GeoPoint geoPoint, MapView mapView) {



//  Log.i("My Info", "overlay-on tap called");
     Log.i("BITMAP OVERALY", "TAP at"+geoPoint);     

 //  take left lon add right lon...add basically get a range of lons that the point can  
fall under//
//   if it falls within the range get the percentage ...


 //  the start left most lon is equivalent to 0 the right most is equavalent to the 
width--1600
//   find the relative position on that range

     double xpixel=0;
     double ypixel=0;

     double latgeopoint=geoPoint.getLatitudeE6();
     double longeopoint=geoPoint.getLongitudeE6();


    //find out if it is within longitude range of bitmap
    if (longeopoint>W && longeopoint<E){
        //find out if it is within latitude range of bitmap
        if (latgeopoint>S && latgeopoint<N){

        Log.i("BITMAP OVERALY", "passed if statement- 
lon,lat"+longeopoint+","+latgeopoint);

        //work  on lon side
        double lonrange=W-longeopoint;
        Log.i("BITMAP OVERALY", "lonrange="+lonrange);

        //-64678700456
        double lonratio=lonrange/W-E;
        Log.i("BITMAP OVERALY", "lonratio="+lonratio);

        xpixel=lonratio*bmp.getWidth();
        Log.i("BITMAP OVERALY", "xpixel="+xpixel);

        //work on lat side

        double latrange=N-latgeopoint;
        Log.i("BITMAP OVERALY", "latrange="+latrange);

        //26748254607
        double latratio=latrange/N-S;
        Log.i("BITMAP OVERALY", "latratio="+latratio);

        ypixel=latratio*bmp.getHeight();
        Log.i("BITMAP OVERALY", "ypixel="+ypixel);


        //end if lat
        }
    //end if lon    
    }


     //convert doubles to ints
    int pixelx = (int)xpixel;
    int pixely = (int)ypixel;

    Log.i("BITMAP OVERALY", "pixelx,pixely="+pixelx+","+pixely);



    int pixel = bmp.getPixel(pixelx, pixely);



    int redValue = Color.red(pixel);
    int greenValue = Color.green(pixel);
    int blueValue = Color.blue(pixel);

    float[] hsv = new float[3];
    Color.RGBToHSV(redValue, greenValue, blueValue, hsv);

    String mytemp="";



    if (hsv[0]<5){mytemp="Greater than 110";}
    if (hsv[0]<=20 && hsv[0]>5){mytemp="100 to 110";}
    if (hsv[0]<=45 && hsv[0]>20){mytemp="90 to 100";}
    if (hsv[0]<=60 && hsv[0]>45){mytemp="80 to 90";}
    if (hsv[0]<=80 && hsv[0]>60){mytemp="70 to 80";}
    if (hsv[0]<=120 && hsv[0]>80){mytemp="60 to 70";}
    if (hsv[0]<=150 && hsv[0]>120){mytemp="50 to 60";}







            AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);


              dialog.setNegativeButton("Close",
                      new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {

                                dialog.cancel();

                          }
                      });


              dialog.setTitle("BITMAP TAP hsv=" + hsv[0] + " " + hsv[1] + " " + 
hsv[2] + " TEMP="+mytemp);



              dialog.show();



    return false; 
 //end on tap   
} 



}
4

1 回答 1

0

万一其他人偶然发现这一点-我找到了解决方案。显然,错误是由于发生了网络墨卡托地图翻译。我覆盖在地图上的位图仅在远北和南边界处准确。那就是误差为零的地方。相对于纬度,我越接近位图的中点,错误就会增加。通过在位图上绘制一组像素,然后将它们与已知的纬度线进行比较,我能够量化中间点的误差。在这种特殊情况下,中点处的误差约为 54 个像素。我还测试了已知纬度的其他几个点,以创建错误数据集。现在我知道了我的错误,我可以插入一个更正以应用于每个特定的纬度。为了准确插值,我使用三次插值。

于 2013-09-24T14:00:31.440 回答