How to change GIS coordinates via scripting?

Category:
Scripts
Summary

I have a list of all locations and corresponding GIS/GPS coordinates saved as csv file. Locations have already been implemented in StationWare and now we want to add GPS coordinates automatically.

Answer

The script includes following functionality:

  1. Accessing a csv file and searching for the corresponding locations in StationWare.
  2. After getting the location in StationWare change the value of the additional attributes assigned as GIS parameters.
  3. Update the location.

Make sure that additional attributes are defined and assigned as GIS parameters to the corresponding location type. In the following example the GIS coordinates are assigned to the location type "Substation".

  1. Define an additional attribute container "GIS" with the additional attributes that represent the longitude and latitude parameters.
  2. Go to the Administration Page and navigate to the Location Type "Substation".
  3. Select the GIS tab, enable the GIS feature and select the additional attributes defining the longitude and latitude coordinates. It is also possible to define filters in the GIS tab that can be used in the map representation of the locations. More information about the filter configuration can be found in the User Manual.

Starting with the script:

  • The first step is to access the csv file that contains all data. This procedure is described more in detail in the FAQ "Is it possible to access and use a csv files via Python scripts?"
  • Then search the location getting from the csv file in StationWare. Here we assume that this matching is done via the naming (compare the names).

So loop through the csv file row by row and compare the location name of the row with the location names in StationWare also getting by looping through the StationWare hierarchy. After getting the matched location access the details and change the CustomAttributes.

if row[0]==Location.Name:
  subStationDetails=Service.LocationGetDetails(objSubstation.Id)
allSubStationAttributes=subStationDetails.CustomAttributes
for eachSubStationAttribute in allSubStationAttributes:
if eachSubStationAttribute.Name=="Latitude_Northing":
eachSubStationAttribute.Value=row[position of the latitude]
Service.LocationUpdate(subStationDetails.Info.Id, subStationDetails.Info.Name,subStationDetails.Info.Description, System.Array[ICustomAttribute]([eachSubStationAttribute]))
if eachSubStationAttribute.Name=="Longitude_Easting":
eachSubStationAttribute.Value=row[position of the longitude]
Service.LocationUpdate(subStationDetails.Info.Id, subStationDetails.Info.Name,subStationDetails.Info.Description, System.Array[ICustomAttribute]([eachSubStationAttribute]))
Back