'txt2shp.ave 'Sample script demonstrating the import of ASCII non-delimited data 'into a point shapefile 'Assumes a file with the following format: 'LAT N LON W MAG TIME 'dd mm.mm ddd mm.mm d.d hhmm 'For example: '35 59.97 120 34.06 1.2 905 '38 49.45 122 47.91 1.7 924 '38 30.49 122 36.13 1.5 948 '38 49.73 122 49.74 1.6 1707 '38 49.86 122 49.62 1.4 1731 'Mark Cederholm 'plp@pierssen.com 'http://www.pierssen.com/arcview/arcview.htm 'http://www.pierssen.com/PC/arcinfo.htm '======================================================================= '**** get input file txt_name = FileDialog.Show("*.*", "Input ASCII File", "Import ASCII") if (txt_name = nil) then exit end '**** get output file out_name = txt_name.clone out_name.SetExtension("shp") out_name = FileDialog.Put(out_name, "*.shp", "Output Shapefile") if (out_name = nil) then exit end txt_file = LineFile.Make(txt_name, #FILE_PERM_READ) '**** create shapefile and fields '**** seach online help: Field (Class) for supported field types LShape = FTab.MakeNew(out_name, Point) fields = List.Make fields.Add(Field.Make("id",#FIELD_LONG,1,0)) fields.Add(Field.Make("magnitude",#FIELD_DECIMAL,3,1)) fields.Add(Field.Make("hour",#FIELD_BYTE,2,0)) fields.Add(Field.Make("min",#FIELD_BYTE,2,0)) LShape.AddFields(fields) '**** process records id = 0 record = txt_file.ReadElt while (record <> nil) '**** get coordinates and convert to DD '**** search online help: String (Class) for string functions d_lat = record.Middle(0,2).AsNumber m_lat = record.Middle(3,4).AsNumber lat = d_lat + ( m_lat / 60 ) d_lon = record.Middle(9,3).AsNumber m_lon = record.Middle(13,4).AsNumber lon = (d_lon + ( m_lon / 60 )).Negate thePoint = Point.Make(lon,lat) '**** get attributes id = id + 1 mag = record.Middle(19,3).AsNumber hour = record.Middle(23,2).AsNumber minute = record.Middle(25,2).AsNumber '**** create shape entry recno = LShape.AddRecord LShape.SetValue(LShape.FindField("shape"),recno,thePoint) LShape.SetValue(LShape.FindField("id"),recno,id) LShape.SetValue(LShape.FindField("magnitude"),recno,mag) LShape.SetValue(LShape.FindField("hour"),recno,hour) LShape.SetValue(LShape.FindField("min"),recno,minute) '**** read next record record = txt_file.ReadElt end txt_file.close MsgBox.Info("Done."," ") '=======================================================================