Noen dager i Bucureşti

Jeg fikk det uungåelige spørsmålet i første møte med noen lokale: “Hva synes du om Bucharest?” Jeg valgte å være diplomatisk og svarte noe om at det er en storby med storbyens gode og dårlige sider – men gled nok litt mye over på de dårlige sidene. Etter noen kvelder med lange spaserturer gjennom deler av byen, glir de dårlige sidene med byen mer og mer bort. For all del, man ser mennesker i Bucureşti som helt klart sliter med livet, men med våren, eller det har vel etter norsk definisjon nesten blitt tidlig sommer her nede, blir det lett å glemme det som er vanskelig. Byen dufter av blomstrende trær og nyslått gress, kastanjene blomstrer i Calea 13 Septembrie og selv løshundene, det vil si, i Bucharest heter det ikke løshunder men felleshunder, ser ut for å nyte livet. En av dem følger etter en som går langs fortauet, når vi møtes synes den tydeligvis jeg er mer spennende, så den vender om og traver noen skritt etter meg i noen kvartaler. Ikke noe agressivitet, ikke noe tigging, kanskje den bare ombestemte seg og vi tilfeldigvis skulle samme vei til samme tid, kanskje den synes jeg så ut som om jeg trengte litt følge, eller kanskje den hadde et håp om at jeg hadde noe mat den kunne få lurt av meg. I nærheten av folkepalasset gikk våre veier hver sin vei.

I gamlebyen, de få kvartalene som har overlevd både 2. verdenskrig, flere jordskjelv og ikke minst Chauchescos gigantomane planer, er mange av tverrgatene gravd opp. Et byfornyelsesprosjekt ble satt i gang for en tid siden, men med manglende penger, uenighet om kontrakter og arkeologiske funn, har prosjektet kjørt seg fast. Langs gater med hardtrampet jorddekke og en slags plankebrygge for fotgjengerene er mange av husene i god stand, mens andre er i forskjellige stadier av forfall. For noen av disse siste ser det ut som om noen har begynt å ta tak, mens andre står tilsynelatend urørt av annet enn tidens tann – eventuelt, å dømme etter lys og lyder hadde noen av dem allikevel innbyggere. Fritt valg mellom overfylte utesteder i de ferdige gatene eller en ‘brygge’ i anleggsområdet med nok folk til at man ikke følte seg ensom, men samtidig ikke hadde vansker med å finne et bord.

Og med lokale kontakter dukker det også opp små paradiser som ikke ennå finnes i guidebøker eller på nettsteder. Litt i utkanten av sentrum er et lite pensjonat med kanskje 10 rom i to bygg, en hage mellom med sitteplasser og et lite svømmebasseng. Et sånt sted hvor man blir med ut for å ta en titt på hagen. Der sitter innehaveren sammen med en venn. De slår rett over i engelsk og man blir invitert til å ta plass og kunne nesten blitt sittende til solen kom opp igjen og nattergalen etter sigende skulle gi lyd fra seg. Litt kjølig å sitte ute i t-skjorte, men ikke værre enn at man overhodet ikke vurderer å gå inn.

Men så var det tiggerene da. Mange som minner om de i Oslo, og det er et fenomen rumenerene er kjent med og bekymret over. En eldre mann klare vel å beholde verdigheten der han gikk mellom biler på rødt lys og solgte pakker med papirlommetørklær, og i den andre enden, alle de som gikk eller satt med små barn på armen eller på fanget. Alltid sovende barn. Er de dopet på noe? Hvor mange av disse er det som virkelig er ute med et ønske om at barna skal få det bedre enn dem, og hvor mange har barna bare et middel for å samle penger? Så de så kan settes igjen et eller et annet sted og erstattes med en ny toåring når de har gått over bærbar størrelse.

Men som turist ser man ofte ikke så mye lengere enn sin egen fasinasjon over det ukjente – og gleden når det ukjente går over til å bli kjent. Når man begynner å forstå retningene og få tak på referansepunktene i den byen som nylig var helt ukjent. Når man vet om et sted det går an å slå seg ned og drikke en øl og vet hvor det spilles god jazz. Når man vet at neste gang jeg kommer tilbake, da vet jeg hvor jeg skal bo.

Posted in Diverse | Comments Off on Noen dager i Bucureşti

Vår korte tid som betalende riks-tv kunde

Sent i februar fikk vi en telefon fra riks-tv som lurte på om vi ville ha flere kanaler. Vi har nå en gang reservert oss mot telefonsalg, så jeg vet ikke hvilket smutthull de snek seg gjennom, men enden på visa ble at vi bestilte abbonement på TV2 og disneychannel. Stor glede hos barna, men når vi prøvde å se på kanalene, fikk vi fortsatt beskjed om at de var stengt. Vi tenkte ting kanskje tok tid, eller at vi måtte få tilsendt noe, men ingenting skjedde, før vi fikk en regning tidlig i mars, med betaling tilbake til dagen vi bestilte abbonementet. Jeg sendte da en mail til dem og sa at vi fortsatt ikke tok inn kanalene og at det ikke i noe tilfelle var aktuelt å betale for den tiden vi ikke hadde sett dem. Ingen respons fra riks-tv – før vi fikk en purring. Da ble jeg sint og ringte kundeservice og forklarte hvorfor jeg ikke aktet å betale regningen og at jeg anså kundeforholdet som avsluttet. “Et øyeblikk” sa kundebehandleren – så ble det stille i fem minutter – til jeg la på. En rimelig irritert mail til rikstv og to dager senere fikk jeg endelig en bekreftelse på at abbonementet var sagt opp og saldoen min var i null. Jeg kan ikke se at jeg betalte noe ekstra for telefon til kundeservice, det skal de ha, men løftet deres om at “Vi vil at du skal bli en fornøyd kunde” … vel i forhold til risk-tv er jeg ikke fornøyd i det hele tatt og vil vel tenke meg om et par ganger før jeg vurderer å bli kunde igjen.

Posted in Diverse | Comments Off on Vår korte tid som betalende riks-tv kunde

Password problem on Debian

After setting up a fresh debian system, I was not able to change or set any passwords on it.
Whatever I tried I got the error messages

passwd: System error
passwd: password unchanged

I came across a few people with the same problems and some hints on the debian user list but not an explicite solution. But the hints there and the fact that I got the line

passwd[10717]: pam_winbind(passwd:chauthtok): valid_user: wbcGetpwnam gave WBC_ERR_DOMAIN_NOT_FOUND

told me to look for windows-like things in /etc/pam.d/common-password and there it was the line

password        requisite                       pam_winbind.so

Since I do not connect to any windows domain server I commented out that line and things worked fine after that.

Posted in Diverse | Comments Off on Password problem on Debian

Upgrading bios when running Linux…

I would like to upgrade the bios of a HP pavillion of mine that PC is running Linux. The download was an exe-file, where the data parts were so well hidden that no decompression program I have was able to find it. I tried to run it on another PC I have with XP, but then the program claimed it was going to upgrade the bios on that PC… I did not think putting the bios image from an old desktop HP on a new portable Dell would be a good idea. But then, wine to the rescue.

Install wine on the PC in question (or any other linux PC) and run the bios updater there, just let it try to upgrade the bios, then it will crash, but before that, it has unpacked what was needed. I found all the files in ~/.wine/c_drive/windows/temp/pft1a08.tmp (guess the last directory will be different, but with a newly installed wine the temp dir was pretty empty.)

Inside that directory resided

347.rom CopyDisk.exe install.exe sp26713.img sp26713.iso sp26713.rtf WBDED44I.DLL wilx44i.dll WinFlash.exe WINFLASH.HLP WinFlash.sys

