Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   MySQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=21)
-   -   Sistemas de Informacion Geografico (https://www.clubdelphi.com/foros/showthread.php?t=31879)

Mefistofeles 20-05-2006 03:33:52

Sistemas de Informacion Geografico
 
Hola gente, alguien sabe de alguna funcion que verifique si un punto pertenece a un poligono? Estoy trabajando con SIG (Sistemas de Informacion Geografico), utilizo una tabla con un campo tipo POLYGON y quiero saber si un valor tipo POINT pertece a ese campo POLYGON. Espero que alguien este trabajando con estos tipos de datos. Desde ya, muchas gracias.

JCarlosas 21-05-2006 17:21:39

Hola, de la gaveta empolvado saque esto algoritmos que alguna vez use.
Ahora no recuerdo la diferencia entre ellos, pero creo que radica en que si el ulitmo punto tiene o no que ser igual al primero.
En su epoca me funcionaron bien.
Espero que resuelvas.
Saludos
Juan Carlos

Código Delphi [-]
Function EstaElPuntoDentroDelPoligono(P:TPointDouble;Pol:Array of TPointDouble):Boolean;
Var
 Nc, //Número de cortes
 I : Integer;
 Alfa,
 XQ : Double;      //Era antes Real
 Db, Da: TCoordenada;   //Eran antes entero
Begin
  Result := False;
  Nc := -1;
  for I := 0 to length(Pol)-1 do
    begin
      If I = Length(Pol)-1 then
        Begin
          Da := Pol[i].Y - P.Y;
          Db := Pol[0].Y - P.Y;
          If ((Da >= 0) And (Db < 0)) Or ((Db >= 0) And (Da < 0)) then
            Begin
              Alfa := Da/(Da-Db);
              XQ := Pol[i].X + Alfa * (Pol[0].X-Pol[i].X);
              If XQ > P.X Then Inc(Nc);
            End;
        End
      Else
        Begin
          Da := Pol[i].Y - P.Y;  //dA = yA - yP y dB = yB - yP.
          Db := Pol[I+1].Y - P.Y;
          If ((Da >= 0) And (Db < 0)) Or ((Db >= 0) And (Da < 0)) then
            Begin
              Alfa := Da/(Da-Db);
              XQ := Pol[i].X + Alfa * (Pol[I+1].X-Pol[i].X); //xQ = xA + alfa(xB-xA).
              If XQ > P.X Then Inc(Nc);
            End;
        End;
    end;
  If (Not Odd(Nc)) And (Nc >= 0) Then Result := true;
End;

Function EstaElPuntoDentroDelPoligono2(P:TPointDouble;Pol:Array of TPointDouble):Boolean;
Var
 Nc, //Número de cortes
 I, LongPol : Integer;
 Alfa,
 XQ : Double;      //Era antes Real
 Db, Da: TCoordenada;   //Eran antes entero
Begin
  Result := False;
  Nc := -1;
  for I := 0 to length(Pol)-2 do
        Begin
          Da := Pol[i].Y - P.Y;  //dA = yA - yP y dB = yB - yP.
          Db := Pol[I+1].Y - P.Y;
          If ((Da >= 0) And (Db < 0)) Or ((Db >= 0) And (Da < 0)) then
            Begin
              Alfa := Da/(Da-Db);
              XQ := Pol[i].X + Alfa * (Pol[I+1].X-Pol[i].X); //xQ = xA + alfa(xB-xA).
              If XQ > P.X Then Inc(Nc);
            End;
        End;
  If (Not Odd(Nc)) And (Nc >= 0) Then Result := true;
End;
Function EstaElPuntoDentroDelPoligono3(P:TPointDouble;Pol:Array of TPointDouble):Boolean;
Var
 Nc, //Número de cortes
 I : Integer;
 Alfa,
 XQ : Double;      //Era antes Real
 Db, Da: TCoordenada;   //Eran antes entero
Begin
  Result := False;
  Nc := -1;
  for I := 0 to length(Pol)-1 do
    begin
      If I = Length(Pol)-1 then
        Begin
          Da := Pol[i].Y - P.Y;
          Db := Pol[0].Y - P.Y;
          If ((Da >= 0) And (Db < 0)) Or ((Db >= 0) And (Da < 0)) then
            Begin
              Alfa := Da/(Da-Db);
              XQ := Pol[i].X + Alfa * (Pol[0].X-Pol[i].X);
              If XQ > P.X Then Inc(Nc);
            End;
        End
      Else
        Begin
          Da := Pol[i].Y - P.Y;  //dA = yA - yP y dB = yB - yP.
          Db := Pol[I+1].Y - P.Y;
          If ((Da >= 0) And (Db < 0)) Or ((Db >= 0) And (Da < 0)) then
            Begin
              Alfa := Da/(Da-Db);
              XQ := Pol[i].X + Alfa * (Pol[I+1].X-Pol[i].X); //xQ = xA + alfa(xB-xA).
              If XQ > P.X Then Inc(Nc);
            End;
        End;
    end;
  If Not (Odd(Nc)) or (Nc < 0) Then Result := true;
End;


La franja horaria es GMT +2. Ahora son las 06:33:06.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi