Page 1 of 1

Get actual X,Y values from MapPolygon

Posted: Mon Apr 26, 2010 6:18 pm
by 9085137
Hi,

I created a Polygon for MapSeries using Lat/Long and tried to retrieve X,Y positions of vertex to get extent of polygon.
And I generated a function as follows. But the X,Y values using GetX() function gave pixel value rather than actual Lat/Long values.
It seems that it is possible if I use ITChartPtr where tPolygon belongs to, then the actual values can be retrieved by using IAxis.
But I don't want to use ITChartPtr in this function.

Is there anyboy who have an idea about this matter?

Thank you in advance.

Dalshin

BOOL TChartConfig::GetExtentOfPolygon(IMapPolygonPtr tPolygon, MapExtent &PolygonExtent)
{
IPointArrayPtr vertexPts = tPolygon->GetPoints;
if(vertexPts->Count==0) return FALSE;
double dXmax=0, dXmin=1.0E+300;
double dYmax=0, dYmin=1.0E+300;
for(int i=0; i<vertexPts->Count; i++)
{
if(vertexPts->Item->GetX() > dXmax) dXmax = vertexPts->Item->GetX();
if(vertexPts->Item->GetX() < dXmin) dXmin = vertexPts->Item->GetX();
if(vertexPts->Item->GetY() > dYmax) dYmax = vertexPts->Item->GetY();
if(vertexPts->Item->GetY() < dYmin) dYmin = vertexPts->Item->GetY();
}
PolygonExtent.XMax = dXmax;
PolygonExtent.XMin = dXmin;
PolygonExtent.YMax = dYmax;
PolygonExtent.YMin = dYmin;

// do quality check of Extent
return TRUE;
}

Re: Get actual X,Y values from MapPolygon

Posted: Mon Apr 26, 2010 6:49 pm
by 9085137
If I have to use ITChartPtr for solving above issue without getting ITChartPtr as an additional parameter of the function.
Then, one more qustion is that how I can approach chart(ITChartPtr) which contain MapSeries or MapPolygon.

Dalshin

Re: Get actual X,Y values from MapPolygon

Posted: Thu Apr 29, 2010 3:42 pm
by yeray
Hi Dalshin,

I think you could convert your values in pixels to axis' values with the according axis CalcPosPoint function.
Here is the test example I made in delphi:

Code: Select all

var Series1: TWorldSeries;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;

  Series1:=TWorldSeries.Create(self);
  Chart1.AddSeries(Series1);
  Series1.Map:=wmEurope;
end;

procedure TForm1.Button1Click(Sender: TObject);
var PolygonExtent: array of TPoint;
begin
  Series1.ValueColor[47]:=clred;

  SetLength(PolygonExtent,2);
  GetExtentOfPolygon(Series1.Polygon[47],PolygonExtent);
  Chart1.Title.Text.Text:='XMin: '  + IntToStr(PolygonExtent[1].X) + ', XMax: ' + IntToStr(PolygonExtent[0].X) + #13#10;
  Chart1.Title.Text.Text:=Chart1.Title.Text.Text + 'YMin: ' + IntToStr(PolygonExtent[1].Y) + ', YMax: ' + IntToStr(PolygonExtent[0].Y);
  Chart1.Title.Text.Text:=Chart1.Title.Text.Text + 'XMin: '  + FloatToStr(Chart1.Axes.Bottom.CalcPosPoint(PolygonExtent[1].X)) + ', XMax: ' + FloatToStr(Chart1.Axes.Bottom.CalcPosPoint(PolygonExtent[0].X)) + #13#10;
  Chart1.Title.Text.Text:=Chart1.Title.Text.Text + 'YMin: ' + FloatToStr(Chart1.Axes.Left.CalcPosPoint(PolygonExtent[1].Y)) + ', YMax: ' + FloatToStr(Chart1.Axes.Left.CalcPosPoint(PolygonExtent[0].Y));
end;

function TForm1.GetExtentOfPolygon(tPolygon: TTeePolygon; out PolygonExtent: array of TPoint): boolean;
var dXMax, dXMin, dYMax, dYMin: Longint;
    vertexPts: TPointArray;
    i: Integer;
begin
  vertexPts:=tPolygon.GetPoints;

  if(length(vertexPts)=0) then
  begin
    result:=False
  end
  else
  begin
    dXmax:=vertexPts[0].X;
    dXmin:=vertexPts[0].X;
    dYmax:=vertexPts[0].Y;
    dYmin:=vertexPts[0].Y;
    for i:=0 to Length(vertexPts)-1 do
    begin
      if(vertexPts[i].X > dXmax) then dXmax:=vertexPts[i].X;
      if(vertexPts[i].X < dXmin) then dXmin:=vertexPts[i].X;
      if(vertexPts[i].Y > dYmax) then dYmax:=vertexPts[i].Y;
      if(vertexPts[i].Y < dYmin) then dYmin:=vertexPts[i].Y;
    end;
    PolygonExtent[0].X:=dXmax;
    PolygonExtent[1].X:=dXmin;
    PolygonExtent[0].Y:=dYmax;
    PolygonExtent[1].Y:=dYmin;

    result:=True;
  end;
end;