I guess 347.rom is the update image, which I might be possible to use through flashrom or something similiar, but I just burned the sp26713.iso-file to a cdrom, booted from that and had the bios upgraded 3 minutes later. If I had had some floppy disks around, I could have tried the img-file. Felt as a bit of waste to burn 1 MB on a CD for a one-off use…

But the PC was neither able to boot from USB after the upgrade which was the reason for starting it all … :-p

Posted in Diverse | Comments Off on Upgrading bios when running Linux…

Convert vmap0 layers into shapefiles

The vmap0 dataset is a slightly dated, but anyhow often usable dataset of maps of all of the world in scale 1:1 000 000. It can be downloaded at e.g. mapability.com. The problem shows up as soon as one tries to use the dataset as it is in a quite unique format. Luckily, the format is known by ogr, so the data can be converted to something usable. When downloaded and unzipped, the dataset contains a lot of layers with various types of information. To get an overview, use ogrinfo:

ogrinfo -ro -summary gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia

gltp is the protocol, vrf is the format. I unzipped my dataset (v0eur.tar.gz) into c:\osgeo4w\share\maps and the catalog structure below that point was made. The ogrinfo should list approximately 60 data sets. Each of those may be converted using ogr2ogr like

ogr2ogr landicea.shp gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia landicea@phys(*)_area landicea 

To repeat this 60 times is a bit tedious, so let’s use the information from ogrinfo which makes a line like

33: landicea@phys(*)_area (Polygon)

for each dataset.

running this through the regexp

/[0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)/

gives out the the two strings we needs for ogr2ogr. (The regexp throws away any number of numbers followed by a colon and space then captures the following string, the part of that string which is before an @-sign and the part of the string between the 2 and the next opening paranthesis then throws away a space and something inside a pair of parantesies). if we use sed to run this, the command

sed 's![0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)!ogr2ogr v0\2\3.shp gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia \1 \2!' < vmap0layers 

will return the ogr2ogr command lines needed to do the conversion to shape files.

So let's put it all together:

set uri=gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia
ogrinfo -ro -summary %uri% > vmap0layers
sed 's![0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)!ogr2ogr v0\2\3.shp %uri% \1 \2!' < vmap0layers  > converts.bat

(I was using ! to mark the regexp to avoid problems with the slashes in the directory) The script above was tested in cmd and 4nt on windows xp. a slightly changed version should work in /bin/sh or compatibles;

export uri=gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia
ogrinfo -ro -summary $uri > vmap0layers
sed 's![0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)!ogr2ogr v0\2\3.shp  $uri \1 \2!' < vmap0layers  > converts.bat

Just remember to adjust the uri variable to whereever your maps are stored.

Thanks to grymoire for some reminders on sed and to blacksworld.net for explanation to extract the layers one by one.

sed (stream editor) is a standard unix / linux utility. It can be installed on windows as a part of the osgeo4w suite.

Posted in Diverse, mapserver | Comments Off on Convert vmap0 layers into shapefiles

Hiding the map= parameter from a map server application

In the mapserver documentation, one is told to use a cgi-wrapper script to hide the map= parameter. Then there is shown a script to use on ‘any system having a /bin/sh’ I tried to rewrite that as a php-script to use under windows, but that did not work, so apaches mod_rewrite to the rescue in four small steps:

  1. make sure the mod_rewrite is enabled in httpd.conf. Usually it is commented out by default, if necessary remove the comment sign.
  2. Enable mod_rewrite for the actual document root. I am using virtual servers and added the following lines in the actual <VirtualHost > section:

    <Directory “c:\documents and settings\vserver\radioecology”>
    Options FollowSymLinks
    AllowOverride All
    </Directory>

  3. Restart apache
  4. make a .htaccess file in the actual directory:

    RewriteEngine on
    RewriteRule ^wmsmap?(.*) /cgi-bin/mapserv.exe?map=/documents+and+settings/vserver/radioecology/mobilweb/mobilwms.map&$1

    (Everything following RewriteRule must be on one line. in this case, the map file I want to pull in is “/documents+and+settings/vserver/radioecology/mobilweb/mobilwms.map” adjust as needed for your application.)

    The rewriteRule says: given a webpage starting with wmsmap, pick out the query parameters, make a new page request starting with /cgi-bin/mapserv.exe?map=(…)? and add on whatever was the query parameter in the original page request. Quite simple when one just knows how to do it.

