Search This Blog

Tuesday, July 23, 2013

PowerShell–batch search/replace in filenames

I needed to rename a set of files , keeping the original name but adding a suffix. Powershell can do this quite easily using the following:


PS C:\data\photos> Dir | Rename-Item -NewName { $ -replace ".jpg","_840.jpg" }


this will take all .jpg files in the folder and change the name to include an _840.jpg… which in my case was the vertical dimensions of the image set.

Thursday, July 11, 2013

Powershell – how to renumber files sequentially

Sourced from

here is how to use powershell to renumber files sequentially.. be careful not to renumber files you don’t want renumbered!! Best to move all the files to a new temp folder to do this….

1) copy paste as single line into powershell

function Rename-Bulk($prefix){$files = Get-ChildItem;$id = 1;$files | foreach { Rename-Item -Path $_.fullname -NewName ( $prefix + ((($id++).tostring()).padleft(($files.count.tostring()).length) -replace ' ','0' ) + $_.extension) }}

2) CD to folder in powershell

3)  Rename-Bulk('img')   where img is the prefix for all output with sequential number following

Powershell – Merging files to then load into PostgreSQL

Merging a set of files into one large file

Start PowerShell then use CD to move to the Directory with the files to merge
Get-Content .\*.txt | Out-File c:\temp\merged.txt
This will find all .txt (text) files and merge into a single document in c:\temp folder.

However I found the output was in Unicode format… and to then load this into PostgreSQL
So I  then loaded and saved the file using textpad in UTF-8 format
then create the table in PG….
create table houseprice03_msoa_ew
(la_code text,
la_name text,
msoa_code text,
msoa_name text,
price_all_dwellings_2percentile integer,
price_all_dwellings_lower_quartile integer,
price_all_dwellings__median integer,
price_all_dwellings__upper_quartile integer,
price_all_dwellings_98precentilentile integer,
price_all_dwellings__mean integer

and then copy the data into that table…

COPY houseprice03_msoa_ew FROM 'C:\Data\GIS\MartynDorey\CensusData\2003 Houseprices\houseprice2003_G080309_2288_GeoPolicy_MSOA.csv' DELIMITER ',' CSV HEADER;

OSM in 3D – F4

I read a Tweet about a new 3D visualisation of OSM using a new rendering engine.

It includes some animation (eg water surfaces, and fountains)…

Overall the graphic is pretty good.. but the actual data is still poor.

It assumes a flat world with no terrain, and building heights are somewhat arbitrary.

Here’s a view of Edinburgh (Scotland).. looking along Princes Street with Edinburgh Castle on the right, and Calton Hill in the distance. In reality the Castle is way up high on a volcanic plug (hill)… and the gardens infront of it are in a valley.



Here’s another view…. this time looking at the Castle from above East Princes Street Gardens (near The Mound)




Here’s a quick comparison of the first image from F4 and Google Earth… as you can see GE includes the topography.