Knowledge Base Article
KB10749 - How to use the DK to create a new SHP points file, with attributes, from a text (*.txt) file? Each row of the *.txt file contains an X coordinate value, a Y coordinate value, and two additional items of information that I wish to be recorded as attribute information for each SHP point. Each row in the file looks something list this: 350000;7180000;Jose da Silva;Rua Marcos da Costa
The DK can be used to import data from a *.txt, Excel (*.xls) spreadsheet, or database file as point features in any of the write-supported vector layer formats, eg., SHP, MID, DXF, GML, KML, etc.
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 ;
Alternatively, as of the v. 8.7, the DK directly supports the Coma Separated Value (*.cxv) text file format. The DK can directly open, import from, export to, and save editing changes to, a CSV file. This includes both the points geometry and attribute information. Therefore, if your text file points data can be organized into the CSV text file format, you can simply open the file as a CSV layer for further procesing (export to SHP) or import the CSV file directly into a SHP file layer, with attributes.
Created: 2007-04-04, Modified: 2007-08-01
|