From Cory Eicher

Friday, June 09, 2006

How to scale a dataset

Problem

A colleague of mine recently asked me how to scale a dataset. He had the requirement to make an entire line or polygon dataset a factor larger or smaller. e.g. scale the dataset by a factor of 5.

Mathematical Solution

I knew that matrix algebra might help us here. I did some web research and confirmed that you can scale a 2d point by taking a matrix that looks like this (x and y are the scale factors in the x and y dimensions)...

x 0 0
0 y 0
0 0 1

...and multiplying by your point, which looks like this...

x1
y1
1

Here are some good links on matrix algebra:

http://easyweb.easynet.co.uk/~mrmeanie/matrix/matrices.htm (background)

http://www.engineering.usu.edu/cee/faculty/gurro/Classes/Classes_Spring2002/VBGradClass/VBGradClass.htm (includes vb code sample to multiply two matrices)

Coding a Solution

I coded a solution in VBA to do this scaling on a shapefile. My goal was to mimic the 'dataset scaling' function described above, and that I'm also told that Manifold GIS provides. I didn't end up using the vb code mentioned above to multiply two matrices, but I did use matrix algebra indirectly.

A few important observations:

1) I found it necessary to first introduce a false origin at the lower left of the original dataset before performing the scaling. Easy way to do this, determine lower left coordinates and subtract from all point coordinates.

2) Scaling was straightforward. Just multiple all x coords by x scale factor and all y coords by y scale factor. In my case, the x and y scale factors were equal.

3) Now my dataset is larger, but where is it? Well, it's anchored to the lower left of the orginal dataset. The Manifold functionality centers the new dataset on the old. So, based on the x and y extents of the orig and scaled dataset, I calculated the distance that I needed to move my scaled dataset "down and to the left" (to use the a technical term ; ), then I achieved this using simple subraction on my x and y coordinates.

4) Finally, don't forget to "undo" the false origin set in step 1). Do this by adding back in the dataset lower left x and y coordinates that were subtracted in step 1).

There you have it, how to scale a dataset and recenter it on the original dataset.

VBA code is here.

News

I also have some professional news. I've accepted a position to work for ESRI Switzerland in Zurich. I'll be working on projects there mostly related to cartography and ArcGIS. I'm very excited about the position and the move. This means that I'll be getting out of the full-time independent consultant business, but I hope to continue with this blog from my new "position", pun intended.

Talk to you soon,

-Cory

2 Comments:

Dan Haug said...

Hey Cory,
Congrats on your change of position! Too bad you didn't get to go in time for the World Cup.
-Dan

11:18 PM

 
Anonymous said...

This post has been removed by a blog administrator.

8:40 PM

 

Post a Comment

<< Home