Posted in Diverse, mapserver | Comments Off on Hiding the map= parameter from a map server application

How to make a bar graph with a split Y axis in R

There is a function, gap.barplot for doing that in the plotrix package, but I was not happy with the way the result looked, so I started out making my own way using subplot in the TeachingDemos library. I have gutted the two functions I actually used from TeachingDemos to just get the functionality I need for this plot:


# dataset:
data=data.frame(R=c(120,11),U=c(32,1),C=c(12,3),G=c(4,0),J=c(6,0),I=c(3,2),N=c(4,0))
# I want to plot the lower values up to 55, then a split to 95 for the
# last top. This should make it clear which is the highest, without
# drowning out the other data.

# I want the split to be approx 5% of the scale,

# as I am to plot the ranges 0 - 55 and 95 - 140, in total 10 decades, 
lower=c(0,55)
upper=c(95,140)
# This is 10 decades. I multiply that with 2 and add 5% and get 21 units on the outer
# Y axis:
y_outer=21

lowspan=c(0,11)
topspan=c(lowspan[2]+1,21)

ylabel="Number of something"
legendtext=c('Group 1','Group 2')


cnvrt.coords <-function(x,y=NULL){
# Stolen from the teachingDemos library, simplified for this use case
	xy <- xy.coords(x,y, recycle=TRUE)
	cusr <- par('usr')
	cplt <- par('plt')	
	plt <- list()
	plt$x <- (xy$x-cusr[1])/(cusr[2]-cusr[1])
	plt$y <- (xy$y-cusr[3])/(cusr[4]-cusr[3])
	fig <- list()
	fig$x <- plt$x*(cplt[2]-cplt[1])+cplt[1]
	fig$y <- plt$y*(cplt[4]-cplt[3])+cplt[3]
	return( list(fig=fig) )
}

subplot <- function(fun, x, y=NULL){
# Stolen from the teachingDemos library, simplified for this use case
	old.par <- par(no.readonly=TRUE)
	on.exit(par(old.par))
	xy <- xy.coords(x,y)
	xy <- cnvrt.coords(xy)$fig
	par(plt=c(xy$x,xy$y), new=TRUE)
	fun
	tmp.par <- par(no.readonly=TRUE)
	return(invisible(tmp.par))
}

##############################################
#
#
# The main program starts here:
#
#

# Setting up an outer wireframe for the plots. 
plot(c(0,1),c(0,y_outer),type='n',axes=FALSE,ylab=ylabel,xlab='')
# Plotting the lower range in the lower 11/21 of the plot.
# xpd=FALSE to clip the bars
subplot(barplot(as.matrix(data),col=heat.colors(2),ylim=lower,xpd=FALSE,las=3),x=c(0,1),y=lowspan)



# Plotting the upper range in the upper 9/21 of the plot, 1/21 left to
# the split. Again xpd=FALSE, names.arg is set up to avoid having
# the names plotted here, must be some easier way to do this but
# this works
subplot(barplot(as.matrix(data),col=heat.colors(2),ylim=upper,xpd=FALSE,names.arg=vector(mode="character",length=length(data))), x=c(0,1),y=topspan)

# Legend. An annoiance is that the colors comes in the opposite
# order than in the plot.
legend("topright",legendtext,fill=heat.colors(2))

# so far so good. (Just run the upper part to see the result so far)
# Just want to make the ends of the axes a bit nicer.
# All the following plots are in units of the outer coordinate system

