Knowledge Base



KB10749 - Import data from a text (*.txt) file into a SHP layer with attributes.

The DK can be used to import data from a *.txt database file (or from an Excel spreadsheet) directly or, perhaps more easily, by taking advantage of the DK support for the Comma Separated Values (CSV) file format. (Importing data from an Excel spreadsheet using the TatukGIS Editor is explained in KB10902.)

CSV support. ​​The DK can directly open, import from, export to, and save editing changes to, a Comma Separated Values (*. CSV) file. This includes both the points geometry and attribute information. Therefore, if points in a text file can be organized into the CSV text file format, the data can be simply opened into a CSV layer for further processing or imported directly into a SHP file layer, with attributes. ​

​Direct text file import. The DK can be used to import data directly from a *.txt database file or Excel (*.xls) spreadsheet as point features into a SHP file or any other TatukGIS write-supported vector layer format. The following provides a skeleton of the method:

  lv := TGIS_LayerVector,Create ;
  lv.Name := 'my_layer' ;
  GIS.Add( lv ) ;

  lv.AddField( 'name', gisFieldTypeString, 255, 0 ) ;
  lv.AddField( 'address', gisFieedTypeString, 255, 0 ) ;

  while not sourcefile.Eof do begin
    parse_sourcefile( x, y, name, address ) ; // user defined funtion
    shp := lv.CreateShaoe( gisShapeTypePoint );
    shp.Lock( gisLockExtent ) ;
    shp.AddPart() ;
    shp.AddPoint( GisPoint( x, y ) ) ;
    shp.Unlock ;
    shp.SetField( 'name', name ) ;
    shp.SetField( 'address', address ) ;
  end ;

Created: April 04, 2007, Modified: December 29, 2015
follow us on Facebook  follow us on Twitter  follow us on Google +  follow us on LinkedIn  Embarcadero