[Mapserver-users] QueryByPoint using Java/MapScript returns no results

Umberto Nicoletti unicoletti at prometeo.it
Wed Mar 31 08:31:37 EST 2004


--=-CNm9JGPrzGoaZdAs9K6e
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

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 ) {
                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();
                    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


--=-CNm9JGPrzGoaZdAs9K6e
Content-Disposition: attachment; filename=mydemo.map
Content-Type: text/plain; name=mydemo.map; charset=iso-8859-15
Content-Transfer-Encoding: 7bit

#
# Start of map file
#
NAME DEMO
STATUS ON
SIZE 600 600
EXTENT 388107.634400379 5203120.88405952 500896.339019834 5310243.30613897
UNITS METERS
SHAPEPATH "/home/unicoletti/Workspace/Java/mapServer/resources/itasca/data"
IMAGECOLOR 255 255 255

# you may need to change this to match your MapServer build
IMAGETYPE PNG

#
# Projection definition, consult the PROJ.4 documentation for parameter discussion
#
#PROJECTION
#  "proj=utm"
#  "ellps=GRS80"
#  "zone=15"
#  "north"
#  "no_defs"
#
#  OR: 
#
#  "init=epsg:26915"
#END

#
# Start of web interface definition (including WMS enabling metadata)
#
WEB
  HEADER demo_header.html
  TEMPLATE demo.html
  FOOTER demo_footer.html
  MINSCALE 1000
  MAXSCALE 1550000
  IMAGEPATH "set in demo_init.html"
  IMAGEURL "set in demo_init.html"
  METADATA
    WMS_TITLE "UMN MapServer Itasca Demo"
    WMS_ABSTRACT "This is the UMN MapServer demonstration application for Itasca County located in north central Minnesota."
    WMS_ACCESSCONSTRAINTS none

    # change this value to match your setup
    WMS_ONLINERESOURCE "http://localhost.localdomain/mapserver_demos/itasca/demo_init.html"

    WMS_SRS "EPSG:26915"
  END
END

QUERYMAP
  SIZE 200 200
  STATUS ON
  STYLE HILITE
  COLOR 255 0 0
END

#
# Start of reference map
#
REFERENCE
  IMAGE /home/unicoletti/Workspace/Java/ms/WEB-INF/maps/itasca/graphics/reference.png
  EXTENT 393234.393701263 5205405.16440722 495769.579718949 5307959.02579127
  SIZE 120 120
  STATUS ON
  COLOR -1 -1 -1
  OUTLINECOLOR 255 0 0
END

#
# Start of legend
#
LEGEND
  KEYSIZE 18 12
  LABEL
    TYPE BITMAP
    SIZE MEDIUM
    COLOR 0 0 89
  END
  STATUS ON
END

#
# Start of scalebar
#
SCALEBAR
  IMAGECOLOR 255 255 255
  LABEL
    COLOR 255 255 255
    SIZE tiny    
  END
  STYLE 1
  SIZE 80 2
  COLOR 255 255 255
  UNITS MILES
  INTERVALS 1
  TRANSPARENT TRUE
  STATUS TRUE
END

#
# Start of symbol definitions (we're only using a few)
#
SYMBOL
  NAME 'circle'
  TYPE ELLIPSE
  POINTS 1 1 END
  FILLED TRUE
END

#
# Start of layer definitions
#

LAYER
  NAME ctybdpy2
  TYPE POLYGON
  STATUS DEFAULT
  DATA ctybdpy2
  
  CLASSITEM 'cty_name'
  CLASS
    EXPRESSION 'Itasca'
    OUTLINECOLOR 128 128 128
    COLOR 225 225 185
  END
  CLASS # every other county in the state
    EXPRESSION /./ 
    OUTLINECOLOR 128 128 128
    COLOR 255 255 255
  END
  METADATA
    WMS_TITLE "County Boundary"
    WMS_ABSTRACT "Itasca County boundary shapefile. See http://deli.dnr.state.mn.us/metadata/full/ctybdne2.html for more information."
    WMS_SRS "EPSG:26915"
  END
END

LAYER
  NAME mcd90py2
  GROUP cities
  TYPE POLYGON
  DATA mcd90py2
  STATUS OFF
  CLASSITEM city_name	
  CLASS
    NAME "Cities & Towns"
    EXPRESSION /./
    COLOR 255 225 90
    TEMPLATE "mcd90py2.html"
  END

  HEADER "mcd90py2_header.html"
  FOOTER "mcd90py2_footer.html"

  DUMP TRUE # allow GML export

  METADATA
    WMS_TITLE "Minor Civil Divisions"
    WMS_ABSTRACT "Minor civil divisions for Itasca County. (boundaries only)"
    WMS_SRS "EPSG:26915"
  END
END

LAYER
  NAME twprgpy3
  TYPE POLYGON
  DATA twprgpy3
  STATUS OFF
  CLASS
    SYMBOL 'circle'
    SIZE 2
    NAME 'Townships'
    OUTLINECOLOR 181 181 145
  END
  METADATA
    WMS_TITLE "Township Boundaries"
    WMS_ABSTRACT "Pulic Land Survey (PLS) township boundaries for Itasca County. See http://deli.dnr.state.mn.us/metadata/full/twprgne2.html for more information."
    WMS_SRS "EPSG:26915"
  END
END

LAYER
  NAME lakespy2
  TYPE POLYGON
  STATUS OFF
  DATA lakespy2

  CLASS
    NAME 'Lakes & Rivers'
    TEMPLATE "lakespy2.html"
    COLOR 49 117 185  
  END

  HEADER "lakespy2_header.html"
  FOOTER "lakespy2_footer.html"
  
  TOLERANCE 3

  DUMP TRUE # allow GML export

  METADATA
    WMS_TITLE "Lakes and Rivers"
    WMS_ABSTRACT "DLG lake and river polygons for Itasca County. See http://deli.dnr.state.mn.us/metadata/full/dlglkpy2.html for more information."
    WMS_SRS "EPSG:26915"
  END
END # lakes

LAYER
  NAME dlgstln2
  TYPE LINE
  STATUS OFF
  DATA dlgstln2

  CLASS
    NAME "Streams"
    TEMPLATE "dlgstln2.html"    
    COLOR 49 117 185
  END

  HEADER "dlgstln2_header.html"
  FOOTER "dlgstln2_footer.html"

  TOLERANCE 5  

  DUMP TRUE # allow GML export

  METADATA
    WMS_TITLE "Streams"
    WMS_ABSTRACT "DLG streams for Itasca County. See http://deli.dnr.state.mn.us/metadata/full/dlgstln2.html for more information."
    WMS_SRS "EPSG:26915"
  END
END # streams

LAYER
  NAME ctyrdln3
  GROUP roads
  MAXSCALE 300000
  STATUS OFF
  DATA ctyrdln3
  TYPE LINE
  CLASS
    COLOR 0 0 0
  END

  METADATA
    WMS_TITLE "County Roads"
    WMS_ABSTRACT "County roads. (lines only)  Derived from MNDOT roads layer, see http://deli.dnr.state.mn.us/metadata/full/dotrdln2.html for more information."
    WMS_SRS "EPSG:26915"
  END
END # county roads

LAYER
  NAME majrdln3
  GROUP roads
  MAXSCALE 600000
  STATUS OFF
  DATA majrdln3
  TYPE LINE
  CLASS
    NAME "Roads"
    COLOR 0 0 0
  END

  METADATA
    WMS_TITLE "Highways"
    WMS_ABSTRACT "Highways- state, US and interstate. (lines only)  Derived from MNDOT roads layer, see http://deli.dnr.state.mn.us/metadata/full/dotrdln2.html for more information."
    WMS_SRS "EPSG:26915"
  END
END # highways

LAYER
  NAME majrdln3_anno
  GROUP roads
  MAXSCALE 600000
  STATUS OFF
  DATA majrdln3
  TYPE ANNOTATION
  LABELITEM "road_num"  
  CLASSITEM "road_class"
  CLASS
    EXPRESSION "3"
    COLOR 0 0 0 # dummy color
    SYMBOL 'symbols/sthwy.png'
    LABEL
      MINFEATURESIZE 50
      MINDISTANCE 150
      POSITION CC
      SIZE TINY
      COLOR 0 0 0
    END
  END
  CLASS
    EXPRESSION "2" 
    COLOR 0 0 0 # dummy color
    SYMBOL 'symbols/ushwy.png'
    LABEL
      MINFEATURESIZE 50
      MINDISTANCE 150
      POSITION CC
      SIZE TINY
      COLOR 0 0 0
    END
  END
  CLASS
    EXPRESSION "1" 
    COLOR 0 0 0 # dummy color
    SYMBOL 'symbols/interstate.png'
    LABEL
      MINFEATURESIZE 50
      MINDISTANCE 150
      POSITION CC
      SIZE TINY
      COLOR 255 255 255
    END
  END

  METADATA
    WMS_TITLE "Highways"
    WMS_ABSTRACT "Highways- state, US and interstate. (shields only)  Derived from MNDOT roads layer, see http://deli.dnr.state.mn.us/metadata/full/dotrdln2.html for more information."
    WMS_SRS "EPSG:26915"
  END
END # highway annotation

LAYER
  NAME airports
  TYPE POINT
  DATA airports
  STATUS OFF
  CLASS
    NAME 'Airports'
    COLOR 128 255 164
    SYMBOL 'circle'
    SIZE 7
    TEMPLATE "airports.html"
  END

  HEADER "airports_header.html"
  FOOTER "airports_footer.html"

  TOLERANCE 5

  METADATA
    WMS_TITLE "Airports"
    WMS_ABSTRACT "Airport runways for Itasca County."
    WMS_SRS "EPSG:26915"
  END
END

LAYER
  NAME mcd90py2_anno
  NAME cities
  TYPE ANNOTATION
  DATA mcd90py2
  STATUS OFF
  LABELITEM "city_name"
  CLASSITEM "city_name"
  LABELMAXSCALE 500000
  CLASS
    EXPRESSION /./
    COLOR -1 -1 -1
    LABEL
      COLOR 0 0 0
      SHADOWCOLOR 218 218 218
      SHADOWSIZE 2 2
      TYPE BITMAP
      SIZE MEDIUM
      POSITION CC
      PARTIALS FALSE
      BUFFER 2
    END
  END

  METADATA
    WMS_TITLE "Minor Civil Divisions"
    WMS_ABSTRACT "Minor civil divisions for Itasca County. (annotation only)"
    WMS_SRS "EPSG:26915"
  END
END

END # Map File

--=-CNm9JGPrzGoaZdAs9K6e--




More information about the mapserver-users mailing list