Changeset 6913 in osm for applications/editors/josm
- Timestamp:
- 2008-02-18T13:09:09+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Lakewalker.java
r6910 r6913 103 103 ArrayList<double[]> nodelist = new ArrayList<double[]>(); 104 104 105 int[] xy = geo_to_xy(lat,lon );105 int[] xy = geo_to_xy(lat,lon,this.resolution); 106 106 107 107 if(!bbox.contains(lat, lon)){ … … 112 112 113 113 while(true){ 114 double[] geo = xy_to_geo(xy[0],xy[1] );114 double[] geo = xy_to_geo(xy[0],xy[1],this.resolution); 115 115 if(bbox.contains(geo[0],geo[1])==false){ 116 116 break; … … 135 135 136 136 int[] startxy = new int[] {xy[0], xy[1]}; 137 double[] startgeo = xy_to_geo(xy[0],xy[1] );137 double[] startgeo = xy_to_geo(xy[0],xy[1],this.resolution); 138 138 139 139 System.out.println("Found shore at "+startxy[0]+","+startxy[1]); … … 158 158 159 159 new_dir = (last_dir + d + 4) % 8; 160 161 //System.out.println(last_dir+", "+d+" "+new_dir); 162 160 163 161 test_x = xy[0] + this.dirslon[new_dir]; 164 162 test_y = xy[1] + this.dirslat[new_dir]; 165 163 166 double[] geo = xy_to_geo( xy[0],xy[1]);164 double[] geo = xy_to_geo(test_x,test_y,this.resolution); 167 165 168 166 if(!bbox.contains(geo[0], geo[1])){ … … 172 170 173 171 v = wms.getPixel(test_x, test_y,0xFF0000FF); 174 //System.out.println(new_dir+" "+test_x+","+test_y+" "+v);175 172 if(v > this.threshold){ 176 173 break; … … 182 179 } 183 180 } 184 185 //System.out.println("Found empty space"); 186 181 187 182 // Remember this direction 188 183 last_dir = new_dir; … … 194 189 } 195 190 196 double[] geo = xy_to_geo(xy[0],xy[1] );191 double[] geo = xy_to_geo(xy[0],xy[1],this.resolution); 197 192 nodelist.add(geo); 198 193 System.out.println("Adding node at "+xy[0]+","+xy[1]+" ("+geo[1]+","+geo[0]+")"); … … 298 293 } 299 294 300 p rivate double[] xy_to_geo(int x, int y){295 public double[] xy_to_geo(int x, int y, double resolution){ 301 296 double[] geo = new double[2]; 302 geo[0] = y / (double)this.resolution;303 geo[1] = x / (double)this.resolution;297 geo[0] = y / resolution; 298 geo[1] = x / resolution; 304 299 return geo; 305 300 } 306 301 307 p rivate int[] geo_to_xy(double lat, double lon){302 public int[] geo_to_xy(double lat, double lon, double resolution){ 308 303 int[] xy = new int[2]; 309 304 310 xy[0] = (int)Math.floor(lon * this.resolution + 0.5); 311 xy[1] = (int)Math.floor(lat * this.resolution + 0.5); 312 313 System.out.println("("+lon+","+lat+") maps to ("+xy[0]+","+xy[1]+")"); 314 305 xy[0] = (int)Math.floor(lon * resolution + 0.5); 306 xy[1] = (int)Math.floor(lat * resolution + 0.5); 307 315 308 return xy; 316 309 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerWMS.java
r6910 r6913 42 42 43 43 int[] bottom_left_xy = new int[2]; 44 bottom_left_xy[0] = (int)(x / this.tilesize) * this.tilesize;45 bottom_left_xy[1] = (int)(y / this.tilesize) * this.tilesize;44 bottom_left_xy[0] = floor(x,this.tilesize); 45 bottom_left_xy[1] = floor(y,this.tilesize); 46 46 47 47 int[] top_right_xy = new int[2]; … … 49 49 top_right_xy[1] = (int)bottom_left_xy[1] + this.tilesize; 50 50 51 double[] topright_geo = xy_to_geo(top_right_xy[0],top_right_xy[1] );52 double[] bottomleft_geo = xy_to_geo(bottom_left_xy[0],bottom_left_xy[1] );51 double[] topright_geo = xy_to_geo(top_right_xy[0],top_right_xy[1],this.resolution); 52 double[] bottomleft_geo = xy_to_geo(bottom_left_xy[0],bottom_left_xy[1],this.resolution); 53 53 54 54 String filename = this.wmslayer+"/landsat_"+this.resolution+"_"+this.tilesize+ … … 129 129 } 130 130 131 132 133 131 public int getPixel(int x, int y, int pixcol){ 134 132 … … 141 139 return -1; 142 140 } 143 144 int tx = (int)(Math.floor(x / this.tilesize) *this.tilesize);145 int ty = (int)(Math.floor(y / this.tilesize) *this.tilesize);146 141 142 int tx = floor(x,this.tilesize); 143 int ty = floor(y,this.tilesize); 144 147 145 int pixel_x = (x-tx); 148 146 int pixel_y = (this.tilesize-1)-(y-ty); 149 147 148 //System.out.println("("+x+","+y+") maps to ("+pixel_x+","+pixel_y+") by ("+tx+", "+ty+")"); 149 150 150 int rgb = image.getRGB(pixel_x,pixel_y); 151 151 … … 179 179 } 180 180 181 public int floor(int num, int precision){ 182 double dnum = num/(double)precision; 183 BigDecimal val = new BigDecimal(dnum) ; 184 val = val.setScale(0, BigDecimal.ROUND_FLOOR); 185 return val.intValue()*precision; 186 } 187 188 public double floor(double num) { 189 BigDecimal val = new BigDecimal(num) ; 190 val = val.setScale(0, BigDecimal.ROUND_FLOOR); 191 return val.doubleValue() ; 192 } 193 194 public double[] xy_to_geo(int x, int y, double resolution){ 195 double[] geo = new double[2]; 196 geo[0] = y / resolution; 197 geo[1] = x / resolution; 198 return geo; 199 } 200 201 public int[] geo_to_xy(double lat, double lon, double resolution){ 202 int[] xy = new int[2]; 203 204 xy[0] = (int)Math.floor(lon * resolution + 0.5); 205 xy[1] = (int)Math.floor(lat * resolution + 0.5); 206 207 return xy; 208 } 209 181 210 private void printarr(int[] a){ 182 211 for(int i = 0; i<a.length; i++){ … … 184 213 } 185 214 } 215 /* 186 216 private double[] xy_to_geo(int x, int y){ 187 217 double[] geo = new double[2]; … … 199 229 return xy; 200 230 } 231 */ 201 232 }
Note:
See TracChangeset
for help on using the changeset viewer.