lowertop=lowspan[2]+0.1     # Where to end the lower axis
breakheight=0.5   # Height of the break
upperbot=lowertop+breakheight # Where to start the upper axes
markerheight=0.4 # Heightdifference for the break markers
markerwidth=.04  # With of the break markers

# Draw the break markers:
lines(c(0,0),c(1,lowertop))
lines(c(markerwidth/-2,markerwidth/2),c(lowertop-markerheight/2,lowertop+markerheight/2))
lines(c(0,0),c(upperbot,14))
lines(c(markerwidth/-2,markerwidth/2),c(upperbot-markerheight/2,upperbot+markerheight/2))



Or download the barplot with split – R code

Bar plot with break

R is a free software environment for statistical computing and graphics. For more information and download, see http://www.r-project.org/

Posted in Data, R | Comments Off on How to make a bar graph with a split Y axis in R

Hva en direktør tør

Noen av oss vet at vi ikke kan få alt vi ønsker oss. Noen av oss vet at det er ekstremt patetisk å skylde på andre for feil vi helt klart er skyld i selv. Noen av oss har en liten ide om at det kan være gunstig å ikke makse ut alle kreditter i gode tider. Men, dette er tydeligvis ikke noen kunnskap man trenger for å være direktør. Konsekvensene om man skal ta ham alvorlig er jo egentlig enda værre. Han mener i så fall at han kan være direktør med 100000 kr i måneden i lønn på et tidspunkt han hadde så dårlig styring på egen økonomi at alle andre enn ham selv burde forstått at han ikke burde få et lån på 1.9 millioner. Eventuelt skulle jeg gjerne likt å hørt levenet han hadde satt i gang om dnbnor hadde nektet ham lånet i 2008 før finanskrisen slo inn.

Posted in Diverse | Comments Off on Hva en direktør tør

Setting up a mysql database for spatial data

I would prefer to use postgis, but have to resign to mysql. I want to create a table with spatial information and be able to access it from mapserver. As I am going to store a lot of datapoints, they may be stored just as two columns with x and y values, but as the dataset grows, that starts to be a bit slow.

I started of with a table with more than 20 columns holding point measurements and a lot of metadata related to those measurements. No, it is not practical to split that table up. I tried to add a point column to that table

alter table mobile_rawdata add column coord point

and then I copied the coordinates into that column

update rawdata set coord=point(lon,lat) where not lat is null;

again fine and dandy, but when I tried to put a spatial index on that column, I was told that that was not possible for a column with null values.

So I made a new table

create table mobile_spatial(
OGR_FID serial primary key,
SHAPE geometry not null,
rawdataid integer not null,
addtime timestamp default current_timestamp);

note that the shape column is to be of type geometry, if it is set to another spatial type, ogr will not recognice it. The column names OGR_FID and SHAPE are used as those are default values for ogr. Rawdataid pointing to the id of the old mobile_rawdata table.

Then I tested it with

ogrinfo -so MySQL:radioecology_9,user=user,password=pass mobile_spatial

but ogrinfo still did not understand that this was supposed to be a table with geometry. Reading up a bit more, I found that I needed two more tables in the database: SPATIAL_REF_SYS to store the, well, spatial reference systems and geometry_columns to store information on what kind of geometry the tables had.

I didn’t manage to find a description for those tables but according to gdal.org they will be created when a shape file is imported using ogr2ogr. Trying to import a shape file, I had them created:

