package uk.ac.leeds.ccg.raster; import java.lang.*; import java.io.*; //import java.util.*; import java.util.*; //change for 1.2! import uk.ac.leeds.ccg.geotools.*; public final class circleRaster extends Raster{ private final static boolean DEBUG=true; private boolean quantizeOn = true; public boolean isQuantizeOn(){ return quantizeOn; } public void setQuantizeOn(boolean flag){ quantizeOn=flag; } /** * Builds a raster surface based on an array of circles, * produces the * surface by using a density kernel based on the value of the circle. * The mapextent is calculated from the circles. * @see uk.ac.leeds.ccg.raster.circleRaster#quantize * @param circles[] the array of circles * @param size the size of the cells in the raster * @param data[] the values of the circles */ public circleRaster(){ super(); if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.raster.circleRaster constructed. Will identify itself as CRa->"); } public circleRaster(GeoCircle[] circles,double size,double data[]){ if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.raster.circleRaster constructed. Will identify itself as CRa->"); sparseness=0.0d; sparse=true; GeoRectangle extent = new GeoRectangle(); cellsize=size; // we should calculate this? for(int i=0; i50.0d) { setSparse(true); } min=Double.MAX_VALUE; max=Double.MIN_VALUE; for(int i=0;i<(height);i++){ for(int j=0;j50.0d) { setSparse(true); } min=Double.MAX_VALUE; max=Double.MIN_VALUE; for(int i=0;i<(height);i++){ for(int j=0;j50.0d) { setSparse(true); } min=Double.MAX_VALUE; max=Double.MIN_VALUE; for(int i=0;i<(height);i++){ for(int j=0;juk.ac.leeds.ccg.raster.circleRaster constructed. Will identify itself as CRa->"); setQuantizeOn(quantize); sparseness=0.0d; GeoRectangle extent = m; cellsize=size; // we should calculate this? originx=extent.x; originx=Math.floor(extent.x/cellsize)*cellsize; originy=extent.y; originy=Math.floor(extent.y/cellsize)*cellsize; width=(int)Math.ceil(extent.width/cellsize); height=(int)Math.ceil(extent.height/cellsize); cells= new double[height*width]; for(int i=0; i50.0d) { setSparse(true); } min=Double.MAX_VALUE; max=Double.MIN_VALUE; for(int i=0;i50.0d) { setSparse(true); } min=Double.MAX_VALUE; max=Double.MIN_VALUE; for(int i=0;iuk.ac.leeds.ccg.raster.circleRaster constructed. Will identify itself as CRa->"); sparseness=0.0d; GeoRectangle extent = m; cellsize=size; // we should calculate this? originx=extent.x; originx=Math.floor(extent.x/cellsize)*cellsize; originy=extent.y; originy=Math.floor(extent.y/cellsize)*cellsize; width=(int)Math.ceil(extent.width/cellsize); height=(int)Math.ceil(extent.height/cellsize); cells= new double[height*width]; //if(getSparseness()>50.0d) { // setSparse(true); //} min=Double.MAX_VALUE; max=Double.MIN_VALUE; } /** * Builds a raster surface of the centres of the circles * @param circles the circles to be used * @param size the size of the cells in the raster in geographic units */ public circleRaster(GeoCircle[] circles,double size){ if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.raster.circleRaster constructed. Will identify itself as CRa->"); GeoRectangle extent = new GeoRectangle(); cellsize=size; // we should calculate this? for(int i=0; iuk.ac.leeds.ccg.raster.circleRaster constructed. Will identify itself as CRa->"); //System.out.println("CRa->Build a raster - calc extent"); GeoRectangle extent = new GeoRectangle(); cellsize=size; // we should calculate this? for(int i=0; iBuilt a raster - calc extent"); } public circleRaster(Vector circles,GeoData data ,double size,GeoRectangle extent){ if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.raster.circleRaster constructed. Will identify itself as CRa->"); //System.out.println("CRa->Build a raster - given extent"); buildRaster(circles,data,size,extent); //System.out.println("CRa->Built a raster - given extent"); } public void buildRaster(Vector circles,GeoData data ,double size,GeoRectangle extent){ sparseness=0.0d; cellsize=size; // we should calculate this? originx=extent.x; originx=Math.floor(extent.x/cellsize)*cellsize; originy=extent.y; originy=Math.floor(extent.y/cellsize)*cellsize; width=(int)Math.ceil(extent.width/cellsize); height=(int)Math.ceil(extent.height/cellsize); cells= new double[height*width]; //System.out.println("CRa->About to build a raster "+circles.size()+" Circles"); for(int i=0; ihalf finished building a raster "+circles.size()+" Circles"); min=Double.MAX_VALUE; max=Double.MIN_VALUE; for(int i=0;i<(height*width);i++){ min=Math.min(min,getValue(i)); max=Math.max(max,getValue(i)); } //System.out.println("CRa->finished building a raster "+circles.size()+" Circles"); } /** * Builds a raster surface of the centres of the circles, cellsize is one * geographic unit. * @param circles the circles to be used */ public circleRaster(GeoCircle[] circles){ this(circles,1.0); } /** * produce a kernel density surface at x,y with radius r and height value * after Epanechnikov (1969) and Brunsdon (1990) */ double lastRadius = -1; int m; int numb; double xker[]; double xadr[]; double yadr[]; protected final void quantize(double x,double y,double radius,double value){ if(radius<(cellsize)){ addToCell(x,y,value); return; } if(radius !=lastRadius){ lastRadius=radius; double rsq = radius*radius; double min= -radius-cellsize/2.0; double max= radius+cellsize/2.0; numb=(int)(Math.ceil((2.0*(radius+cellsize)))/cellsize); xker = new double[numb*numb]; xadr = new double[numb*numb]; yadr = new double[numb*numb]; double yy,xx,xxsq,dis,sum; xx=min; m=0; sum=0; for(int i=0;i<=numb;i++){ yy=max; xxsq=xx*xx; for (int j=0;j<=numb;j++){ dis=xxsq+yy*yy; if(dis<=rsq){ //System.out.println("CRa->x "+xx+" y "+yy+" "+dis+" "+rsq); xadr[m]=xx; yadr[m]=yy; xker[m]=1.0d-dis/rsq; sum+=xker[m]; m++; } yy-=cellsize; } xx+=cellsize; } if(sum>0.0d){ sum=(1.0d/sum); } for(int j=0;jrow "+cr.getCellRow((double)(i+2))+" col "+cr.getCellCol((double)(j+2))); cr.addToCell((double)(i+2),(double)(j+2),(i*j+1)); } } double [] x = new double[4]; double [] y = new double[4]; x[0]=2.0;y[0]=2.0; x[1]=5.0;y[1]=2.0; x[2]=5.0;y[2]=5.0; x[3]=2.0;y[3]=5.0; GeoPolygon gp = new GeoPolygon(1,x,y,4); PolygonLayer pl = new PolygonLayer(); pl.addGeoPolygon(gp); RasterLayer rl = new RasterLayer(cr); Shader sh = new RampShader(0.0,10.0); sh.setMissingValueCode(0.0); Theme t = new Theme(rl,sh); // PointLayer pl = new PointLayer(); //pl.addGeoPoint(gp); Theme t2 = new Theme(pl); t2.getShadeStyle().setLineWidth(5); t2.getShadeStyle().setLineColor(java.awt.Color.black); t2.getShadeStyle().setIsFilled(false); CircleLayer cl = new CircleLayer(); cl.addGeoCircle(c); Theme t3 = new Theme(cl); t3.getShadeStyle().setIsFilled(false); v.addTheme(t); v.addTheme(t2); v.addTheme(t3); XYDisplay xyd=new XYDisplay(); v.addMouseMotionListener(xyd); v.addMouseListener(xyd); java.awt.Panel p = new java.awt.Panel(); p.setLayout(new java.awt.FlowLayout()); p.add(new uk.ac.leeds.ccg.widgets.ToolBar(v)); p.add(xyd); f.add(p,"South"); f.pack(); f.setVisible(true); } }