Q&A - Question

Measure Tool

Question
crec asked on September 22, 2017, keyword: Developer Kernel
Hi,
How can use measure tool by code in .net. this tool is available in TatukGIS Viewer but there is not any sample to show how initializing this tool by code.
Answers
Artur Redzko (TatukGIS) replied September 22, 2017
Measure tool is built using Edit mode and uses edited shape and EditorChangeEvent event to calculate length and area. Please check sample SimpleEdit how to use edit mode. Simplified code to measure shape is :
// TForm1 is a main form, GIS is the viewer 
var
    layer     : TGIS_LayerVector ;
    isLine    : Boolean ;
    isPolygon : Boolean ;
    unitMsr   : TGIS_CSUnits ;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // open background layer
  GIS.Open( TGIS_Utils.GisSamplesDataDir + '\World\WorldDCW\world.shp' );
  GIS.Mode := TGIS_ViewerMode.Drag;

  // create measure layer
  layer := TGIS_LayerVector.Create ;
  layer.Params.Line.Color := TGIS_Color.Red ;
  layer.Params.Line.Width := 25 ;
  layer.SetCSByEPSG( 4326 ) ;
  GIS.Add( layer ) ;
  GIS.RestrictedExtent := GIS.Extent ;

  isLine := False ;
  isPolygon := False ;
  unitMsr := TGIS_Utils.CSUnitsList.ByEPSG( 904201 ) ;
  GIS.Editor.EditingLinesStyle.PenWidth := 10 ;
end;

// viewer event to handle mouse click
procedure TForm1.GISTapSimpleEvent(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
var
  ptg : TGIS_Point;
begin
  if GIS.Mode = TGIS_ViewerMode.Edit then
    exit ;
  ptg := GIS.ScreenToMap( Point( Round(x), Round(y) ) ) ;
  if isLine then begin
    GIS.Editor.CreateShape( layer, ptg, TGIS_ShapeType.Arc ) ;
    GIS.Mode := TGIS_ViewerMode.Edit ;
  end
  else if isPolygon then begin
    GIS.Editor.CreateShape( layer, ptg, TGIS_ShapeType.Polygon ) ;
    GIS.Mode := TGIS_ViewerMode.Edit ;
  end ;
end;

// viewer event to handle editor changes
procedure TForm1.GISEditorChangeEvent(Sender: TObject);
begin
  if Assigned( GIS.Editor.CurrentShape ) then
    if isLine then
      edtLength.Text := unitMsr.asLinear( TGIS_Shape( GIS.Editor.CurrentShape ).LengthCS, True )
    else if isPolygon then begin
      edtLength.Text := unitMsr.asLinear( TGIS_Shape(GIS.Editor.CurrentShape).LengthCS, True ) ;
      edtArea.Text := unitMsr.AsAreal( TGIS_Shape(GIS.Editor.CurrentShape).AreaCS, True, '%s²' );
    end
end;
If you would like to answer the question please Sign In.
*
*
Please review our recent Privacy Policy.
If you have any questions or requests, please contact us.
Rules
The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers.
 
  1. Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone.
  2. Keep the content positive and professional.
  3. Be courteous to others by posting information when a question or issue asked on the Q & A is answered or resolved by other means (such as with help from TatukGIS technical support). Offer others at least a hint how the posted question was answered or the issue was resolved.
  4. The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.