Skip to content
You are here: Home » Documents » Point_java.txt
Views
  • State: published

Point_java.txt

Document Actions

Click here to get the file

Size 1.6 kB - File type text/plain

File contents

import java.math.*;

public class Point{

	double lat;
	double lon;

	public Point(double lat, double lon){
		this.lat = lat;
		this.lon = lon;
	}

	public Point(){
	}

	public void setLon(double lon){
		this.lon=lon;
	}

	public void setLat(double lat){
		this.lat=lat;
      }

	public String getCMapStr(double res){

		StringBuffer sb = new StringBuffer();

		if (lat >= 0 ){

			if(lon>=0)
				sb.append('1');
			else
				sb.append('7');


		}
		else{

			if(lon>=0)
				sb.append('3');
			else
				sb.append('5');
		}

		int i,j;

		double llat = Math.abs(lat);
		if (llat >= 90) llat=89.9;
		double llon = Math.abs(lon);
		if (llon >= 180) llon=179.9;

		i=(int)(llat/10);
		sb.append(i);

		j=(int)(llon/10);
		if(j<10)sb.append('0');
		sb.append(j);

		if (res == 10) return sb.toString();

		sb.append(':');

		llat-=i*10;
		llon-=j*10;

		i=(int)llat;
		j=(int)llon;

		if (i<5){

			if(j<5)
				sb.append('1');
			else
				sb.append('2');
		}
		else{
			if(j<5)
				sb.append('3');
			else
				sb.append('4');

		}
		if (res == 5) return sb.toString();

		sb.append(i);
		sb.append(j);

		if (res == 1) return sb.toString();

		sb.append(':');

		i = (int)((llat-i)*10);
		j = (int)((llon-j)*10);

		if (i<5){

			if(j<5)
				sb.append('1');
			else
				sb.append('2');
		}
		else{
			if(j<5)
				sb.append('3');
			else
				sb.append('4');

		}

		if ( res == 0.5) return sb.toString();
		sb.append(i);
		sb.append(j);

		return sb.toString();


	}

	public static void main(String [] argv){

		Point pt = new Point(Double.parseDouble(argv[0]),Double.parseDouble(argv[1]));
		System.out.println(pt.getCMapStr(1));

	}
}
Created by admin
Last modified 2006-03-23 08:44
 

Personal tools
The c-squares mapper perl script is now on sourceforge at http://sourceforge.net/projects/csquares/
A "c-squares-discuss" listserver has been established for interested developers and/or implementers to exchange information or post enquiries relevant to c-squares. To join the list, send an email to c-squares-discuss-request@marine.csiro.au with the word 'subscribe' in the BODY of the email.