Show DBF values above MapWinGis + Delphi points

2

I have the following code to open a .shp file and to plot it in a MapWinGis Map1 component.

procedure TForm1.Button1Click(Sender: TObject);
 var shp: Shapefile;
 HandleLayer: integer;
begin
  shp:= CoShapefile.Create;
  shp.Open ('C:\Users\Documents\BD Demo\Alta Cruz\cruz\alta_cruz.shp', nil) ;
  Map1.Focused;
  HandleLayer:= Map1.AddLayer (shp, true);
  Map1.ZoomToMaxExtents;

And a good code to open the points file:

procedure TForm1.Button2Click(Sender: TObject);
 var shp: Shapefile;
 HandleLayer: integer;
begin
  shp:= CoShapefile.Create;
  shp.Open ('C:\Users\Desktop\opa\Win32\Debug\Amostragem.shp', nil) ;
  Map1.Focused;
  HandleLayer:= Map1.AddLayer (shp, true);
  Map1.ZoomToMaxExtents;
  shp.StartEditingShapes(true, null);

And as a result I have this:

WhatIneededwastoreadthe.dbffilefromthesamplefile,anddisplaythepointsasintheexamplebelow:

The above example was done gis; QGIS

Is it possible to do the same?

    
asked by anonymous 01.06.2016 / 21:44

1 answer

1

I do not know this area and I have not worked with MapWinGis either.

To open a DBF (FoxPro Data File) file, you need to create a connection to that database.

You can use the TADOConnection component, and the Connection String (ConnectionString)="Driver = {Microsoft dBASE Driver (* .dbf)}; DriverID = 277; Dbq = c: \ mydbpath ; " where mydbpath is the path to the folder where your DBF file is located. Type what you used in .open (''). Also change the LoginPrompt property to False.

To read the DFB file, you will need a component, TADOQuery, set in the Connection property the TADOConnection that you added earlier. Set the following query in the SQL property:

Select * from <arquivodbf>

In order to read the entire contents of the file you can use the following code (See comments after the code):

ADOConnection1.Connected:= True;
ADOQuery1.Open;
while not ADOQuery1.Eof do
  begin
  memo1.Lines.Add(ADOQuery1.FieldByName('Codigo').Value);
  ADOQuery1.Next;
end;
ADOQuery1.Close;
ADOConnection1.Connected:= False;

Comments: ADOConnection1 is my TADOConnection ADOQuery1 is TADOQuery memo1 is where I am playing the value I read in the fields, you should adapt your need.

I've worked a lot with DBF files, if need be, we'll talk and change the answer until you solve your problem.

Hugs!

God Bless Us!

    
10.06.2016 / 19:32