MapWinGIS::SampleCode-CreatingNewPointSF

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

procedure TForm1.Button17Click(Sender: TObject);
var
   I, J: integer;
   FN: string;
   Flag: boolean;
   S: string;
begin
     OpenDialog1.FilterIndex := 1;
     OpenDialog1.Title := 'Create NEW ShapeFile';
     OpenDialog1.DefaultExt := 'shp';
     if(OpenDialog1.execute) then
     begin
        FN := ExtractFileName(OpenDialog1.FileName);
        Flag := True;
        if( FileExists(OpenDialog1.FileName) ) then
        begin
           MessageDlg('ShapeFile '+FN+' already exists. Try again with a new FileName',
                mtInformation, , 0);
           Flag := False;
        end;
        if (Flag) then
        begin
           Button18.enabled:=True;
           fCount := 0;
           sfCount := sfCount + 1;
           sf := CoShapefile.Create();
           sf.CreateNew(OpenDialog1.FileName,SHP_POINT);
           Map1.AddLayer(sf, true);
           Map1.MoveLayerTop(sfCount);
           I := sf.ShapeFileType;
           S := IntToStr(sfCount)+': '+FN+'  ('+Shp_Types+')';
           sfName := S;
        sfPos := sfCount-1;          // original
        sfPos := sfCount-1;          // was
        sfPos := sfCount-1;          // should be
//           Map1.LayerName := S;
           LayerList1.AddTop(S);
           LayerList1.ItemIndex := sfCount-1;
           sf.StartEditingShapes(True, nil);

           fCount := fCount + 1;
           Field := CoField.Create;
           Field.Type_ := INTEGER_FIELD;
           Field.Name := 'PID';
           J := 0;
           sf.EditInsertField(Field, J, nil);
           fCount := fCount + 1;
           Field := CoField.Create;
           Field.Type_ := STRING_FIELD;
           Field.Name := 'Attrib_1';
           J := 1;
           sf.EditInsertField(Field, J, nil);

           sfCurrent := sfCount;
           Digitise.checked := True;
           SCount := 0;
           PCount := 0;
           MapLoaded := True;
        end;
     end;
end;

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS::SampleCode-CreatingNewPointSF"

This page has been accessed 2,240 times. This page was last modified on 26 November 2005, at 17:00.