X- en Y-Coördinaten toevoegen

Wanneer je klikt op Open Theme Table  (van een shapefile met stippen) verschijnt een database met wel heel weinig info daarin.

 
Wanneer je in deze database bij iedere stip de Amersfoortcoördinaten wilt toevoegen moet dat met een script.; script maken, compilen en runnen:
Klik in het project (*.apr) op Scripts | New.
Selecteer de tekst in het raam hier onderaan de pagina.
Kopieer dat stuk tekst en plak dat in het nieuwe script.
klik nu op compile 
Geef meteen het Script een naam zodat je weet waar het over gaat b.v.
Als je onderstaand scherm ziet; selecteer Script1
klik op PROJECT | RENAME
noem hem X en Y toevoegen
(andere naam mag natuurlijk ook)

Terug in de view selecteer je de shapefile waarbij je de Amersfoortcoördinaten wilt toevoegen.
Vervolgens klik je op WINDOWS | X EN Y TOEVOEGEN
Het script opent zich waarna je op het mannetje  moet klikken.
In de theme table zijn nu twee nieuwe kolommen aangemaakt.

X-coord en Y-coord
Omdat Map- en Distance Units zijn weergegeven in meters (zie VIEW | PROPORTIONS), is dat ook nu het geval.
X-coordinaat 204144.42357 heeft dus een (schijn)nauwkeurigheid tot op de honderste milimeter.

Wanneer je nieuwe stippen aan de shapefile toevoegd word niet de coördinaten toegevoegd. Hiervoor moet je steeds opnieuw het script laten runnen.
Let er op dat er geen stippen geselecteerd zijn tijdens het "runnen van het script" want dan worden alleen bij de geselecteerde stippen de coördinaten aangepast/toegevoegd; de rest veranderd in 0.
In dat geval No Panic; deselect de stippen en opnieuw runnen en alles is weer ok.

Script voor het toevoegen van X- en Y Amersfoortcoördinaten.

theView = av.GetActiveDoc
'must be global to work in Calc exp below
_theProjection = theView.GetProjection 
project_flag = _theProjection.IsNull.Not  'true if projected
theTheme = theView.GetActiveThemes.Get(0)

'Check if point or polygon theme
if (((theTheme.GetSrcName.GetSubName = "point") or 
    (theTheme.GetSrcName.GetSubName = "polygon")).Not) then
  MsgBox.Info("Active theme must be polygon or point theme","")
  return nil
end 

'get the theme table and current edit state

theFTab = theTheme.GetFTab
theFields = theFTab.GetFields
edit_state = theFTab.IsEditable

'make sure table is editable and that fields can be added
if (theFtab.CanEdit) then
  theFTab.SetEditable(true)
  if ((theFTab.CanAddFields).Not) then
    MsgBox.Info("Can't add fields to the table."+NL+"Check write permission.",
    "Can't add X,Y coordinates")
    return nil
  end
else
  MsgBox.Info("Can't modify the feature table."+NL+
  "Check write permission.","Can't add X,Y coordinates")

  return nil
end

'Check if fields named "X-coord" and Y-coord" exist
x_exists = (theFTab.FindField("X-coord") = NIL).Not
y_exists = (theFtab.FindField("Y-coord") = NIL).Not

if (x_exists or y_exists) then 
  if (MsgBox.YesNo("Overwrite existing fields?",
  "X-coord, Y-coord fields already exist", false)) then
    'if ok to overwrite, delete the fields as they may not be defined
    'as required by this script (eg., created from another script).
    if (x_exists) then

      theFTab.RemoveFields({theFTab.FindField("X-coord")})
    end
    if (y_exists) then
      theFTab.RemoveFields({theFTab.FindField("Y-coord")})
    end
  else
    return nil
  end  'if (MsgBox...)
end  'if

x = Field.Make ("X-coord",#FIELD_DECIMAL,18,5)
y = Field.Make ("Y-coord",#FIELD_DECIMAL,18,5)
theFTab.AddFields({x,y})

'Get point coordinates or polygon centroid coordinates
if (theTheme.GetSrcName.GetSubName = "point") then
  if (project_flag) then

    'Projection defined
    theFTab.Calculate("[Shape].ReturnProjected(_theProjection).GetX", x)
    theFTab.Calculate("[Shape].ReturnProjected(_theProjection).GetY", y)
  else
    'No projection defined
    theFTab.Calculate("[Shape].GetX", x)
    theFTab.Calculate("[Shape].GetY", y)
  end  'if
else  'polygon case
  if (project_flag) then
    theFTab.Calculate("[Shape].ReturnCenter.ReturnProjected(_theProjection).GetX", x)
    theFTab.Calculate("[Shape].ReturnCenter.ReturnProjected(_theProjection).GetY", y)

  else
    theFTab.Calculate("[Shape].ReturnCenter.GetX", x)
    theFTab.Calculate("[Shape].ReturnCenter.GetY", y)
  end  ' if
end

'Return editing state to pre-script running state
theFTab.SetEditable(edit_state)