<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
&nbsp;&nbsp;&nbsp; Hi dear list. This will be a long one:<br>
<br>
&nbsp;&nbsp;&nbsp; I chopped a map into multiple adjacent rectangles (like a grid), in
the hopes of feeding each rectangle (or subzone, or cell, call what you
like :) trough a queryByRectangle() in order to get the number of
shapes present at that sub-area of a layer, and use the resulting
numbers on a statistic analysis of the number of ocurrences.<br>
&nbsp;&nbsp;&nbsp; Everyhing seems to be working fine, except my queries return weird
numResults.<br>
&nbsp;&nbsp;&nbsp; For example, in the case below I am creating 4 cells and ploting 10
points on the upper right cell. however logs ALSO return 10
non-existing points in the upper left cell, where there is nothing. If
I up the number of cells (how the final application will/should be
like), the count numbers go completelly insane.<br>
&nbsp;&nbsp;&nbsp;&nbsp; Am I misunderstanding the use of queryByRect? I also tried drawing
the rectangles as shapes and doing a queryByShape and it gets worse: he
counts all the 10 points as being in present in all cells. Geting the
index of these shapes show that they are the all the same set of 10,
magically "appearing" in other areas (they arent there, just
numResults() think they are)<br>
&nbsp;&nbsp;&nbsp; Any help is appreciated, code below, the log output below it:<br>
<br>
<br>
&nbsp;&nbsp;&nbsp; //Creating layer GRID - This layer is debug only<br>
&nbsp;&nbsp;&nbsp; layerObj grid = new layerObj(mapa);<br>
&nbsp;&nbsp;&nbsp; grid.setType(edu.umn.gis.mapscript.MS_LAYER_TYPE.MS_LAYER_POLYGON);<br>
&nbsp;&nbsp;&nbsp; grid.setName("Grid");<br>
&nbsp;&nbsp;&nbsp; classObj gclas = new classObj(grid);<br>
&nbsp;&nbsp;&nbsp; styleObj gstyle = new styleObj(gclas);<br>
&nbsp;&nbsp;&nbsp; colorObj gcolor = new colorObj(0,0,0,0);<br>
&nbsp;&nbsp;&nbsp; gstyle.setOutlinecolor(gcolor);<br>
&nbsp;&nbsp;&nbsp; gclas.setNumstyles(1);<br>
&nbsp;&nbsp;&nbsp; gclas.insertStyle(gstyle, 0);<br>
&nbsp;&nbsp;&nbsp; grid.setStatus(mapscript.MS_ON);<br>
<br>
&nbsp;&nbsp;&nbsp; //Divisor: there will be 'divisor ^ 2' cells<br>
&nbsp;&nbsp;&nbsp; int divisor = 2;<br>
<br>
&nbsp;&nbsp;&nbsp; double minX = mapa.getExtent().getMinx();<br>
&nbsp;&nbsp;&nbsp; double minY = mapa.getExtent().getMiny();<br>
&nbsp;&nbsp;&nbsp; double maxX = mapa.getExtent().getMaxx();<br>
&nbsp;&nbsp;&nbsp; double maxY = mapa.getExtent().getMaxy();&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; double deviationX = (maxX - minX)/divisor;<br>
&nbsp;&nbsp;&nbsp; double deviationY = (maxY - minY)/divisor;<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; double[] lineX = new double[divisor+1];<br>
&nbsp;&nbsp;&nbsp; double[] lineY = new double[divisor+1];<br>
&nbsp;&nbsp;&nbsp; double stepX = minX;<br>
&nbsp;&nbsp;&nbsp; double stepY = minY;<br>
&nbsp;&nbsp;&nbsp; lineY[0] = minY;<br>
&nbsp;&nbsp;&nbsp; lineX[0] = minX;<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; log.debug("Extent:" + mapa.getExtent()); <br>
&nbsp;&nbsp;&nbsp; log.debug("devX: " + deviationX + " devY: " + deviationY);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; int h = 1;<br>
&nbsp; &nbsp;&nbsp;&nbsp; while (stepY &lt;= maxY){<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stepY += deviationY; <br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(stepY &lt;= maxY)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lineY[h] = stepY;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; h++;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //log.debug("stepY: " + stepY);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; h = 1;<br>
&nbsp; &nbsp;&nbsp;&nbsp; while (stepX &lt;= maxX){<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stepX += deviationX; <br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(stepX &lt;= maxX)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lineX[h] = stepX;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; h++;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //log.debug("stepX: " + stepX);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp; &nbsp;&nbsp;&nbsp; //Hack to avoid float number imprecisions at the hightest extents<br>
&nbsp; &nbsp;&nbsp;&nbsp; lineY[lineY.length -1] =&nbsp; Double.valueOf(maxY);<br>
&nbsp; &nbsp;&nbsp;&nbsp; lineX[lineX.length -1] =&nbsp; Double.valueOf(maxX);<br>
<br>
&nbsp; &nbsp;&nbsp;&nbsp; int j = 0; //DEBUG Indice independente<br>
&nbsp; &nbsp;&nbsp;&nbsp; List&lt;rectObj&gt; cell = new ArrayList&lt;rectObj&gt;();<br>
&nbsp; &nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; (lineX.length -1); i ++){<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(h = 0; h &lt; (lineY.length -1); h++){<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rectObj tempRect = new rectObj(lineX[i], lineY[h],
lineX[i+1], lineY[h+1], mapscript.MS_FALSE);<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cell.add(tempRect);<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //Actually drawing the grid is for pure debug purposes<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //TODO Remove from final version<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; shapeObj tempPoly = tempRect.toPolygon();<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tempPoly.setIndex(j);<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tempPoly.setTileindex(j);<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; grid.addFeature(tempPoly);<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; j++;<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; //Creating layer that will house the points and adding a ramdon
debug set<br>
&nbsp;&nbsp;&nbsp; layerObj crimes = new layerObj(mapa);<br>
&nbsp;&nbsp;&nbsp; crimes.setType(edu.umn.gis.mapscript.MS_LAYER_TYPE.MS_LAYER_POINT);<br>
&nbsp;&nbsp;&nbsp; crimes.setName("Crimes");<br>
&nbsp;&nbsp;&nbsp; classObj clas = new classObj(crimes);<br>
&nbsp;&nbsp;&nbsp; styleObj style = new styleObj(clas);<br>
&nbsp;&nbsp;&nbsp; style.setSymbol(IPSUSPEITO);<br>
&nbsp;&nbsp;&nbsp; clas.setNumstyles(1);<br>
&nbsp;&nbsp;&nbsp; clas.insertStyle(style, 0);<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; shapeObj gridShape = new shapeObj(mapscript.MS_SHAPEFILE_POINT);<br>
&nbsp;&nbsp;&nbsp; lineObj gridLinha = new lineObj();<br>
&nbsp;&nbsp;&nbsp; pointObj gridPonto = new pointObj(0.0, 0.0, 0.0);<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; Random rnd = new Random();<br>
&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; 10; i++){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gridLinha = new lineObj();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //rect 3 - Meaning points will exist at the upper right cell<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double lat = rnd.nextDouble() * 180;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double lon = rnd.nextDouble() * 80;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gridPonto.setXY(lat, lon, 0.0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gridLinha.add(gridPonto);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gridShape.add(gridLinha);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gridShape.setIndex(i);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gridShape.setTileindex(i);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; crimes.addFeature(gridShape); //pr&eacute;stenss&atilde;o!<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; crimes.setTransparency(mapscript.MS_GD_ALPHA);<br>
&nbsp;&nbsp;&nbsp; String template = "pathe/to/my/dir/crimes.html"; //changed for this
email&acute;s purpose ;)<br>
&nbsp;&nbsp;&nbsp; crimes.setTemplate(template);<br>
&nbsp;&nbsp;&nbsp; grid.setTemplate(gridtemplate);<br>
&nbsp;&nbsp;&nbsp; crimes.setStatus(mapscript.MS_ON);<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; //Testes: queries<br>
&nbsp;&nbsp;&nbsp; Iterator cellIterator = cell.iterator();<br>
&nbsp;&nbsp;&nbsp; int f = 0; //debug<br>
&nbsp;&nbsp;&nbsp; while(cellIterator.hasNext()){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rectObj rect = (rectObj)cellIterator.next();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; crimes.queryByRect(mapa, rect);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; crimes.open();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; resultCacheObj results = crimes.getResults();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.debug("---------------------");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.debug("Retangulo -&gt; " + rect.getMinx() + ", " +
rect.getMiny() + " -- " +<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rect.getMaxx() + ", " +
rect.getMaxy());<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.debug("NumResults -&gt; " + results.getNumresults());<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //log.debug("=====================");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //if(results != null){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Trecho abaixo recupera os shapes relacionados (pontos).
Irrelevante p/ o gr&aacute;fico.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* for(int e = 0; e &lt; results.getNumresults(); e++){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; resultCacheMemberObj result = results.getResult(e);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.debug("result("+e+") name: " + result.toString());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.debug("crimes.getFeature("+e+"):
getShapeindex("+result.getShapeindex()+"), Tileindex("+
result.getTileindex()+")");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; shapeObj ocorrencia =
crimes.getFeature(result.getShapeindex(), result.getTileindex());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.debug("Feature " + e + " -&gt; " +
ocorrencia.toString());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ocorrencia.getClass();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }*/<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //}<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //log.debug("=====================");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.debug("---------------------");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; f++;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; crimes.close();<br>
<br>
}<br>
<br>
&nbsp;&nbsp;&nbsp; The above code draws the 4 cell grid on my map and correctly plots
the 10 points at the upper right cell, but this is the logs result:<br>
<br>
Extent:{ 'minx': -180 , 'miny': -92.18668454494383 , 'maxx': 180 ,
'maxy': 85.79084354494383 }<br>
devX: 180.0 devY: 88.98876404494382<br>
---------------------<br>
Retangulo -&gt; -180.0, -92.18668454494383 -- 0.0, -3.1979205000000093<br>
NumResults -&gt; 0&nbsp;&nbsp;&nbsp; &lt;-- This one is right<br>
---------------------<br>
---------------------<br>
&nbsp;Retangulo -&gt; -180.0, -3.1979205000000093 -- 0.0, 85.79084354494383<br>
NumResults -&gt; 10 &lt;-- This one is WRONG!<br>
---------------------<br>
---------------------<br>
Retangulo -&gt; 0.0, -92.18668454494383 -- 180.0, -3.1979205000000093<br>
NumResults -&gt; 0 &lt;-- This one is right<br>
---------------------<br>
---------------------<br>
Retangulo -&gt; 0.0, -3.1979205000000093 -- 180.0, 85.79084354494383<br>
NumResults -&gt; 10 &lt;-- This one is right<br>
---------------------<br>
<br>
&nbsp;&nbsp;&nbsp; Any ideas?<br>
&nbsp;&nbsp;&nbsp; Thanks a lot in advance<br>
<br>
<div class="moz-signature">-- <br>
<font color="#000000" face="Verdana, Arial, Helvetica" size="1">
<br>
<br>
<font color="#000000" size="2"><b>Rodrigo Del C. Andrade</b></font><br>
<font color="#606060"><i>Estagi&aacute;rio N&iacute;vel Superior</i></font><br>
<font color="#606060"><i>SIC - SSE - Solu&ccedil;&otilde;es Seguran&ccedil;a P&uacute;blica</i></font><br>
<br>
<font color="#000080"><b>D&Iacute;GITRO TECNOLOGIA</b></font><br>
<font color="#000000"><b>E-mail:</b></font>
<a href="mailto:rodrigo.andrade@digitro.com.br"><font color="#606060">rodrigo.andrade@digitro.com.br</font></a><br>
<font color="#000000"><b>Fone:</b></font>
<font color="#000000">+55 48 3281-7390 / +55 48 3281-7000</font><br>
<font color="#000000"><b>Fax:</b></font>
<font color="#000000">+55 48 3281-7299</font><br>
<font color="#000000"><b>Site:</b></font>
<a href="http://www.digitro.com"><font color="#606060">www.digitro.com</font></a>
</font></div>
</body>
</html>