map series does not adjust to new Z values
Posted: Fri Mar 21, 2008 8:45 pm
I am trying to write a GIS application, and am able to initialize my map by
1. clearing the sample shapes
2. adding a shape for each county and associating a Z value with it
3. calling ClearPalette and CreateRangePalette
And I end up with a nice map, where each county is color-coded according to its Z value, and the legend matches up with those Z values.
However, if I try to change what is plotted by
1. clicking on a radio button
2. calling an update function
3. going through the existing shapes county by county and changing the Z values
4. calling ClearPalette and CreateRangePalette
the plot does not adjust to the new Z values. For example, the initial variable that gets plotted has a maximum value of 466,700. When I try to switch to plotting a percentage, the new Z values are indeed between 0 and 100, but my palette/legend does not change, and calling MaxZValue still returns 466,700. The resulting plot is all one color, since the original palette called for painting all shapes with Z values smaller than 22,223 white, and of course ALL of the percentages fit this category.
I've looked around for the right function to call to get my map series object to recalculate the palette/legend, but without any luck. Any suggestions?
Thanks!
P.S. In case it helps, here is my update function:
1. clearing the sample shapes
2. adding a shape for each county and associating a Z value with it
3. calling ClearPalette and CreateRangePalette
And I end up with a nice map, where each county is color-coded according to its Z value, and the legend matches up with those Z values.
However, if I try to change what is plotted by
1. clicking on a radio button
2. calling an update function
3. going through the existing shapes county by county and changing the Z values
4. calling ClearPalette and CreateRangePalette
the plot does not adjust to the new Z values. For example, the initial variable that gets plotted has a maximum value of 466,700. When I try to switch to plotting a percentage, the new Z values are indeed between 0 and 100, but my palette/legend does not change, and calling MaxZValue still returns 466,700. The resulting plot is all one color, since the original palette called for painting all shapes with Z values smaller than 22,223 white, and of course ALL of the percentages fit this category.
I've looked around for the right function to call to get my map series object to recalculate the palette/legend, but without any luck. Any suggestions?
Thanks!
P.S. In case it helps, here is my update function:
Code: Select all
procedure TTfrmMain.updatePlot();
var
i, j, yr, plotType, eInd: Integer;
yrFile: file of WheatData;
pgon: Polygon;
wheatEntry: WheatData;
maxZ: Double;
begin
// determine year
yr := StrToInt(cbPlotYear.Items[cbPlotYear.ItemIndex]) - 1900;
msUSWheat.Title := Concat('Wheat Data 19',IntToStr(yr));
try
// open yrFile
AssignFile(yrFile,Concat('gis_data\wheat_19',IntToStr(yr),'.dat'));
Reset(yrFile);
// determine plotType
plotType := rgPlotType.ItemIndex;
// go through polygon by polygon
i := 0;
maxZ := 0;
while not eof(yrFile) do
begin
Read(yrFile,wheatEntry);
for j := 1 to wheatEntry.nParts do
begin
if wheatEntry.isData then
begin
case plotType of
0: msUSWheat.Shapes[i].Z := wheatEntry.acresPlanted;
1: msUSWheat.Shapes[i].Z := wheatEntry.acresHarvested;
2: msUSWheat.Shapes[i].Z := wheatEntry.percentHarvested;
3: msUSWheat.Shapes[i].Z := wheatEntry.yieldPerAcre;
4: msUSWheat.Shapes[i].Z := wheatEntry.totProduction;
end;
if msUSWheat.Shapes[i].Z > maxZ then
maxZ := msUSWheat.Shapes[i].Z;
end
else
msUSWheat.Shapes[i].Z := 0;
inc(i);
end;
end;
msUSWheat.ClearPalette;
msUSWheat.CreateRangePalette;
finally
CloseFile(yrFile);
end;
end;