Show DBF values above Mapwingis + Delphi points

Asked

Viewed 255 times

2

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

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 very similar code to open the stitch 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 it:

inserir a descrição da imagem aqui

what I needed was to read the . dbf File from the sample file, and display the points as in the example below:

inserir a descrição da imagem aqui

The example above was made the gis; QGIS

it is possible to do the same?

1 answer

1


I do not know this area of yours and also did not work with Mapwingis.

To open a DBF file (Foxpro Data 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. Type what you used in . open('). Also change the Loginprompt property to False.

To read the DFB file, you will need a component, Tadoquery, to set in the Connection property the Tadoconnection you added earlier. Set the following query in the SQL property:

Select * from <arquivodbf>

To be able to read all the contents of the file you can use the following code (See the notes 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 the Tadoquery memo1 is the place where I am throwing the value I read in the fields, you must adapt your need.

I’ve worked a lot with DBF files, in case you need, we’ll talk and change the answer until you solve your problem.

Hugs!

God Bless Us!

  • Sorry for the delay, I had a personal problem, I wanted to be able to give you the reward. .

  • Kra does not worry good is that it worked and now you are again in production with your project! Hugs!

  • Taking advantage, as I release the dbf after using it?

  • Yes, I was reading your question in the other topic. For me you did everything right. Closed your Adoquery, then closed the connection. It may seem a little extreme, but have you thought about, instead of using the component in your form, creating Adoquery next to its function ? You could destroy it and recreate it whenever necessary. The problem of the file being in use has to do with the existence of the component. Well, I’ve been there and that’s how I solved my problem.

  • I’ll try, thanks buddy.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.