MapWinGIS::SampleCode-LoadingAndColorChange

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.BitBtn1Click(Sender: TObject);
var
   I, K: integer;
   Ext, S: String;
   Colour: Array[0..10] of LongWord;
begin
     Colour[0] := ColorToRGB(clBlack);
     Colour[1] := ColorToRGB(clRed);
     Colour[2] := ColorToRGB(clBlue);
     Colour[3] := ColorToRGB(clGreen);
     OpenDialog1.Title := 'Open GIS Shape File';
     OpenDialog1.FilterIndex := 1;
  if(OpenDialog1.Execute) then
  begin
     Ext := ExtractFileExt(OpenDialog1.FileName);
     Ext := UpperCase(Ext);

     if(Ext = '.SHP') Then
     begin
        sfCount := sfCount + 1;
        sf := CoShapefile.Create();
        sf.Open(OpenDialog1.FileName, nil);
        Map1.AddLayer(sf, true);
        I := sf.ShapeFileType;

        S := IntToStr(sfCount)+': '+ExtractFileName(OpenDialog1.FileName)
                                +'  ('+Shp_Types+')';
        sfName := S;
        sfPos := sfCount-1;          // original
        sfPos := sfCount-1;          // was
        sfPos := sfCount-1;          // should be
//        Map1.LayerName := S;
        Map1.ShapeLayerLineColor := Colour;
        sfCurrent := sfCount;
        Map1.MoveLayerTop(sfCount);
        LayerList1.AddTop(S);
        LayerList1.ItemIndex := sfCount-1;

        // colour the layer of lines  (3 and 5)

        If( (I=1) or (I=3) or (I=5)) then
        begin
          for K := 0 to sf.NumShapes-1 do
          begin
             Map1.ShapeLineColor := Colour;
          end;
          Map1.Update;
        end;

     end;
     MapLoaded := True;
   end;
end;

Where "Shp_Types" are defined in the TForm.OnCreate procedure as:

  sfCount := 0;
  imCount := 0;
  Shp_Types[0] := 'NULLSHAPE';
  Shp_Types[1] := 'POINT';
  Shp_Types[3] := 'POLYLINE';
  Shp_Types[5] := 'POLYGON ';
  Shp_Types[8] := 'MULTIPOINT';
  Shp_Types[11] := 'POINTZ';
  Shp_Types[13] := 'POLYLINEZ';
  Shp_Types[15] := 'POLYGONZ';
  Shp_Types[18] := 'MULTIPOINTZ';
  Shp_Types[21] := 'POINTM';
  Shp_Types[23] := 'POLYLINEM';
  Shp_Types[25] := 'POLYGONM';
  Shp_Types[28] := 'MULTIPOINTM';
  Shp_Types[31] := 'MULTIPATCH';
  Map1.CursorMode := cmNone;

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

This page has been accessed 3,029 times. This page was last modified on 26 November 2005, at 16:59.