LibreOffice Calc

From OpenStreetMap Wiki
Jump to navigation Jump to search

LibreOffice Calc is the spread sheet program of Libre Office.

Spreadsheets can be used to organize worklists, ...

Macros for LibreOffice Calc

The picture shows a list of wikidata items of rivers with it's coordinates

If you have a text list of osm items or coordinates you can use macros to call josm, the osm homepage or other services to get more informations. Macros can be bind to buttons in your toolbar.

Just select a cell with a number and jump to the tool or service you like.

Call a Coordinate in Josm

If you have a coord list in two rows of a table (lat lon) you can select the left cell and call this macro on it.

It will:

  • change the cell colour to yellow (mark a visited cell)
  • calculate a bbox for josm load_and_zoom command
  • calls the josm remote api url with curl (a command line tool on unix)
sub josm_coord
	'call coord in josm with load and zoom
	oDoc = thisComponent
	oCell = oDoc.getCurrentSelection()
	oCell.CellBackColor = RGB (255, 255, 127)
	oSheet = oDoc.getSheets.getByIndex(oCell.CellAddress.Sheet)
	iCol = oCell.CellAddress.Column
	iRow = oCell.CellAddress.Row
	OCell2 = oSheet.getCellByPosition(iCol+1,iRow)
	d = 0.005
	if HasUnoInterfaces(oCell, "com.sun.star.table.XCell") then
		baseurl =  "http://localhost:8111/load_and_zoom?"
		bbox1 = "left=" + (oCell2.value - d) + "&right=" + (oCell2.value + d) 
		bbox2 = "&top=" + (oCell.value + d) + "&bottom=" + (oCell.value - d)
		fullurl = baseurl + bbox1 + bbox2
		fullurl = join(split(fullurl,","),".")
		shell("curl " + fullurl)
	end if
end sub

Note: There's an extra line to replace the decimal ',' with '.' for josm.

Load a relation with josm

If you have a list of relations you can walk through it.

It will:

  • change the cell colour to yellow (mark a visited cell)
  • load the full relation to josm
  • select the relation and zoom to it
sub josm_load
	' load a relation in josm
	oDoc = thisComponent
	oCell=oDoc.getCurrentSelection()
	oCell.CellBackColor = RGB (255, 255, 127)
	baseurl =  "http://localhost:8111/"
	api = "https://www.openstreetmap.org/api/0.6/relation/"
	if HasUnoInterfaces(oCell, "com.sun.star.table.XCell") then
		' load relation
		fullurl =  baseurl + "import?url=" + api + oCell.value + "/full"
		shell("curl " + fullurl)
		'select relation
		fullurl = baseurl + "zoom?left=8.302&right=8.303&top=47.001&bottom=47.000&select=relation" + oCell.value
		shell("curl " + fullurl)
	end if
end sub

Open OpenStreetMap Page with a relation

Just create an url and open it with firefox.

sub browse_relation
	' browse the relation with the id of the selected cell
	oDoc = thisComponent
	oCell=oDoc.getCurrentSelection()
	if HasUnoInterfaces(oCell, "com.sun.star.table.XCell") then
		url =  "http://www.openstreetmap.org/browse/relation/" + oCell.value
		shell("/usr/bin/firefox " + url)
	end if
end sub

Open the history of a relation

sub browse_history
	' browse the relation with the id of the selected cell
	oDoc = thisComponent
	oCell = oDoc.getCurrentSelection()
	if HasUnoInterfaces(oCell, "com.sun.star.table.XCell") then
		url =  "http://www.openstreetmap.org/browse/relation/" + oCell.value + "/history"
		shell("/usr/bin/firefox " + url)
	end if
end sub

Jump to a wikidata item

sub wikidata
	'call wikidata with the cell content
	oDoc = thisComponent
	oCell = oDoc.getCurrentSelection()
	oCell.CellBackColor = RGB (255, 255, 127)
	if HasUnoInterfaces(oCell, "com.sun.star.table.XCell") then
		url =  "https://www.wikidata.org/wiki/Q" + oCell.value
		shell("/usr/bin/firefox " + url)
	end if
end sub