[Mapserver-users] Problems with queryByRect() in Perl with 3.6.4

PATTERSON KENNETH ALLEN kapatter at srpnet.com
Mon Dec 1 13:23:03 EST 2003


I am trying to query the mapfile to get all point shapes within a rectangle.  I have a very simple shape file with three layers.  One layer contains point data (gauge).  After the call to $gLayer ->queryByRect( $ms, $rectang ) that returns 1, I call $gLayer ->getResult(0).  GetResult(0) returns nothing and $gLayer ->{resultcach} is also empty.  What is going on?  I've checked through the archive and find some discussions like this but none have given me any insight.  I am able to draw and see all the data just fine.

This is the code (more or less):

	my $gLayer = $msMap->getLayerByName( "gauge" );
	if (!$gLayer) {
		print "\tError: unable to find layer we want\n";
		return( 0 );
	}

	my $rectang = new mapscript::rectObj();

	# Just load up the full extent.
	$rectang->{minx} = $msMap->{extent}->{minx};
	$rectang->{maxx} = $msMap->{extent}->{maxx};
	$rectang->{miny} = $msMap->{extent}->{miny};
	$rectang->{maxy} = $msMap->{extent}->{maxy};
	
	print "\tCurrent Query Rectangle (minx, maxx, miny, maxy):\n";
	print "\t\t($rectang->{minx}, $rectang->{maxx}, 	$rectang->{miny}, $rectang->{maxy} )\n";

	my $query_status = $gLayer->queryByRect( $msMap, $rectang );
	print "\tQuery Status = $query_status\n";
	
	my $result_mem = $gLayer->getResult(0);
	my $result_cache = $gLayer->{resultcache};
	print "\t\tGauge layer query results: $query_status, $result_mem, $result_cache\n";


This produces the following output:

	Current Query Rectangle (minx, maxx, miny, maxy):
		(-114.8, -109.06, 31.2808666666667, 37.0231333333333 )
	Query Status = 1
		Gauge layer query results: 1, , 

--------------------------------------------------------
My mapfile is:
#
# Start of map file
#
NAME HyTest
STATUS ON
SIZE 600 600
# SRP Extent
EXTENT -114.8 31.3 -109.06 37.004
#
UNITS dd
SHAPEPATH "/var/www/html/hymap/data"
IMAGECOLOR 0 0 0 # Black colored background
TRANSPARENT on
FONTSET "/var/www/cgi-bin/prod/fontset.txt"
IMAGETYPE PNG
(Blah, blah, blah)

#
# Start of layer definitions
#

LAYER
  NAME "All Roads"
  TYPE LINE
  GROUP Geographical
  STATUS on
  DATA .../roads3.shp"
  CLASS
    NAME 'All Roads'
    #COLOR 100 100 100 # Colors for Gray Background
    COLOR 150 150 150 # Colors for Black/White Background
	TEXT ([HWYNAME])
    LABEL
	  TYPE TRUETYPE
	  FONT universB
	  ANTIALIAS TRUE
	  ANGLE AUTO
      POSITION AUTO
	  MINSIZE 6
	  MAXSIZE 6
      MINFEATURESIZE 200
      MINDISTANCE 300
      #COLOR 100 100 100  # Colors for Gray Background
      COLOR 150 150 150  # Colors for Black/White Background
	  OFFSET 0 2
    END # Label
  END
END # All roads


LAYER
	NAME "gauge"
	GROUP "Point Source Data"
	TYPE POINT
	STATUS ON
	DATA "...gauge.shp"

	CLASS
		NAME 'gauge'
		STATUS ON
		COLOR 0 200 0
		SYMBOL 'circle'
		MINSCALE 800000
		SIZE 4
	END # Class

	CLASS
		NAME 'gauge'
		STATUS ON
		COLOR 0 200 0
		SYMBOL 'circle'
		MINSCALE 100
		MAXSCALE 800000
		SIZE 8
		TEXT ([DB_NM]|[STATN_ID])					
		LABEL
			BACKGROUNDCOLOR 80 80 80
			TYPE TRUETYPE
			FONT helmetBI
			MINSIZE 7
			MAXSIZE 12
			PARTIALS FALSE
			BUFFER 2
			MINFEATURESIZE 40
			MINDISTANCE 50
			OFFSET 0 4
			POSITION LC
			WRAP "|"
			COLOR 250 250 0
		END  #LABEL
	END # Class

end # mapfile








More information about the mapserver-users mailing list