CREATE TABLE geometry_columns (
`F_TABLE_CATALOG` varchar(256) DEFAULT NULL,
`F_TABLE_SCHEMA` varchar(256) DEFAULT NULL,
`F_TABLE_NAME` varchar(256) NOT NULL,
`F_GEOMETRY_COLUMN` varchar(256) NOT NULL,
`COORD_DIMENSION` int(11) DEFAULT NULL,
`SRID` int(11) DEFAULT NULL,
`TYPE` varchar(256) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

and

CREATE TABLE spatial_ref_sys (
`SRID` int(11) NOT NULL,
`AUTH_NAME` varchar(256) DEFAULT NULL,
`AUTH_SRID` int(11) DEFAULT NULL,
`SRTEXT` varchar(2048) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

the important column in the latter is the SRTEXT, eg for standard WGS84 lat lon, that is

GEOGCS[“WGS 84”, DATUM[“WGS_1984”,SPHEROID[“WGS 84”, 6378137, 298.257223563, AUTHORITY[“EPSG”,”7030″]], AUTHORITY[“EPSG”,”6326″]], PRIMEM[“Greenwich”,0,AUTHORITY[“EPSG”,”8901″]], UNIT[“degree”, 0.01745329251994328,
AUTHORITY[“EPSG”,”9122″]], AUTHORITY[“EPSG”,”4326″]]

the SRID field is to be pointed to by the SRID in the geometry_column table.

The geometry_column table has to have the following values:
F_TABLE_NAME : Name of table
F_GEOMETRY_COLUMN: Column in table that holds the geometrical information
COORD_DIMENTION: Dimentionallity of dataset, usually 2
SRID : pointer to the spatial_ref_sys table
TYPE: Type of geometry in the geometry colum, e.g. POINT or POLYGON
the last to columns may be blank.

Posted in mapserver | Comments Off on Setting up a mysql database for spatial data

Query a layer in mapscript php

When learning to use mapserver and mapscript, the first steps have been to display, zoom and pan. Zooming and panning is quite easy, it is just a line like

$map->zoompoint($zoomfactor,$clickpoint,$map->width,$map->height,$mapextent);
where $map is a mapboject, $zoomfactor is a number telling how many times to zoom in or out, positive for zoom in, negative for zoom out, $clickpoint is a pointobject of the location of the click in image coordinates.

Then enter the urge to do a query as well – but not much luck. I reused the same $clickpoint and tried
$map->queryByPoint($clickpoint, MS_SINGLE, 1);
(after doing some adjustments in the map file) but to no luck. Digging into the kmap source code, I understood after a while that the coordinates needed to be in map coordinates and not image coordinates. That is just a simple linear transformation, just with the little snag that the y-coordinates go the opposite direction in the image than in the map. Kmap called the transformation function twice, once for each koordinate, I preferred to make one function for the two-dimentional transformation:

function pix2geo($mapx,$mapy,$minx,$miny,$maxx,$maxy,$sizex,$sizey)
					 
// $mapx and $mapy: image coordinates of point of interest 				 
// $minx, $maxx,$miny, $maxy map extent in map coordinates
// $sizex and $sizey, width and height of image
{	
	list($miny,$maxy)=array($maxy,$miny); 
	// swaps miny and max y since the coordinates acsends upwards in the map, downwards in the picture
	$geopoint=array();
	foreach( array('x','y') as $dim){
		$p=array();
		foreach(array('map','min','max','size') as $par){
			$name="$par$dim";
			$p[$par]=$$name;
		}
		$geowidth=$p['max']-$p['min'];
		$geopoint[$dim]=$p['map']/$p['size']*$geowidth+$p['min'];
	}
	return(array($geopoint['x'],$geopoint['y']));
}

This can be used like:

list($geoX,$geoY)=pix2geo($_GET['MAP_x']*1,$_GET['MAP_y']*1,$minx,$miny,$maxx,$maxy,$map->width,$map->height);
$geopoint=ms_newpointObj();
$geopoint->setXY( $geoX,$geoY);
$map->queryByPoint($geopoint, MS_SINGLE, 1);

followed by getNumResults for each layer, getResult, getShape and finally getting the relevant values out of the shape.

I have to admit, I simplified things a bit at the beginning. The point needs to be in the projection of the queried data set. As I have the queried dataset in geographical projection and want to have the map in utm, I still have a problem there..

Posted in mapserver | Comments Off on Query a layer in mapscript php