[Fwd: Re: [Mapserver-users] QueryByPoint using Java/MapScript returns no results [SOLVED]]

Umberto Nicoletti unicoletti at prometeo.it
Mon Apr 5 03:04:34 EDT 2004


It was easy, but difficult to spot.
Here it is, in case anybody is interested.
 
> On Wed, 2004-03-31 at 15:31, Umberto Nicoletti wrote:
> > Hi list,
> > I am using Java mapscript to build a demo application using the itasca
> > map. I have had some success zooming/panning, but now I am stuck with
> > querying.
> > 
> > I am running on Linux, with mapserver 4.0, java 1.4.1.
> > 
> > This is the code snippet that performs the query:
> > 
> >     private void queryLayer(int i, pointObj queryPoint) {
> >         layerObj layer=map.getLayer(i);
> >         if (layer!=null && isVisible(layer) ) {
> >             if ( layer.open() == mapscript.MS_SUCCESS ) {
 
remove this layer.open()
 
> >                 if (log.isDebugEnabled()) {
> >                     log.debug("Querying layer: "+layer.getName());
> >                 }
> >                 if (
> > layer.queryByPoint(map,queryPoint,mapscript.MS_MULTIPLE,0) ==
> > mapscript.MS_SUCCESS ) {
> >                     resultCacheObj resultCache = layer.getResultcache();
 
put layer.open() here and move layer.close() up the nesting hierarchy.

Regards,
Umberto 
 
> >                     for (int j=0;j<resultCache.getNumresults();j++) {
> >                         if (log.isDebugEnabled())
> >                             log.debug("Layer "+layer.getName()+", result
> > number:"+j);
> >                         resultCacheMemberObj
> > resultMember=layer.getResult(j);
> >                         //shapeObj shape=new
> > shapeObj(mapscript.MS_SHAPE_NULL);
> >                         shapeObj shape=new shapeObj(layer.getType());
> >                        
> > layer.getShape(shape,resultMember.getTileindex(),resultMember.getShapeindex());
> >                         if (shape!=null) {
> >                             log.debug("Shape.text="+shape.getText());
> >                             log.debug("Shape "+j+"
> > numValues="+shape.getNumvalues());
> >                             for (int z=0;z<shape.getNumvalues();z++) {
> >                                
> > log.info("Shape.value["+z+"]="+shape.getValue(z));
> >                             }
> >                         } else {
> >                             log.error("Shape "+j+" is null!");
> >                         }
> >                     }
> >                 } else {
> >                     log.warn("Query on layer "+layer.getName()+"
> > failed.");
> >                 }
> >                 layer.close();
> >             } else {
> >                 log.warn("Cannot open layer "+layer.getName()+" vfor
> > query");
> >             }
> >         }
> >     }
> > 
> > There is an outer loop on all layers of course, but that is not shown.
> > And this is the output I get in my logs:
> > 
> > DEBUG [http8080-Processor4] (?:?) - Map point is:
> > (444126.024361375,5236694.413626128)
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: ctybdpy2
> >  WARN [http8080-Processor4] (?:?) - Query on layer ctybdpy2 failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: mcd90py2
> >  WARN [http8080-Processor4] (?:?) - Query on layer mcd90py2 failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: twprgpy3
> >  WARN [http8080-Processor4] (?:?) - Query on layer twprgpy3 failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: lakespy2
> > DEBUG [http8080-Processor4] (?:?) - Layer lakespy2, result number:0
> > DEBUG [http8080-Processor4] (?:?) - Shape.text=null
> > DEBUG [http8080-Processor4] (?:?) - Shape 0 numValues=0
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: dlgstln2
> >  WARN [http8080-Processor4] (?:?) - Query on layer dlgstln2 failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: ctyrdln3
> >  WARN [http8080-Processor4] (?:?) - Query on layer ctyrdln3 failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: majrdln3
> >  WARN [http8080-Processor4] (?:?) - Query on layer majrdln3 failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: majrdln3_anno
> >  WARN [http8080-Processor4] (?:?) - Query on layer majrdln3_anno failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: airports
> >  WARN [http8080-Processor4] (?:?) - Query on layer airports failed.
> > DEBUG [http8080-Processor4] (?:?) - Querying layer: cities
> >  WARN [http8080-Processor4] (?:?) - Query on layer cities failed.
> > 
> > What it looks to me is that it finds (correctly) a shape, but the shape
> > hasn't any attribute attached.
> > Please note that the same code works on the Europe map from the php
> > mapscript by example.
> > 
> > What am I doing wrong?
> > I attach my demo.map.
> > 
> > Thanks for your help,
> > Umberto
> > 




More information about the mapserver-users mailing list