[Mapserver-users] Query by point shape and tile indexes are -1
Sean Gillies
sgillies at frii.com
Tue Mar 9 11:20:58 PST 2004
On Mar 9, 2004, at 11:45 AM, Will Richardson wrote:
> Hello,
>
> I am trying to do a query after i add a feature to a layer and the
> shape and
> tile indexes are -1 so i can't get the shape that was queried. Below
> is my
> code in java, if you have any suggestions, please let me know.
>
> thanks
>
> layerObj layer = map.getLayerByName( "towermark" );
> layer.setStatus( MapScript.MS_ON );
>
> pointObj myHouse = new pointObj();
> myHouse.setX( -104.06478597176886 );
> myHouse.setY( 38.46972580576644 );
>
> lineObj line = new lineObj();
> line.add( myHouse );
> shapeObj shape = new shapeObj( MapScript.MS_SHAPE_POINT );
> shape.add( line );
> layer.addFeature( shape );
>
> imageObj image = map.draw();
>
> pointObj queryPoint = new pointObj();
> queryPoint.setX( -104.06478597176886 );
> queryPoint.setY( 38.46972580576644 );
> int result = layer.queryByPoint( map, queryPoint,
> MapScript.MS_SINGLE, 10 );
>
> System.out.println( "result of query: " + result );
> System.out.println( "MS_SUCCESS: " + MapScript.MS_SUCCESS
> );
> System.out.println( "MS_FAILURE: " + MapScript.MS_FAILURE
> );
>
> resultCacheObj cache = layer.getResultcache();
> //prints 1
> System.out.println( "number of results: " +
> cache.getNumresults
> () );
>
> resultCacheMemberObj resultObj = layer.getResult( 0 );
> System.out.println( "shape index: " +
> resultObj.getShapeindex() );
> System.out.println( "tile index: " +
> resultObj.getTileindex() );
> System.out.println( "Class index: " +
> resultObj.getClassindex() );
>
> shape = layer.getShape( resultObj.getTileindex(),
> resultObj.getShapeindex() );
> if ( shape != null )
> {
> System.out.println( "shape.getNumvalues(): " +
> shape.getNumvalues() );
> }
> ______
Will,
I think you forgot to ask your question ... you want to know why
getShape doesn't work as expected?
You don't say so, but I am assuming you are using a Java mapscript from
Mapserver 3.x? True? Well, one problem is that getShape doesn't
return a shapeObj. Your code will have to be something like this:
shapeObj shape = shapeObj(layer.type);
layer.getShape(shape, resultObj.getTileindex(),
resultObj.getShapeindex());
Hope this helps,
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the MapServer-users
mailing list